From 2fd25e2d98fa7cd898a337a604b1ff90cb8152bd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 26 Jun 2020 11:29:27 +0200 Subject: reduce visibility --- crates/rust-analyzer/src/cli/load_cargo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index b1250f2fe..d8677c231 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs @@ -54,7 +54,7 @@ pub fn load_cargo( Ok((host, vfs)) } -pub(crate) fn load( +fn load( crate_graph: CrateGraph, source_root_config: SourceRootConfig, vfs: &mut vfs::Vfs, -- cgit v1.2.3 From 34118779ecd315efd2e17d0a055c3afc8ed0fed6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 26 Jun 2020 11:39:27 +0200 Subject: Workaround use Trait as _ bug in rust-analyzer --- crates/rust-analyzer/src/global_state.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index a9a1d09fd..5b6c7922d 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -13,7 +13,6 @@ use ra_db::{CrateId, VfsPath}; use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; use stdx::format_to; -use vfs::loader::Handle as _; use crate::{ config::Config, @@ -90,8 +89,8 @@ impl GlobalState { pub(crate) fn new(sender: Sender, config: Config) -> GlobalState { let loader = { let (sender, receiver) = unbounded::(); - let handle = - vfs_notify::NotifyHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); + let handle: vfs_notify::NotifyHandle = + vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); let handle = Box::new(handle) as Box; Handle { handle, receiver } }; -- cgit v1.2.3 From 751b8792a2db3a744b22f5261d4136e671b14835 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 26 Jun 2020 11:43:07 +0200 Subject: Simplify --- crates/rust-analyzer/src/global_state.rs | 8 -------- crates/rust-analyzer/src/main_loop.rs | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 5b6c7922d..6a5ba138f 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -170,14 +170,6 @@ impl GlobalState { } } - pub(crate) fn maybe_collect_garbage(&mut self) { - self.analysis_host.maybe_collect_garbage() - } - - pub(crate) fn collect_garbage(&mut self) { - self.analysis_host.collect_garbage() - } - pub(crate) fn send(&mut self, message: lsp_server::Message) { self.sender.send(message).unwrap() } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 386a47621..162c0057e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -158,7 +158,7 @@ impl GlobalState { } Task::Unit => (), } - self.maybe_collect_garbage(); + self.analysis_host.maybe_collect_garbage(); } Event::Vfs(task) => match task { vfs::loader::Message::Loaded { files } => { @@ -274,7 +274,7 @@ impl GlobalState { self.req_queue.incoming.register(req.id.clone(), (req.method.clone(), request_received)); RequestDispatcher { req: Some(req), global_state: self } - .on_sync::(|s, ()| Ok(s.collect_garbage()))? + .on_sync::(|s, ()| Ok(s.analysis_host.collect_garbage()))? .on_sync::(|s, p| handlers::handle_join_lines(s.snapshot(), p))? .on_sync::(|s, p| handlers::handle_on_enter(s.snapshot(), p))? .on_sync::(|_, ()| Ok(()))? -- cgit v1.2.3 From b039f0d1baa34b7d53117085438769cc3402e112 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 26 Jun 2020 11:44:46 +0200 Subject: Simplify --- crates/rust-analyzer/src/global_state.rs | 23 +---------------------- crates/rust-analyzer/src/handlers.rs | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 6a5ba138f..7533bb319 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs @@ -12,7 +12,6 @@ use parking_lot::RwLock; use ra_db::{CrateId, VfsPath}; use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; -use stdx::format_to; use crate::{ config::Config, @@ -82,7 +81,7 @@ pub(crate) struct GlobalStateSnapshot { pub(crate) check_fixes: CheckFixes, pub(crate) latest_requests: Arc>, vfs: Arc)>>, - workspaces: Arc>, + pub(crate) workspaces: Arc>, } impl GlobalState { @@ -233,26 +232,6 @@ impl GlobalStateSnapshot { ProjectWorkspace::Json { .. } => None, }) } - - pub(crate) fn status(&self) -> String { - let mut buf = String::new(); - if self.workspaces.is_empty() { - buf.push_str("no workspaces\n") - } else { - buf.push_str("workspaces:\n"); - for w in self.workspaces.iter() { - format_to!(buf, "{} packages loaded\n", w.n_packages()); - } - } - buf.push_str("\nanalysis:\n"); - buf.push_str( - &self - .analysis - .status() - .unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()), - ); - buf - } } pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 12b494496..6c21f25fe 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -39,7 +39,20 @@ use crate::{ pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result { let _p = profile("handle_analyzer_status"); - let mut buf = snap.status(); + + let mut buf = String::new(); + if snap.workspaces.is_empty() { + buf.push_str("no workspaces\n") + } else { + buf.push_str("workspaces:\n"); + for w in snap.workspaces.iter() { + format_to!(buf, "{} packages loaded\n", w.n_packages()); + } + } + buf.push_str("\nanalysis:\n"); + buf.push_str( + &snap.analysis.status().unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()), + ); format_to!(buf, "\n\nrequests:\n"); let requests = snap.latest_requests.read(); for (is_last, r) in requests.iter() { -- cgit v1.2.3