Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/load_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 3 additions & 33 deletions crates/rust-analyzer/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +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 vfs::loader::Handle as _;

use crate::{
config::Config,
Expand Down Expand Up @@ -83,15 +81,15 @@ pub(crate) struct GlobalStateSnapshot {
pub(crate) check_fixes: CheckFixes,
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
workspaces: Arc<Vec<ProjectWorkspace>>,
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
}

impl GlobalState {
pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> GlobalState {
let loader = {
let (sender, receiver) = unbounded::<vfs::loader::Message>();
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<dyn vfs::loader::Handle>;
Handle { handle, receiver }
};
Expand Down Expand Up @@ -171,14 +169,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()
}
Expand Down Expand Up @@ -242,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 {
Expand Down
15 changes: 14 additions & 1 deletion crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ use crate::{

pub(crate) fn handle_analyzer_status(snap: GlobalStateSnapshot, _: ()) -> Result<String> {
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() {
Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.collect_garbage()))?
.on_sync::<lsp_ext::CollectGarbage>(|s, ()| Ok(s.analysis_host.collect_garbage()))?
.on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
.on_sync::<lsp_ext::OnEnter>(|s, p| handlers::handle_on_enter(s.snapshot(), p))?
.on_sync::<lsp_types::request::Shutdown>(|_, ()| Ok(()))?
Expand Down