@@ -6,16 +6,18 @@ use std::{
66use tower_lsp:: {
77 Client , LanguageServer ,
88 lsp_types:: {
9- CompletionOptions , HoverProviderCapability , InitializeParams , InitializeResult ,
10- InitializedParams , ServerCapabilities , ServerInfo , TextDocumentSyncCapability ,
11- TextDocumentSyncKind ,
9+ CompletionOptions , DidOpenTextDocumentParams , HoverProviderCapability , InitializeParams ,
10+ InitializeResult , InitializedParams , MessageType , ServerCapabilities , ServerInfo ,
11+ TextDocumentSyncCapability , TextDocumentSyncKind ,
1212 } ,
1313} ;
1414
15+ use crate :: { bridge:: check_for_file, diags:: to_tower_diag} ;
16+
1517#[ derive( Debug ) ]
1618pub struct LSPBackend {
17- lsp_client : Client ,
18- documents : Arc < Mutex < HashSet < String > > > ,
19+ pub lsp_client : Client ,
20+ pub documents : Arc < Mutex < HashSet < String > > > ,
1921}
2022
2123#[ tower_lsp:: async_trait]
@@ -40,6 +42,27 @@ impl LanguageServer for LSPBackend {
4042 } )
4143 }
4244
45+ async fn did_open ( & self , param : DidOpenTextDocumentParams ) {
46+ let uri = param. text_document . uri . to_string ( ) ;
47+ let text = param. text_document . text ;
48+
49+ self . documents . lock ( ) . unwrap ( ) . insert ( uri. clone ( ) ) ;
50+
51+ let mut diags = vec ! [ ] ;
52+
53+ self . lsp_client
54+ . log_message ( MessageType :: ERROR , format ! ( "Path: {}" , uri) )
55+ . await ;
56+
57+ for diag in check_for_file ( uri. clone ( ) . replace ( "file://" , "" ) ) {
58+ diags. push ( to_tower_diag ( diag) )
59+ }
60+
61+ self . lsp_client
62+ . publish_diagnostics ( uri. parse ( ) . unwrap ( ) , diags, None )
63+ . await ;
64+ }
65+
4366 async fn shutdown ( & self ) -> tower_lsp:: jsonrpc:: Result < ( ) > {
4467 Ok ( ( ) )
4568 }
0 commit comments