@@ -5,21 +5,22 @@ use async_std::task::{self};
5
5
use base_db:: { Change , Document , DocumentChange , PgLspPath , StatementRef } ;
6
6
use crossbeam_channel:: { unbounded, Receiver , Sender } ;
7
7
use ide:: IDE ;
8
- use lsp_server:: { Connection , Message , Notification } ;
8
+ use lsp_server:: { Connection , Message , Notification , RequestId } ;
9
9
use lsp_types:: {
10
10
notification:: {
11
11
DidChangeConfiguration , DidChangeTextDocument , DidCloseTextDocument , DidOpenTextDocument ,
12
12
DidSaveTextDocument , LogMessage , Notification as _, PublishDiagnostics , ShowMessage ,
13
13
} ,
14
- request:: { RegisterCapability , WorkspaceConfiguration } ,
14
+ request:: { HoverRequest , RegisterCapability , WorkspaceConfiguration } ,
15
15
ConfigurationItem , ConfigurationParams , DidChangeConfigurationParams ,
16
16
DidChangeTextDocumentParams , DidCloseTextDocumentParams , DidOpenTextDocumentParams ,
17
- DidSaveTextDocumentParams , InitializeParams , InitializeResult , LogMessageParams ,
18
- PublishDiagnosticsParams , Registration , RegistrationParams , SaveOptions , ServerCapabilities ,
19
- ServerInfo , ShowMessageParams , TextDocumentSyncCapability , TextDocumentSyncKind ,
20
- TextDocumentSyncOptions , TextDocumentSyncSaveOptions ,
17
+ DidSaveTextDocumentParams , HoverParams , HoverProviderCapability , InitializeParams ,
18
+ InitializeResult , LogMessageParams , PublishDiagnosticsParams , Registration , RegistrationParams ,
19
+ SaveOptions , ServerCapabilities , ServerInfo , ShowMessageParams , TextDocumentSyncCapability ,
20
+ TextDocumentSyncKind , TextDocumentSyncOptions , TextDocumentSyncSaveOptions ,
21
21
} ;
22
22
use schema_cache:: SchemaCache ;
23
+ use serde:: Serialize ;
23
24
use std:: sync:: Arc ;
24
25
use threadpool:: ThreadPool ;
25
26
use tracing:: { event, instrument, Level } ;
@@ -65,7 +66,7 @@ pub struct Server {
65
66
internal_rx : Receiver < InternalMessage > ,
66
67
pool : ThreadPool ,
67
68
client_flags : Arc < ClientFlags > ,
68
- ide : IDE ,
69
+ ide : Arc < IDE > ,
69
70
db_conn : Option < DbConnection > ,
70
71
}
71
72
@@ -192,6 +193,7 @@ impl Server {
192
193
} ) ) ,
193
194
} ,
194
195
) ) ,
196
+ hover_provider : Some ( HoverProviderCapability :: Simple ( true ) ) ,
195
197
..ServerCapabilities :: default ( )
196
198
}
197
199
}
@@ -302,6 +304,28 @@ impl Server {
302
304
Ok ( ( ) )
303
305
}
304
306
307
+ fn hover ( & mut self , id : RequestId , mut params : HoverParams ) -> anyhow:: Result < ( ) > {
308
+ normalize_uri ( & mut params. text_document_position_params . text_document . uri ) ;
309
+
310
+ self . run_query ( id, move |ide| ide. hover ( params) ) ;
311
+
312
+ Ok ( ( ) )
313
+ }
314
+
315
+ fn run_query < R , Q > ( & self , id : RequestId , query : Q )
316
+ where
317
+ R : Serialize ,
318
+ Q : FnOnce ( & IDE ) -> R + Send + ' static ,
319
+ {
320
+ let client = self . client . clone ( ) ;
321
+ let ide = Arc :: clone ( & self . ide ) ;
322
+
323
+ self . pool . execute ( move || {
324
+ let response = lsp_server:: Response :: new_ok ( id, query ( & ide) ) ;
325
+ client. send_response ( response) . unwrap ( ) ;
326
+ } ) ;
327
+ }
328
+
305
329
#[ instrument( skip( self ) , name = "pglsp/refresh_schema_cache" ) ]
306
330
fn refresh_schema_cache ( & self ) {
307
331
if self . db_conn . is_none ( ) {
@@ -350,6 +374,7 @@ impl Server {
350
374
}
351
375
352
376
if let Some ( response) = dispatch:: RequestDispatcher :: new( request)
377
+ . on:: <HoverRequest , _>( |id, params| self . hover( id, params) ) ?
353
378
. default ( )
354
379
{
355
380
self . client. send_response( response) ?;
0 commit comments