@@ -50,9 +50,9 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID
50
50
registerLinkProvider ( provider : vscode . TerminalLinkProvider ) : vscode . Disposable ;
51
51
registerProfileProvider ( extension : IExtensionDescription , id : string , provider : vscode . TerminalProfileProvider ) : vscode . Disposable ;
52
52
registerTerminalQuickFixProvider ( id : string , extensionId : string , provider : vscode . TerminalQuickFixProvider ) : vscode . Disposable ;
53
- getEnvironmentVariableCollection ( extension : IExtensionDescription , persistent ?: boolean ) : vscode . EnvironmentVariableCollection ;
53
+ getEnvironmentVariableCollection ( extension : IExtensionDescription ) : IEnvironmentVariableCollection ;
54
54
}
55
-
55
+ type IEnvironmentVariableCollection = vscode . EnvironmentVariableCollection & { getScopedEnvironmentVariableCollection ( scope : vscode . EnvironmentVariableScope | undefined ) : vscode . EnvironmentVariableCollection } ;
56
56
export interface ITerminalInternalOptions {
57
57
isFeatureTerminal ?: boolean ;
58
58
useShellEnvironment ?: boolean ;
@@ -823,13 +823,13 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
823
823
return index ;
824
824
}
825
825
826
- public getEnvironmentVariableCollection ( extension : IExtensionDescription ) : vscode . EnvironmentVariableCollection {
826
+ public getEnvironmentVariableCollection ( extension : IExtensionDescription ) : IEnvironmentVariableCollection {
827
827
let collection = this . _environmentVariableCollections . get ( extension . identifier . value ) ;
828
828
if ( ! collection ) {
829
829
collection = new EnvironmentVariableCollection ( ) ;
830
830
this . _setEnvironmentVariableCollection ( extension . identifier . value , collection ) ;
831
831
}
832
- return collection ;
832
+ return collection . getScopedEnvironmentVariableCollection ( undefined ) ;
833
833
}
834
834
835
835
private _syncEnvironmentVariableCollection ( extensionIdentifier : string , collection : EnvironmentVariableCollection ) : void {
@@ -867,8 +867,9 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
867
867
}
868
868
}
869
869
870
- class EnvironmentVariableCollection implements vscode . EnvironmentVariableCollection {
870
+ class EnvironmentVariableCollection {
871
871
readonly map : Map < string , IEnvironmentVariableMutator > = new Map ( ) ;
872
+ private readonly scopedCollections : Map < string , ScopedEnvironmentVariableCollection > = new Map ( ) ;
872
873
readonly descriptionMap : Map < string , IEnvironmentDescriptionMutator > = new Map ( ) ;
873
874
private _persistent : boolean = true ;
874
875
@@ -887,23 +888,30 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect
887
888
this . map = new Map ( serialized ) ;
888
889
}
889
890
890
- get size ( ) : number {
891
- return this . map . size ;
891
+ getScopedEnvironmentVariableCollection ( scope : vscode . EnvironmentVariableScope | undefined ) : IEnvironmentVariableCollection {
892
+ const scopedCollectionKey = this . getScopeKey ( scope ) ;
893
+ let scopedCollection = this . scopedCollections . get ( scopedCollectionKey ) ;
894
+ if ( ! scopedCollection ) {
895
+ scopedCollection = new ScopedEnvironmentVariableCollection ( this , scope ) ;
896
+ this . scopedCollections . set ( scopedCollectionKey , scopedCollection ) ;
897
+ scopedCollection . onDidChangeCollection ( ( ) => this . _onDidChangeCollection . fire ( ) ) ;
898
+ }
899
+ return scopedCollection ;
892
900
}
893
901
894
- replace ( variable : string , value : string , scope ? : vscode . EnvironmentVariableScope ) : void {
902
+ replace ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
895
903
this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Replace , scope } ) ;
896
904
}
897
905
898
- append ( variable : string , value : string , scope ? : vscode . EnvironmentVariableScope ) : void {
906
+ append ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
899
907
this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Append , scope } ) ;
900
908
}
901
909
902
- prepend ( variable : string , value : string , scope ? : vscode . EnvironmentVariableScope ) : void {
910
+ prepend ( variable : string , value : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
903
911
this . _setIfDiffers ( variable , { value, type : EnvironmentVariableMutatorType . Prepend , scope } ) ;
904
912
}
905
913
906
- private _setIfDiffers ( variable : string , mutator : vscode . EnvironmentVariableMutator ) : void {
914
+ private _setIfDiffers ( variable : string , mutator : vscode . EnvironmentVariableMutator & { scope : vscode . EnvironmentVariableScope | undefined } ) : void {
907
915
if ( ! mutator . scope ) {
908
916
delete ( mutator as any ) . scope ; // Convenient for tests
909
917
}
@@ -917,44 +925,42 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect
917
925
}
918
926
}
919
927
920
- get ( variable : string , scope ? : vscode . EnvironmentVariableScope ) : vscode . EnvironmentVariableMutator | undefined {
928
+ get ( variable : string , scope : vscode . EnvironmentVariableScope | undefined ) : vscode . EnvironmentVariableMutator | undefined {
921
929
const key = this . getKey ( variable , scope ) ;
922
930
const value = this . map . get ( key ) ;
923
931
return value ? convertMutator ( value ) : undefined ;
924
932
}
925
933
926
934
private getKey ( variable : string , scope : vscode . EnvironmentVariableScope | undefined ) {
927
- const workspaceKey = this . getWorkspaceKey ( scope ?. workspaceFolder ) ;
928
- return workspaceKey ? `${ variable } :::${ workspaceKey } ` : variable ;
935
+ const scopeKey = this . getScopeKey ( scope ) ;
936
+ return scopeKey . length ? `${ variable } :::${ scopeKey } ` : variable ;
929
937
}
930
938
931
- private getWorkspaceKey ( workspaceFolder : vscode . WorkspaceFolder | undefined ) : string | undefined {
932
- return workspaceFolder ? workspaceFolder . uri . toString ( ) : undefined ;
939
+ private getScopeKey ( scope : vscode . EnvironmentVariableScope | undefined ) : string {
940
+ return this . getWorkspaceKey ( scope ?. workspaceFolder ) ?? '' ;
933
941
}
934
942
935
- forEach ( callback : ( variable : string , mutator : vscode . EnvironmentVariableMutator , collection : vscode . EnvironmentVariableCollection ) => any , thisArg ?: any ) : void {
936
- this . map . forEach ( ( value , _ ) => callback . call ( thisArg , value . variable , convertMutator ( value ) , this ) ) ;
943
+ private getWorkspaceKey ( workspaceFolder : vscode . WorkspaceFolder | undefined ) : string | undefined {
944
+ return workspaceFolder ? workspaceFolder . uri . toString ( ) : undefined ;
937
945
}
938
946
939
- [ Symbol . iterator ] ( ) : IterableIterator < [ variable : string , mutator : vscode . EnvironmentVariableMutator ] > {
940
- const map : Map < string , vscode . EnvironmentVariableMutator > = new Map ( ) ;
941
- this . map . forEach ( ( mutator , _key ) => {
942
- if ( mutator . scope ) {
943
- // Scoped mutators are not supported via this iterator, as it returns variable as the key which is supposed to be unique.
944
- return ;
947
+ public getVariableMap ( scope : vscode . EnvironmentVariableScope | undefined ) : Map < string , IEnvironmentVariableMutator > {
948
+ const map = new Map < string , IEnvironmentVariableMutator > ( ) ;
949
+ for ( const [ key , value ] of this . map ) {
950
+ if ( this . getScopeKey ( value . scope ) === this . getScopeKey ( scope ) ) {
951
+ map . set ( key , value ) ;
945
952
}
946
- map . set ( mutator . variable , convertMutator ( mutator ) ) ;
947
- } ) ;
948
- return map . entries ( ) ;
953
+ }
954
+ return map ;
949
955
}
950
956
951
- delete ( variable : string , scope ? : vscode . EnvironmentVariableScope ) : void {
957
+ delete ( variable : string , scope : vscode . EnvironmentVariableScope | undefined ) : void {
952
958
const key = this . getKey ( variable , scope ) ;
953
959
this . map . delete ( key ) ;
954
960
this . _onDidChangeCollection . fire ( ) ;
955
961
}
956
962
957
- clear ( scope ? : vscode . EnvironmentVariableScope ) : void {
963
+ clear ( scope : vscode . EnvironmentVariableScope | undefined ) : void {
958
964
if ( scope ?. workspaceFolder ) {
959
965
for ( const [ key , mutator ] of this . map ) {
960
966
if ( mutator . scope ?. workspaceFolder ?. index === scope . workspaceFolder . index ) {
@@ -969,8 +975,8 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect
969
975
this . _onDidChangeCollection . fire ( ) ;
970
976
}
971
977
972
- setDescription ( description : string | vscode . MarkdownString | undefined , scope ? : vscode . EnvironmentVariableScope ) : void {
973
- const key = this . getKey ( '' , scope ) ;
978
+ setDescription ( description : string | vscode . MarkdownString | undefined , scope : vscode . EnvironmentVariableScope | undefined ) : void {
979
+ const key = this . getScopeKey ( scope ) ;
974
980
const current = this . descriptionMap . get ( key ) ;
975
981
if ( ! current || current . description !== description ) {
976
982
let descriptionStr : string | undefined ;
@@ -986,12 +992,78 @@ class EnvironmentVariableCollection implements vscode.EnvironmentVariableCollect
986
992
}
987
993
}
988
994
989
- private clearDescription ( scope ?: vscode . EnvironmentVariableScope ) : void {
990
- const key = this . getKey ( '' , scope ) ;
995
+ public getDescription ( scope : vscode . EnvironmentVariableScope | undefined ) : string | vscode . MarkdownString | undefined {
996
+ const key = this . getScopeKey ( scope ) ;
997
+ return this . descriptionMap . get ( key ) ?. description ;
998
+ }
999
+
1000
+ private clearDescription ( scope : vscode . EnvironmentVariableScope | undefined ) : void {
1001
+ const key = this . getScopeKey ( scope ) ;
991
1002
this . descriptionMap . delete ( key ) ;
992
1003
}
993
1004
}
994
1005
1006
+ class ScopedEnvironmentVariableCollection implements vscode . EnvironmentVariableCollection , IEnvironmentVariableCollection {
1007
+ public get persistent ( ) : boolean { return this . collection . persistent ; }
1008
+ public set persistent ( value : boolean ) {
1009
+ this . collection . persistent = value ;
1010
+ }
1011
+
1012
+ protected readonly _onDidChangeCollection = new Emitter < void > ( ) ;
1013
+ get onDidChangeCollection ( ) : Event < void > { return this . _onDidChangeCollection && this . _onDidChangeCollection . event ; }
1014
+
1015
+ constructor (
1016
+ private readonly collection : EnvironmentVariableCollection ,
1017
+ private readonly scope : vscode . EnvironmentVariableScope | undefined
1018
+ ) {
1019
+ }
1020
+
1021
+ getScopedEnvironmentVariableCollection ( ) {
1022
+ return this . collection . getScopedEnvironmentVariableCollection ( this . scope ) ;
1023
+ }
1024
+
1025
+ replace ( variable : string , value : string ) : void {
1026
+ this . collection . replace ( variable , value , this . scope ) ;
1027
+ }
1028
+
1029
+ append ( variable : string , value : string ) : void {
1030
+ this . collection . append ( variable , value , this . scope ) ;
1031
+ }
1032
+
1033
+ prepend ( variable : string , value : string ) : void {
1034
+ this . collection . prepend ( variable , value , this . scope ) ;
1035
+ }
1036
+
1037
+ get ( variable : string ) : vscode . EnvironmentVariableMutator | undefined {
1038
+ return this . collection . get ( variable , this . scope ) ;
1039
+ }
1040
+
1041
+ 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 ) ;
1043
+ }
1044
+
1045
+ [ Symbol . iterator ] ( ) : IterableIterator < [ variable : string , mutator : vscode . EnvironmentVariableMutator ] > {
1046
+ return this . collection . getVariableMap ( this . scope ) . entries ( ) ;
1047
+ }
1048
+
1049
+ delete ( variable : string ) : void {
1050
+ this . collection . delete ( variable , this . scope ) ;
1051
+ this . _onDidChangeCollection . fire ( undefined ) ;
1052
+ }
1053
+
1054
+ clear ( ) : void {
1055
+ this . collection . clear ( this . scope ) ;
1056
+ }
1057
+
1058
+ set description ( description : string | vscode . MarkdownString | undefined ) {
1059
+ this . collection . setDescription ( description , this . scope ) ;
1060
+ }
1061
+
1062
+ get description ( ) : string | vscode . MarkdownString | undefined {
1063
+ return this . collection . getDescription ( this . scope ) ;
1064
+ }
1065
+ }
1066
+
995
1067
export class WorkerExtHostTerminalService extends BaseExtHostTerminalService {
996
1068
constructor (
997
1069
@IExtHostRpcService extHostRpc : IExtHostRpcService
0 commit comments