mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
internal: Don't requery crates_for for flycheck when crates are known
This commit is contained in:
parent
2025b43653
commit
806d54c18a
3 changed files with 26 additions and 22 deletions
|
@ -696,6 +696,7 @@ impl GlobalStateSnapshot {
|
||||||
};
|
};
|
||||||
|
|
||||||
return Some(TargetSpec::ProjectJson(ProjectJsonTargetSpec {
|
return Some(TargetSpec::ProjectJson(ProjectJsonTargetSpec {
|
||||||
|
crate_id,
|
||||||
label: build.label,
|
label: build.label,
|
||||||
target_kind: build.target_kind,
|
target_kind: build.target_kind,
|
||||||
shell_runnables: project.runnables().to_owned(),
|
shell_runnables: project.runnables().to_owned(),
|
||||||
|
|
|
@ -10,6 +10,7 @@ use lsp_types::{
|
||||||
DidOpenTextDocumentParams, DidSaveTextDocumentParams, WorkDoneProgressCancelParams,
|
DidOpenTextDocumentParams, DidSaveTextDocumentParams, WorkDoneProgressCancelParams,
|
||||||
};
|
};
|
||||||
use paths::Utf8PathBuf;
|
use paths::Utf8PathBuf;
|
||||||
|
use stdx::TupleExt;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
use vfs::{AbsPathBuf, ChangeKind, VfsPath};
|
use vfs::{AbsPathBuf, ChangeKind, VfsPath};
|
||||||
|
|
||||||
|
@ -290,11 +291,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||||
let mut updated = false;
|
let mut updated = false;
|
||||||
let task = move || -> std::result::Result<(), ide::Cancelled> {
|
let task = move || -> std::result::Result<(), ide::Cancelled> {
|
||||||
// Is the target binary? If so we let flycheck run only for the workspace that contains the crate.
|
// Is the target binary? If so we let flycheck run only for the workspace that contains the crate.
|
||||||
let target = TargetSpec::for_file(&world, file_id)?.and_then(|x| {
|
let target = TargetSpec::for_file(&world, file_id)?.and_then(|it| {
|
||||||
let tgt_kind = x.target_kind();
|
let tgt_kind = it.target_kind();
|
||||||
let tgt_name = match x {
|
let (tgt_name, crate_id) = match it {
|
||||||
TargetSpec::Cargo(c) => c.target,
|
TargetSpec::Cargo(c) => (c.target, c.crate_id),
|
||||||
TargetSpec::ProjectJson(p) => p.label,
|
TargetSpec::ProjectJson(p) => (p.label, p.crate_id),
|
||||||
};
|
};
|
||||||
|
|
||||||
let tgt = match tgt_kind {
|
let tgt = match tgt_kind {
|
||||||
|
@ -305,25 +306,25 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(tgt)
|
Some((tgt, crate_id))
|
||||||
});
|
});
|
||||||
|
|
||||||
let crate_ids = if target.is_some() {
|
let crate_ids = match target {
|
||||||
// Trigger flychecks for the only workspace which the binary crate belongs to
|
// Trigger flychecks for the only crate which the target belongs to
|
||||||
world.analysis.crates_for(file_id)?.into_iter().unique().collect::<Vec<_>>()
|
Some((_, krate)) => vec![krate],
|
||||||
} else {
|
None => {
|
||||||
// Trigger flychecks for all workspaces that depend on the saved file
|
// Trigger flychecks for all workspaces that depend on the saved file
|
||||||
// Crates containing or depending on the saved file
|
// Crates containing or depending on the saved file
|
||||||
world
|
world
|
||||||
.analysis
|
.analysis
|
||||||
.crates_for(file_id)?
|
.crates_for(file_id)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|id| world.analysis.transitive_rev_deps(id))
|
.flat_map(|id| world.analysis.transitive_rev_deps(id))
|
||||||
.flatten()
|
.flatten()
|
||||||
.unique()
|
.unique()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let crate_root_paths: Vec<_> = crate_ids
|
let crate_root_paths: Vec<_> = crate_ids
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|&crate_id| {
|
.filter_map(|&crate_id| {
|
||||||
|
@ -375,7 +376,8 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
|
||||||
match package
|
match package
|
||||||
.filter(|_| !world.config.flycheck_workspace() || target.is_some())
|
.filter(|_| !world.config.flycheck_workspace() || target.is_some())
|
||||||
{
|
{
|
||||||
Some(package) => flycheck.restart_for_package(package, target.clone()),
|
Some(package) => flycheck
|
||||||
|
.restart_for_package(package, target.clone().map(TupleExt::head)),
|
||||||
None => flycheck.restart_workspace(saved_file.clone()),
|
None => flycheck.restart_workspace(saved_file.clone()),
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -62,6 +62,7 @@ pub(crate) struct CargoTargetSpec {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct ProjectJsonTargetSpec {
|
pub(crate) struct ProjectJsonTargetSpec {
|
||||||
|
pub(crate) crate_id: CrateId,
|
||||||
pub(crate) label: String,
|
pub(crate) label: String,
|
||||||
pub(crate) target_kind: TargetKind,
|
pub(crate) target_kind: TargetKind,
|
||||||
pub(crate) shell_runnables: Vec<Runnable>,
|
pub(crate) shell_runnables: Vec<Runnable>,
|
||||||
|
|
Loading…
Reference in a new issue