@@ -20,6 +20,7 @@ import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport"
2020import { Storage } from "./storage"
2121import { AuthorityPrefix , expandPath , parseRemoteAuthority } from "./util"
2222import { WorkspaceMonitor } from "./workspaceMonitor"
23+ import { write } from "fs"
2324
2425export interface RemoteDetails extends vscode . Disposable {
2526 url : string
@@ -50,7 +51,11 @@ export class Remote {
5051 /**
5152 * Try to get the workspace running. Return undefined if the user canceled.
5253 */
53- private async maybeWaitForRunning ( restClient : Api , workspace : Workspace ) : Promise < Workspace | undefined > {
54+ private async maybeWaitForRunning (
55+ restClient : Api ,
56+ workspace : Workspace ,
57+ binPath : string ,
58+ ) : Promise < Workspace | undefined > {
5459 // Maybe already running?
5560 if ( workspace . latest_build . status === "running" ) {
5661 return workspace
@@ -63,6 +68,28 @@ export class Remote {
6368 let terminal : undefined | vscode . Terminal
6469 let attempts = 0
6570
71+ function initWriteEmitterAndTerminal ( ) : vscode . EventEmitter < string > {
72+ if ( ! writeEmitter ) {
73+ writeEmitter = new vscode . EventEmitter < string > ( )
74+ }
75+ if ( ! terminal ) {
76+ terminal = vscode . window . createTerminal ( {
77+ name : "Build Log" ,
78+ location : vscode . TerminalLocation . Panel ,
79+ // Spin makes this gear icon spin!
80+ iconPath : new vscode . ThemeIcon ( "gear~spin" ) ,
81+ pty : {
82+ onDidWrite : writeEmitter . event ,
83+ close : ( ) => undefined ,
84+ open : ( ) => undefined ,
85+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86+ } as Partial < vscode . Pseudoterminal > as any ,
87+ } )
88+ terminal . show ( true )
89+ }
90+ return writeEmitter
91+ }
92+
6693 try {
6794 // Show a notification while we wait.
6895 return await this . vscodeProposed . window . withProgress (
@@ -78,33 +105,17 @@ export class Remote {
78105 case "pending" :
79106 case "starting" :
80107 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- }
108+ writeEmitter = initWriteEmitterAndTerminal ( )
99109 this . storage . writeToCoderOutputChannel ( `Waiting for ${ workspaceName } ...` )
100110 workspace = await waitForBuild ( restClient , writeEmitter , workspace )
101111 break
102112 case "stopped" :
103113 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
104114 return undefined
105115 }
116+ writeEmitter = initWriteEmitterAndTerminal ( )
106117 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
107- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
118+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
108119 break
109120 case "failed" :
110121 // On a first attempt, we will try starting a failed workspace
@@ -113,8 +124,9 @@ export class Remote {
113124 if ( ! ( await this . confirmStart ( workspaceName ) ) ) {
114125 return undefined
115126 }
127+ writeEmitter = initWriteEmitterAndTerminal ( )
116128 this . storage . writeToCoderOutputChannel ( `Starting ${ workspaceName } ...` )
117- workspace = await startWorkspaceIfStoppedOrFailed ( restClient , workspace )
129+ workspace = await startWorkspaceIfStoppedOrFailed ( restClient , binPath , workspace , writeEmitter )
118130 break
119131 }
120132 // Otherwise fall through and error.
@@ -292,7 +304,7 @@ export class Remote {
292304 disposables . push ( this . registerLabelFormatter ( remoteAuthority , workspace . owner_name , workspace . name ) )
293305
294306 // If the workspace is not in a running state, try to get it running.
295- const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace )
307+ const updatedWorkspace = await this . maybeWaitForRunning ( workspaceRestClient , workspace , binaryPath )
296308 if ( ! updatedWorkspace ) {
297309 // User declined to start the workspace.
298310 await this . closeRemote ( )
0 commit comments