@@ -50,7 +50,11 @@ export class Remote {
50
50
/**
51
51
* Try to get the workspace running. Return undefined if the user canceled.
52
52
*/
53
- private async maybeWaitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace | undefined > {
53
+ private async maybeWaitForRunning (
54
+ restClient : Api ,
55
+ workspace : Workspace ,
56
+ binPath : string ,
57
+ ) : Promise < Workspace | undefined > {
54
58
// Maybe already running?
55
59
if ( workspace . latest_build . status === "running" ) {
56
60
return workspace
@@ -63,6 +67,28 @@ export class Remote {
63
67
let terminal : undefined | vscode . Terminal
64
68
let attempts = 0
65
69
70
+ function initWriteEmitterAndTerminal ( ) : vscode . EventEmitter < string > {
71
+ if ( ! writeEmitter ) {
72
+ writeEmitter = new vscode . EventEmitter < string > ( )
73
+ }
74
+ if ( ! terminal ) {
75
+ terminal = vscode . window . createTerminal ( {
76
+ name : "Build Log" ,
77
+ location : vscode . TerminalLocation . Panel ,
78
+ // Spin makes this gear icon spin!
79
+ iconPath : new vscode . ThemeIcon ( "gear~spin" ) ,
80
+ pty : {
81
+ onDidWrite : writeEmitter . event ,
82
+ close : ( ) => undefined ,
83
+ open : ( ) => undefined ,
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ } as Partial < vscode . Pseudoterminal > as any ,
86
+ } )
87
+ terminal . show ( true )
88
+ }
89
+ return writeEmitter
90
+ }
91
+
66
92
try {
67
93
// Show a notification while we wait.
68
94
return await this . vscodeProposed . window . withProgress (
@@ -78,33 +104,17 @@ export class Remote {
78
104
case "pending" :
79
105
case "starting" :
80
106
case "stopping" :
81
- if ( ! writeEmitter ) {
82
- writeEmitter = new vscode . EventEmitter < string > ( )
83
- }
84
- if ( ! terminal ) {
85
- terminal = vscode . window . createTerminal ( {
86
- name : "Build Log" ,
87
- location : vscode . TerminalLocation . Panel ,
88
- // Spin makes this gear icon spin!
89
- iconPath : new vscode . ThemeIcon ( "gear~spin" ) ,
90
- pty : {
91
- onDidWrite : writeEmitter . event ,
92
- close : ( ) => undefined ,
93
- open : ( ) => undefined ,
94
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
- } as Partial < vscode . Pseudoterminal > as any ,
96
- } )
97
- terminal . show ( true )
98
- }
107
+ writeEmitter = initWriteEmitterAndTerminal ( )
99
108
this . storage . writeToCoderOutputChannel ( `Waiting for ${ workspaceName } ...` )
100
109
workspace = await waitForBuild ( restClient , writeEmitter , workspace )
101
110
break
102
111
case "stopped" :
103
112
if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
104
113
return undefined
105
114
}
115
+ writeEmitter = initWriteEmitterAndTerminal ( )
106
116
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
107
- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
117
+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
108
118
break
109
119
case "failed" :
110
120
// On a first attempt, we will try starting a failed workspace
@@ -113,8 +123,9 @@ export class Remote {
113
123
if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
114
124
return undefined
115
125
}
126
+ writeEmitter = initWriteEmitterAndTerminal ( )
116
127
this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
117
- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
128
+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
118
129
break
119
130
}
120
131
// Otherwise fall through and error.
@@ -292,7 +303,7 @@ export class Remote {
292
303
disposables . push ( this . registerLabelFormatter ( remoteAuthority , workspace . owner_name , workspace . name ) )
293
304
294
305
// If the workspace is not in a running state, try to get it running.
295
- const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace )
306
+ const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace , binaryPath )
296
307
if ( ! updatedWorkspace ) {
297
308
// User declined to start the workspace.
298
309
await this . closeRemote ( )
0 commit comments