@@ -428,16 +428,16 @@ impl GlobalState {
428
428
}
429
429
430
430
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
437
437
. 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
+ } )
441
441
} )
442
442
. map ( |( base, pat) | lsp_types:: FileSystemWatcher {
443
443
glob_pattern : lsp_types:: GlobPattern :: Relative (
@@ -450,8 +450,24 @@ impl GlobalState {
450
450
) ,
451
451
kind : None ,
452
452
} )
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 ( )
454
467
} ;
468
+
469
+ let registration_options =
470
+ lsp_types:: DidChangeWatchedFilesRegistrationOptions { watchers } ;
455
471
let registration = lsp_types:: Registration {
456
472
id : "workspace/didChangeWatchedFiles" . to_owned ( ) ,
457
473
method : "workspace/didChangeWatchedFiles" . to_owned ( ) ,
0 commit comments