diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/project_model/src/project_json.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 18 |
2 files changed, 19 insertions, 7 deletions
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs index 979e90058..545f254aa 100644 --- a/crates/project_model/src/project_json.rs +++ b/crates/project_model/src/project_json.rs | |||
@@ -13,6 +13,7 @@ use crate::cfg_flag::CfgFlag; | |||
13 | #[derive(Clone, Debug, Eq, PartialEq)] | 13 | #[derive(Clone, Debug, Eq, PartialEq)] |
14 | pub struct ProjectJson { | 14 | pub struct ProjectJson { |
15 | pub(crate) sysroot_src: Option<AbsPathBuf>, | 15 | pub(crate) sysroot_src: Option<AbsPathBuf>, |
16 | project_root: Option<AbsPathBuf>, | ||
16 | crates: Vec<Crate>, | 17 | crates: Vec<Crate>, |
17 | } | 18 | } |
18 | 19 | ||
@@ -36,6 +37,7 @@ impl ProjectJson { | |||
36 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { | 37 | pub fn new(base: &AbsPath, data: ProjectJsonData) -> ProjectJson { |
37 | ProjectJson { | 38 | ProjectJson { |
38 | sysroot_src: data.sysroot_src.map(|it| base.join(it)), | 39 | sysroot_src: data.sysroot_src.map(|it| base.join(it)), |
40 | project_root: base.parent().map(AbsPath::to_path_buf), | ||
39 | crates: data | 41 | crates: data |
40 | .crates | 42 | .crates |
41 | .into_iter() | 43 | .into_iter() |
@@ -89,6 +91,12 @@ impl ProjectJson { | |||
89 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { | 91 | pub fn crates(&self) -> impl Iterator<Item = (CrateId, &Crate)> + '_ { |
90 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) | 92 | self.crates.iter().enumerate().map(|(idx, krate)| (CrateId(idx as u32), krate)) |
91 | } | 93 | } |
94 | pub fn path(&self) -> Option<&AbsPath> { | ||
95 | match &self.project_root { | ||
96 | Some(p) => Some(p.as_path()), | ||
97 | None => None, | ||
98 | } | ||
99 | } | ||
92 | } | 100 | } |
93 | 101 | ||
94 | #[derive(Deserialize)] | 102 | #[derive(Deserialize)] |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index bab6f8a71..b819618cb 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | use std::{mem, sync::Arc}; | 2 | use std::{mem, sync::Arc}; |
3 | 3 | ||
4 | use base_db::{CrateGraph, SourceRoot, VfsPath}; | 4 | use base_db::{CrateGraph, SourceRoot, VfsPath}; |
5 | use flycheck::FlycheckHandle; | 5 | use flycheck::{FlycheckConfig, FlycheckHandle}; |
6 | use ide::AnalysisChange; | 6 | use ide::AnalysisChange; |
7 | use project_model::{ProcMacroClient, ProjectWorkspace}; | 7 | use project_model::{ProcMacroClient, ProjectWorkspace}; |
8 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; | 8 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; |
@@ -244,13 +244,17 @@ impl GlobalState { | |||
244 | .iter() | 244 | .iter() |
245 | // FIXME: Figure out the multi-workspace situation | 245 | // FIXME: Figure out the multi-workspace situation |
246 | .find_map(|w| match w { | 246 | .find_map(|w| match w { |
247 | ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo), | 247 | ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo.workspace_root()), |
248 | ProjectWorkspace::Json { .. } => None, | 248 | ProjectWorkspace::Json { project, .. } => { |
249 | }) | 249 | // Enable flychecks for json projects if a custom flycheck command was supplied |
250 | .map(move |cargo| { | 250 | // in the workspace configuration. |
251 | let cargo_project_root = cargo.workspace_root().to_path_buf(); | 251 | match config { |
252 | FlycheckHandle::spawn(sender, config, cargo_project_root.into()) | 252 | FlycheckConfig::CustomCommand { .. } => project.path(), |
253 | _ => None, | ||
254 | } | ||
255 | } | ||
253 | }) | 256 | }) |
257 | .map(move |root| FlycheckHandle::spawn(sender, config, root.to_path_buf().into())) | ||
254 | } | 258 | } |
255 | } | 259 | } |
256 | 260 | ||