feat: Only flycheck workspace that belongs to saved file
This commit is contained in:
parent
ea416175d5
commit
a63b5d3c84
@ -55,6 +55,7 @@ pub struct FlycheckHandle {
|
|||||||
// XXX: drop order is significant
|
// XXX: drop order is significant
|
||||||
sender: Sender<Restart>,
|
sender: Sender<Restart>,
|
||||||
_thread: jod_thread::JoinHandle,
|
_thread: jod_thread::JoinHandle,
|
||||||
|
id: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlycheckHandle {
|
impl FlycheckHandle {
|
||||||
@ -70,13 +71,17 @@ impl FlycheckHandle {
|
|||||||
.name("Flycheck".to_owned())
|
.name("Flycheck".to_owned())
|
||||||
.spawn(move || actor.run(receiver))
|
.spawn(move || actor.run(receiver))
|
||||||
.expect("failed to spawn thread");
|
.expect("failed to spawn thread");
|
||||||
FlycheckHandle { sender, _thread: thread }
|
FlycheckHandle { id, sender, _thread: thread }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Schedule a re-start of the cargo check worker.
|
/// Schedule a re-start of the cargo check worker.
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
self.sender.send(Restart).unwrap();
|
self.sender.send(Restart).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> usize {
|
||||||
|
self.id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
|
@ -103,6 +103,14 @@ impl AsRef<Path> for AbsPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToOwned for AbsPath {
|
||||||
|
type Owned = AbsPathBuf;
|
||||||
|
|
||||||
|
fn to_owned(&self) -> Self::Owned {
|
||||||
|
AbsPathBuf(self.0.to_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a Path> for &'a AbsPath {
|
impl<'a> TryFrom<&'a Path> for &'a AbsPath {
|
||||||
type Error = &'a Path;
|
type Error = &'a Path;
|
||||||
fn try_from(path: &'a Path) -> Result<&'a AbsPath, &'a Path> {
|
fn try_from(path: &'a Path) -> Result<&'a AbsPath, &'a Path> {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
//! requests/replies and notifications back to the client.
|
//! requests/replies and notifications back to the client.
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
|
ops::Deref,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@ -720,13 +721,62 @@ impl GlobalState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
|
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
|
||||||
for flycheck in &this.flycheck {
|
let mut updated = false;
|
||||||
flycheck.update();
|
if let Ok(vfs_path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||||
|
let (vfs, _) = &*this.vfs.read();
|
||||||
|
if let Some(file_id) = vfs.file_id(&vfs_path) {
|
||||||
|
let analysis = this.analysis_host.analysis();
|
||||||
|
let crate_ids = analysis.crate_for(file_id)?;
|
||||||
|
|
||||||
|
let paths: Vec<_> = crate_ids
|
||||||
|
.iter()
|
||||||
|
.filter_map(|&crate_id| {
|
||||||
|
analysis
|
||||||
|
.crate_root(crate_id)
|
||||||
|
.map(|file_id| {
|
||||||
|
vfs.file_path(file_id).as_path().map(ToOwned::to_owned)
|
||||||
|
})
|
||||||
|
.transpose()
|
||||||
|
})
|
||||||
|
.collect::<ide::Cancellable<_>>()?;
|
||||||
|
let paths: Vec<_> = paths.iter().map(Deref::deref).collect();
|
||||||
|
|
||||||
|
let workspace_ids =
|
||||||
|
this.workspaces.iter().enumerate().filter(|(_, ws)| match ws {
|
||||||
|
project_model::ProjectWorkspace::Cargo { cargo, .. } => {
|
||||||
|
cargo.packages().filter(|&pkg| cargo[pkg].is_member).any(
|
||||||
|
|pkg| {
|
||||||
|
cargo[pkg].targets.iter().any(|&it| {
|
||||||
|
paths.contains(&cargo[it].root.as_path())
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
project_model::ProjectWorkspace::Json { project, .. } => project
|
||||||
|
.crates()
|
||||||
|
.any(|(c, _)| crate_ids.iter().any(|&crate_id| crate_id == c)),
|
||||||
|
project_model::ProjectWorkspace::DetachedFiles { .. } => false,
|
||||||
|
});
|
||||||
|
'workspace: for (id, _) in workspace_ids {
|
||||||
|
for flycheck in &this.flycheck {
|
||||||
|
if id == flycheck.id() {
|
||||||
|
updated = true;
|
||||||
|
flycheck.update();
|
||||||
|
continue 'workspace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(abs_path) = vfs_path.as_path() {
|
||||||
|
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
|
||||||
|
this.fetch_workspaces_queue
|
||||||
|
.request_op(format!("DidSaveTextDocument {}", abs_path.display()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
|
if !updated {
|
||||||
if reload::should_refresh_for_change(&abs_path, ChangeKind::Modify) {
|
for flycheck in &this.flycheck {
|
||||||
this.fetch_workspaces_queue
|
flycheck.update();
|
||||||
.request_op(format!("DidSaveTextDocument {}", abs_path.display()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user