@@ -3,18 +3,17 @@ use std::{str::FromStr, sync::Arc};
33use futures:: future:: join_all;
44use log:: { debug, info, warn} ;
55use rustc_hash:: FxBuildHasher ;
6- use serde_json:: json;
76use tokio:: sync:: { OnceCell , RwLock , SetError } ;
87use tower_lsp_server:: {
98 Client , LanguageServer ,
109 jsonrpc:: { Error , ErrorCode , Result } ,
1110 lsp_types:: {
1211 CodeActionParams , CodeActionResponse , ConfigurationItem , Diagnostic ,
1312 DidChangeConfigurationParams , DidChangeTextDocumentParams , DidChangeWatchedFilesParams ,
14- DidChangeWatchedFilesRegistrationOptions , DidChangeWorkspaceFoldersParams ,
15- DidCloseTextDocumentParams , DidOpenTextDocumentParams , DidSaveTextDocumentParams ,
16- DocumentFormattingParams , ExecuteCommandParams , InitializeParams , InitializeResult ,
17- InitializedParams , Registration , ServerInfo , TextEdit , Unregistration , Uri , WorkspaceEdit ,
13+ DidChangeWorkspaceFoldersParams , DidCloseTextDocumentParams , DidOpenTextDocumentParams ,
14+ DidSaveTextDocumentParams , DocumentFormattingParams , ExecuteCommandParams ,
15+ InitializeParams , InitializeResult , InitializedParams , Registration , ServerInfo , TextEdit ,
16+ Unregistration , Uri , WorkspaceEdit ,
1817 } ,
1918} ;
2019
@@ -204,13 +203,7 @@ impl LanguageServer for Backend {
204203 // init all file watchers
205204 if capabilities. dynamic_watchers {
206205 for worker in workers {
207- registrations. push ( Registration {
208- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
209- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
210- register_options : Some ( json ! ( DidChangeWatchedFilesRegistrationOptions {
211- watchers: worker. init_watchers( ) . await
212- } ) ) ,
213- } ) ;
206+ registrations. extend ( worker. init_watchers ( ) . await ) ;
214207 }
215208 }
216209
@@ -326,7 +319,7 @@ impl LanguageServer for Backend {
326319 continue ;
327320 } ;
328321
329- let ( diagnostics, watchers , formatter_activated) =
322+ let ( diagnostics, registrations , unregistrations , formatter_activated) =
330323 worker. did_change_configuration ( & option. options ) . await ;
331324
332325 if formatter_activated && self . capabilities . get ( ) . is_some_and ( |c| c. dynamic_formatting )
@@ -338,23 +331,8 @@ impl LanguageServer for Backend {
338331 new_diagnostics. extend ( diagnostics) ;
339332 }
340333
341- if let Some ( watchers) = watchers
342- && self . capabilities . get ( ) . is_some_and ( |capabilities| capabilities. dynamic_watchers )
343- {
344- // remove the old watcher
345- removing_registrations. push ( Unregistration {
346- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
347- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
348- } ) ;
349- // add the new watcher
350- adding_registrations. push ( Registration {
351- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
352- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
353- register_options : Some ( json ! ( DidChangeWatchedFilesRegistrationOptions {
354- watchers
355- } ) ) ,
356- } ) ;
357- }
334+ removing_registrations. extend ( unregistrations) ;
335+ adding_registrations. extend ( registrations) ;
358336 }
359337
360338 if !new_diagnostics. is_empty ( ) {
@@ -464,13 +442,7 @@ impl LanguageServer for Backend {
464442
465443 worker. start_worker ( options) . await ;
466444
467- added_registrations. push ( Registration {
468- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
469- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
470- register_options : Some ( json ! ( DidChangeWatchedFilesRegistrationOptions {
471- watchers: worker. init_watchers( ) . await
472- } ) ) ,
473- } ) ;
445+ added_registrations. extend ( worker. init_watchers ( ) . await ) ;
474446 workers. push ( worker) ;
475447 }
476448 // client does not support the request
0 commit comments