@@ -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
@@ -327,7 +320,7 @@ impl LanguageServer for Backend {
327320 continue ;
328321 } ;
329322
330- let ( diagnostics, watchers , formatter_activated) =
323+ let ( diagnostics, registrations , unregistrations , formatter_activated) =
331324 worker. did_change_configuration ( & option. options ) . await ;
332325
333326 if formatter_activated && self . capabilities . get ( ) . is_some_and ( |c| c. dynamic_formatting )
@@ -344,23 +337,8 @@ impl LanguageServer for Backend {
344337 }
345338 }
346339
347- if let Some ( watchers) = watchers
348- && self . capabilities . get ( ) . is_some_and ( |capabilities| capabilities. dynamic_watchers )
349- {
350- // remove the old watcher
351- removing_registrations. push ( Unregistration {
352- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
353- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
354- } ) ;
355- // add the new watcher
356- adding_registrations. push ( Registration {
357- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
358- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
359- register_options : Some ( json ! ( DidChangeWatchedFilesRegistrationOptions {
360- watchers
361- } ) ) ,
362- } ) ;
363- }
340+ removing_registrations. extend ( unregistrations) ;
341+ adding_registrations. extend ( registrations) ;
364342 }
365343
366344 if !new_diagnostics. is_empty ( ) {
@@ -487,13 +465,7 @@ impl LanguageServer for Backend {
487465
488466 worker. start_worker ( options) . await ;
489467
490- added_registrations. push ( Registration {
491- id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
492- method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
493- register_options : Some ( json ! ( DidChangeWatchedFilesRegistrationOptions {
494- watchers: worker. init_watchers( ) . await
495- } ) ) ,
496- } ) ;
468+ added_registrations. extend ( worker. init_watchers ( ) . await ) ;
497469 workers. push ( worker) ;
498470 }
499471 // client does not support the request
0 commit comments