aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/project_model/src/cargo_workspace.rs20
-rw-r--r--crates/project_model/src/workspace.rs34
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--crates/rust-analyzer/src/reload.rs7
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/support.rs8
6 files changed, 35 insertions, 41 deletions
diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs
index 608a031d4..540b57ae4 100644
--- a/crates/project_model/src/cargo_workspace.rs
+++ b/crates/project_model/src/cargo_workspace.rs
@@ -65,6 +65,10 @@ pub struct CargoConfig {
65 /// rustc target 65 /// rustc target
66 pub target: Option<String>, 66 pub target: Option<String>,
67 67
68 /// Don't load sysroot crates (`std`, `core` & friends). Might be useful
69 /// when debugging isolated issues.
70 pub no_sysroot: bool,
71
68 /// rustc private crate source 72 /// rustc private crate source
69 pub rustc_source: Option<AbsPathBuf>, 73 pub rustc_source: Option<AbsPathBuf>,
70} 74}
@@ -140,27 +144,27 @@ impl PackageData {
140impl CargoWorkspace { 144impl CargoWorkspace {
141 pub fn from_cargo_metadata( 145 pub fn from_cargo_metadata(
142 cargo_toml: &AbsPath, 146 cargo_toml: &AbsPath,
143 cargo_features: &CargoConfig, 147 config: &CargoConfig,
144 ) -> Result<CargoWorkspace> { 148 ) -> Result<CargoWorkspace> {
145 let mut meta = MetadataCommand::new(); 149 let mut meta = MetadataCommand::new();
146 meta.cargo_path(toolchain::cargo()); 150 meta.cargo_path(toolchain::cargo());
147 meta.manifest_path(cargo_toml.to_path_buf()); 151 meta.manifest_path(cargo_toml.to_path_buf());
148 if cargo_features.all_features { 152 if config.all_features {
149 meta.features(CargoOpt::AllFeatures); 153 meta.features(CargoOpt::AllFeatures);
150 } else { 154 } else {
151 if cargo_features.no_default_features { 155 if config.no_default_features {
152 // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` 156 // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
153 // https://github.com/oli-obk/cargo_metadata/issues/79 157 // https://github.com/oli-obk/cargo_metadata/issues/79
154 meta.features(CargoOpt::NoDefaultFeatures); 158 meta.features(CargoOpt::NoDefaultFeatures);
155 } 159 }
156 if !cargo_features.features.is_empty() { 160 if !config.features.is_empty() {
157 meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); 161 meta.features(CargoOpt::SomeFeatures(config.features.clone()));
158 } 162 }
159 } 163 }
160 if let Some(parent) = cargo_toml.parent() { 164 if let Some(parent) = cargo_toml.parent() {
161 meta.current_dir(parent.to_path_buf()); 165 meta.current_dir(parent.to_path_buf());
162 } 166 }
163 if let Some(target) = cargo_features.target.as_ref() { 167 if let Some(target) = config.target.as_ref() {
164 meta.other_options(vec![String::from("--filter-platform"), target.clone()]); 168 meta.other_options(vec![String::from("--filter-platform"), target.clone()]);
165 } 169 }
166 let mut meta = meta.exec().with_context(|| { 170 let mut meta = meta.exec().with_context(|| {
@@ -170,8 +174,8 @@ impl CargoWorkspace {
170 let mut out_dir_by_id = FxHashMap::default(); 174 let mut out_dir_by_id = FxHashMap::default();
171 let mut cfgs = FxHashMap::default(); 175 let mut cfgs = FxHashMap::default();
172 let mut proc_macro_dylib_paths = FxHashMap::default(); 176 let mut proc_macro_dylib_paths = FxHashMap::default();
173 if cargo_features.load_out_dirs_from_check { 177 if config.load_out_dirs_from_check {
174 let resources = load_extern_resources(cargo_toml, cargo_features)?; 178 let resources = load_extern_resources(cargo_toml, config)?;
175 out_dir_by_id = resources.out_dirs; 179 out_dir_by_id = resources.out_dirs;
176 cfgs = resources.cfgs; 180 cfgs = resources.cfgs;
177 proc_macro_dylib_paths = resources.proc_dylib_paths; 181 proc_macro_dylib_paths = resources.proc_dylib_paths;
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index 43ea351d1..8a1a60e0e 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -1,3 +1,7 @@
1//! Handles lowering of build-system specific workspace information (`cargo
2//! metadata` or `rust-project.json`) into representation stored in the salsa
3//! database -- `CrateGraph`.
4
1use std::{fmt, fs, path::Component, process::Command}; 5use std::{fmt, fs, path::Component, process::Command};
2 6
3use anyhow::{Context, Result}; 7use anyhow::{Context, Result};
@@ -56,11 +60,7 @@ impl fmt::Debug for ProjectWorkspace {
56} 60}
57 61
58impl ProjectWorkspace { 62impl ProjectWorkspace {
59 pub fn load( 63 pub fn load(manifest: ProjectManifest, config: &CargoConfig) -> Result<ProjectWorkspace> {
60 manifest: ProjectManifest,
61 cargo_config: &CargoConfig,
62 with_sysroot: bool,
63 ) -> Result<ProjectWorkspace> {
64 let res = match manifest { 64 let res = match manifest {
65 ProjectManifest::ProjectJson(project_json) => { 65 ProjectManifest::ProjectJson(project_json) => {
66 let file = fs::read_to_string(&project_json).with_context(|| { 66 let file = fs::read_to_string(&project_json).with_context(|| {
@@ -84,32 +84,30 @@ impl ProjectWorkspace {
84 cmd 84 cmd
85 })?; 85 })?;
86 86
87 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, cargo_config) 87 let cargo = CargoWorkspace::from_cargo_metadata(&cargo_toml, config).with_context(
88 .with_context(|| { 88 || {
89 format!( 89 format!(
90 "Failed to read Cargo metadata from Cargo.toml file {}, {}", 90 "Failed to read Cargo metadata from Cargo.toml file {}, {}",
91 cargo_toml.display(), 91 cargo_toml.display(),
92 cargo_version 92 cargo_version
93 ) 93 )
94 })?; 94 },
95 let sysroot = if with_sysroot { 95 )?;
96 let sysroot = if config.no_sysroot {
97 Sysroot::default()
98 } else {
96 Sysroot::discover(&cargo_toml).with_context(|| { 99 Sysroot::discover(&cargo_toml).with_context(|| {
97 format!( 100 format!(
98 "Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?", 101 "Failed to find sysroot for Cargo.toml file {}. Is rust-src installed?",
99 cargo_toml.display() 102 cargo_toml.display()
100 ) 103 )
101 })? 104 })?
102 } else {
103 Sysroot::default()
104 }; 105 };
105 106
106 let rustc = if let Some(rustc_dir) = &cargo_config.rustc_source { 107 let rustc = if let Some(rustc_dir) = &config.rustc_source {
107 Some( 108 Some(CargoWorkspace::from_cargo_metadata(&rustc_dir, config).with_context(
108 CargoWorkspace::from_cargo_metadata(&rustc_dir, cargo_config) 109 || format!("Failed to read Cargo metadata for Rust sources"),
109 .with_context(|| { 110 )?)
110 format!("Failed to read Cargo metadata for Rust sources")
111 })?,
112 )
113 } else { 111 } else {
114 None 112 None
115 }; 113 };
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index ab1e2ab92..76526c66c 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -21,7 +21,6 @@ pub fn load_cargo(
21 let ws = ProjectWorkspace::load( 21 let ws = ProjectWorkspace::load(
22 root, 22 root,
23 &CargoConfig { load_out_dirs_from_check, ..Default::default() }, 23 &CargoConfig { load_out_dirs_from_check, ..Default::default() },
24 true,
25 )?; 24 )?;
26 25
27 let (sender, receiver) = unbounded(); 26 let (sender, receiver) = unbounded();
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 372180ab5..d16796590 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -49,7 +49,6 @@ pub struct Config {
49 pub hover: HoverConfig, 49 pub hover: HoverConfig,
50 pub semantic_tokens_refresh: bool, 50 pub semantic_tokens_refresh: bool,
51 51
52 pub with_sysroot: bool,
53 pub linked_projects: Vec<LinkedProject>, 52 pub linked_projects: Vec<LinkedProject>,
54 pub root_path: AbsPathBuf, 53 pub root_path: AbsPathBuf,
55} 54}
@@ -155,7 +154,6 @@ impl Config {
155 Config { 154 Config {
156 client_caps: ClientCapsConfig::default(), 155 client_caps: ClientCapsConfig::default(),
157 156
158 with_sysroot: true,
159 publish_diagnostics: true, 157 publish_diagnostics: true,
160 diagnostics: DiagnosticsConfig::default(), 158 diagnostics: DiagnosticsConfig::default(),
161 diagnostics_map: DiagnosticsMapConfig::default(), 159 diagnostics_map: DiagnosticsMapConfig::default(),
@@ -209,7 +207,6 @@ impl Config {
209 207
210 let data = ConfigData::from_json(json); 208 let data = ConfigData::from_json(json);
211 209
212 self.with_sysroot = data.withSysroot;
213 self.publish_diagnostics = data.diagnostics_enable; 210 self.publish_diagnostics = data.diagnostics_enable;
214 self.diagnostics = DiagnosticsConfig { 211 self.diagnostics = DiagnosticsConfig {
215 disable_experimental: !data.diagnostics_enableExperimental, 212 disable_experimental: !data.diagnostics_enableExperimental,
@@ -246,6 +243,7 @@ impl Config {
246 load_out_dirs_from_check: data.cargo_loadOutDirsFromCheck, 243 load_out_dirs_from_check: data.cargo_loadOutDirsFromCheck,
247 target: data.cargo_target.clone(), 244 target: data.cargo_target.clone(),
248 rustc_source: rustc_source, 245 rustc_source: rustc_source,
246 no_sysroot: data.cargo_noSysroot,
249 }; 247 };
250 self.runnables = RunnablesConfig { 248 self.runnables = RunnablesConfig {
251 override_cargo: data.runnables_overrideCargo, 249 override_cargo: data.runnables_overrideCargo,
@@ -492,6 +490,7 @@ config_data! {
492 cargo_loadOutDirsFromCheck: bool = false, 490 cargo_loadOutDirsFromCheck: bool = false,
493 cargo_noDefaultFeatures: bool = false, 491 cargo_noDefaultFeatures: bool = false,
494 cargo_target: Option<String> = None, 492 cargo_target: Option<String> = None,
493 cargo_noSysroot: bool = false,
495 494
496 checkOnSave_enable: bool = true, 495 checkOnSave_enable: bool = true,
497 checkOnSave_allFeatures: Option<bool> = None, 496 checkOnSave_allFeatures: Option<bool> = None,
@@ -544,7 +543,6 @@ config_data! {
544 rustfmt_extraArgs: Vec<String> = Vec::new(), 543 rustfmt_extraArgs: Vec<String> = Vec::new(),
545 rustfmt_overrideCommand: Option<Vec<String>> = None, 544 rustfmt_overrideCommand: Option<Vec<String>> = None,
546 545
547 withSysroot: bool = true,
548 rustcSource : Option<String> = None, 546 rustcSource : Option<String> = None,
549 } 547 }
550} 548}
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 11c8d0e5f..fa6e09f42 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -96,17 +96,12 @@ impl GlobalState {
96 self.task_pool.handle.spawn({ 96 self.task_pool.handle.spawn({
97 let linked_projects = self.config.linked_projects.clone(); 97 let linked_projects = self.config.linked_projects.clone();
98 let cargo_config = self.config.cargo.clone(); 98 let cargo_config = self.config.cargo.clone();
99 let with_sysroot = self.config.with_sysroot.clone();
100 move || { 99 move || {
101 let workspaces = linked_projects 100 let workspaces = linked_projects
102 .iter() 101 .iter()
103 .map(|project| match project { 102 .map(|project| match project {
104 LinkedProject::ProjectManifest(manifest) => { 103 LinkedProject::ProjectManifest(manifest) => {
105 project_model::ProjectWorkspace::load( 104 project_model::ProjectWorkspace::load(manifest.clone(), &cargo_config)
106 manifest.clone(),
107 &cargo_config,
108 with_sysroot,
109 )
110 } 105 }
111 LinkedProject::InlineJsonProject(it) => { 106 LinkedProject::InlineJsonProject(it) => {
112 project_model::ProjectWorkspace::load_inline(it.clone()) 107 project_model::ProjectWorkspace::load_inline(it.clone())
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs
index fe9362bc0..b210b98f0 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/support.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs
@@ -12,7 +12,7 @@ use lsp_types::{
12 notification::Exit, request::Shutdown, TextDocumentIdentifier, Url, WorkDoneProgress, 12 notification::Exit, request::Shutdown, TextDocumentIdentifier, Url, WorkDoneProgress,
13}; 13};
14use lsp_types::{ProgressParams, ProgressParamsValue}; 14use lsp_types::{ProgressParams, ProgressParamsValue};
15use project_model::ProjectManifest; 15use project_model::{CargoConfig, ProjectManifest};
16use rust_analyzer::{ 16use rust_analyzer::{
17 config::{ClientCapsConfig, Config, FilesConfig, FilesWatcher, LinkedProject}, 17 config::{ClientCapsConfig, Config, FilesConfig, FilesWatcher, LinkedProject},
18 main_loop, 18 main_loop,
@@ -47,8 +47,8 @@ impl<'a> Project<'a> {
47 self 47 self
48 } 48 }
49 49
50 pub(crate) fn with_sysroot(mut self, sysroot: bool) -> Project<'a> { 50 pub(crate) fn with_sysroot(mut self, yes: bool) -> Project<'a> {
51 self.with_sysroot = sysroot; 51 self.with_sysroot = yes;
52 self 52 self
53 } 53 }
54 54
@@ -90,7 +90,7 @@ impl<'a> Project<'a> {
90 work_done_progress: true, 90 work_done_progress: true,
91 ..Default::default() 91 ..Default::default()
92 }, 92 },
93 with_sysroot: self.with_sysroot, 93 cargo: CargoConfig { no_sysroot: !self.with_sysroot, ..Default::default() },
94 linked_projects, 94 linked_projects,
95 files: FilesConfig { watcher: FilesWatcher::Client, exclude: Vec::new() }, 95 files: FilesConfig { watcher: FilesWatcher::Client, exclude: Vec::new() },
96 ..Config::new(tmp_dir_path) 96 ..Config::new(tmp_dir_path)