diff options
Diffstat (limited to 'editors/code/src/commands.ts')
-rw-r--r-- | editors/code/src/commands.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 19a9c2a0d..1f3a7cf7e 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts | |||
@@ -55,6 +55,38 @@ export function analyzerStatus(ctx: Ctx): Cmd { | |||
55 | }; | 55 | }; |
56 | } | 56 | } |
57 | 57 | ||
58 | export function memoryUsage(ctx: Ctx): Cmd { | ||
59 | const tdcp = new class implements vscode.TextDocumentContentProvider { | ||
60 | readonly uri = vscode.Uri.parse('rust-analyzer-memory://memory'); | ||
61 | readonly eventEmitter = new vscode.EventEmitter<vscode.Uri>(); | ||
62 | |||
63 | provideTextDocumentContent(_uri: vscode.Uri): vscode.ProviderResult<string> { | ||
64 | if (!vscode.window.activeTextEditor) return ''; | ||
65 | |||
66 | return ctx.client.sendRequest(ra.memoryUsage, null).then((mem) => { | ||
67 | return 'Per-query memory usage:\n' + mem + '\n(note: database has been cleared)'; | ||
68 | }); | ||
69 | } | ||
70 | |||
71 | get onDidChange(): vscode.Event<vscode.Uri> { | ||
72 | return this.eventEmitter.event; | ||
73 | } | ||
74 | }(); | ||
75 | |||
76 | ctx.pushCleanup( | ||
77 | vscode.workspace.registerTextDocumentContentProvider( | ||
78 | 'rust-analyzer-memory', | ||
79 | tdcp, | ||
80 | ), | ||
81 | ); | ||
82 | |||
83 | return async () => { | ||
84 | tdcp.eventEmitter.fire(tdcp.uri); | ||
85 | const document = await vscode.workspace.openTextDocument(tdcp.uri); | ||
86 | return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true); | ||
87 | }; | ||
88 | } | ||
89 | |||
58 | export function matchingBrace(ctx: Ctx): Cmd { | 90 | export function matchingBrace(ctx: Ctx): Cmd { |
59 | return async () => { | 91 | return async () => { |
60 | const editor = ctx.activeRustEditor; | 92 | const editor = ctx.activeRustEditor; |