@@ -27,13 +27,29 @@ export interface RemoteDetails extends vscode.Disposable {
27
27
28
28
export class Remote {
29
29
public constructor (
30
+ // We use the proposed API to get access to useCustom in dialogs.
30
31
private readonly vscodeProposed : typeof vscode ,
31
32
private readonly storage : Storage ,
32
33
private readonly commands : Commands ,
33
34
private readonly mode : vscode . ExtensionMode ,
34
35
) { }
35
36
36
- private async waitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace > {
37
+ private async confirmStart ( workspaceName : string ) : Promise < boolean > {
38
+ const action = await this . vscodeProposed . window . showInformationMessage (
39
+ `Unable to connect to the workspace ${ workspaceName } because it is not running. Start the workspace?` ,
40
+ {
41
+ useCustom : true ,
42
+ modal : true ,
43
+ } ,
44
+ "Start" ,
45
+ )
46
+ return action === "Start"
47
+ }
48
+
49
+ /**
50
+ * Try to get the workspace running. Return undefined if the user canceled.
51
+ */
52
+ private async maybeWaitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace | undefined > {
37
53
// Maybe already running?
38
54
if ( workspace . latest_build . status === "running" ) {
39
55
return workspace
@@ -83,18 +99,24 @@ export class Remote {
83
99
workspace = await waitForBuild ( restClient , writeEmitter , workspace )
84
100
break
85
101
case "stopped" :
102
+ if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
103
+ return undefined
104
+ }
86
105
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
87
106
workspace = await startWorkspace ( restClient , workspace )
88
107
break
89
108
case "failed" :
90
109
// On a first attempt, we will try starting a failed workspace
91
110
// (for example canceling a start seems to cause this state).
92
111
if ( attempts === 1 ) {
112
+ if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
113
+ return undefined
114
+ }
93
115
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
94
116
workspace = await startWorkspace ( restClient , workspace )
95
117
break
96
118
}
97
- // Otherwise fall through and error.
119
+ // Otherwise fall through and error.
98
120
case "canceled" :
99
121
case "canceling" :
100
122
case "deleted" :
@@ -255,8 +277,13 @@ export class Remote {
255
277
const action = await WorkspaceAction . init ( this . vscodeProposed , workspaceRestClient , this . storage )
256
278
257
279
// If the workspace is not in a running state, try to get it running.
258
- workspace = await this . waitForRunning ( workspaceRestClient , workspace )
259
- this . commands . workspace = workspace
280
+ const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace )
281
+ if ( ! updatedWorkspace ) {
282
+ // User declined to start the workspace.
283
+ await this . closeRemote ( )
284
+ return
285
+ }
286
+ this . commands . workspace = workspace = updatedWorkspace
260
287
261
288
// Pick an agent.
262
289
this . storage . writeToCoderOutputChannel ( `Finding agent for ${ workspaceName } ...` )
0 commit comments