File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ export function activate(context: vscode.ExtensionContext) {
1414 activation = context ;
1515}
1616
17- export function deactivate ( ) {
18- server . stopOrReset ( activation ) ;
17+ export async function deactivate ( ) {
18+ await server . shutdown ( activation ) ;
1919}
2020
2121function registerStopOrReset ( context : vscode . ExtensionContext | undefined ) : vscode . Disposable {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const millis = 10000;
1313const none = - 1 ;
1414const prefix = 'Trace Server' ;
1515const suffix = ' failure or so.' ;
16+ const SHUTDOWN_DELAY = 2000 ;
1617
1718export class TraceServer {
1819 private server : ChildProcess | undefined ;
@@ -71,6 +72,24 @@ export class TraceServer {
7172 this . server = undefined ;
7273 }
7374
75+ async shutdown ( context : vscode . ExtensionContext ) {
76+ // Take the pid from the server instead from workspace state because
77+ // during shutdown the workspace can't be queried anymore
78+ const pid = this . server ? this . server . pid : undefined ;
79+ if ( ! pid ) {
80+ return ;
81+ }
82+ if ( pid ) {
83+ treeKill ( pid ) ;
84+ // Allow the treeKill to finish collecting and killing all
85+ // spawned processes.
86+ await new Promise ( resolve => setTimeout ( resolve , SHUTDOWN_DELAY ) ) ;
87+
88+ // Try to reset pid in workspace state
89+ await context ?. workspaceState . update ( key , none ) ;
90+ }
91+ }
92+
7493 async startIfStopped ( context : vscode . ExtensionContext | undefined ) {
7594 const pid = context ?. workspaceState . get ( key ) ;
7695 const stopped = ! pid || pid === none ;
You can’t perform that action at this time.
0 commit comments