diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index 8ecb8b17c8..961f7b230d 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs @@ -72,13 +72,14 @@ impl db::RootDatabase { 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) diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 3502bfd2e5..ffd026b045 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -285,6 +285,10 @@ impl AnalysisHost { 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 diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index f51576521e..ddd20a41fc 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -205,17 +205,26 @@ fn main_loop_inner( 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::() { + Ok((id, ())) => { + state.collect_garbadge(); + let resp = RawResponse::ok::(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) => { diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index ec6b6d905c..5968e592b1 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -19,6 +19,14 @@ impl Request for AnalyzerStatus { 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 { diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 5cb97b29b7..bf04f1125e 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -231,6 +231,10 @@ impl ServerWorldState { vfs: Arc::clone(&self.vfs), } } + + pub fn collect_garbadge(&mut self) { + self.analysis_host.collect_garbage() + } } impl ServerWorld { diff --git a/editors/code/package.json b/editors/code/package.json index 3e07032c7f..86683eb73e 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -98,6 +98,10 @@ { "command": "ra-lsp.analyzerStatus", "title": "Status of rust-analyzer (debug)" + }, + { + "command": "ra-lsp.collectGarbage", + "title": "Run rust-analyzer's GC" } ], "keybindings": [ diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 3af95c5997..dc7b01403e 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -49,6 +49,9 @@ export function activate(context: vscode.ExtensionContext) { 'ra-lsp.analyzerStatus', commands.analyzerStatus.makeCommand(context) ); + registerCommand('ra-lsp.collectGarbage', () => + Server.client.sendRequest('ra/collectGarbage', null) + ); registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);