Skip to content

Commit 4bc8015

Browse files
bors[bot]woody77
andauthored
Merge #6013
6013: Add support for custom flycheck commands with JSON project workspaces r=jonas-schievink a=woody77 Enable flychecks with JSON project workspaces if an override command was provided as part of the client configuration: ``` "rust-analyzer.checkOnSave.enable": true, "rust-analyzer.checkOnSave.overrideCommand": ["custom_tool", "arg1", "arg2"], ``` Co-authored-by: Aaron Wood <[email protected]>
2 parents 5df69d9 + 74c26a7 commit 4bc8015

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

crates/project_model/src/project_json.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::cfg_flag::CfgFlag;
1313
#[derive(Clone, Debug, Eq, PartialEq)]
1414
pub struct ProjectJson {
1515
pub(crate) sysroot_src: Option<AbsPathBuf>,
16+
project_root: Option<AbsPathBuf>,
1617
crates: Vec<Crate>,
1718
}
1819

@@ -36,6 +37,7 @@ impl ProjectJson {
3637
pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
3738
ProjectJson {
3839
sysroot_src: data.sysroot_src.map(|it| base.join(it)),
40+
project_root: base.parent().map(AbsPath::to_path_buf),
3941
crates: data
4042
.crates
4143
.into_iter()
@@ -89,6 +91,12 @@ impl ProjectJson {
8991
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
9092
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
9193
}
94+
pub fn path(&self) -> Option<&AbsPath> {
95+
match &self.project_root {
96+
Some(p) => Some(p.as_path()),
97+
None => None,
98+
}
99+
}
92100
}
93101

94102
#[derive(Deserialize)]

crates/rust-analyzer/src/reload.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::{mem, sync::Arc};
33

44
use base_db::{CrateGraph, SourceRoot, VfsPath};
5-
use flycheck::FlycheckHandle;
5+
use flycheck::{FlycheckConfig, FlycheckHandle};
66
use ide::AnalysisChange;
77
use project_model::{ProcMacroClient, ProjectWorkspace};
88
use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
@@ -244,13 +244,17 @@ impl GlobalState {
244244
.iter()
245245
// FIXME: Figure out the multi-workspace situation
246246
.find_map(|w| match w {
247-
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo),
248-
ProjectWorkspace::Json { .. } => None,
249-
})
250-
.map(move |cargo| {
251-
let cargo_project_root = cargo.workspace_root().to_path_buf();
252-
FlycheckHandle::spawn(sender, config, cargo_project_root.into())
247+
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo.workspace_root()),
248+
ProjectWorkspace::Json { project, .. } => {
249+
// Enable flychecks for json projects if a custom flycheck command was supplied
250+
// in the workspace configuration.
251+
match config {
252+
FlycheckConfig::CustomCommand { .. } => project.path(),
253+
_ => None,
254+
}
255+
}
253256
})
257+
.map(move |root| FlycheckHandle::spawn(sender, config, root.to_path_buf().into()))
254258
}
255259
}
256260

0 commit comments

Comments
 (0)