aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs2
-rw-r--r--crates/rust-analyzer/src/global_state.rs36
-rw-r--r--crates/rust-analyzer/src/handlers.rs15
-rw-r--r--crates/rust-analyzer/src/main_loop.rs4
4 files changed, 20 insertions, 37 deletions
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(
54 Ok((host, vfs)) 54 Ok((host, vfs))
55} 55}
56 56
57pub(crate) fn load( 57fn load(
58 crate_graph: CrateGraph, 58 crate_graph: CrateGraph,
59 source_root_config: SourceRootConfig, 59 source_root_config: SourceRootConfig,
60 vfs: &mut vfs::Vfs, 60 vfs: &mut vfs::Vfs,
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index a9a1d09fd..7533bb319 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -12,8 +12,6 @@ use parking_lot::RwLock;
12use ra_db::{CrateId, VfsPath}; 12use ra_db::{CrateId, VfsPath};
13use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; 13use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId};
14use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; 14use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
15use stdx::format_to;
16use vfs::loader::Handle as _;
17 15
18use crate::{ 16use crate::{
19 config::Config, 17 config::Config,
@@ -83,15 +81,15 @@ pub(crate) struct GlobalStateSnapshot {
83 pub(crate) check_fixes: CheckFixes, 81 pub(crate) check_fixes: CheckFixes,
84 pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, 82 pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
85 vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, 83 vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
86 workspaces: Arc<Vec<ProjectWorkspace>>, 84 pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
87} 85}
88 86
89impl GlobalState { 87impl GlobalState {
90 pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> GlobalState { 88 pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> GlobalState {
91 let loader = { 89 let loader = {
92 let (sender, receiver) = unbounded::<vfs::loader::Message>(); 90 let (sender, receiver) = unbounded::<vfs::loader::Message>();
93 let handle = 91 let handle: vfs_notify::NotifyHandle =
94 vfs_notify::NotifyHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); 92 vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap()));
95 let handle = Box::new(handle) as Box<dyn vfs::loader::Handle>; 93 let handle = Box::new(handle) as Box<dyn vfs::loader::Handle>;
96 Handle { handle, receiver } 94 Handle { handle, receiver }
97 }; 95 };
@@ -171,14 +169,6 @@ impl GlobalState {
171 } 169 }
172 } 170 }
173 171
174 pub(crate) fn maybe_collect_garbage(&mut self) {
175 self.analysis_host.maybe_collect_garbage()
176 }
177
178 pub(crate) fn collect_garbage(&mut self) {
179 self.analysis_host.collect_garbage()
180 }
181
182 pub(crate) fn send(&mut self, message: lsp_server::Message) { 172 pub(crate) fn send(&mut self, message: lsp_server::Message) {
183 self.sender.send(message).unwrap() 173 self.sender.send(message).unwrap()
184 } 174 }
@@ -242,26 +232,6 @@ impl GlobalStateSnapshot {
242 ProjectWorkspace::Json { .. } => None, 232 ProjectWorkspace::Json { .. } => None,
243 }) 233 })
244 } 234 }
245
246 pub(crate) fn status(&self) -> String {
247 let mut buf = String::new();
248 if self.workspaces.is_empty() {
249 buf.push_str("no workspaces\n")
250 } else {
251 buf.push_str("workspaces:\n");
252 for w in self.workspaces.iter() {
253 format_to!(buf, "{} packages loaded\n", w.n_packages());
254 }
255 }
256 buf.push_str("\nanalysis:\n");
257 buf.push_str(
258 &self
259 .analysis
260 .status()
261 .unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
262 );
263 buf
264 }
265} 235}
266 236
267pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { 237pub(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::{
39 39
40pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> { 40pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> {
41 let _p = profile("handle_analyzer_status"); 41 let _p = profile("handle_analyzer_status");
42 let mut buf = snap.status(); 42
43 let mut buf = String::new();
44 if snap.workspaces.is_empty() {
45 buf.push_str("no workspaces\n")
46 } else {
47 buf.push_str("workspaces:\n");
48 for w in snap.workspaces.iter() {
49 format_to!(buf, "{} packages loaded\n", w.n_packages());
50 }
51 }
52 buf.push_str("\nanalysis:\n");
53 buf.push_str(
54 &snap.analysis.status().unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
55 );
43 format_to!(buf, "\n\nrequests:\n"); 56 format_to!(buf, "\n\nrequests:\n");
44 let requests = snap.latest_requests.read(); 57 let requests = snap.latest_requests.read();
45 for (is_last, r) in requests.iter() { 58 for (is_last, r) in requests.iter() {
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 {
158 } 158 }
159 Task::Unit => (), 159 Task::Unit => (),
160 } 160 }
161 self.maybe_collect_garbage(); 161 self.analysis_host.maybe_collect_garbage();
162 } 162 }
163 Event::Vfs(task) => match task { 163 Event::Vfs(task) => match task {
164 vfs::loader::Message::Loaded { files } => { 164 vfs::loader::Message::Loaded { files } => {
@@ -274,7 +274,7 @@ impl GlobalState {
274 self.req_queue.incoming.register(req.id.clone(), (req.method.clone(), request_received)); 274 self.req_queue.incoming.register(req.id.clone(), (req.method.clone(), request_received));
275 275
276 RequestDispatcher { req: Some(req), global_state: self } 276 RequestDispatcher { req: Some(req), global_state: self }
277 .on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))? 277 .on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.analysis_host.collect_garbage()))?
278 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 278 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
279 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))? 279 .on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
280 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))? 280 .on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?