mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-21 19:04:24 +00:00
Add a command to compute memory usage statistics
This commit is contained in:
parent
0f5d62a3f3
commit
f44c4b61e1
8 changed files with 74 additions and 1 deletions
|
@ -55,6 +55,38 @@ export function analyzerStatus(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function memoryUsage(ctx: Ctx): Cmd {
|
||||
const tdcp = new class implements vscode.TextDocumentContentProvider {
|
||||
readonly uri = vscode.Uri.parse('rust-analyzer-memory://memory');
|
||||
readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
|
||||
provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> {
|
||||
if (!vscode.window.activeTextEditor) return '';
|
||||
|
||||
return ctx.client.sendRequest(ra.memoryUsage, null).then((mem) => {
|
||||
return 'Per-query memory usage:\n' + mem + '\n(note: database has been cleared)';
|
||||
});
|
||||
}
|
||||
|
||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
||||
return this.eventEmitter.event;
|
||||
}
|
||||
}();
|
||||
|
||||
ctx.pushCleanup(
|
||||
vscode.workspace.registerTextDocumentContentProvider(
|
||||
'rust-analyzer-memory',
|
||||
tdcp,
|
||||
),
|
||||
);
|
||||
|
||||
return async () => {
|
||||
tdcp.eventEmitter.fire(tdcp.uri);
|
||||
const document = await vscode.workspace.openTextDocument(tdcp.uri);
|
||||
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
|
||||
};
|
||||
}
|
||||
|
||||
export function matchingBrace(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import * as lc from "vscode-languageclient";
|
||||
|
||||
export const analyzerStatus = new lc.RequestType<null, string, void>("rust-analyzer/analyzerStatus");
|
||||
export const memoryUsage = new lc.RequestType<null, string, void>("rust-analyzer/memoryUsage");
|
||||
|
||||
export type Status = "loading" | "ready" | "invalid" | "needsReload";
|
||||
export const status = new lc.NotificationType<Status>("rust-analyzer/status");
|
||||
|
|
|
@ -96,6 +96,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
|||
});
|
||||
|
||||
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
|
||||
ctx.registerCommand('memoryUsage', commands.memoryUsage);
|
||||
ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace);
|
||||
ctx.registerCommand('matchingBrace', commands.matchingBrace);
|
||||
ctx.registerCommand('joinLines', commands.joinLines);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue