diff --git a/src/vs/workbench/api/common/extHostDebugService.ts b/src/vs/workbench/api/common/extHostDebugService.ts index 94132fed5b8..72b1bb63bc7 100644 --- a/src/vs/workbench/api/common/extHostDebugService.ts +++ b/src/vs/workbench/api/common/extHostDebugService.ts @@ -985,7 +985,7 @@ export class ExtHostVariableResolverService extends AbstractVariableResolverServ getWorkspaceFolderCount: (): number => { return folders.length; }, - getConfigurationValue: (folderUri: URI, section: string): string | undefined => { + getConfigurationValue: (folderUri: URI | undefined, section: string): string | undefined => { return configurationService.getConfiguration(undefined, folderUri).get(section); }, getExecPath: (): string | undefined => { diff --git a/src/vs/workbench/services/configurationResolver/browser/configurationResolverService.ts b/src/vs/workbench/services/configurationResolver/browser/configurationResolverService.ts index 42b3431dc41..0343dc63dd8 100644 --- a/src/vs/workbench/services/configurationResolver/browser/configurationResolverService.ts +++ b/src/vs/workbench/services/configurationResolver/browser/configurationResolverService.ts @@ -44,7 +44,7 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR getWorkspaceFolderCount: (): number => { return workspaceContextService.getWorkspace().folders.length; }, - getConfigurationValue: (folderUri: uri, suffix: string): string | undefined => { + getConfigurationValue: (folderUri: uri | undefined, suffix: string): string | undefined => { return configurationService.getValue(suffix, folderUri ? { resource: folderUri } : {}); }, getExecPath: (): string | undefined => { diff --git a/src/vs/workbench/services/configurationResolver/common/variableResolver.ts b/src/vs/workbench/services/configurationResolver/common/variableResolver.ts index c29a083e759..1b832ff39d2 100644 --- a/src/vs/workbench/services/configurationResolver/common/variableResolver.ts +++ b/src/vs/workbench/services/configurationResolver/common/variableResolver.ts @@ -18,7 +18,7 @@ import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; export interface IVariableResolveContext { getFolderUri(folderName: string): uri | undefined; getWorkspaceFolderCount(): number; - getConfigurationValue(folderUri: uri, section: string): string | undefined; + getConfigurationValue(folderUri: uri | undefined, section: string): string | undefined; getExecPath(): string | undefined; getFilePath(): string | undefined; getSelectedText(): string | undefined; @@ -162,9 +162,9 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe }; // common error handling for all variables that require an open folder and accept a folder name argument - const getFolderUri = (withArg = true): uri => { + const getFolderUri = (): uri => { - if (withArg && argument) { + if (argument) { const folder = this._context.getFolderUri(argument); if (folder) { return folder; @@ -200,7 +200,7 @@ export class AbstractVariableResolverService implements IConfigurationResolverSe case 'config': if (argument) { - const config = this._context.getConfigurationValue(getFolderUri(false), argument); + const config = this._context.getConfigurationValue(folderUri, argument); if (types.isUndefinedOrNull(config)) { throw new Error(localize('configNotFound', "'{0}' can not be resolved because setting '{1}' not found.", match, argument)); } diff --git a/src/vs/workbench/services/configurationResolver/test/electron-browser/configurationResolverService.test.ts b/src/vs/workbench/services/configurationResolver/test/electron-browser/configurationResolverService.test.ts index 9d1f709f55c..f616e92e6ee 100644 --- a/src/vs/workbench/services/configurationResolver/test/electron-browser/configurationResolverService.test.ts +++ b/src/vs/workbench/services/configurationResolver/test/electron-browser/configurationResolverService.test.ts @@ -206,6 +206,17 @@ suite('Configuration Resolver Service', () => { assert.strictEqual(service.resolve(workspace, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz'); }); + test('substitute configuration variable with undefined workspace folder', () => { + let configurationService: IConfigurationService = new TestConfigurationService({ + editor: { + fontFamily: 'foo' + } + }); + + let service = new TestConfigurationResolverService({ getExecPath: () => undefined }, environmentService.userEnv, new TestEditorServiceWithActiveEditor(), configurationService, mockCommandService, new TestContextService(), quickInputService); + assert.strictEqual(service.resolve(undefined, 'abc ${config:editor.fontFamily} xyz'), 'abc foo xyz'); + }); + test('substitute many configuration variables', () => { let configurationService: IConfigurationService; configurationService = new TestConfigurationService({