@@ -25,6 +25,7 @@ import { withNullAsUndefined } from 'vs/base/common/types';
25
25
import { Promises } from 'vs/base/common/async' ;
26
26
import { EditorGroupColumn } from 'vs/workbench/services/editor/common/editorGroupColumn' ;
27
27
import { ViewColumn } from 'vs/workbench/api/common/extHostTypeConverters' ;
28
+ import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions' ;
28
29
29
30
export interface IExtHostTerminalService extends ExtHostTerminalServiceShape , IDisposable {
30
31
@@ -826,7 +827,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
826
827
public getEnvironmentVariableCollection ( extension : IExtensionDescription ) : IEnvironmentVariableCollection {
827
828
let collection = this . _environmentVariableCollections . get ( extension . identifier . value ) ;
828
829
if ( ! collection ) {
829
- collection = new EnvironmentVariableCollection ( ) ;
830
+ collection = new EnvironmentVariableCollection ( extension ) ;
830
831
this . _setEnvironmentVariableCollection ( extension . identifier . value , collection ) ;
831
832
}
832
833
return collection . getScopedEnvironmentVariableCollection ( undefined ) ;
@@ -841,7 +842,7 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
841
842
public $initEnvironmentVariableCollections ( collections : [ string , ISerializableEnvironmentVariableCollection ] [ ] ) : void {
842
843
collections . forEach ( entry => {
843
844
const extensionIdentifier = entry [ 0 ] ;
844
- const collection = new EnvironmentVariableCollection ( entry [ 1 ] ) ;
845
+ const collection = new EnvironmentVariableCollection ( undefined , entry [ 1 ] ) ;
845
846
this . _setEnvironmentVariableCollection ( extensionIdentifier , collection ) ;
846
847
} ) ;
847
848
}
@@ -883,6 +884,11 @@ class EnvironmentVariableCollection {
883
884
get onDidChangeCollection ( ) : Event < void > { return this . _onDidChangeCollection && this . _onDidChangeCollection . event ; }
884
885
885
886
constructor (
887
+ // HACK: Only check proposed options if extension is set (when the collection is not
888
+ // restored by serialization). This saves us from getting the extension details and
889
+ // shouldn't ever happen since you can only set them initially via the proposed check.
890
+ // TODO: This should be removed when the env var extension API(s) are stabilized
891
+ private readonly _extension : IExtensionDescription | undefined ,
886
892
serialized ?: ISerializableEnvironmentVariableCollection
887
893
) {
888
894
this . map = new Map ( serialized ) ;
@@ -899,19 +905,31 @@ class EnvironmentVariableCollection {
899
905
return scopedCollection ;
900
906
}
901
907
902
- replace ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
903
- this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Replace , scope } ) ;
908
+ replace ( variable : string , value : string , options : vscode . EnvironmentVariableMutatorOptions | undefined , scope : vscode . EnvironmentVariableScope | undefined ) : void {
909
+ if ( this . _extension && options ) {
910
+ isProposedApiEnabled ( this . _extension , 'envCollectionOptions' ) ;
911
+ }
912
+ this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Replace , options : options ?? { } , scope } ) ;
904
913
}
905
914
906
- append ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
907
- this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Append , scope } ) ;
915
+ append ( variable : string , value : string , options : vscode . EnvironmentVariableMutatorOptions | undefined , scope : vscode . EnvironmentVariableScope | undefined ) : void {
916
+ if ( this . _extension && options ) {
917
+ isProposedApiEnabled ( this . _extension , 'envCollectionOptions' ) ;
918
+ }
919
+ this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Append , options : options ?? { } , scope } ) ;
908
920
}
909
921
910
- prepend ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
911
- this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Prepend , scope } ) ;
922
+ prepend ( variable : string , value : string , options : vscode . EnvironmentVariableMutatorOptions | undefined , scope : vscode . EnvironmentVariableScope | undefined ) : void {
923
+ if ( this . _extension && options ) {
924
+ isProposedApiEnabled ( this . _extension , 'envCollectionOptions' ) ;
925
+ }
926
+ this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Prepend , options : options ?? { } , scope } ) ;
912
927
}
913
928
914
929
private _setIfDiffers ( variable : string , mutator : vscode . EnvironmentVariableMutator & { scope : vscode . EnvironmentVariableScope | undefined } ) : void {
930
+ if ( mutator . options && mutator . options . applyAtProcessCreation === false && ! mutator . options . applyAtShellIntegration ) {
931
+ throw new Error ( 'EnvironmentVariableMutatorOptions must apply at either process creation or shell integration' ) ;
932
+ }
915
933
if ( ! mutator . scope ) {
916
934
delete ( mutator as any ) . scope ; // Convenient for tests
917
935
}
@@ -928,6 +946,7 @@ class EnvironmentVariableCollection {
928
946
get ( variable : string , scope : vscode . EnvironmentVariableScope | undefined ) : vscode . EnvironmentVariableMutator | undefined {
929
947
const key = this . getKey ( variable , scope ) ;
930
948
const value = this . map . get ( key ) ;
949
+ // TODO: Set options to defaults if needed
931
950
return value ? convertMutator ( value ) : undefined ;
932
951
}
933
952
@@ -944,11 +963,11 @@ class EnvironmentVariableCollection {
944
963
return workspaceFolder ? workspaceFolder . uri . toString ( ) : undefined ;
945
964
}
946
965
947
- public getVariableMap ( scope : vscode . EnvironmentVariableScope | undefined ) : Map < string , IEnvironmentVariableMutator > {
948
- const map = new Map < string , IEnvironmentVariableMutator > ( ) ;
966
+ public getVariableMap ( scope : vscode . EnvironmentVariableScope | undefined ) : Map < string , vscode . EnvironmentVariableMutator > {
967
+ const map = new Map < string , vscode . EnvironmentVariableMutator > ( ) ;
949
968
for ( const [ key , value ] of this . map ) {
950
969
if ( this . getScopeKey ( value . scope ) === this . getScopeKey ( scope ) ) {
951
- map . set ( key , value ) ;
970
+ map . set ( key , convertMutator ( value ) ) ;
952
971
}
953
972
}
954
973
return map ;
@@ -1022,24 +1041,24 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC
1022
1041
return this . collection . getScopedEnvironmentVariableCollection ( this . scope ) ;
1023
1042
}
1024
1043
1025
- replace ( variable : string , value : string ) : void {
1026
- this . collection . replace ( variable , value , this . scope ) ;
1044
+ replace ( variable : string , value : string , options ?: vscode . EnvironmentVariableMutatorOptions | undefined ) : void {
1045
+ this . collection . replace ( variable , value , options , this . scope ) ;
1027
1046
}
1028
1047
1029
- append ( variable : string , value : string ) : void {
1030
- this . collection . append ( variable , value , this . scope ) ;
1048
+ append ( variable : string , value : string , options ?: vscode . EnvironmentVariableMutatorOptions | undefined ) : void {
1049
+ this . collection . append ( variable , value , options , this . scope ) ;
1031
1050
}
1032
1051
1033
- prepend ( variable : string , value : string ) : void {
1034
- this . collection . prepend ( variable , value , this . scope ) ;
1052
+ prepend ( variable : string , value : string , options ?: vscode . EnvironmentVariableMutatorOptions | undefined ) : void {
1053
+ this . collection . prepend ( variable , value , options , this . scope ) ;
1035
1054
}
1036
1055
1037
1056
get ( variable : string ) : vscode . EnvironmentVariableMutator | undefined {
1038
1057
return this . collection . get ( variable , this . scope ) ;
1039
1058
}
1040
1059
1041
1060
forEach ( callback : ( variable : string , mutator : vscode . EnvironmentVariableMutator , collection : vscode . EnvironmentVariableCollection ) => any , thisArg ?: any ) : void {
1042
- this . collection . getVariableMap ( this . scope ) . forEach ( ( value , variable ) => callback . call ( thisArg , variable , convertMutator ( value ) , this ) , this . scope ) ;
1061
+ this . collection . getVariableMap ( this . scope ) . forEach ( ( value , variable ) => callback . call ( thisArg , variable , value , this ) , this . scope ) ;
1043
1062
}
1044
1063
1045
1064
[ Symbol . iterator ] ( ) : IterableIterator < [ variable : string , mutator : vscode . EnvironmentVariableMutator ] > {
@@ -1102,6 +1121,7 @@ function asTerminalColor(color?: vscode.ThemeColor): ThemeColor | undefined {
1102
1121
function convertMutator ( mutator : IEnvironmentVariableMutator ) : vscode . EnvironmentVariableMutator {
1103
1122
const newMutator = { ...mutator } ;
1104
1123
newMutator . scope = newMutator . scope ?? undefined ;
1124
+ newMutator . options = newMutator . options ?? undefined ;
1105
1125
delete ( newMutator as any ) . variable ;
1106
1126
return newMutator as vscode . EnvironmentVariableMutator ;
1107
1127
}
0 commit comments