1
- import { commands , debug , ExtensionContext , Webview , WebviewPanel , window , workspace } from 'vscode' ;
1
+ import { commands , debug , ExtensionContext , WebviewPanel , window , workspace } from 'vscode' ;
2
2
import { ComlinkFrontendApi } from 'shared/src/index' ;
3
3
import { getMonacoTheme } from './webview/themes' ;
4
4
import { createWebview , getVueFrontendPanelContent } from './webview/content' ;
@@ -9,40 +9,27 @@ import { FrontendApi } from './debug/frontend-functions';
9
9
10
10
let currentFrontendRpcChannel : Comlink . Remote < ComlinkFrontendApi > | undefined = undefined ;
11
11
12
- async function updateViewWithStackTrace ( _webview : Webview , _context : ExtensionContext ) {
12
+ async function updateViewWithStackTrace ( ) {
13
13
try {
14
14
if ( ! currentFrontendRpcChannel ) {
15
15
throw new Error ( "No rpc channel found" ) ;
16
16
}
17
17
const result = await getStacktraceInfo ( ) ;
18
18
await currentFrontendRpcChannel . setStackTrace ( result ) ;
19
19
} catch ( e : unknown ) {
20
- // todo remove in release build!
21
20
window . showErrorMessage ( "failed to load stacktrace, due to error, please try to open view again. Error: " + e ) ;
22
21
}
23
22
}
24
23
24
+
25
25
export async function activate ( context : ExtensionContext ) {
26
26
let currentPanel : WebviewPanel | undefined = undefined ;
27
27
// started debug session
28
- context . subscriptions . push ( debug . onDidStartDebugSession ( async ( e ) => {
29
- if ( currentPanel ?. webview ) {
30
- await updateViewWithStackTrace ( currentPanel . webview , context ) ;
31
- }
32
- } ) ) ;
33
-
28
+ context . subscriptions . push ( debug . onDidStartDebugSession ( updateViewWithStackTrace ) ) ;
34
29
// step into, step out, step over, change active stack item, change active debug session, receive custom event
35
- context . subscriptions . push ( debug . onDidChangeActiveStackItem ( async ( e ) => {
36
- if ( currentPanel ?. webview ) {
37
- await updateViewWithStackTrace ( currentPanel . webview , context ) ;
38
- }
39
- } ) ) ;
40
-
41
- context . subscriptions . push ( debug . onDidChangeActiveDebugSession ( async ( e ) => {
42
- if ( currentPanel ?. webview ) {
43
- await updateViewWithStackTrace ( currentPanel . webview , context ) ;
44
- }
45
- } ) ) ;
30
+ context . subscriptions . push ( debug . onDidChangeActiveStackItem ( updateViewWithStackTrace ) ) ;
31
+ // stopped/started/changed debug session
32
+ context . subscriptions . push ( debug . onDidChangeActiveDebugSession ( updateViewWithStackTrace ) ) ;
46
33
47
34
workspace . onDidChangeConfiguration ( async event => {
48
35
if ( event . affectsConfiguration ( 'workbench.colorTheme' ) ) {
@@ -51,6 +38,13 @@ export async function activate(context: ExtensionContext) {
51
38
}
52
39
} ) ;
53
40
41
+ function disposeRpcChannel ( ) {
42
+ if ( currentFrontendRpcChannel ) {
43
+ currentFrontendRpcChannel [ Comlink . releaseProxy ] ( ) ;
44
+ currentFrontendRpcChannel = undefined ;
45
+ }
46
+ }
47
+
54
48
commands . registerCommand ( 'call-graph.show-call-graph' , async ( ) => {
55
49
try {
56
50
if ( ! currentPanel ?. webview ) {
@@ -69,17 +63,11 @@ export async function activate(context: ExtensionContext) {
69
63
70
64
currentPanel . onDidDispose ( ( ) => {
71
65
currentPanel = undefined ;
72
- if ( currentFrontendRpcChannel ) {
73
- currentFrontendRpcChannel [ Comlink . releaseProxy ] ( ) ;
74
- }
75
- currentFrontendRpcChannel = undefined ;
66
+ disposeRpcChannel ( ) ;
76
67
} ) ;
77
68
78
69
// release current channel if needed
79
- if ( currentFrontendRpcChannel ) {
80
- currentFrontendRpcChannel [ Comlink . releaseProxy ] ( ) ;
81
- currentFrontendRpcChannel = undefined ;
82
- }
70
+ disposeRpcChannel ( ) ;
83
71
84
72
currentFrontendRpcChannel = Comlink . wrap < ComlinkFrontendApi > ( getComlinkChannel ( currentPanel . webview , context ) ) ;
85
73
@@ -88,7 +76,7 @@ export async function activate(context: ExtensionContext) {
88
76
89
77
90
78
if ( debug . activeDebugSession ) {
91
- await updateViewWithStackTrace ( currentPanel . webview , context ) ;
79
+ await updateViewWithStackTrace ( ) ;
92
80
} else {
93
81
window . showWarningMessage ( 'No active debug session, the view will automatically update when a debug session is started' ) ;
94
82
}
@@ -99,7 +87,7 @@ export async function activate(context: ExtensionContext) {
99
87
100
88
101
89
window . registerWebviewPanelSerializer ( 'graph-visualization' , {
102
- deserializeWebviewPanel : async function ( webviewPanel : WebviewPanel , state : unknown ) : Promise < void > {
90
+ deserializeWebviewPanel : async ( webviewPanel : WebviewPanel , _state : unknown ) = > {
103
91
currentPanel = webviewPanel ;
104
92
await commands . executeCommand ( 'call-graph.show-call-graph' ) ;
105
93
}
0 commit comments