Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21483 from Veykril/push-vswqqvzqyvnv
feat: Trigger flycheck if non-workspace files get modified
Lukas Wirth 3 months ago
parent 6705e57 · parent 4d8fbb1 · commit 54dd939
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/handlers/notification.rs13
2 files changed, 19 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 8d6b19a84c..7064546374 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1067,6 +1067,7 @@ pub struct Config {
/// The workspace roots as registered by the LSP client
workspace_roots: Vec<AbsPathBuf>,
caps: ClientCapabilities,
+ /// The LSP root path, deprecated in favor of `workspace_roots`
root_path: AbsPathBuf,
snippets: Vec<Snippet>,
client_info: Option<ClientInfo>,
@@ -1390,6 +1391,10 @@ impl Config {
self.discovered_projects_from_command.push(ProjectJsonFromCommand { data, buildfile });
}
+
+ pub fn workspace_roots(&self) -> &[AbsPathBuf] {
+ &self.workspace_roots
+ }
}
#[derive(Default, Debug)]
@@ -1766,6 +1771,7 @@ impl Config {
}
pub fn root_path(&self) -> &AbsPathBuf {
+ // We should probably use `workspace_roots` here if set
&self.root_path
}
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs
index 6cc40677fb..138310b78f 100644
--- a/crates/rust-analyzer/src/handlers/notification.rs
+++ b/crates/rust-analyzer/src/handlers/notification.rs
@@ -289,11 +289,24 @@ pub(crate) fn handle_did_change_watched_files(
state: &mut GlobalState,
params: DidChangeWatchedFilesParams,
) -> anyhow::Result<()> {
+ // we want to trigger flycheck if a file outside of our workspaces has changed,
+ // as to reduce stale diagnostics when outside changes happen
+ let mut trigger_flycheck = false;
for change in params.changes.iter().unique_by(|&it| &it.uri) {
if let Ok(path) = from_proto::abs_path(&change.uri) {
+ if !trigger_flycheck {
+ trigger_flycheck =
+ state.config.workspace_roots().iter().any(|root| !path.starts_with(root));
+ }
state.loader.handle.invalidate(path);
}
}
+
+ if trigger_flycheck && state.config.check_on_save(None) {
+ for flycheck in state.flycheck.iter() {
+ flycheck.restart_workspace(None);
+ }
+ }
Ok(())
}