diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-26 10:46:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-26 10:46:45 +0100 |
commit | 38cd1b70e8d4b8f57ac2ae0702cf4728764094d9 (patch) | |
tree | 2e41f0f53b488a162c4e86b93de3b2b49eb7fdd6 /crates | |
parent | 8a96815d009b688819dd7a8af28e989de61305d1 (diff) | |
parent | b039f0d1baa34b7d53117085438769cc3402e112 (diff) |
Merge #5071
5071: Cleanups r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 36 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 15 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 4 |
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 | ||
57 | pub(crate) fn load( | 57 | fn 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; | |||
12 | use ra_db::{CrateId, VfsPath}; | 12 | use ra_db::{CrateId, VfsPath}; |
13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; | 13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; |
14 | use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; | 14 | use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; |
15 | use stdx::format_to; | ||
16 | use vfs::loader::Handle as _; | ||
17 | 15 | ||
18 | use crate::{ | 16 | use 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 | ||
89 | impl GlobalState { | 87 | impl 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 | ||
267 | pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url { | 237 | 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::{ | |||
39 | 39 | ||
40 | pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> { | 40 | pub(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(()))? |