From 695569d9784b4a7d6e91451a0cc354f8bd009b59 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 23 May 2021 20:32:22 +0300 Subject: Draft detached files retrieval --- crates/project_model/src/lib.rs | 1 + crates/project_model/src/workspace.rs | 3 +++ crates/rust-analyzer/src/bin/main.rs | 2 +- crates/rust-analyzer/src/config.rs | 20 ++++++++++++++++++-- crates/rust-analyzer/src/main_loop.rs | 1 + crates/rust-analyzer/src/reload.rs | 1 + 6 files changed, 25 insertions(+), 3 deletions(-) (limited to 'crates') 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; pub enum ProjectManifest { ProjectJson(AbsPathBuf), CargoToml(AbsPathBuf), + DetachedFile(AbsPathBuf), } impl 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 { let rustc_cfg = rustc_cfg::get(Some(&cargo_toml), config.target.as_deref()); ProjectWorkspace::Cargo { cargo, sysroot, rustc, rustc_cfg } } + ProjectManifest::DetachedFile(_) => { + todo!("TODO kb") + } }; 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<()> { let discovered = ProjectManifest::discover_all(&workspace_roots); log::info!("discovered projects: {:?}", discovered); - if discovered.is_empty() { + if discovered.is_empty() && config.detached_files().is_empty() { log::error!("failed to find any projects in {:?}", workspace_roots); } 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 { pub struct Config { caps: lsp_types::ClientCapabilities, data: ConfigData, + detached_files: Vec, pub discovered_projects: Option>, pub root_path: AbsPathBuf, } @@ -328,13 +329,24 @@ pub struct WorkspaceSymbolConfig { impl Config { pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { - Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } + Config { + caps, + data: ConfigData::default(), + detached_files: Vec::new(), + discovered_projects: None, + root_path, + } } - pub fn update(&mut self, json: serde_json::Value) { + pub fn update(&mut self, mut json: serde_json::Value) { log::info!("updating config from JSON: {:#}", json); if json.is_null() || json.as_object().map_or(false, |it| it.is_empty()) { return; } + self.detached_files = get_field::>(&mut json, "detachedFiles", None, "[]") + .into_iter() + .map(AbsPathBuf::assert) + .map(ProjectManifest::DetachedFile) + .collect(); self.data = ConfigData::from_json(json); } @@ -387,6 +399,10 @@ impl Config { } } + pub fn detached_files(&self) -> &[ProjectManifest] { + &self.detached_files + } + pub fn did_save_text_document_dynamic_registration(&self) -> bool { let caps = 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 { impl GlobalState { fn run(mut self, inbox: Receiver) -> Result<()> { if self.config.linked_projects().is_empty() + && self.config.detached_files().is_empty() && self.config.notifications().cargo_toml_not_found { 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 { log::info!("will fetch workspaces"); self.task_pool.handle.spawn_with_sender({ + // TODO kb reload workspace here? let linked_projects = self.config.linked_projects(); let cargo_config = self.config.cargo(); -- cgit v1.2.3