From d24e759f13a4b5284b408309320fd071448ce347 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 14 May 2026 12:27:02 +0200 Subject: [PATCH 1/4] flycheck: Run on DidChangeWatchedFiles notifications instead of didSave Co-authored-by: Smit Barmase --- .../src/handlers/notification.rs | 20 +++++++++++++++---- crates/stdx/src/lib.rs | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 09b6794e4f43..c9a4592e44fe 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -6,6 +6,7 @@ use std::{ panic::UnwindSafe, }; +use indexmap::IndexSet; use itertools::Itertools; use lsp_types::{ CancelParams, DidChangeConfigurationParams, DidChangeTextDocumentParams, @@ -292,22 +293,33 @@ pub(crate) fn handle_did_change_watched_files( // 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; + let mut vfs_paths_to_rescan = IndexSet::new(); 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 if no workspaces contain this file. + // Trigger if no workspaces contain this file trigger_flycheck = state.config.workspace_roots().iter().all(|root| !path.starts_with(root)); } state.loader.handle.invalidate(path); } + if let Ok(path) = from_proto::vfs_path(&change.uri) { + vfs_paths_to_rescan.insert(path); + } } - if trigger_flycheck && state.config.check_on_save(None) { - for flycheck in state.flycheck.iter() { - flycheck.restart_workspace(None); + if state.config.check_on_save(None) { + if trigger_flycheck { + for flycheck in state.flycheck.iter() { + flycheck.restart_workspace(None); + } + } else { + for path in vfs_paths_to_rescan { + run_flycheck(state, path); + } } } + Ok(()) } diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 275e0e5ac8db..dd6dc9f1b016 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -460,3 +460,6 @@ mod tests { test_replace(".a.b.c.", '.', "", "abc"); } } +// private comment +// private comment +// private comment From 050710e70e8a7c1f6f5eb650ccf28a75ae74a322 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 14 May 2026 12:31:08 +0200 Subject: [PATCH 2/4] Keep running flycheck on save when server-side file watcher is enabled Co-authored-by: Smit Barmase --- crates/rust-analyzer/src/handlers/notification.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index c9a4592e44fe..b8d6abe9af77 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -18,7 +18,7 @@ use triomphe::Arc; use vfs::{AbsPathBuf, ChangeKind, VfsPath}; use crate::{ - config::{Config, ConfigChange}, + config::{Config, ConfigChange, FilesWatcher}, flycheck::{InvocationStrategy, PackageSpecifier, Target}, global_state::{FetchWorkspaceRequest, GlobalState}, lsp::{from_proto, utils::apply_document_changes}, @@ -197,7 +197,10 @@ pub(crate) fn handle_did_save_text_document( } } - if !state.config.check_on_save(Some(sr)) || run_flycheck(state, vfs_path) { + if !state.config.check_on_save(Some(sr)) + || matches!(state.config.files().watcher, FilesWatcher::Server) + || run_flycheck(state, vfs_path) + { return Ok(()); } } else if state.config.check_on_save(None) && state.config.flycheck_workspace(None) { From 5729ca583631bc164936fefb976b456d2686e03a Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 14 May 2026 12:32:35 +0200 Subject: [PATCH 3/4] Revert errroneous diff Co-authored-by: Smit Barmase --- crates/rust-analyzer/src/handlers/notification.rs | 2 +- crates/stdx/src/lib.rs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index b8d6abe9af77..6ed3d534163d 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -300,7 +300,7 @@ pub(crate) fn handle_did_change_watched_files( 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 if no workspaces contain this file + // Trigger if no workspaces contain this file. trigger_flycheck = state.config.workspace_roots().iter().all(|root| !path.starts_with(root)); } diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index dd6dc9f1b016..275e0e5ac8db 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -460,6 +460,3 @@ mod tests { test_replace(".a.b.c.", '.', "", "abc"); } } -// private comment -// private comment -// private comment From dc6c25c08ce386066c00fea037979c6f10000de2 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 20 May 2026 14:58:34 +0200 Subject: [PATCH 4/4] Update crates/rust-analyzer/src/handlers/notification.rs --- crates/rust-analyzer/src/handlers/notification.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 6ed3d534163d..0e87307c0a84 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -198,7 +198,7 @@ pub(crate) fn handle_did_save_text_document( } if !state.config.check_on_save(Some(sr)) - || matches!(state.config.files().watcher, FilesWatcher::Server) + || matches!(state.config.files().watcher, FilesWatcher::Client) || run_flycheck(state, vfs_path) { return Ok(());