self.set_source_root(root_id, Arc::new(source_root));
}
- #[allow(unused)]
/// Ideally, we should call this function from time to time to collect heavy
/// syntax trees. However, if we actually do that, everything is recomputed
/// for some reason. Needs investigation.
- fn gc_syntax_trees(&mut self) {
+ pub(crate) fn collect_garbage(&mut self) {
self.query(ra_db::SourceFileQuery)
.sweep(salsa::SweepStrategy::default().discard_values());
+ self.query(hir::db::HirSourceFileQuery)
+ .sweep(salsa::SweepStrategy::default().discard_values());
self.query(hir::db::FileItemsQuery)
.sweep(salsa::SweepStrategy::default().discard_values());
self.query(hir::db::FileItemQuery)
pub fn apply_change(&mut self, change: AnalysisChange) {
self.db.apply_change(change)
}
+
+ pub fn collect_garbage(&mut self) {
+ self.db.collect_garbage();
+ }
}
/// Analysis is a snapshot of a world state at a moment in time. It is the main
Some(req) => req,
None => return Ok(()),
};
- match on_request(state, pending_requests, pool, &task_sender, req)? {
- None => (),
- Some(req) => {
- log::error!("unknown request: {:?}", req);
- let resp = RawResponse::err(
- req.id,
- ErrorCode::MethodNotFound as i32,
- "unknown request".to_string(),
- );
+ match req.cast::<req::CollectGarbage>() {
+ Ok((id, ())) => {
+ state.collect_garbadge();
+ let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
msg_sender.send(RawMessage::Response(resp)).unwrap()
}
+ Err(req) => {
+ match on_request(state, pending_requests, pool, &task_sender, req)? {
+ None => (),
+ Some(req) => {
+ log::error!("unknown request: {:?}", req);
+ let resp = RawResponse::err(
+ req.id,
+ ErrorCode::MethodNotFound as i32,
+ "unknown request".to_string(),
+ );
+ msg_sender.send(RawMessage::Response(resp)).unwrap()
+ }
+ }
+ }
}
}
RawMessage::Notification(not) => {
const METHOD: &'static str = "ra/analyzerStatus";
}
+pub enum CollectGarbage {}
+
+impl Request for CollectGarbage {
+ type Params = ();
+ type Result = ();
+ const METHOD: &'static str = "ra/collectGarbage";
+}
+
pub enum SyntaxTree {}
impl Request for SyntaxTree {
vfs: Arc::clone(&self.vfs),
}
}
+
+ pub fn collect_garbadge(&mut self) {
+ self.analysis_host.collect_garbage()
+ }
}
impl ServerWorld {
{
"command": "ra-lsp.analyzerStatus",
"title": "Status of rust-analyzer (debug)"
+ },
+ {
+ "command": "ra-lsp.collectGarbage",
+ "title": "Run rust-analyzer's GC"
}
],
"keybindings": [
'ra-lsp.analyzerStatus',
commands.analyzerStatus.makeCommand(context)
);
+ registerCommand('ra-lsp.collectGarbage', () =>
+ Server.client.sendRequest<null>('ra/collectGarbage', null)
+ );
registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);