Skip to content

Commit bc75c51

Browse files
alexr00gjsjohnmurray
authored andcommitted
Add resolveWithEnvironment to config resovler
Part of microsoft#120328
1 parent 2f66b8b commit bc75c51

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

src/vs/workbench/services/configurationResolver/common/configurationResolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IStringDictionary } from 'vs/base/common/collections';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
88
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
99
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
10+
import { IProcessEnvironment } from 'vs/base/common/platform';
1011

1112
export const IConfigurationResolverService = createDecorator<IConfigurationResolverService>('configurationResolverService');
1213

@@ -33,6 +34,8 @@ export interface IConfigurationResolverService {
3334
*/
3435
resolveAny(folder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): any;
3536

37+
resolveWithEnvironment(environment: IProcessEnvironment, folder: IWorkspaceFolder | undefined, value: string): string;
38+
3639
resolveAsync(folder: IWorkspaceFolder | undefined, value: string): Promise<string>;
3740
resolveAsync(folder: IWorkspaceFolder | undefined, value: string[]): Promise<string[]>;
3841
resolveAsync(folder: IWorkspaceFolder | undefined, value: IStringDictionary<string>): Promise<IStringDictionary<string>>;

src/vs/workbench/services/configurationResolver/common/variableResolver.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
5858
}
5959
}
6060

61+
public resolveWithEnvironment(environment: IProcessEnvironment, root: IWorkspaceFolder | undefined, value: string): string {
62+
return this.recursiveResolve(environment, root ? root.uri : undefined, value);
63+
}
64+
6165
public async resolveAsync(root: IWorkspaceFolder | undefined, value: string): Promise<string>;
6266
public async resolveAsync(root: IWorkspaceFolder | undefined, value: string[]): Promise<string[]>;
6367
public async resolveAsync(root: IWorkspaceFolder | undefined, value: IStringDictionary<string>): Promise<IStringDictionary<string>>;
6468
public async resolveAsync(root: IWorkspaceFolder | undefined, value: any): Promise<any> {
65-
return this.recursiveResolve(root ? root.uri : undefined, value);
69+
return this.recursiveResolve(this._envVariables, root ? root.uri : undefined, value);
6670
}
6771

6872
/**
@@ -72,7 +76,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
7276
public resolve(root: IWorkspaceFolder | undefined, value: string[]): string[];
7377
public resolve(root: IWorkspaceFolder | undefined, value: IStringDictionary<string>): IStringDictionary<string>;
7478
public resolve(root: IWorkspaceFolder | undefined, value: any): any {
75-
return this.recursiveResolve(root ? root.uri : undefined, value);
79+
return this.recursiveResolve(this._envVariables, root ? root.uri : undefined, value);
7680
}
7781

7882
/**
@@ -97,7 +101,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
97101
delete result.linux;
98102

99103
// substitute all variables recursively in string values
100-
return this.recursiveResolve(workspaceFolder ? workspaceFolder.uri : undefined, result, commandValueMapping, resolvedVariables);
104+
return this.recursiveResolve(this._envVariables, workspaceFolder ? workspaceFolder.uri : undefined, result, commandValueMapping, resolvedVariables);
101105
}
102106

103107
public resolveAny(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): any {
@@ -130,23 +134,23 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
130134
}
131135
}
132136

133-
private recursiveResolve(folderUri: uri | undefined, value: any, commandValueMapping?: IStringDictionary<string>, resolvedVariables?: Map<string, string>): any {
137+
private recursiveResolve(environment: IProcessEnvironment | undefined, folderUri: uri | undefined, value: any, commandValueMapping?: IStringDictionary<string>, resolvedVariables?: Map<string, string>): any {
134138
if (types.isString(value)) {
135-
return this.resolveString(folderUri, value, commandValueMapping, resolvedVariables);
139+
return this.resolveString(environment, folderUri, value, commandValueMapping, resolvedVariables);
136140
} else if (types.isArray(value)) {
137-
return value.map(s => this.recursiveResolve(folderUri, s, commandValueMapping, resolvedVariables));
141+
return value.map(s => this.recursiveResolve(environment, folderUri, s, commandValueMapping, resolvedVariables));
138142
} else if (types.isObject(value)) {
139143
let result: IStringDictionary<string | IStringDictionary<string> | string[]> = Object.create(null);
140144
Object.keys(value).forEach(key => {
141-
const replaced = this.resolveString(folderUri, key, commandValueMapping, resolvedVariables);
142-
result[replaced] = this.recursiveResolve(folderUri, value[key], commandValueMapping, resolvedVariables);
145+
const replaced = this.resolveString(environment, folderUri, key, commandValueMapping, resolvedVariables);
146+
result[replaced] = this.recursiveResolve(environment, folderUri, value[key], commandValueMapping, resolvedVariables);
143147
});
144148
return result;
145149
}
146150
return value;
147151
}
148152

149-
private resolveString(folderUri: uri | undefined, value: string, commandValueMapping: IStringDictionary<string> | undefined, resolvedVariables?: Map<string, string>): string {
153+
private resolveString(environment: IProcessEnvironment | undefined, folderUri: uri | undefined, value: string, commandValueMapping: IStringDictionary<string> | undefined, resolvedVariables?: Map<string, string>): string {
150154

151155
// loop through all variables occurrences in 'value'
152156
const replaced = value.replace(AbstractVariableResolverService.VARIABLE_REGEXP, (match: string, variable: string) => {
@@ -155,7 +159,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
155159
return match;
156160
}
157161

158-
let resolvedValue = this.evaluateSingleVariable(match, variable, folderUri, commandValueMapping);
162+
let resolvedValue = this.evaluateSingleVariable(environment, match, variable, folderUri, commandValueMapping);
159163

160164
if (resolvedVariables) {
161165
resolvedVariables.set(variable, resolvedValue);
@@ -171,7 +175,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
171175
return this._labelService ? this._labelService.getUriLabel(displayUri, { noPrefix: true }) : displayUri.fsPath;
172176
}
173177

174-
private evaluateSingleVariable(match: string, variable: string, folderUri: uri | undefined, commandValueMapping: IStringDictionary<string> | undefined): string {
178+
private evaluateSingleVariable(environment: IProcessEnvironment | undefined, match: string, variable: string, folderUri: uri | undefined, commandValueMapping: IStringDictionary<string> | undefined): string {
175179

176180
// try to separate variable arguments from variable name
177181
let argument: string | undefined;
@@ -230,8 +234,8 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
230234

231235
case 'env':
232236
if (argument) {
233-
if (this._envVariables) {
234-
const env = this._envVariables[isWindows ? argument.toLowerCase() : argument];
237+
if (environment) {
238+
const env = environment[isWindows ? argument.toLowerCase() : argument];
235239
if (types.isString(env)) {
236240
return env;
237241
}

0 commit comments

Comments
 (0)