Path: blob/main/src/vs/workbench/services/configurationResolver/common/configurationResolver.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IStringDictionary } from '../../../../base/common/collections.js';6import { ErrorNoTelemetry } from '../../../../base/common/errors.js';7import { IProcessEnvironment } from '../../../../base/common/platform.js';8import { ConfigurationTarget } from '../../../../platform/configuration/common/configuration.js';9import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';10import { IWorkspaceFolderData } from '../../../../platform/workspace/common/workspace.js';11import { ConfigurationResolverExpression } from './configurationResolverExpression.js';1213export const IConfigurationResolverService = createDecorator<IConfigurationResolverService>('configurationResolverService');1415export interface IConfigurationResolverService {16readonly _serviceBrand: undefined;1718/** Variables the resolver is able to resolve. */19readonly resolvableVariables: ReadonlySet<string>;2021resolveWithEnvironment(environment: IProcessEnvironment, folder: IWorkspaceFolderData | undefined, value: string): Promise<string>;2223/**24* Recursively resolves all variables in the given config and returns a copy of it with substituted values.25* Command variables are only substituted if a "commandValueMapping" dictionary is given and if it contains an entry for the command.26*/27resolveAsync<T>(folder: IWorkspaceFolderData | undefined, config: T): Promise<T extends ConfigurationResolverExpression<infer R> ? R : T>;2829/**30* Recursively resolves all variables (including commands and user input) in the given config and returns a copy of it with substituted values.31* If a "variables" dictionary (with names -> command ids) is given, command variables are first mapped through it before being resolved.32*33* @param section For example, 'tasks' or 'debug'. Used for resolving inputs.34* @param variables Aliases for commands.35*/36resolveWithInteractionReplace(folder: IWorkspaceFolderData | undefined, config: unknown, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<any>;3738/**39* Similar to resolveWithInteractionReplace, except without the replace. Returns a map of variables and their resolution.40* Keys in the map will be of the format input:variableName or command:variableName.41*/42resolveWithInteraction(folder: IWorkspaceFolderData | undefined, config: unknown, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<Map<string, string> | undefined>;4344/**45* Contributes a variable that can be resolved later. Consumers that use resolveAny, resolveWithInteraction,46* and resolveWithInteractionReplace will have contributed variables resolved.47*/48contributeVariable(variable: string, resolution: () => Promise<string | undefined>): void;49}5051interface PromptStringInputInfo {52id: string;53type: 'promptString';54description: string;55default?: string;56password?: boolean;57}5859interface PickStringInputInfo {60id: string;61type: 'pickString';62description: string;63options: (string | { value: string; label?: string })[];64default?: string;65}6667interface CommandInputInfo {68id: string;69type: 'command';70command: string;71args?: any;72}7374export type ConfiguredInput = PromptStringInputInfo | PickStringInputInfo | CommandInputInfo;7576export enum VariableKind {77Unknown = 'unknown',7879Env = 'env',80Config = 'config',81Command = 'command',82Input = 'input',83ExtensionInstallFolder = 'extensionInstallFolder',8485WorkspaceFolder = 'workspaceFolder',86Cwd = 'cwd',87WorkspaceFolderBasename = 'workspaceFolderBasename',88UserHome = 'userHome',89LineNumber = 'lineNumber',90ColumnNumber = 'columnNumber',91SelectedText = 'selectedText',92File = 'file',93FileWorkspaceFolder = 'fileWorkspaceFolder',94FileWorkspaceFolderBasename = 'fileWorkspaceFolderBasename',95RelativeFile = 'relativeFile',96RelativeFileDirname = 'relativeFileDirname',97FileDirname = 'fileDirname',98FileExtname = 'fileExtname',99FileBasename = 'fileBasename',100FileBasenameNoExtension = 'fileBasenameNoExtension',101FileDirnameBasename = 'fileDirnameBasename',102ExecPath = 'execPath',103ExecInstallFolder = 'execInstallFolder',104PathSeparator = 'pathSeparator',105PathSeparatorAlias = '/'106}107108export const allVariableKinds = Object.values(VariableKind).filter((value): value is VariableKind => typeof value === 'string');109110export class VariableError extends ErrorNoTelemetry {111constructor(public readonly variable: VariableKind, message?: string) {112super(message);113}114}115116117