@@ -35,21 +35,11 @@ class DashboardPanel {
3535 } ) ) ;
3636 this . setWebviewMessageListener ( ) ;
3737 this . webView . html = this . getWebviewContent ( ) ;
38- this . disposables . push ( vscode . commands . registerCommand ( 'java.dashboard.refresh' , async ( ) => {
39- this . refreshLSInfo ( ) ;
40- } ) ) ;
38+
4139
4240 this . disposables . push ( vscode . commands . registerCommand ( 'java.dashboard.revealFileInOS' , async ( arg : { path : string } ) => {
4341 await vscode . commands . executeCommand ( 'revealFileInOS' , vscode . Uri . file ( arg . path ) ) ;
4442 } ) ) ;
45-
46- this . disposables . push ( vscode . commands . registerCommand ( 'java.dashboard.dumpState' , async ( ) => {
47- const doc = await vscode . workspace . openTextDocument ( {
48- language : 'json' ,
49- content : JSON . stringify ( currentState , null , 2 )
50- } ) ;
51- vscode . window . showTextDocument ( doc ) ;
52- } ) ) ;
5343 }
5444
5545 private postMessage ( message : UpdateMessage ) {
@@ -134,7 +124,7 @@ class DashboardPanel {
134124 ` ;
135125 }
136126
137- private async refreshLSInfo ( ) : Promise < void > {
127+ public async refreshLSInfo ( ) : Promise < void > {
138128 if ( ! this . webView ) {
139129 return ;
140130 }
@@ -154,32 +144,49 @@ class DashboardPanel {
154144}
155145
156146export namespace Dashboard {
157- export function initialize ( context : vscode . ExtensionContext ) : void {
158- console . log ( 'registering dashboard webview provider' ) ;
159- let dashboardPanel : DashboardPanel ;
160- let webviewPanel : vscode . WebviewPanel ;
161-
162- context . subscriptions . push ( vscode . commands . registerCommand ( Commands . OPEN_JAVA_DASHBOARD , async ( ) => {
163- if ( ! dashboardPanel ) {
164- webviewPanel = vscode . window . createWebviewPanel ( 'java.dashboard' , 'Java Dashboard' , vscode . ViewColumn . Active , {
165- enableScripts : true ,
166- enableCommandUris : true ,
167- retainContextWhenHidden : true ,
168- localResourceRoots : [ context . extensionUri ] ,
169- } ) ;
170- webviewPanel . iconPath = Uri . file ( path . join ( context . extensionPath , 'icons' , 'icon128.png' ) ) ;
171- dashboardPanel = new DashboardPanel ( webviewPanel . webview , context ) ;
172-
173- webviewPanel . onDidDispose ( ( ) => {
174- dashboardPanel . dispose ( ) ;
175- dashboardPanel = undefined ;
176- webviewPanel = undefined ;
177- vscode . commands . executeCommand ( 'setContext' , 'java:dashboard' , false ) ;
178- } , undefined , context . subscriptions ) ;
179- } else {
180- webviewPanel . reveal ( ) ;
181- }
182- } ) ) ;
183- console . log ( 'registered dashboard webview provider' ) ;
184- }
147+ export function initialize ( context : vscode . ExtensionContext ) : void {
148+ console . log ( 'registering dashboard webview provider' ) ;
149+
150+ let dashboardPanel : DashboardPanel | undefined = undefined ;
151+ let webviewPanel : vscode . WebviewPanel | undefined = undefined ;
152+
153+ context . subscriptions . push ( vscode . commands . registerCommand ( 'java.dashboard.refresh' , async ( ) => {
154+ await vscode . commands . executeCommand ( Commands . OPEN_JAVA_DASHBOARD ) ;
155+ if ( dashboardPanel ) {
156+ await dashboardPanel . refreshLSInfo ( ) ;
157+ }
158+ } ) ) ;
159+
160+ context . subscriptions . push ( vscode . commands . registerCommand ( 'java.dashboard.dumpState' , async ( ) => {
161+ const doc = await vscode . workspace . openTextDocument ( {
162+ language : 'json' ,
163+ content : JSON . stringify ( currentState , null , 2 )
164+ } ) ;
165+ vscode . window . showTextDocument ( doc ) ;
166+ } ) ) ;
167+
168+ context . subscriptions . push ( vscode . commands . registerCommand ( Commands . OPEN_JAVA_DASHBOARD , async ( ) => {
169+ if ( ! dashboardPanel || ! webviewPanel ) {
170+ webviewPanel = vscode . window . createWebviewPanel ( 'java.dashboard' , 'Java Dashboard' , vscode . ViewColumn . Active , {
171+ enableScripts : true ,
172+ enableCommandUris : true ,
173+ retainContextWhenHidden : true ,
174+ localResourceRoots : [ context . extensionUri ] ,
175+ } ) ;
176+
177+ webviewPanel . iconPath = Uri . file ( path . join ( context . extensionPath , 'icons' , 'icon128.png' ) ) ;
178+ dashboardPanel = new DashboardPanel ( webviewPanel . webview , context ) ;
179+
180+ webviewPanel . onDidDispose ( ( ) => {
181+ dashboardPanel ?. dispose ( ) ;
182+ dashboardPanel = undefined ;
183+ webviewPanel = undefined ;
184+ vscode . commands . executeCommand ( 'setContext' , 'java:dashboard' , false ) ;
185+ } , undefined , context . subscriptions ) ;
186+ } else {
187+ webviewPanel . reveal ( ) ;
188+ }
189+ } ) ) ;
190+ console . log ( 'registered dashboard webview provider' ) ;
191+ }
185192}
0 commit comments