aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/project_model/src/lib.rs1
-rw-r--r--crates/project_model/src/workspace.rs3
-rw-r--r--crates/rust-analyzer/src/bin/main.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs20
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--crates/rust-analyzer/src/reload.rs1
6 files changed, 25 insertions, 3 deletions
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs
index 8c6cf94c2..c2fde00d5 100644
--- a/crates/project_model/src/lib.rs
+++ b/crates/project_model/src/lib.rs
@@ -50,6 +50,7 @@ pub use proc_macro_api::ProcMacroClient;
50pub enum ProjectManifest { 50pub enum ProjectManifest {
51 ProjectJson(AbsPathBuf), 51 ProjectJson(AbsPathBuf),
52 CargoToml(AbsPathBuf), 52 CargoToml(AbsPathBuf),
53 DetachedFile(AbsPathBuf),
53} 54}
54 55
55impl ProjectManifest { 56impl ProjectManifest {
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index 607e62ea5..5fd648710 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -148,6 +148,9 @@ impl ProjectWorkspace {
148 let rustc_cfg = rustc_cfg::get(Some(&cargo_toml), config.target.as_deref()); 148 let rustc_cfg = rustc_cfg::get(Some(&cargo_toml), config.target.as_deref());
149 ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } 149 ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg }
150 } 150 }
151 ProjectManifest::DetachedFile(_) => {
152 todo!("TODO kb")
153 }
151 }; 154 };
152 155
153 Ok(res) 156 Ok(res)
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index f0abb5b15..7ee35d52b 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -214,7 +214,7 @@ fn run_server() -> Result<()> {
214 214
215 let discovered = ProjectManifest::discover_all(&workspace_roots); 215 let discovered = ProjectManifest::discover_all(&workspace_roots);
216 log::info!("discovered projects: {:?}", discovered); 216 log::info!("discovered projects: {:?}", discovered);
217 if discovered.is_empty() { 217 if discovered.is_empty() && config.detached_files().is_empty() {
218 log::error!("failed to find any projects in {:?}", workspace_roots); 218 log::error!("failed to find any projects in {:?}", workspace_roots);
219 } 219 }
220 220
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index b700d025f..570534c9a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -236,6 +236,7 @@ impl Default for ConfigData {
236pub struct Config { 236pub struct Config {
237 caps: lsp_types::ClientCapabilities, 237 caps: lsp_types::ClientCapabilities,
238 data: ConfigData, 238 data: ConfigData,
239 detached_files: Vec<ProjectManifest>,
239 pub discovered_projects: Option<Vec<ProjectManifest>>, 240 pub discovered_projects: Option<Vec<ProjectManifest>>,
240 pub root_path: AbsPathBuf, 241 pub root_path: AbsPathBuf,
241} 242}
@@ -328,13 +329,24 @@ pub struct WorkspaceSymbolConfig {
328 329
329impl Config { 330impl Config {
330 pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { 331 pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self {
331 Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } 332 Config {
333 caps,
334 data: ConfigData::default(),
335 detached_files: Vec::new(),
336 discovered_projects: None,
337 root_path,
338 }
332 } 339 }
333 pub fn update(&mut self, json: serde_json::Value) { 340 pub fn update(&mut self, mut json: serde_json::Value) {
334 log::info!("updating config from JSON: {:#}", json); 341 log::info!("updating config from JSON: {:#}", json);
335 if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) { 342 if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) {
336 return; 343 return;
337 } 344 }
345 self.detached_files = get_field::<Vec<PathBuf>>(&mut json, "detachedFiles", None, "[]")
346 .into_iter()
347 .map(AbsPathBuf::assert)
348 .map(ProjectManifest::DetachedFile)
349 .collect();
338 self.data = ConfigData::from_json(json); 350 self.data = ConfigData::from_json(json);
339 } 351 }
340 352
@@ -387,6 +399,10 @@ impl Config {
387 } 399 }
388 } 400 }
389 401
402 pub fn detached_files(&self) -> &[ProjectManifest] {
403 &self.detached_files
404 }
405
390 pub fn did_save_text_document_dynamic_registration(&self) -> bool { 406 pub fn did_save_text_document_dynamic_registration(&self) -> bool {
391 let caps = 407 let caps =
392 try_or!(self.caps.text_document.as_ref()?.synchronization.clone()?, Default::default()); 408 try_or!(self.caps.text_document.as_ref()?.synchronization.clone()?, Default::default());
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index f837b89dd..cb002f700 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -103,6 +103,7 @@ impl fmt::Debug for Event {
103impl GlobalState { 103impl GlobalState {
104 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> { 104 fn run(mut self, inbox: Receiver<lsp_server::Message>) -> Result<()> {
105 if self.config.linked_projects().is_empty() 105 if self.config.linked_projects().is_empty()
106 && self.config.detached_files().is_empty()
106 && self.config.notifications().cargo_toml_not_found 107 && self.config.notifications().cargo_toml_not_found
107 { 108 {
108 self.show_message( 109 self.show_message(
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 0ae2758cc..cfa95275d 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -146,6 +146,7 @@ impl GlobalState {
146 log::info!("will fetch workspaces"); 146 log::info!("will fetch workspaces");
147 147
148 self.task_pool.handle.spawn_with_sender({ 148 self.task_pool.handle.spawn_with_sender({
149 // TODO kb reload workspace here?
149 let linked_projects = self.config.linked_projects(); 150 let linked_projects = self.config.linked_projects();
150 let cargo_config = self.config.cargo(); 151 let cargo_config = self.config.cargo();
151 152