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