feat: Trigger flycheck if non-workspace files get modified

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
This commit is contained in:
Lukas Wirth 2026-01-16 13:35:31 +01:00
parent c6ec8ea033
commit bfbee86a2d
2 changed files with 19 additions and 0 deletions

View file

@ -1043,6 +1043,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>,
@ -1366,6 +1367,10 @@ impl Config {
self.discovered_projects_from_command.push(ProjectJsonFromCommand { data, buildfile });
}
pub fn workspace_roots(&self) -> &[AbsPathBuf] {
&self.workspace_roots
}
}
#[derive(Default, Debug)]
@ -1742,6 +1747,7 @@ impl Config {
}
pub fn root_path(&self) -> &AbsPathBuf {
// We should probably use `workspace_roots` here if set
&self.root_path
}

View file

@ -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(())
}