Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only flycheck update the workspace that changed #11038

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl fmt::Display for FlycheckConfig {
/// The spawned thread is shut down when this struct is dropped.
#[derive(Debug)]
pub struct FlycheckHandle {
id: usize,
// XXX: drop order is significant
sender: Sender<Restart>,
_thread: jod_thread::JoinHandle,
Expand All @@ -66,13 +67,18 @@ impl FlycheckHandle {
.name("Flycheck".to_owned())
.spawn(move || actor.run(receiver))
.expect("failed to spawn thread");
FlycheckHandle { sender, _thread: thread }
FlycheckHandle { id, sender, _thread: thread }
}

/// Schedule a re-start of the cargo check worker.
pub fn update(&self) {
self.sender.send(Restart).unwrap();
}

/// Returns the ID of the corresponding workspace
pub fn id(&self) -> usize {
self.id
}
}

pub enum Message {
Expand Down
17 changes: 14 additions & 3 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crossbeam_channel::{select, Receiver};
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
use lsp_server::{Connection, Notification, Request};
use lsp_types::notification::Notification as _;
use project_model::ProjectWorkspace;
use vfs::{ChangeKind, FileId};

use crate::{
Expand Down Expand Up @@ -698,10 +699,20 @@ impl GlobalState {
Ok(())
})?
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
for flycheck in &this.flycheck {
flycheck.update();
}
if let Ok(abs_path) = from_proto::abs_path(&params.text_document.uri) {
for flycheck in &this.flycheck {
let id = flycheck.id();
let root = match &this.workspaces[id] {
ProjectWorkspace::Cargo { cargo, .. } => cargo.workspace_root(),
ProjectWorkspace::Json { project, .. } => project.path(),
// DetachedFiles workspaces are never flychecked
ProjectWorkspace::DetachedFiles { .. } => unreachable!(),
};
if abs_path.starts_with(root) {
flycheck.update();
// FIXME: break here? the file should only belong to one workspace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[path] and include! would beg to differ 🥲.

}
}
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
this.fetch_workspaces_queue.request_op();
}
Expand Down