aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/imp.rs5
-rw-r--r--crates/ra_ide_api/src/lib.rs4
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs27
-rw-r--r--crates/ra_lsp_server/src/req.rs8
-rw-r--r--crates/ra_lsp_server/src/server_world.rs4
-rw-r--r--editors/code/package.json4
-rw-r--r--editors/code/src/extension.ts3
7 files changed, 44 insertions, 11 deletions
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 8ecb8b17c..961f7b230 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -72,13 +72,14 @@ impl db::RootDatabase {
72 self.set_source_root(root_id, Arc::new(source_root)); 72 self.set_source_root(root_id, Arc::new(source_root));
73 } 73 }
74 74
75 #[allow(unused)]
76 /// Ideally, we should call this function from time to time to collect heavy 75 /// Ideally, we should call this function from time to time to collect heavy
77 /// syntax trees. However, if we actually do that, everything is recomputed 76 /// syntax trees. However, if we actually do that, everything is recomputed
78 /// for some reason. Needs investigation. 77 /// for some reason. Needs investigation.
79 fn gc_syntax_trees(&mut self) { 78 pub(crate) fn collect_garbage(&mut self) {
80 self.query(ra_db::SourceFileQuery) 79 self.query(ra_db::SourceFileQuery)
81 .sweep(salsa::SweepStrategy::default().discard_values()); 80 .sweep(salsa::SweepStrategy::default().discard_values());
81 self.query(hir::db::HirSourceFileQuery)
82 .sweep(salsa::SweepStrategy::default().discard_values());
82 self.query(hir::db::FileItemsQuery) 83 self.query(hir::db::FileItemsQuery)
83 .sweep(salsa::SweepStrategy::default().discard_values()); 84 .sweep(salsa::SweepStrategy::default().discard_values());
84 self.query(hir::db::FileItemQuery) 85 self.query(hir::db::FileItemQuery)
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 3502bfd2e..ffd026b04 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -285,6 +285,10 @@ impl AnalysisHost {
285 pub fn apply_change(&mut self, change: AnalysisChange) { 285 pub fn apply_change(&mut self, change: AnalysisChange) {
286 self.db.apply_change(change) 286 self.db.apply_change(change)
287 } 287 }
288
289 pub fn collect_garbage(&mut self) {
290 self.db.collect_garbage();
291 }
288} 292}
289 293
290/// Analysis is a snapshot of a world state at a moment in time. It is the main 294/// 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 f51576521..ddd20a41f 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(
205 Some(req) => req, 205 Some(req) => req,
206 None => return Ok(()), 206 None => return Ok(()),
207 }; 207 };
208 match on_request(state, pending_requests, pool, &task_sender, req)? { 208 match req.cast::<req::CollectGarbage>() {
209 None => (), 209 Ok((id, ())) => {
210 Some(req) => { 210 state.collect_garbadge();
211 log::error!("unknown request: {:?}", req); 211 let resp = RawResponse::ok::<req::CollectGarbage>(id, &());
212 let resp = RawResponse::err(
213 req.id,
214 ErrorCode::MethodNotFound as i32,
215 "unknown request".to_string(),
216 );
217 msg_sender.send(RawMessage::Response(resp)).unwrap() 212 msg_sender.send(RawMessage::Response(resp)).unwrap()
218 } 213 }
214 Err(req) => {
215 match on_request(state, pending_requests, pool, &task_sender, req)? {
216 None => (),
217 Some(req) => {
218 log::error!("unknown request: {:?}", req);
219 let resp = RawResponse::err(
220 req.id,
221 ErrorCode::MethodNotFound as i32,
222 "unknown request".to_string(),
223 );
224 msg_sender.send(RawMessage::Response(resp)).unwrap()
225 }
226 }
227 }
219 } 228 }
220 } 229 }
221 RawMessage::Notification(not) => { 230 RawMessage::Notification(not) => {
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index ec6b6d905..5968e592b 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 {
19 const METHOD: &'static str = "ra/analyzerStatus"; 19 const METHOD: &'static str = "ra/analyzerStatus";
20} 20}
21 21
22pub enum CollectGarbage {}
23
24impl Request for CollectGarbage {
25 type Params = ();
26 type Result = ();
27 const METHOD: &'static str = "ra/collectGarbage";
28}
29
22pub enum SyntaxTree {} 30pub enum SyntaxTree {}
23 31
24impl Request for SyntaxTree { 32impl Request for SyntaxTree {
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index 5cb97b29b..bf04f1125 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 {
231 vfs: Arc::clone(&self.vfs), 231 vfs: Arc::clone(&self.vfs),
232 } 232 }
233 } 233 }
234
235 pub fn collect_garbadge(&mut self) {
236 self.analysis_host.collect_garbage()
237 }
234} 238}
235 239
236impl ServerWorld { 240impl ServerWorld {
diff --git a/editors/code/package.json b/editors/code/package.json
index 3e07032c7..86683eb73 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -98,6 +98,10 @@
98 { 98 {
99 "command": "ra-lsp.analyzerStatus", 99 "command": "ra-lsp.analyzerStatus",
100 "title": "Status of rust-analyzer (debug)" 100 "title": "Status of rust-analyzer (debug)"
101 },
102 {
103 "command": "ra-lsp.collectGarbage",
104 "title": "Run rust-analyzer's GC"
101 } 105 }
102 ], 106 ],
103 "keybindings": [ 107 "keybindings": [
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 3af95c599..dc7b01403 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -49,6 +49,9 @@ export function activate(context: vscode.ExtensionContext) {
49 'ra-lsp.analyzerStatus', 49 'ra-lsp.analyzerStatus',
50 commands.analyzerStatus.makeCommand(context) 50 commands.analyzerStatus.makeCommand(context)
51 ); 51 );
52 registerCommand('ra-lsp.collectGarbage', () =>
53 Server.client.sendRequest<null>('ra/collectGarbage', null)
54 );
52 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle); 55 registerCommand('ra-lsp.syntaxTree', commands.syntaxTree.handle);
53 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle); 56 registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
54 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle); 57 registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);