Skip to content

Commit 1bb1405

Browse files
committed
Make start and stop commands real async commands
With this the execution can be awaited for when executing the commands programmatically before continuing. Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 5fc4471 commit 1bb1405

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ export function deactivate() {
1919
}
2020

2121
function registerStopOrReset(context: vscode.ExtensionContext | undefined): vscode.Disposable {
22-
return vscode.commands.registerCommand(stopOrReset, () => {
23-
return server.stopOrReset(context);
22+
return vscode.commands.registerCommand(stopOrReset, async () => {
23+
await server.stopOrReset(context);
2424
});
2525
}
2626
export const registerStopOrReset_test = registerStopOrReset;
2727

2828
function registerStartIfStopped(context: vscode.ExtensionContext | undefined): vscode.Disposable {
29-
return vscode.commands.registerCommand(startIfStopped, () => {
30-
server.startIfStopped(context);
29+
return vscode.commands.registerCommand(startIfStopped, async () => {
30+
await server.startIfStopped(context);
3131
});
3232
}
3333
export const registerStartIfStopped_test = registerStartIfStopped;

src/trace-server.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const suffix = ' failure or so.';
1717
export class TraceServer {
1818
private server: ChildProcess | undefined;
1919

20-
private start(context: vscode.ExtensionContext | undefined) {
20+
private async start(context: vscode.ExtensionContext | undefined) {
2121
const from = this.getSettings();
2222
const server = spawn(this.getPath(from), this.getArgs(from));
2323

@@ -26,8 +26,8 @@ export class TraceServer {
2626
return;
2727
}
2828
this.server = server;
29-
context?.workspaceState.update(key, this.server.pid);
30-
this.waitFor(context);
29+
await context?.workspaceState.update(key, this.server.pid);
30+
await this.waitFor(context);
3131
}
3232

3333
async stopOrReset(context: vscode.ExtensionContext | undefined) {
@@ -46,7 +46,7 @@ export class TraceServer {
4646
clearTimeout(id);
4747
});
4848
}
49-
vscode.window.withProgress(
49+
await vscode.window.withProgress(
5050
{
5151
location: vscode.ProgressLocation.Notification,
5252
title: prefix,
@@ -67,7 +67,7 @@ export class TraceServer {
6767
} else {
6868
vscode.window.showWarningMessage(not);
6969
}
70-
context?.workspaceState.update(key, none);
70+
await context?.workspaceState.update(key, none);
7171
this.server = undefined;
7272
}
7373

@@ -77,14 +77,14 @@ export class TraceServer {
7777
const foreigner = await this.isUp();
7878

7979
if (stopped && !foreigner) {
80-
this.start(context);
80+
await this.start(context);
8181
} else if (foreigner) {
8282
vscode.window.showWarningMessage(prefix + ' not started as already running.');
8383
} else {
8484
// Not UP but there is still a pid stored.
8585
// Likely because Codium or so exited without one using the stop command prior.
86-
context?.workspaceState.update(key, none);
87-
this.start(context);
86+
await context?.workspaceState.update(key, none);
87+
await this.start(context);
8888
}
8989
}
9090

@@ -139,7 +139,7 @@ export class TraceServer {
139139
}
140140

141141
private async waitFor(context: vscode.ExtensionContext | undefined) {
142-
vscode.window.withProgress(
142+
await vscode.window.withProgress(
143143
{
144144
location: vscode.ProgressLocation.Notification,
145145
title: prefix,
@@ -159,7 +159,7 @@ export class TraceServer {
159159
}
160160
if (timeout) {
161161
this.showError(prefix + ' startup timed-out after ' + millis + 'ms.');
162-
this.stopOrReset(context);
162+
await this.stopOrReset(context);
163163
break;
164164
}
165165
}

0 commit comments

Comments
 (0)