Skip to content

Commit 899db83

Browse files
committed
Auto merge of rust-lang#16957 - poliorcetics:ab/push-tlzsqmqqurxs, r=lnicola
fix: check for client support of relative glob patterns before using them Fixes rust-lang#16955
2 parents 29a8e65 + 8f9a58c commit 899db83

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

crates/rust-analyzer/src/config.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,17 @@ impl Config {
10131013
)
10141014
}
10151015

1016+
pub fn did_change_watched_files_relative_pattern_support(&self) -> bool {
1017+
try_or_def!(
1018+
self.caps
1019+
.workspace
1020+
.as_ref()?
1021+
.did_change_watched_files
1022+
.as_ref()?
1023+
.relative_pattern_support?
1024+
)
1025+
}
1026+
10161027
pub fn prefill_caches(&self) -> bool {
10171028
self.data.cachePriming_enable
10181029
}

crates/rust-analyzer/src/reload.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)