@@ -428,16 +428,16 @@ impl GlobalState {
428428 }
429429
430430 if let FilesWatcher :: Client = self . config . files ( ) . watcher {
431- let registration_options = lsp_types :: DidChangeWatchedFilesRegistrationOptions {
432- watchers : self
433- . workspaces
434- . iter ( )
435- . flat_map ( |ws| ws . to_roots ( ) )
436- . filter ( |it| it . is_local )
431+ let filter =
432+ self . workspaces . iter ( ) . flat_map ( |ws| ws . to_roots ( ) ) . filter ( |it| it . is_local ) ;
433+
434+ let watchers = if self . config . did_change_watched_files_relative_pattern_support ( ) {
435+ // When relative patterns are supported by the client, prefer using them
436+ filter
437437 . flat_map ( |root| {
438- root. include
439- . into_iter ( )
440- . flat_map ( |it| [ ( it . clone ( ) , "**/*.rs" ) , ( it , "**/Cargo.{lock,toml}" ) ] )
438+ root. include . into_iter ( ) . flat_map ( |base| {
439+ [ ( base . clone ( ) , "**/*.rs" ) , ( base , "**/Cargo.{lock,toml}" ) ]
440+ } )
441441 } )
442442 . map ( |( base, pat) | lsp_types:: FileSystemWatcher {
443443 glob_pattern : lsp_types:: GlobPattern :: Relative (
@@ -450,8 +450,24 @@ impl GlobalState {
450450 ) ,
451451 kind : None ,
452452 } )
453- . collect ( ) ,
453+ . collect ( )
454+ } else {
455+ // When they're not, integrate the base to make them into absolute patterns
456+ filter
457+ . flat_map ( |root| {
458+ root. include . into_iter ( ) . flat_map ( |base| {
459+ [ format ! ( "{base}/**/*.rs" ) , format ! ( "{base}/**/Cargo.{{lock,toml}}" ) ]
460+ } )
461+ } )
462+ . map ( |glob_pattern| lsp_types:: FileSystemWatcher {
463+ glob_pattern : lsp_types:: GlobPattern :: String ( glob_pattern) ,
464+ kind : None ,
465+ } )
466+ . collect ( )
454467 } ;
468+
469+ let registration_options =
470+ lsp_types:: DidChangeWatchedFilesRegistrationOptions { watchers } ;
455471 let registration = lsp_types:: Registration {
456472 id : "workspace/didChangeWatchedFiles" . to_owned ( ) ,
457473 method : "workspace/didChangeWatchedFiles" . to_owned ( ) ,
0 commit comments