@@ -17,7 +17,7 @@ import { getHeaderCommand } from "./headers"
1717import { SSHConfig , SSHValues , mergeSSHConfigValues } from "./sshConfig"
1818import { computeSSHProperties , sshSupportsSetEnv } from "./sshSupport"
1919import { Storage } from "./storage"
20- import { AuthorityPrefix , parseRemoteAuthority } from "./util"
20+ import { AuthorityPrefix , expandPath , parseRemoteAuthority } from "./util"
2121import { supportsCoderAgentLogDirFlag } from "./version"
2222import { WorkspaceAction } from "./workspaceAction"
2323
@@ -33,6 +33,7 @@ export class Remote {
3333 private readonly storage : Storage ,
3434 private readonly commands : Commands ,
3535 private readonly mode : vscode . ExtensionMode ,
36+ private coderVersion : semver . SemVer | null = null ,
3637 ) { }
3738
3839 private async confirmStart ( workspaceName : string ) : Promise < boolean > {
@@ -195,13 +196,13 @@ export class Remote {
195196
196197 // First thing is to check the version.
197198 const buildInfo = await workspaceRestClient . getBuildInfo ( )
198- const parsedVersion = semver . parse ( buildInfo . version )
199+ this . coderVersion = semver . parse ( buildInfo . version )
199200 // Server versions before v0.14.1 don't support the vscodessh command!
200201 if (
201- parsedVersion ?. major === 0 &&
202- parsedVersion ?. minor <= 14 &&
203- parsedVersion ?. patch < 1 &&
204- parsedVersion ?. prerelease . length === 0
202+ this . coderVersion ?. major === 0 &&
203+ this . coderVersion ?. minor <= 14 &&
204+ this . coderVersion ?. patch < 1 &&
205+ this . coderVersion ?. prerelease . length === 0
205206 ) {
206207 await this . vscodeProposed . window . showErrorMessage (
207208 "Incompatible Server" ,
@@ -215,7 +216,6 @@ export class Remote {
215216 await this . closeRemote ( )
216217 return
217218 }
218- const hasCoderLogs = supportsCoderAgentLogDirFlag ( parsedVersion )
219219
220220 // Next is to find the workspace from the URI scheme provided.
221221 let workspace : Workspace
@@ -501,7 +501,7 @@ export class Remote {
501501 // "Host not found".
502502 try {
503503 this . storage . writeToCoderOutputChannel ( "Updating SSH config..." )
504- await this . updateSSHConfig ( workspaceRestClient , parts . label , parts . host , hasCoderLogs )
504+ await this . updateSSHConfig ( workspaceRestClient , parts . label , parts . host )
505505 } catch ( error ) {
506506 this . storage . writeToCoderOutputChannel ( `Failed to configure SSH: ${ error } ` )
507507 throw error
@@ -541,9 +541,29 @@ export class Remote {
541541 }
542542 }
543543
544+ /**
545+ * Format's the --log-dir argument for the ProxyCommand
546+ */
547+ private async formatLogArg ( ) : Promise < string > {
548+ if ( ! supportsCoderAgentLogDirFlag ( this . coderVersion ) ) {
549+ return ""
550+ }
551+
552+ // If the proxyLogDirectory is not set in the extension settings we don't send one.
553+ // Question for Asher: How do VSCode extension settings behave in terms of semver for the extension?
554+ const logDir = expandPath ( String ( vscode . workspace . getConfiguration ( ) . get ( "coder.proxyLogDirectory" ) ?? "" ) . trim ( ) )
555+ if ( ! logDir ) {
556+ return ""
557+ }
558+
559+ await fs . mkdir ( logDir , { recursive : true } )
560+ this . storage . writeToCoderOutputChannel ( `SSH proxy diagnostics are being written to ${ logDir } ` )
561+ return ` --log-dir ${ escape ( logDir ) } `
562+ }
563+
544564 // updateSSHConfig updates the SSH configuration with a wildcard that handles
545565 // all Coder entries.
546- private async updateSSHConfig ( restClient : Api , label : string , hostName : string , hasCoderLogs = false ) {
566+ private async updateSSHConfig ( restClient : Api , label : string , hostName : string ) {
547567 let deploymentSSHConfig = { }
548568 try {
549569 const deploymentConfig = await restClient . getDeploymentSSHConfig ( )
@@ -634,16 +654,12 @@ export class Remote {
634654 if ( typeof headerCommand === "string" && headerCommand . trim ( ) . length > 0 ) {
635655 headerArg = ` --header-command ${ escapeSubcommand ( headerCommand ) } `
636656 }
637- let logArg = ""
638- if ( hasCoderLogs ) {
639- await fs . mkdir ( this . storage . getLogPath ( ) , { recursive : true } )
640- logArg = ` --log-dir ${ escape ( this . storage . getLogPath ( ) ) } `
641- }
657+
642658 const sshValues : SSHValues = {
643659 Host : label ? `${ AuthorityPrefix } .${ label } --*` : `${ AuthorityPrefix } --*` ,
644660 ProxyCommand : `${ escape ( binaryPath ) } ${ headerArg } vscodessh --network-info-dir ${ escape (
645661 this . storage . getNetworkInfoPath ( ) ,
646- ) } ${ logArg } --session-token-file ${ escape ( this . storage . getSessionTokenPath ( label ) ) } --url-file ${ escape (
662+ ) } ${ await this . formatLogArg ( ) } --session-token-file ${ escape ( this . storage . getSessionTokenPath ( label ) ) } --url-file ${ escape (
647663 this . storage . getUrlPath ( label ) ,
648664 ) } %h`,
649665 ConnectTimeout : "0" ,
0 commit comments