@@ -50,7 +50,11 @@ export class Remote {
5050 /**
5151 * Try to get the workspace running. Return undefined if the user canceled.
5252 */
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 > {
5458 // Maybe already running?
5559 if ( workspace . latest_build . status === "running" ) {
5660 return workspace
@@ -63,6 +67,28 @@ export class Remote {
6367 let terminal : undefined | vscode . Terminal
6468 let attempts = 0
6569
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+
6692 try {
6793 // Show a notification while we wait.
6894 return await this . vscodeProposed . window . withProgress (
@@ -78,33 +104,17 @@ export class Remote {
78104 case "pending" :
79105 case "starting" :
80106 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 ( )
99108 this . storage . writeToCoderOutputChannel ( `Waiting for ${ workspaceName } ...` )
100109 workspace = await waitForBuild ( restClient , writeEmitter , workspace )
101110 break
102111 case "stopped" :
103112 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
104113 return undefined
105114 }
115+ writeEmitter = initWriteEmitterAndTerminal ( )
106116 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
107- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
117+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
108118 break
109119 case "failed" :
110120 // On a first attempt, we will try starting a failed workspace
@@ -113,8 +123,9 @@ export class Remote {
113123 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
114124 return undefined
115125 }
126+ writeEmitter = initWriteEmitterAndTerminal ( )
116127 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
117- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
128+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
118129 break
119130 }
120131 // Otherwise fall through and error.
@@ -292,7 +303,7 @@ export class Remote {
292303 disposables . push ( this . registerLabelFormatter ( remoteAuthority , workspace . owner_name , workspace . name ) )
293304
294305 // 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 )
296307 if ( ! updatedWorkspace ) {
297308 // User declined to start the workspace.
298309 await this . closeRemote ( )
0 commit comments