@@ -430,14 +430,16 @@ export class Remote {
430430return
431431}
432432
433+ const logDir = this . getLogDir ( featureSet )
434+
433435// This ensures the Remote SSH extension resolves the host to execute the
434436// Coder binary properly.
435437//
436438// If we didn't write to the SSH config file, connecting would fail with
437439// "Host not found".
438440try {
439441this . storage . writeToCoderOutputChannel ( "Updating SSH config..." )
440- await this . updateSSHConfig ( workspaceRestClient , parts . label , parts . host , binaryPath , featureSet )
442+ await this . updateSSHConfig ( workspaceRestClient , parts . label , parts . host , binaryPath , logDir )
441443} catch ( error ) {
442444this . storage . writeToCoderOutputChannel ( `Failed to configure SSH:${ error } ` )
443445throw error
@@ -450,7 +452,7 @@ export class Remote {
450452return
451453}
452454disposables . push ( this . showNetworkUpdates ( pid ) )
453- this . commands . workspaceLogPath = path . join ( this . storage . getLogPath ( ) , `${ pid } .log` )
455+ this . commands . workspaceLogPath = logDir ? path . join ( logDir , `${ pid } .log` ) : undefined
454456} )
455457
456458// Register the label formatter again because SSH overrides it!
@@ -476,20 +478,25 @@ export class Remote {
476478}
477479
478480/**
479- * Format's the --log-dir argument for the ProxyCommand
481+ * Return the --log-dir argument value for the ProxyCommand. It may be an
482+ * empty string if the setting is not set or the cli does not support it.
480483 */
481- private async formatLogArg ( featureSet :FeatureSet ) :Promise < string > {
484+ private getLogDir ( featureSet :FeatureSet ) :string {
482485if ( ! featureSet . proxyLogDirectory ) {
483486return ""
484487}
485-
486488// If the proxyLogDirectory is not set in the extension settings we don't send one.
487- // Question for Asher: How do VSCode extension settings behave in terms of semver for the extension?
488- const logDir = expandPath ( String ( vscode . workspace . getConfiguration ( ) . get ( "coder.proxyLogDirectory" ) ?? "" ) . trim ( ) )
489+ return expandPath ( String ( vscode . workspace . getConfiguration ( ) . get ( "coder.proxyLogDirectory" ) ?? "" ) . trim ( ) )
490+ }
491+
492+ /**
493+ * Formats the --log-dir argument for the ProxyCommand after making sure it
494+ * has been created.
495+ */
496+ private async formatLogArg ( logDir :string ) :Promise < string > {
489497if ( ! logDir ) {
490498return ""
491499}
492-
493500await fs . mkdir ( logDir , { recursive :true } )
494501this . storage . writeToCoderOutputChannel ( `SSH proxy diagnostics are being written to${ logDir } ` )
495502return ` --log-dir${ escape ( logDir ) } `
@@ -502,7 +509,7 @@ export class Remote {
502509label :string ,
503510hostName :string ,
504511binaryPath :string ,
505- featureSet : FeatureSet ,
512+ logDir : string ,
506513) {
507514let deploymentSSHConfig = { }
508515try {
@@ -585,7 +592,7 @@ export class Remote {
585592Host :label ?`${ AuthorityPrefix } .${ label } --*` :`${ AuthorityPrefix } --*` ,
586593ProxyCommand :`${ escape ( binaryPath ) } ${ headerArg } vscodessh --network-info-dir${ escape (
587594this . storage . getNetworkInfoPath ( ) ,
588- ) } ${ await this . formatLogArg ( featureSet ) } --session-token-file${ escape ( this . storage . getSessionTokenPath ( label ) ) } --url-file${ escape (
595+ ) } ${ await this . formatLogArg ( logDir ) } --session-token-file${ escape ( this . storage . getSessionTokenPath ( label ) ) } --url-file${ escape (
589596this . storage . getUrlPath ( label ) ,
590597) } %h`,
591598ConnectTimeout :"0" ,