Skip to content

Commit 38cd1b7

Browse files
bors[bot]matklad
andauthored
Merge #5071
5071: Cleanups r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 8a96815 + b039f0d commit 38cd1b7

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn load_cargo(
5454
Ok((host, vfs))
5555
}
5656

57-
pub(crate) fn load(
57+
fn load(
5858
crate_graph: CrateGraph,
5959
source_root_config: SourceRootConfig,
6060
vfs: &mut vfs::Vfs,

crates/rust-analyzer/src/global_state.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use parking_lot::RwLock;
1212
use ra_db::{CrateId, VfsPath};
1313
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId};
1414
use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
15-
use stdx::format_to;
16-
use vfs::loader::Handle as _;
1715

1816
use crate::{
1917
config::Config,
@@ -83,15 +81,15 @@ pub(crate) struct GlobalStateSnapshot {
8381
pub(crate) check_fixes: CheckFixes,
8482
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
8583
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
86-
workspaces: Arc<Vec<ProjectWorkspace>>,
84+
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
8785
}
8886

8987
impl GlobalState {
9088
pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> GlobalState {
9189
let loader = {
9290
let (sender, receiver) = unbounded::<vfs::loader::Message>();
93-
let handle =
94-
vfs_notify::NotifyHandle::spawn(Box::new(move |msg| sender.send(msg).unwrap()));
91+
let handle: vfs_notify::NotifyHandle =
92+
vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap()));
9593
let handle = Box::new(handle) as Box<dyn vfs::loader::Handle>;
9694
Handle { handle, receiver }
9795
};
@@ -171,14 +169,6 @@ impl GlobalState {
171169
}
172170
}
173171

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-
182172
pub(crate) fn send(&mut self, message: lsp_server::Message) {
183173
self.sender.send(message).unwrap()
184174
}
@@ -242,26 +232,6 @@ impl GlobalStateSnapshot {
242232
ProjectWorkspace::Json { .. } => None,
243233
})
244234
}
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-
}
265235
}
266236

267237
pub(crate) fn file_id_to_url(vfs: &vfs::Vfs, id: FileId) -> Url {

crates/rust-analyzer/src/handlers.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,20 @@ use crate::{
3939

4040
pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> {
4141
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+
);
4356
format_to!(buf, "\n\nrequests:\n");
4457
let requests = snap.latest_requests.read();
4558
for (is_last, r) in requests.iter() {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl GlobalState {
158158
}
159159
Task::Unit => (),
160160
}
161-
self.maybe_collect_garbage();
161+
self.analysis_host.maybe_collect_garbage();
162162
}
163163
Event::Vfs(task) => match task {
164164
vfs::loader::Message::Loaded { files } => {
@@ -274,7 +274,7 @@ impl GlobalState {
274274
self.req_queue.incoming.register(req.id.clone(), (req.method.clone(), request_received));
275275

276276
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()))?
278278
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
279279
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
280280
.on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?

0 commit comments

Comments
 (0)