Skip to content

Commit b342a11

Browse files
committed
Review comments
1 parent bc4ba72 commit b342a11

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

src/remote/remote.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ export class Remote {
291291
this.vscodeProposed,
292292
this.contextManager,
293293
);
294-
disposables.push(monitor);
295294
disposables.push(
295+
monitor,
296296
monitor.onChange.event((w) => (this.commands.workspace = w)),
297297
);
298298

@@ -310,7 +310,7 @@ export class Remote {
310310
disposables.push(stateMachine);
311311

312312
try {
313-
await this.vscodeProposed.window.withProgress(
313+
workspace = await this.vscodeProposed.window.withProgress(
314314
{
315315
location: vscode.ProgressLocation.Notification,
316316
cancellable: false,
@@ -320,10 +320,8 @@ export class Remote {
320320
let inProgress = false;
321321
let pendingWorkspace: Workspace | null = null;
322322

323-
await new Promise<void>((resolve, reject) => {
323+
return new Promise<Workspace>((resolve, reject) => {
324324
const processWorkspace = async (w: Workspace) => {
325-
workspace = w;
326-
327325
if (inProgress) {
328326
// Process one workspace at a time, keeping only the last
329327
pendingWorkspace = w;
@@ -340,26 +338,19 @@ export class Remote {
340338
);
341339
if (isReady) {
342340
subscription.dispose();
343-
resolve();
341+
resolve(w);
344342
return;
345343
}
346-
347-
if (pendingWorkspace) {
348-
const isReadyAfter = await stateMachine.processWorkspace(
349-
pendingWorkspace,
350-
progress,
351-
);
352-
if (isReadyAfter) {
353-
subscription.dispose();
354-
resolve();
355-
}
356-
}
357344
} catch (error) {
358345
subscription.dispose();
359346
reject(error);
360347
} finally {
361348
inProgress = false;
362349
}
350+
351+
if (pendingWorkspace) {
352+
processWorkspace(pendingWorkspace);
353+
}
363354
};
364355

365356
processWorkspace(workspace);
@@ -373,6 +364,9 @@ export class Remote {
373364
stateMachine.dispose();
374365
}
375366

367+
// Mark initial setup as complete so the monitor can start notifying about state changes
368+
monitor.markInitialSetupComplete();
369+
376370
const agents = extractAgents(workspace.latest_build.resources);
377371
const agent = agents.find(
378372
(agent) => agent.id === stateMachine.getAgentId(),

src/remote/workspaceStateMachine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export class WorkspaceStateMachine implements vscode.Disposable {
9595
case "pending":
9696
case "starting":
9797
case "stopping":
98+
// Clear the agent ID since it could change after a restart
99+
this.agentId = undefined;
98100
progress?.report({ message: "Waiting for workspace build..." });
99101
this.logger.info(`Waiting for ${workspaceName}...`);
100102

src/workspace/workspaceMonitor.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class WorkspaceMonitor implements vscode.Disposable {
2929
private notifiedDeletion = false;
3030
private notifiedOutdated = false;
3131
private notifiedNotRunning = false;
32-
private isReady = false;
32+
private completedInitialSetup = false;
3333

3434
readonly onChange = new vscode.EventEmitter<Workspace>();
3535
private readonly statusBarItem: vscode.StatusBarItem;
@@ -111,6 +111,10 @@ export class WorkspaceMonitor implements vscode.Disposable {
111111
return monitor;
112112
}
113113

114+
public markInitialSetupComplete(): void {
115+
this.completedInitialSetup = true;
116+
}
117+
114118
/**
115119
* Permanently close the websocket.
116120
*/
@@ -124,7 +128,6 @@ export class WorkspaceMonitor implements vscode.Disposable {
124128
}
125129

126130
private update(workspace: Workspace) {
127-
this.updateReadyState(workspace);
128131
this.updateContext(workspace);
129132
this.updateStatusBar(workspace);
130133
}
@@ -133,7 +136,7 @@ export class WorkspaceMonitor implements vscode.Disposable {
133136
this.maybeNotifyOutdated(workspace);
134137
this.maybeNotifyAutostop(workspace);
135138
this.maybeNotifyDeletion(workspace);
136-
if (this.isReady) {
139+
if (this.completedInitialSetup) {
137140
// This instance might be created before the workspace is running
138141
this.maybeNotifyNotRunning(workspace);
139142
}
@@ -249,12 +252,6 @@ export class WorkspaceMonitor implements vscode.Disposable {
249252
this.logger.error(message);
250253
}
251254

252-
private updateReadyState(workspace: Workspace): void {
253-
if (workspace.latest_build.status === "running") {
254-
this.isReady = true;
255-
}
256-
}
257-
258255
private updateContext(workspace: Workspace) {
259256
this.contextManager.set("coder.workspace.updatable", workspace.outdated);
260257
}

0 commit comments

Comments
 (0)