aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_project_model/src/lib.rs10
-rw-r--r--crates/rust-analyzer/src/config.rs23
-rw-r--r--crates/rust-analyzer/src/main_loop.rs35
3 files changed, 48 insertions, 20 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index a99612690..7ad941279 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -32,6 +32,12 @@ pub enum ProjectWorkspace {
32 Json { project: JsonProject }, 32 Json { project: JsonProject },
33} 33}
34 34
35impl From<JsonProject> for ProjectWorkspace {
36 fn from(project: JsonProject) -> ProjectWorkspace {
37 ProjectWorkspace::Json { project }
38 }
39}
40
35/// `PackageRoot` describes a package root folder. 41/// `PackageRoot` describes a package root folder.
36/// Which may be an external dependency, or a member of 42/// Which may be an external dependency, or a member of
37/// the current workspace. 43/// the current workspace.
@@ -144,11 +150,11 @@ impl ProjectManifest {
144 150
145impl ProjectWorkspace { 151impl ProjectWorkspace {
146 pub fn load( 152 pub fn load(
147 root: ProjectManifest, 153 manifest: ProjectManifest,
148 cargo_features: &CargoConfig, 154 cargo_features: &CargoConfig,
149 with_sysroot: bool, 155 with_sysroot: bool,
150 ) -> Result<ProjectWorkspace> { 156 ) -> Result<ProjectWorkspace> {
151 let res = match root { 157 let res = match manifest {
152 ProjectManifest::ProjectJson(project_json) => { 158 ProjectManifest::ProjectJson(project_json) => {
153 let file = File::open(&project_json).with_context(|| { 159 let file = File::open(&project_json).with_context(|| {
154 format!("Failed to open json file {}", project_json.display()) 160 format!("Failed to open json file {}", project_json.display())
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 761bc9c2d..0e5dc56fd 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -261,6 +261,22 @@ impl Config {
261 self.lens = LensConfig::NO_LENS; 261 self.lens = LensConfig::NO_LENS;
262 } 262 }
263 263
264 if let Some(linked_projects) = get::<Vec<ManifestOrJsonProject>>(value, "/linkedProjects") {
265 if !linked_projects.is_empty() {
266 self.linked_projects.clear();
267 for linked_project in linked_projects {
268 let linked_project = match linked_project {
269 ManifestOrJsonProject::Manifest(it) => match ProjectManifest::from_manifest_file(it) {
270 Ok(it) => it.into(),
271 Err(_) => continue,
272 }
273 ManifestOrJsonProject::JsonProject(it) => it.into(),
274 };
275 self.linked_projects.push(linked_project);
276 }
277 }
278 }
279
264 log::info!("Config::update() = {:#?}", self); 280 log::info!("Config::update() = {:#?}", self);
265 281
266 fn get<'a, T: Deserialize<'a>>(value: &'a serde_json::Value, pointer: &str) -> Option<T> { 282 fn get<'a, T: Deserialize<'a>>(value: &'a serde_json::Value, pointer: &str) -> Option<T> {
@@ -324,3 +340,10 @@ impl Config {
324 } 340 }
325 } 341 }
326} 342}
343
344#[derive(Deserialize)]
345#[serde(untagged)]
346enum ManifestOrJsonProject {
347 Manifest(PathBuf),
348 JsonProject(JsonProject),
349}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index d901f21d7..1f8f6b978 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -105,24 +105,23 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
105 .linked_projects 105 .linked_projects
106 .iter() 106 .iter()
107 .filter_map(|project| match project { 107 .filter_map(|project| match project {
108 LinkedProject::ProjectManifest(it) => Some(it), 108 LinkedProject::ProjectManifest(manifest) => {
109 LinkedProject::JsonProject(_) => None, 109 ra_project_model::ProjectWorkspace::load(
110 }) 110 manifest.clone(),
111 .filter_map(|root| { 111 &config.cargo,
112 ra_project_model::ProjectWorkspace::load( 112 config.with_sysroot,
113 root.clone(), 113 )
114 &config.cargo, 114 .map_err(|err| {
115 config.with_sysroot, 115 log::error!("failed to load workspace: {:#}", err);
116 ) 116 show_message(
117 .map_err(|err| { 117 lsp_types::MessageType::Error,
118 log::error!("failed to load workspace: {:#}", err); 118 format!("rust-analyzer failed to load workspace: {:#}", err),
119 show_message( 119 &connection.sender,
120 lsp_types::MessageType::Error, 120 );
121 format!("rust-analyzer failed to load workspace: {:#}", err), 121 })
122 &connection.sender, 122 .ok()
123 ); 123 }
124 }) 124 LinkedProject::JsonProject(it) => Some(it.clone().into()),
125 .ok()
126 }) 125 })
127 .collect::<Vec<_>>() 126 .collect::<Vec<_>>()
128 }; 127 };