Add a command to compute memory usage statistics
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user