mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Auto merge of #16957 - poliorcetics:ab/push-tlzsqmqqurxs, r=lnicola
fix: check for client support of relative glob patterns before using them Fixes #16955
This commit is contained in:
commit
899db83128
2 changed files with 37 additions and 10 deletions
|
@ -1013,6 +1013,17 @@ impl Config {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn did_change_watched_files_relative_pattern_support(&self) -> bool {
|
||||||
|
try_or_def!(
|
||||||
|
self.caps
|
||||||
|
.workspace
|
||||||
|
.as_ref()?
|
||||||
|
.did_change_watched_files
|
||||||
|
.as_ref()?
|
||||||
|
.relative_pattern_support?
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prefill_caches(&self) -> bool {
|
pub fn prefill_caches(&self) -> bool {
|
||||||
self.data.cachePriming_enable
|
self.data.cachePriming_enable
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,16 +428,16 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let FilesWatcher::Client = self.config.files().watcher {
|
if let FilesWatcher::Client = self.config.files().watcher {
|
||||||
let registration_options = lsp_types::DidChangeWatchedFilesRegistrationOptions {
|
let filter =
|
||||||
watchers: self
|
self.workspaces.iter().flat_map(|ws| ws.to_roots()).filter(|it| it.is_local);
|
||||||
.workspaces
|
|
||||||
.iter()
|
let watchers = if self.config.did_change_watched_files_relative_pattern_support() {
|
||||||
.flat_map(|ws| ws.to_roots())
|
// When relative patterns are supported by the client, prefer using them
|
||||||
.filter(|it| it.is_local)
|
filter
|
||||||
.flat_map(|root| {
|
.flat_map(|root| {
|
||||||
root.include
|
root.include.into_iter().flat_map(|base| {
|
||||||
.into_iter()
|
[(base.clone(), "**/*.rs"), (base, "**/Cargo.{lock,toml}")]
|
||||||
.flat_map(|it| [(it.clone(), "**/*.rs"), (it, "**/Cargo.{lock,toml}")])
|
})
|
||||||
})
|
})
|
||||||
.map(|(base, pat)| lsp_types::FileSystemWatcher {
|
.map(|(base, pat)| lsp_types::FileSystemWatcher {
|
||||||
glob_pattern: lsp_types::GlobPattern::Relative(
|
glob_pattern: lsp_types::GlobPattern::Relative(
|
||||||
|
@ -450,8 +450,24 @@ impl GlobalState {
|
||||||
),
|
),
|
||||||
kind: None,
|
kind: None,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect()
|
||||||
|
} else {
|
||||||
|
// When they're not, integrate the base to make them into absolute patterns
|
||||||
|
filter
|
||||||
|
.flat_map(|root| {
|
||||||
|
root.include.into_iter().flat_map(|base| {
|
||||||
|
[format!("{base}/**/*.rs"), format!("{base}/**/Cargo.{{lock,toml}}")]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|glob_pattern| lsp_types::FileSystemWatcher {
|
||||||
|
glob_pattern: lsp_types::GlobPattern::String(glob_pattern),
|
||||||
|
kind: None,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let registration_options =
|
||||||
|
lsp_types::DidChangeWatchedFilesRegistrationOptions { watchers };
|
||||||
let registration = lsp_types::Registration {
|
let registration = lsp_types::Registration {
|
||||||
id: "workspace/didChangeWatchedFiles".to_owned(),
|
id: "workspace/didChangeWatchedFiles".to_owned(),
|
||||||
method: "workspace/didChangeWatchedFiles".to_owned(),
|
method: "workspace/didChangeWatchedFiles".to_owned(),
|
||||||
|
|
Loading…
Reference in a new issue