Skip to content

Commit 1a0b772

Browse files
committed
Auto merge of #16153 - Veykril:err-msg, r=Veykril
fix: Notify user that linkedProjects is set when failing to discover projects Fixes #15171
2 parents df94a87 + 8136e73 commit 1a0b772

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

crates/rust-analyzer/src/config.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
//! configure the server itself, feature flags are passed into analysis, and
88
//! tweak things like automatic insertion of `()` in completions.
99
10-
use std::{fmt, iter, ops::Not, path::PathBuf};
10+
use std::{
11+
fmt, iter,
12+
ops::Not,
13+
path::{Path, PathBuf},
14+
};
1115

1216
use cfg::{CfgAtom, CfgDiff};
1317
use flycheck::FlycheckConfig;
@@ -920,7 +924,19 @@ impl Config {
920924
pub fn has_linked_projects(&self) -> bool {
921925
!self.data.linkedProjects.is_empty()
922926
}
923-
pub fn linked_projects(&self) -> Vec<LinkedProject> {
927+
pub fn linked_manifests(&self) -> impl Iterator<Item = &Path> + '_ {
928+
self.data.linkedProjects.iter().filter_map(|it| match it {
929+
ManifestOrProjectJson::Manifest(p) => Some(&**p),
930+
ManifestOrProjectJson::ProjectJson(_) => None,
931+
})
932+
}
933+
pub fn has_linked_project_jsons(&self) -> bool {
934+
self.data
935+
.linkedProjects
936+
.iter()
937+
.any(|it| matches!(it, ManifestOrProjectJson::ProjectJson(_)))
938+
}
939+
pub fn linked_or_discovered_projects(&self) -> Vec<LinkedProject> {
924940
match self.data.linkedProjects.as_slice() {
925941
[] => {
926942
let exclude_dirs: Vec<_> =
@@ -955,15 +971,6 @@ impl Config {
955971
}
956972
}
957973

958-
pub fn add_linked_projects(&mut self, linked_projects: Vec<ProjectJsonData>) {
959-
let mut linked_projects = linked_projects
960-
.into_iter()
961-
.map(ManifestOrProjectJson::ProjectJson)
962-
.collect::<Vec<ManifestOrProjectJson>>();
963-
964-
self.data.linkedProjects.append(&mut linked_projects);
965-
}
966-
967974
pub fn did_save_text_document_dynamic_registration(&self) -> bool {
968975
let caps = try_or_def!(self.caps.text_document.as_ref()?.synchronization.clone()?);
969976
caps.did_save == Some(true) && caps.dynamic_registration == Some(true)

crates/rust-analyzer/src/handlers/request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ pub(crate) fn handle_runnables(
801801
}
802802
}
803803
None => {
804-
if !snap.config.linked_projects().is_empty() {
804+
if !snap.config.linked_or_discovered_projects().is_empty() {
805805
res.push(lsp_ext::Runnable {
806806
label: "cargo check --workspace".to_string(),
807807
location: None,

crates/rust-analyzer/src/reload.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ impl GlobalState {
8080
&self.config.lru_query_capacities().cloned().unwrap_or_default(),
8181
);
8282
}
83-
if self.config.linked_projects() != old_config.linked_projects() {
83+
if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects()
84+
{
8485
self.fetch_workspaces_queue.request_op("linked projects changed".to_string(), false)
8586
} else if self.config.flycheck() != old_config.flycheck() {
8687
self.reload_flycheck();
@@ -128,7 +129,7 @@ impl GlobalState {
128129
status.health = lsp_ext::Health::Warning;
129130
message.push_str("Auto-reloading is disabled and the workspace has changed, a manual workspace reload is required.\n\n");
130131
}
131-
if self.config.linked_projects().is_empty()
132+
if self.config.linked_or_discovered_projects().is_empty()
132133
&& self.config.detached_files().is_empty()
133134
&& self.config.notifications().cargo_toml_not_found
134135
{
@@ -174,7 +175,21 @@ impl GlobalState {
174175

175176
if let Err(_) = self.fetch_workspace_error() {
176177
status.health = lsp_ext::Health::Error;
177-
message.push_str("Failed to load workspaces.\n\n");
178+
message.push_str("Failed to load workspaces.");
179+
180+
if self.config.has_linked_projects() {
181+
message.push_str(
182+
"`rust-analyzer.linkedProjects` have been specified, which may be incorrect. Specified project paths:\n",
183+
);
184+
message.push_str(&format!(
185+
" {}",
186+
self.config.linked_manifests().map(|it| it.display()).format("\n ")
187+
));
188+
if self.config.has_linked_project_jsons() {
189+
message.push_str("\nAdditionally, one or more project jsons are specified")
190+
}
191+
}
192+
message.push_str("\n\n");
178193
}
179194

180195
if !message.is_empty() {
@@ -187,7 +202,7 @@ impl GlobalState {
187202
tracing::info!(%cause, "will fetch workspaces");
188203

189204
self.task_pool.handle.spawn_with_sender(ThreadIntent::Worker, {
190-
let linked_projects = self.config.linked_projects();
205+
let linked_projects = self.config.linked_or_discovered_projects();
191206
let detached_files = self.config.detached_files().to_vec();
192207
let cargo_config = self.config.cargo();
193208

0 commit comments

Comments
 (0)