@@ -6,7 +6,6 @@ import type {
66} from "vscode" ;
77
88type Environment = Record < string , string | undefined > ;
9- type PreviousValue = [ key : string , existed : boolean , value : string | undefined ] ;
109type SshEnvironment = Partial <
1110 Record < "HTTP_PROXY" | "HTTPS_PROXY" | "NO_PROXY" , string >
1211> ;
@@ -62,10 +61,7 @@ export function applySshEnvironment(
6261 } ;
6362}
6463
65- /**
66- * The proxy portion of the SSH environment. Exposed so callers can check whether
67- * proxy settings are configured via `.HTTP_PROXY`.
68- */
64+ /** The proxy portion of the SSH environment, derived from VS Code's settings. */
6965export function getSshProxyEnvironment (
7066 cfg : Pick < WorkspaceConfiguration , "get" > ,
7167) : SshEnvironment {
@@ -75,22 +71,23 @@ export function getSshProxyEnvironment(
7571 joinNoProxy ( cfg . get < string [ ] > ( "http.noProxy" ) ) ;
7672
7773 return {
78- ...( httpProxy ? { HTTP_PROXY : httpProxy , HTTPS_PROXY : httpProxy } : { } ) ,
79- ...( noProxy ? { NO_PROXY : noProxy } : { } ) ,
74+ HTTP_PROXY : httpProxy ,
75+ HTTPS_PROXY : httpProxy ,
76+ NO_PROXY : noProxy ,
8077 } ;
8178}
8279
8380function applyEnvironment (
8481 values : SshEnvironment ,
8582 env : Environment ,
8683) : { dispose ( ) : void } {
87- const previous : PreviousValue [ ] = [ ] ;
84+ // Stored `undefined` means the key was absent and should be deleted on cleanup.
85+ const previous : Environment = { } ;
8886 for ( const [ key , value ] of Object . entries ( values ) ) {
8987 if ( value === undefined ) {
9088 continue ;
9189 }
92- const previousValue = env [ key ] ;
93- previous . push ( [ key , previousValue !== undefined , previousValue ] ) ;
90+ previous [ key ] = env [ key ] ;
9491 env [ key ] = value ;
9592 }
9693
@@ -101,11 +98,11 @@ function applyEnvironment(
10198 return ;
10299 }
103100 disposed = true ;
104- for ( const [ key , existed , value ] of previous ) {
105- if ( existed ) {
106- env [ key ] = value ;
107- } else {
101+ for ( const [ key , value ] of Object . entries ( previous ) ) {
102+ if ( value === undefined ) {
108103 delete env [ key ] ;
104+ } else {
105+ env [ key ] = value ;
109106 }
110107 }
111108 } ,
0 commit comments