]> git.lizzy.rs Git - rust.git/commitdiff
add gc request
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 25 Jan 2019 16:11:58 +0000 (19:11 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 25 Jan 2019 16:11:58 +0000 (19:11 +0300)
crates/ra_ide_api/src/imp.rs
crates/ra_ide_api/src/lib.rs
crates/ra_lsp_server/src/main_loop.rs
crates/ra_lsp_server/src/req.rs
crates/ra_lsp_server/src/server_world.rs
editors/code/package.json
editors/code/src/extension.ts

index 8ecb8b17c8333d42d908a6b37d7ea0a3a09d5bca..961f7b230d78c6f95a33719d81570bc00f31ef13 100644 (file)
@@ -72,13 +72,14 @@ fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange)
         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)
index 3502bfd2e56407d0fd30299a8132091154110355..ffd026b045f6337be6538405b11e895d45ec9734 100644 (file)
@@ -285,6 +285,10 @@ pub fn analysis(&self) -> Analysis {
     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
index f51576521e93c6afd2548148de65a01f1314f94c..ddd20a41fc68ca84690d0b6d8ab72caff341ce5e 100644 (file)
@@ -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::<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) => {
index ec6b6d905cd859bcbd541e88b255c309308a66e3..5968e592b1071550bf7a30a01075cbe0550dce3d 100644 (file)
@@ -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 {
index 5cb97b29b70c27883c2c8cf82e2701defcccfca4..bf04f1125eedf294be09ae6c5e8d0e79c438fd8a 100644 (file)
@@ -231,6 +231,10 @@ pub fn snapshot(&self) -> ServerWorld {
             vfs: Arc::clone(&self.vfs),
         }
     }
+
+    pub fn collect_garbadge(&mut self) {
+        self.analysis_host.collect_garbage()
+    }
 }
 
 impl ServerWorld {
index 3e07032c7ff0c6b72c16e2d3e06da6cc39856875..86683eb73e8714f4d3124fb2d6b91244607f4252 100644 (file)
             {
                 "command": "ra-lsp.analyzerStatus",
                 "title": "Status of rust-analyzer (debug)"
+            },
+            {
+                "command": "ra-lsp.collectGarbage",
+                "title": "Run rust-analyzer's GC"
             }
         ],
         "keybindings": [
index 3af95c5997dcc9f2534dd70de4b01b159f00a392..dc7b01403ea8e9b5fe0c8ed4346c6c12279c4a0d 100644 (file)
@@ -49,6 +49,9 @@ export function activate(context: vscode.ExtensionContext) {
         '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);