Remove deprecated sync methods from configuration resolver
Part of #108804
This commit is contained in:
parent
87eac45476
commit
6a78187837
6 changed files with 106 additions and 143 deletions
|
@ -990,7 +990,7 @@ export class ExtHostVariableResolverService extends AbstractVariableResolverServ
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
}, undefined, process.env);
|
||||
}, undefined, Promise.resolve(process.env));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import * as Types from 'vs/base/common/types';
|
|||
import { Schemas } from 'vs/base/common/network';
|
||||
import { SideBySideEditor, EditorResourceAccessor } from 'vs/workbench/common/editor';
|
||||
import { IStringDictionary, forEach, fromMap } from 'vs/base/common/collections';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { IConfigurationService, IConfigurationOverrides, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { IWorkspaceFolder, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
|
||||
|
@ -30,7 +29,6 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
|
|||
getAppRoot: () => string | undefined,
|
||||
getExecPath: () => string | undefined
|
||||
},
|
||||
envVariables: IProcessEnvironment,
|
||||
envVariablesPromise: Promise<IProcessEnvironment>,
|
||||
editorService: IEditorService,
|
||||
private readonly configurationService: IConfigurationService,
|
||||
|
@ -102,12 +100,12 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
|
|||
}
|
||||
return undefined;
|
||||
}
|
||||
}, labelService, envVariables, envVariablesPromise);
|
||||
}, labelService, envVariablesPromise);
|
||||
}
|
||||
|
||||
public override async resolveWithInteractionReplace(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<any> {
|
||||
// resolve any non-interactive variables and any contributed variables
|
||||
config = this.resolveAny(folder, config);
|
||||
config = await this.resolveAnyAsync(folder, config);
|
||||
|
||||
// resolve input variables in the order in which they are encountered
|
||||
return this.resolveWithInteraction(folder, config, section, variables, target).then(mapping => {
|
||||
|
@ -115,7 +113,7 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
|
|||
if (!mapping) {
|
||||
return null;
|
||||
} else if (mapping.size > 0) {
|
||||
return this.resolveAny(folder, config, fromMap(mapping));
|
||||
return this.resolveAnyAsync(folder, config, fromMap(mapping));
|
||||
} else {
|
||||
return config;
|
||||
}
|
||||
|
@ -363,14 +361,13 @@ export class ConfigurationResolverService extends BaseConfigurationResolverServi
|
|||
|
||||
constructor(
|
||||
@IEditorService editorService: IEditorService,
|
||||
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
|
||||
@IConfigurationService configurationService: IConfigurationService,
|
||||
@ICommandService commandService: ICommandService,
|
||||
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
|
||||
@IQuickInputService quickInputService: IQuickInputService,
|
||||
@ILabelService labelService: ILabelService,
|
||||
) {
|
||||
super({ getAppRoot: () => undefined, getExecPath: () => undefined }, Object.create(null),
|
||||
super({ getAppRoot: () => undefined, getExecPath: () => undefined },
|
||||
Promise.resolve(Object.create(null)), editorService, configurationService,
|
||||
commandService, workspaceContextService, quickInputService, labelService);
|
||||
}
|
||||
|
|
|
@ -14,26 +14,6 @@ export const IConfigurationResolverService = createDecorator<IConfigurationResol
|
|||
export interface IConfigurationResolverService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
/**
|
||||
* @deprecated Use the async version of `resolve` instead.
|
||||
*/
|
||||
resolve(folder: IWorkspaceFolder | undefined, value: string): string;
|
||||
/**
|
||||
* @deprecated Use the async version of `resolve` instead.
|
||||
*/
|
||||
resolve(folder: IWorkspaceFolder | undefined, value: string[]): string[];
|
||||
/**
|
||||
* @deprecated Use the async version of `resolve` instead.
|
||||
*/
|
||||
resolve(folder: IWorkspaceFolder | undefined, value: IStringDictionary<string>): IStringDictionary<string>;
|
||||
|
||||
/**
|
||||
* Recursively resolves all variables in the given config and returns a copy of it with substituted values.
|
||||
* Command variables are only substituted if a "commandValueMapping" dictionary is given and if it contains an entry for the command.
|
||||
* @deprecated Use the async version of `resolveAny` instead.
|
||||
*/
|
||||
resolveAny(folder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): any;
|
||||
|
||||
resolveWithEnvironment(environment: IProcessEnvironment, folder: IWorkspaceFolder | undefined, value: string): string;
|
||||
|
||||
resolveAsync(folder: IWorkspaceFolder | undefined, value: string): Promise<string>;
|
||||
|
|
|
@ -37,52 +37,43 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
|
|||
|
||||
private _context: IVariableResolveContext;
|
||||
private _labelService?: ILabelService;
|
||||
private _envVariables?: IProcessEnvironment;
|
||||
private _envVariablesPromise?: Promise<IProcessEnvironment>;
|
||||
protected _contributedVariables: Map<string, () => Promise<string | undefined>> = new Map();
|
||||
|
||||
constructor(_context: IVariableResolveContext, _labelService?: ILabelService, _envVariables?: IProcessEnvironment, _envVariablesPromise?: Promise<IProcessEnvironment>) {
|
||||
constructor(_context: IVariableResolveContext, _labelService?: ILabelService, _envVariablesPromise?: Promise<IProcessEnvironment>) {
|
||||
this._context = _context;
|
||||
this._labelService = _labelService;
|
||||
// TODO: delete _envVariables in favor of _envVariablesPromise https://github.com/microsoft/vscode/issues/108804
|
||||
if (_envVariables) {
|
||||
if (isWindows) {
|
||||
// windows env variables are case insensitive
|
||||
const ev: IProcessEnvironment = Object.create(null);
|
||||
this._envVariables = ev;
|
||||
Object.keys(_envVariables).forEach(key => {
|
||||
ev[key.toLowerCase()] = _envVariables[key];
|
||||
});
|
||||
} else {
|
||||
this._envVariables = _envVariables;
|
||||
}
|
||||
if (_envVariablesPromise) {
|
||||
this._envVariablesPromise = _envVariablesPromise.then(envVariables => {
|
||||
return this.prepareEnv(envVariables);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private prepareEnv(envVariables: IProcessEnvironment): IProcessEnvironment {
|
||||
// windows env variables are case insensitive
|
||||
if (isWindows) {
|
||||
const ev: IProcessEnvironment = Object.create(null);
|
||||
Object.keys(envVariables).forEach(key => {
|
||||
ev[key.toLowerCase()] = envVariables[key];
|
||||
});
|
||||
return ev;
|
||||
}
|
||||
return envVariables;
|
||||
}
|
||||
|
||||
public resolveWithEnvironment(environment: IProcessEnvironment, root: IWorkspaceFolder | undefined, value: string): string {
|
||||
return this.recursiveResolve(environment, root ? root.uri : undefined, value);
|
||||
return this.recursiveResolve(this.prepareEnv(environment), root ? root.uri : undefined, value);
|
||||
}
|
||||
|
||||
public async resolveAsync(root: IWorkspaceFolder | undefined, value: string): Promise<string>;
|
||||
public async resolveAsync(root: IWorkspaceFolder | undefined, value: string[]): Promise<string[]>;
|
||||
public async resolveAsync(root: IWorkspaceFolder | undefined, value: IStringDictionary<string>): Promise<IStringDictionary<string>>;
|
||||
public async resolveAsync(root: IWorkspaceFolder | undefined, value: any): Promise<any> {
|
||||
return this.recursiveResolve(this._envVariables, root ? root.uri : undefined, value);
|
||||
return this.recursiveResolve(await this._envVariablesPromise, root ? root.uri : undefined, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the async version of `resolve` instead.
|
||||
*/
|
||||
public resolve(root: IWorkspaceFolder | undefined, value: string): string;
|
||||
public resolve(root: IWorkspaceFolder | undefined, value: string[]): string[];
|
||||
public resolve(root: IWorkspaceFolder | undefined, value: IStringDictionary<string>): IStringDictionary<string>;
|
||||
public resolve(root: IWorkspaceFolder | undefined, value: any): any {
|
||||
return this.recursiveResolve(this._envVariables, root ? root.uri : undefined, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the async version of `resolve` instead.
|
||||
*/
|
||||
public resolveAnyBase(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>, resolvedVariables?: Map<string, string>): any {
|
||||
private async resolveAnyBase(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>, resolvedVariables?: Map<string, string>): Promise<any> {
|
||||
|
||||
const result = objects.deepClone(config) as any;
|
||||
|
||||
|
@ -101,20 +92,16 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
|
|||
delete result.linux;
|
||||
|
||||
// substitute all variables recursively in string values
|
||||
return this.recursiveResolve(this._envVariables, workspaceFolder ? workspaceFolder.uri : undefined, result, commandValueMapping, resolvedVariables);
|
||||
}
|
||||
|
||||
public resolveAny(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): any {
|
||||
return this.resolveAnyBase(workspaceFolder, config, commandValueMapping);
|
||||
return this.recursiveResolve(await this._envVariablesPromise, workspaceFolder ? workspaceFolder.uri : undefined, result, commandValueMapping, resolvedVariables);
|
||||
}
|
||||
|
||||
public async resolveAnyAsync(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): Promise<any> {
|
||||
return this.resolveAnyBase(workspaceFolder, config, commandValueMapping);
|
||||
}
|
||||
|
||||
public resolveAnyMap(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): { newConfig: any, resolvedVariables: Map<string, string> } {
|
||||
protected async resolveAnyMap(workspaceFolder: IWorkspaceFolder | undefined, config: any, commandValueMapping?: IStringDictionary<string>): Promise<{ newConfig: any, resolvedVariables: Map<string, string> }> {
|
||||
const resolvedVariables = new Map<string, string>();
|
||||
const newConfig = this.resolveAnyBase(workspaceFolder, config, commandValueMapping, resolvedVariables);
|
||||
const newConfig = await this.resolveAnyBase(workspaceFolder, config, commandValueMapping, resolvedVariables);
|
||||
return { newConfig, resolvedVariables };
|
||||
}
|
||||
|
||||
|
@ -236,7 +223,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe
|
|||
if (argument) {
|
||||
if (environment) {
|
||||
// Depending on the source of the environment, on Windows, the values may all be lowercase.
|
||||
const env = isWindows ? (environment[argument.toLowerCase()] ?? environment[argument]) : environment[argument];
|
||||
const env = environment[isWindows ? argument.toLowerCase() : argument];
|
||||
if (types.isString(env)) {
|
||||
return env;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
|
|||
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { BaseConfigurationResolverService } from 'vs/workbench/services/configurationResolver/browser/configurationResolverService';
|
||||
import { env } from 'vs/base/common/process';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IShellEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/shellEnvironmentService';
|
||||
|
||||
|
@ -35,7 +34,7 @@ export class ConfigurationResolverService extends BaseConfigurationResolverServi
|
|||
getExecPath: (): string | undefined => {
|
||||
return environmentService.execPath;
|
||||
}
|
||||
}, env, shellEnvironmentService.getShellEnv(), editorService, configurationService, commandService, workspaceContextService, quickInputService, labelService);
|
||||
}, shellEnvironmentService.getShellEnv(), editorService, configurationService, commandService, workspaceContextService, quickInputService, labelService);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,111 +75,111 @@ suite('Configuration Resolver Service', () => {
|
|||
labelService = new MockLabelService();
|
||||
containingWorkspace = testWorkspace(uri.parse('file:///VSCode/workspaceLocation'));
|
||||
workspace = containingWorkspace.folders[0];
|
||||
configurationResolverService = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), editorService, new MockInputsConfigurationService(), mockCommandService, new TestContextService(containingWorkspace), quickInputService, labelService);
|
||||
configurationResolverService = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), editorService, new MockInputsConfigurationService(), mockCommandService, new TestContextService(containingWorkspace), quickInputService, labelService);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
configurationResolverService = null;
|
||||
});
|
||||
|
||||
test('substitute one', () => {
|
||||
test('substitute one', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('workspace folder with argument', () => {
|
||||
test('workspace folder with argument', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('workspace folder with invalid argument', () => {
|
||||
assert.throws(() => configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder:invalidLocation} xyz'));
|
||||
assert.rejects(async () => await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder:invalidLocation} xyz'));
|
||||
});
|
||||
|
||||
test('workspace folder with undefined workspace folder', () => {
|
||||
assert.throws(() => configurationResolverService!.resolve(undefined, 'abc ${workspaceFolder} xyz'));
|
||||
assert.rejects(async () => await configurationResolverService!.resolveAsync(undefined, 'abc ${workspaceFolder} xyz'));
|
||||
});
|
||||
|
||||
test('workspace folder with argument and undefined workspace folder', () => {
|
||||
test('workspace folder with argument and undefined workspace folder', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(undefined, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(undefined, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc \\VSCode\\workspaceLocation xyz');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(undefined, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(undefined, 'abc ${workspaceFolder:workspaceLocation} xyz'), 'abc /VSCode/workspaceLocation xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('workspace folder with invalid argument and undefined workspace folder', () => {
|
||||
assert.throws(() => configurationResolverService!.resolve(undefined, 'abc ${workspaceFolder:invalidLocation} xyz'));
|
||||
assert.rejects(async () => await configurationResolverService!.resolveAsync(undefined, 'abc ${workspaceFolder:invalidLocation} xyz'));
|
||||
});
|
||||
|
||||
test('workspace root folder name', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceRootFolderName} xyz'), 'abc workspaceLocation xyz');
|
||||
test('workspace root folder name', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceRootFolderName} xyz'), 'abc workspaceLocation xyz');
|
||||
});
|
||||
|
||||
test('current selected line number', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${lineNumber} xyz'), `abc ${mockLineNumber} xyz`);
|
||||
test('current selected line number', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${lineNumber} xyz'), `abc ${mockLineNumber} xyz`);
|
||||
});
|
||||
|
||||
test('relative file', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${relativeFile} xyz'), 'abc file xyz');
|
||||
test('relative file', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${relativeFile} xyz'), 'abc file xyz');
|
||||
});
|
||||
|
||||
test('relative file with argument', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${relativeFile:workspaceLocation} xyz'), 'abc file xyz');
|
||||
test('relative file with argument', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${relativeFile:workspaceLocation} xyz'), 'abc file xyz');
|
||||
});
|
||||
|
||||
test('relative file with invalid argument', () => {
|
||||
assert.throws(() => configurationResolverService!.resolve(workspace, 'abc ${relativeFile:invalidLocation} xyz'));
|
||||
assert.rejects(async () => await configurationResolverService!.resolveAsync(workspace, 'abc ${relativeFile:invalidLocation} xyz'));
|
||||
});
|
||||
|
||||
test('relative file with undefined workspace folder', () => {
|
||||
test('relative file with undefined workspace folder', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(undefined, 'abc ${relativeFile} xyz'), 'abc \\VSCode\\workspaceLocation\\file xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(undefined, 'abc ${relativeFile} xyz'), 'abc \\VSCode\\workspaceLocation\\file xyz');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(undefined, 'abc ${relativeFile} xyz'), 'abc /VSCode/workspaceLocation/file xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(undefined, 'abc ${relativeFile} xyz'), 'abc /VSCode/workspaceLocation/file xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('relative file with argument and undefined workspace folder', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(undefined, 'abc ${relativeFile:workspaceLocation} xyz'), 'abc file xyz');
|
||||
test('relative file with argument and undefined workspace folder', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(undefined, 'abc ${relativeFile:workspaceLocation} xyz'), 'abc file xyz');
|
||||
});
|
||||
|
||||
test('relative file with invalid argument and undefined workspace folder', () => {
|
||||
assert.throws(() => configurationResolverService!.resolve(undefined, 'abc ${relativeFile:invalidLocation} xyz'));
|
||||
assert.rejects(async () => await configurationResolverService!.resolveAsync(undefined, 'abc ${relativeFile:invalidLocation} xyz'));
|
||||
});
|
||||
|
||||
test('substitute many', () => {
|
||||
test('substitute many', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${workspaceFolder} - ${workspaceFolder}'), '\\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${workspaceFolder} - ${workspaceFolder}'), '\\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${workspaceFolder} - ${workspaceFolder}'), '/VSCode/workspaceLocation - /VSCode/workspaceLocation');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${workspaceFolder} - ${workspaceFolder}'), '/VSCode/workspaceLocation - /VSCode/workspaceLocation');
|
||||
}
|
||||
});
|
||||
|
||||
test('substitute one env variable', () => {
|
||||
test('substitute one env variable', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder} ${env:key1} xyz'), 'abc \\VSCode\\workspaceLocation Value for key1 xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder} ${env:key1} xyz'), 'abc \\VSCode\\workspaceLocation Value for key1 xyz');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, 'abc ${workspaceFolder} ${env:key1} xyz'), 'abc /VSCode/workspaceLocation Value for key1 xyz');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, 'abc ${workspaceFolder} ${env:key1} xyz'), 'abc /VSCode/workspaceLocation Value for key1 xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('substitute many env variable', () => {
|
||||
test('substitute many env variable', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), '\\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for key1 - Value for key2');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), '\\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for key1 - Value for key2');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), '/VSCode/workspaceLocation - /VSCode/workspaceLocation Value for key1 - Value for key2');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), '/VSCode/workspaceLocation - /VSCode/workspaceLocation Value for key1 - Value for key2');
|
||||
}
|
||||
});
|
||||
|
||||
test('disallows nested keys (#77289)', () => {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${env:key1} ${env:key1${env:key2}}'), 'Value for key1 ${env:key1${env:key2}}');
|
||||
test('disallows nested keys (#77289)', async () => {
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${env:key1} ${env:key1${env:key2}}'), 'Value for key1 ${env:key1${env:key2}}');
|
||||
});
|
||||
|
||||
// test('substitute keys and values in object', () => {
|
||||
|
@ -187,22 +187,22 @@ suite('Configuration Resolver Service', () => {
|
|||
// '${workspaceRootFolderName}': '${lineNumber}',
|
||||
// 'hey ${env:key1} ': '${workspaceRootFolderName}'
|
||||
// };
|
||||
// assert.deepStrictEqual(configurationResolverService!.resolve(workspace, myObject), {
|
||||
// assert.deepStrictEqual(configurationResolverService!.resolveAsync(workspace, myObject), {
|
||||
// 'workspaceLocation': `${editorService.mockLineNumber}`,
|
||||
// 'hey Value for key1 ': 'workspaceLocation'
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
test('substitute one env variable using platform case sensitivity', () => {
|
||||
test('substitute one env variable using platform case sensitivity', async () => {
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${env:key1} - ${env:Key1}'), 'Value for key1 - Value for key1');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${env:key1} - ${env:Key1}'), 'Value for key1 - Value for key1');
|
||||
} else {
|
||||
assert.strictEqual(configurationResolverService!.resolve(workspace, '${env:key1} - ${env:Key1}'), 'Value for key1 - ');
|
||||
assert.strictEqual(await configurationResolverService!.resolveAsync(workspace, '${env:key1} - ${env:Key1}'), 'Value for key1 - ');
|
||||
}
|
||||
});
|
||||
|
||||
test('substitute one configuration variable', () => {
|
||||
test('substitute one configuration variable', async () => {
|
||||
let configurationService: IConfigurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
fontFamily: 'foo'
|
||||
|
@ -214,22 +214,22 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz');
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz');
|
||||
});
|
||||
|
||||
test('substitute configuration variable with undefined workspace folder', () => {
|
||||
test('substitute configuration variable with undefined workspace folder', async () => {
|
||||
let configurationService: IConfigurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
fontFamily: 'foo'
|
||||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(service.resolve(undefined, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz');
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(await service.resolveAsync(undefined, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz');
|
||||
});
|
||||
|
||||
test('substitute many configuration variables', () => {
|
||||
test('substitute many configuration variables', async () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
|
@ -242,11 +242,11 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz');
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} xyz'), 'abc foo bar xyz');
|
||||
});
|
||||
|
||||
test('substitute one env variable and a configuration variable', () => {
|
||||
test('substitute one env variable and a configuration variable', async () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
|
@ -259,15 +259,15 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${workspaceFolder} ${env:key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for key1 xyz');
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${config:editor.fontFamily} ${workspaceFolder} ${env:key1} xyz'), 'abc foo \\VSCode\\workspaceLocation Value for key1 xyz');
|
||||
} else {
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${workspaceFolder} ${env:key1} xyz'), 'abc foo /VSCode/workspaceLocation Value for key1 xyz');
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${config:editor.fontFamily} ${workspaceFolder} ${env:key1} xyz'), 'abc foo /VSCode/workspaceLocation Value for key1 xyz');
|
||||
}
|
||||
});
|
||||
|
||||
test('substitute many env variable and a configuration variable', () => {
|
||||
test('substitute many env variable and a configuration variable', async () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
|
@ -280,15 +280,15 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
if (platform.isWindows) {
|
||||
assert.strictEqual(service.resolve(workspace, '${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} ${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), 'foo bar \\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for key1 - Value for key2');
|
||||
assert.strictEqual(await service.resolveAsync(workspace, '${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} ${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), 'foo bar \\VSCode\\workspaceLocation - \\VSCode\\workspaceLocation Value for key1 - Value for key2');
|
||||
} else {
|
||||
assert.strictEqual(service.resolve(workspace, '${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} ${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), 'foo bar /VSCode/workspaceLocation - /VSCode/workspaceLocation Value for key1 - Value for key2');
|
||||
assert.strictEqual(await service.resolveAsync(workspace, '${config:editor.fontFamily} ${config:terminal.integrated.fontFamily} ${workspaceFolder} - ${workspaceFolder} ${env:key1} - ${env:key2}'), 'foo bar /VSCode/workspaceLocation - /VSCode/workspaceLocation Value for key1 - Value for key2');
|
||||
}
|
||||
});
|
||||
|
||||
test('mixed types of configuration variables', () => {
|
||||
test('mixed types of configuration variables', async () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new TestConfigurationService({
|
||||
editor: {
|
||||
|
@ -314,19 +314,19 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} ${config:editor.lineNumbers} ${config:editor.insertSpaces} xyz'), 'abc foo 123 false xyz');
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${config:editor.fontFamily} ${config:editor.lineNumbers} ${config:editor.insertSpaces} xyz'), 'abc foo 123 false xyz');
|
||||
});
|
||||
|
||||
test('uses original variable as fallback', () => {
|
||||
test('uses original variable as fallback', async () => {
|
||||
let configurationService: IConfigurationService;
|
||||
configurationService = new TestConfigurationService({
|
||||
editor: {}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${unknownVariable} xyz'), 'abc ${unknownVariable} xyz');
|
||||
assert.strictEqual(service.resolve(workspace, 'abc ${env:unknownVariable} xyz'), 'abc xyz');
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${unknownVariable} xyz'), 'abc ${unknownVariable} xyz');
|
||||
assert.strictEqual(await service.resolveAsync(workspace, 'abc ${env:unknownVariable} xyz'), 'abc xyz');
|
||||
});
|
||||
|
||||
test('configuration variables with invalid accessor', () => {
|
||||
|
@ -337,15 +337,15 @@ suite('Configuration Resolver Service', () => {
|
|||
}
|
||||
});
|
||||
|
||||
let service = new TestConfigurationResolverService(nullContext, environmentService.userEnv, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
let service = new TestConfigurationResolverService(nullContext, Promise.resolve(environmentService.userEnv), new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService, labelService);
|
||||
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${env} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${env:} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${config} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${config:} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${config:editor} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${config:editor..fontFamily} xyz'));
|
||||
assert.throws(() => service.resolve(workspace, 'abc ${config:editor.none.none2} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${env} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${env:} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${config} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${config:} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${config:editor} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${config:editor..fontFamily} xyz'));
|
||||
assert.rejects(async () => await service.resolveAsync(workspace, 'abc ${config:editor.none.none2} xyz'));
|
||||
});
|
||||
|
||||
test('a single command variable', () => {
|
||||
|
|
Loading…
Reference in a new issue