This repository was archived by the owner on Nov 18, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
rust-analyzer/editors/code Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 61
61
"activationEvents" : [
62
62
" onLanguage:rust" ,
63
63
" onCommand:rust-analyzer.analyzerStatus" ,
64
+ " onCommand:rust-analyzer.memoryUsage" ,
64
65
" onCommand:rust-analyzer.reloadWorkspace" ,
65
66
" workspaceContains:**/Cargo.toml"
66
67
],
142
143
"title" : " Status" ,
143
144
"category" : " Rust Analyzer"
144
145
},
146
+ {
147
+ "command" : " rust-analyzer.memoryUsage" ,
148
+ "title" : " Memory Usage (Clears Database)" ,
149
+ "category" : " Rust Analyzer"
150
+ },
145
151
{
146
152
"command" : " rust-analyzer.reloadWorkspace" ,
147
153
"title" : " Reload workspace" ,
843
849
"command" : " rust-analyzer.analyzerStatus" ,
844
850
"when" : " inRustProject"
845
851
},
852
+ {
853
+ "command" : " rust-analyzer.memoryUsage" ,
854
+ "when" : " inRustProject"
855
+ },
846
856
{
847
857
"command" : " rust-analyzer.reloadWorkspace" ,
848
858
"when" : " inRustProject"
Original file line number Diff line number Diff line change @@ -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
90
export function matchingBrace ( ctx : Ctx ) : Cmd {
59
91
return async ( ) => {
60
92
const editor = ctx . activeRustEditor ;
Original file line number Diff line number Diff line change 5
5
import * as lc from "vscode-languageclient" ;
6
6
7
7
export const analyzerStatus = new lc . RequestType < null , string , void > ( "rust-analyzer/analyzerStatus" ) ;
8
+ export const memoryUsage = new lc . RequestType < null , string , void > ( "rust-analyzer/memoryUsage" ) ;
8
9
9
10
export type Status = "loading" | "ready" | "invalid" | "needsReload" ;
10
11
export const status = new lc . NotificationType < Status > ( "rust-analyzer/status" ) ;
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
96
96
} ) ;
97
97
98
98
ctx . registerCommand ( 'analyzerStatus' , commands . analyzerStatus ) ;
99
+ ctx . registerCommand ( 'memoryUsage' , commands . memoryUsage ) ;
99
100
ctx . registerCommand ( 'reloadWorkspace' , commands . reloadWorkspace ) ;
100
101
ctx . registerCommand ( 'matchingBrace' , commands . matchingBrace ) ;
101
102
ctx . registerCommand ( 'joinLines' , commands . joinLines ) ;
You can’t perform that action at this time.
0 commit comments