Add support for custom flycheck commands with JSON project workspaces
Enable flychecks with JSON project workspaces if an override command was provided as part of the client configuration.
This commit is contained in:
parent
37f3b9ca2a
commit
74c26a785a
2 changed files with 19 additions and 7 deletions
|
|
@ -13,6 +13,7 @@ use crate::cfg_flag::CfgFlag;
|
|||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ProjectJson {
|
||||
pub(crate) sysroot_src: Option<AbsPathBuf>,
|
||||
project_root: Option<AbsPathBuf>,
|
||||
crates: Vec<Crate>,
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ impl ProjectJson {
|
|||
pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson {
|
||||
ProjectJson {
|
||||
sysroot_src: data.sysroot_src.map(|it| base.join(it)),
|
||||
project_root: base.parent().map(AbsPath::to_path_buf),
|
||||
crates: data
|
||||
.crates
|
||||
.into_iter()
|
||||
|
|
@ -89,6 +91,12 @@ impl ProjectJson {
|
|||
pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ {
|
||||
self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate))
|
||||
}
|
||||
pub fn path(&self) -> Option<&AbsPath> {
|
||||
match &self.project_root {
|
||||
Some(p) => Some(p.as_path()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
use std::{mem, sync::Arc};
|
||||
|
||||
use base_db::{CrateGraph, SourceRoot, VfsPath};
|
||||
use flycheck::FlycheckHandle;
|
||||
use flycheck::{FlycheckConfig, FlycheckHandle};
|
||||
use ide::AnalysisChange;
|
||||
use project_model::{ProcMacroClient, ProjectWorkspace};
|
||||
use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
|
||||
|
|
@ -244,13 +244,17 @@ impl GlobalState {
|
|||
.iter()
|
||||
// FIXME: Figure out the multi-workspace situation
|
||||
.find_map(|w| match w {
|
||||
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo),
|
||||
ProjectWorkspace::Json { .. } => None,
|
||||
})
|
||||
.map(move |cargo| {
|
||||
let cargo_project_root = cargo.workspace_root().to_path_buf();
|
||||
FlycheckHandle::spawn(sender, config, cargo_project_root.into())
|
||||
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo.workspace_root()),
|
||||
ProjectWorkspace::Json { project, .. } => {
|
||||
// Enable flychecks for json projects if a custom flycheck command was supplied
|
||||
// in the workspace configuration.
|
||||
match config {
|
||||
FlycheckConfig::CustomCommand { .. } => project.path(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
})
|
||||
.map(move |root| FlycheckHandle::spawn(sender, config, root.to_path_buf().into()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue