mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
add gc request
This commit is contained in:
parent
6df1f71b7d
commit
f6adb85b68
7 changed files with 44 additions and 11 deletions
|
@ -72,13 +72,14 @@ impl db::RootDatabase {
|
||||||
self.set_source_root(root_id, Arc::new(source_root));
|
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
|
/// Ideally, we should call this function from time to time to collect heavy
|
||||||
/// syntax trees. However, if we actually do that, everything is recomputed
|
/// syntax trees. However, if we actually do that, everything is recomputed
|
||||||
/// for some reason. Needs investigation.
|
/// for some reason. Needs investigation.
|
||||||
fn gc_syntax_trees(&mut self) {
|
pub(crate) fn collect_garbage(&mut self) {
|
||||||
self.query(ra_db::SourceFileQuery)
|
self.query(ra_db::SourceFileQuery)
|
||||||
.sweep(salsa::SweepStrategy::default().discard_values());
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
|
self.query(hir::db::HirSourceFileQuery)
|
||||||
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
self.query(hir::db::FileItemsQuery)
|
self.query(hir::db::FileItemsQuery)
|
||||||
.sweep(salsa::SweepStrategy::default().discard_values());
|
.sweep(salsa::SweepStrategy::default().discard_values());
|
||||||
self.query(hir::db::FileItemQuery)
|
self.query(hir::db::FileItemQuery)
|
||||||
|
|
|
@ -285,6 +285,10 @@ impl AnalysisHost {
|
||||||
pub fn apply_change(&mut self, change: AnalysisChange) {
|
pub fn apply_change(&mut self, change: AnalysisChange) {
|
||||||
self.db.apply_change(change)
|
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
|
/// Analysis is a snapshot of a world state at a moment in time. It is the main
|
||||||
|
|
|
@ -205,6 +205,13 @@ fn main_loop_inner(
|
||||||
Some(req) => req,
|
Some(req) => req,
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
|
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)? {
|
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
||||||
None => (),
|
None => (),
|
||||||
Some(req) => {
|
Some(req) => {
|
||||||
|
@ -218,6 +225,8 @@ fn main_loop_inner(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
RawMessage::Notification(not) => {
|
RawMessage::Notification(not) => {
|
||||||
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
|
|
|
@ -19,6 +19,14 @@ impl Request for AnalyzerStatus {
|
||||||
const METHOD: &'static str = "ra/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 {}
|
pub enum SyntaxTree {}
|
||||||
|
|
||||||
impl Request for SyntaxTree {
|
impl Request for SyntaxTree {
|
||||||
|
|
|
@ -231,6 +231,10 @@ impl ServerWorldState {
|
||||||
vfs: Arc::clone(&self.vfs),
|
vfs: Arc::clone(&self.vfs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn collect_garbadge(&mut self) {
|
||||||
|
self.analysis_host.collect_garbage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerWorld {
|
impl ServerWorld {
|
||||||
|
|
|
@ -98,6 +98,10 @@
|
||||||
{
|
{
|
||||||
"command": "ra-lsp.analyzerStatus",
|
"command": "ra-lsp.analyzerStatus",
|
||||||
"title": "Status of rust-analyzer (debug)"
|
"title": "Status of rust-analyzer (debug)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "ra-lsp.collectGarbage",
|
||||||
|
"title": "Run rust-analyzer's GC"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keybindings": [
|
"keybindings": [
|
||||||
|
|
|
@ -49,6 +49,9 @@ export function activate(context: vscode.ExtensionContext) {
|
||||||
'ra-lsp.analyzerStatus',
|
'ra-lsp.analyzerStatus',
|
||||||
commands.analyzerStatus.makeCommand(context)
|
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.syntaxTree', commands.syntaxTree.handle);
|
||||||
registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
|
registerCommand('ra-lsp.extendSelection', commands.extendSelection.handle);
|
||||||
registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
|
registerCommand('ra-lsp.matchingBrace', commands.matchingBrace.handle);
|
||||||
|
|
Loading…
Reference in a new issue