1
1
import type { LabsInfo } from '@volar/vscode' ;
2
2
import * as lsp from '@volar/vscode' ;
3
- import * as fs from 'fs' ;
4
- import * as os from 'os' ;
5
- import * as path from 'path' ;
6
3
import * as vscode from 'vscode' ;
7
- import { quickPick } from '../common/quickPick' ;
8
4
import { getIconPath , useVolarExtensions } from '../common/shared' ;
9
5
10
6
interface LanguageClientItem {
@@ -17,7 +13,7 @@ interface InvalidLanguageClientItem {
17
13
}
18
14
19
15
interface LanguageClientFieldItem extends LanguageClientItem {
20
- field : 'start' | 'stop' | 'restart' | 'initializationOptions' | 'initializeResult' | 'memory' ;
16
+ field : 'start' | 'stop' | 'restart' | 'initializationOptions' | 'initializeResult' ;
21
17
}
22
18
23
19
export function activate ( context : vscode . ExtensionContext ) {
@@ -56,7 +52,6 @@ export function activate(context: vscode.ExtensionContext) {
56
52
stats . push ( { ...element , field : 'restart' } ) ;
57
53
stats . push ( { ...element , field : 'initializationOptions' } ) ;
58
54
stats . push ( { ...element , field : 'initializeResult' } ) ;
59
- stats . push ( { ...element , field : 'memory' } ) ;
60
55
}
61
56
else if ( element . client . state === lsp . State . Starting ) {
62
57
stats . push ( { ...element , field : 'stop' } ) ;
@@ -106,17 +101,6 @@ export function activate(context: vscode.ExtensionContext) {
106
101
} ,
107
102
} ;
108
103
}
109
- else if ( element . field === 'memory' ) {
110
- return {
111
- label : 'TS Memory Treemap' ,
112
- collapsibleState : vscode . TreeItemCollapsibleState . None ,
113
- command : {
114
- command : '_volar.action.tsMemoryTreemap' ,
115
- title : '' ,
116
- arguments : [ element . client , element . extension . exports . volarLabs . languageServerProtocol ] ,
117
- } ,
118
- } ;
119
- }
120
104
else if ( element . field === 'initializationOptions' ) {
121
105
return {
122
106
iconPath : new vscode . ThemeIcon ( 'file' ) ,
@@ -178,70 +162,6 @@ export function activate(context: vscode.ExtensionContext) {
178
162
await client . stop ( ) ;
179
163
await client . start ( ) ;
180
164
} ) ,
181
- vscode . commands . registerCommand ( '_volar.action.tsMemoryTreemap' , async ( client : lsp . BaseLanguageClient , protocol : typeof import ( '@volar/vscode/protocol' ) ) => {
182
-
183
- const select = await quickPick ( [
184
- {
185
- openInBrowser : {
186
- label : 'Open in Browser' ,
187
- description : 'Open the TypeScript Memory Treemap in your browser' ,
188
- } ,
189
- showInVSCode : {
190
- label : 'Show in VS Code' ,
191
- description : 'Show the html file in VS Code' ,
192
- } ,
193
- saveFile : {
194
- label : 'Save File' ,
195
- description : 'Pick a location to save the html file' ,
196
- } ,
197
- }
198
- ] ) ;
199
-
200
- if ( select === undefined ) {
201
- return ; // cancel
202
- }
203
-
204
- vscode . window . withProgress ( {
205
- location : vscode . ProgressLocation . Window ,
206
- cancellable : false ,
207
- title : 'Loading Memory Data'
208
- } , async progress => {
209
-
210
- progress . report ( { increment : 0 } ) ;
211
-
212
- const meta = await client . sendRequest ( protocol . LoadedTSFilesMetaRequest . type ) ;
213
- const { visualizer } = await import ( 'esbuild-visualizer/dist/plugin/index.js' ) ;
214
- const fileContent = await visualizer ( meta as any ) ;
215
-
216
- if ( select === 'openInBrowser' ) {
217
- const tmpPath = path . join ( os . tmpdir ( ) , 'memory-report.html' ) ;
218
- fs . writeFileSync ( tmpPath , fileContent ) ;
219
- await vscode . env . openExternal ( vscode . Uri . file ( tmpPath ) ) ;
220
- }
221
- else if ( select === 'showInVSCode' ) {
222
- const doc = await vscode . workspace . openTextDocument ( { content : fileContent , language : 'html' } ) ;
223
- vscode . window . showTextDocument ( doc ) ;
224
- }
225
- else if ( select === 'saveFile' ) {
226
- const workspaces = vscode . workspace . workspaceFolders ;
227
- if ( ! workspaces ?. length ) {
228
- return ;
229
- }
230
-
231
- const defaultUri = vscode . Uri . joinPath ( workspaces [ 0 ] . uri , 'stats.html' ) ;
232
- const pickedUri = await vscode . window . showSaveDialog ( { defaultUri } ) ;
233
-
234
- if ( ! pickedUri ) {
235
- return ;
236
- }
237
-
238
- await vscode . workspace . fs . writeFile ( pickedUri , Buffer . from ( fileContent ) ) ;
239
- await vscode . window . showTextDocument ( pickedUri ) ;
240
- }
241
-
242
- progress . report ( { increment : 100 } ) ;
243
- } ) ;
244
- } ) ,
245
165
vscode . commands . registerCommand ( 'volar.action.serverStat.initializationOptions' , async ( client : lsp . BaseLanguageClient ) => {
246
166
const doc = await vscode . workspace . openTextDocument ( { content : JSON . stringify ( client . clientOptions . initializationOptions , undefined , '\t' ) , language : 'json' } ) ;
247
167
vscode . window . showTextDocument ( doc ) ;
0 commit comments