aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-08 17:20:45 +0100
committerGitHub <[email protected]>2020-06-08 17:20:45 +0100
commit38ac331f7dea94581ec687167c92c65b10daf38d (patch)
tree7f9cc7d2d7b6dfa363f5a0d310108bad22621291 /crates/rust-analyzer
parent5ed9818a7c855bf914e91324e305f24e4e743057 (diff)
parentdbceaf522b717bd0dda89f6af1684ebd8e033aee (diff)
Merge #4784
4784: Change management of test cfg to better support json projects r=Nashenas88 a=Nashenas88 This helps support json projects where they can decide whether to add the `test` cfg or not. One alternative is to add support for marking json project crates as a sysroot crate, and adding logic to remove the `test` cfg in those cases. In my opinion, that option gives less flexibility to json projects and leads to more functionality that needs to be maintained. Fixes #4508 cc @woody77 Co-authored-by: Paul Daniel Faria <[email protected]> Co-authored-by: Paul Daniel Faria <[email protected]>
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs21
-rw-r--r--crates/rust-analyzer/src/global_state.rs12
2 files changed, 6 insertions, 27 deletions
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index c7e86fe0c..8f2aeac77 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -8,8 +8,7 @@ use crossbeam_channel::{unbounded, Receiver};
8use ra_db::{ExternSourceId, FileId, SourceRootId}; 8use ra_db::{ExternSourceId, FileId, SourceRootId};
9use ra_ide::{AnalysisChange, AnalysisHost}; 9use ra_ide::{AnalysisChange, AnalysisHost};
10use ra_project_model::{ 10use ra_project_model::{
11 get_rustc_cfg_options, CargoConfig, PackageRoot, ProcMacroClient, ProjectManifest, 11 CargoConfig, PackageRoot, ProcMacroClient, ProjectManifest, ProjectWorkspace,
12 ProjectWorkspace,
13}; 12};
14use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; 13use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
15use rustc_hash::{FxHashMap, FxHashSet}; 14use rustc_hash::{FxHashMap, FxHashSet};
@@ -148,26 +147,14 @@ pub(crate) fn load(
148 } 147 }
149 } 148 }
150 149
151 // FIXME: cfg options? 150 let crate_graph =
152 let default_cfg_options = { 151 ws.to_crate_graph(None, &extern_source_roots, proc_macro_client, &mut |path: &Path| {
153 let mut opts = get_rustc_cfg_options(None);
154 opts.insert_atom("test".into());
155 opts.insert_atom("debug_assertion".into());
156 opts
157 };
158
159 let crate_graph = ws.to_crate_graph(
160 &default_cfg_options,
161 &extern_source_roots,
162 proc_macro_client,
163 &mut |path: &Path| {
164 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs 152 // Some path from metadata will be non canonicalized, e.g. /foo/../bar/lib.rs
165 let path = path.canonicalize().ok()?; 153 let path = path.canonicalize().ok()?;
166 let vfs_file = vfs.load(&path); 154 let vfs_file = vfs.load(&path);
167 log::debug!("vfs file {:?} -> {:?}", path, vfs_file); 155 log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
168 vfs_file.map(vfs_file_to_id) 156 vfs_file.map(vfs_file_to_id)
169 }, 157 });
170 );
171 log::debug!("crate graph: {:?}", crate_graph); 158 log::debug!("crate graph: {:?}", crate_graph);
172 analysis_change.set_crate_graph(crate_graph); 159 analysis_change.set_crate_graph(crate_graph);
173 160
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 0bebb5bf6..73b0f881d 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -15,7 +15,7 @@ use ra_flycheck::{Flycheck, FlycheckConfig};
15use ra_ide::{ 15use ra_ide::{
16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, 16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId,
17}; 17};
18use ra_project_model::{get_rustc_cfg_options, ProcMacroClient, ProjectWorkspace}; 18use ra_project_model::{ProcMacroClient, ProjectWorkspace};
19use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; 19use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch};
20use relative_path::RelativePathBuf; 20use relative_path::RelativePathBuf;
21use stdx::format_to; 21use stdx::format_to;
@@ -135,14 +135,6 @@ impl GlobalState {
135 } 135 }
136 } 136 }
137 137
138 // FIXME: Read default cfgs from config
139 let default_cfg_options = {
140 let mut opts = get_rustc_cfg_options(config.cargo.target.as_ref());
141 opts.insert_atom("test".into());
142 opts.insert_atom("debug_assertion".into());
143 opts
144 };
145
146 let proc_macro_client = match &config.proc_macro_srv { 138 let proc_macro_client = match &config.proc_macro_srv {
147 None => ProcMacroClient::dummy(), 139 None => ProcMacroClient::dummy(),
148 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) { 140 Some((path, args)) => match ProcMacroClient::extern_process(path.into(), args) {
@@ -168,7 +160,7 @@ impl GlobalState {
168 }; 160 };
169 for ws in workspaces.iter() { 161 for ws in workspaces.iter() {
170 crate_graph.extend(ws.to_crate_graph( 162 crate_graph.extend(ws.to_crate_graph(
171 &default_cfg_options, 163 config.cargo.target.as_deref(),
172 &extern_source_roots, 164 &extern_source_roots,
173 &proc_macro_client, 165 &proc_macro_client,
174 &mut load, 166 &mut load,