Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/configurationResolver/common/configurationResolver.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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
86
WorkspaceFolder = 'workspaceFolder',
87
Cwd = 'cwd',
88
WorkspaceFolderBasename = 'workspaceFolderBasename',
89
UserHome = 'userHome',
90
LineNumber = 'lineNumber',
91
ColumnNumber = 'columnNumber',
92
SelectedText = 'selectedText',
93
File = 'file',
94
FileWorkspaceFolder = 'fileWorkspaceFolder',
95
FileWorkspaceFolderBasename = 'fileWorkspaceFolderBasename',
96
RelativeFile = 'relativeFile',
97
RelativeFileDirname = 'relativeFileDirname',
98
FileDirname = 'fileDirname',
99
FileExtname = 'fileExtname',
100
FileBasename = 'fileBasename',
101
FileBasenameNoExtension = 'fileBasenameNoExtension',
102
FileDirnameBasename = 'fileDirnameBasename',
103
ExecPath = 'execPath',
104
ExecInstallFolder = 'execInstallFolder',
105
PathSeparator = 'pathSeparator',
106
PathSeparatorAlias = '/'
107
}
108
109
export const allVariableKinds = Object.values(VariableKind).filter((value): value is VariableKind => typeof value === 'string');
110
111
export class VariableError extends ErrorNoTelemetry {
112
constructor(public readonly variable: VariableKind, message?: string) {
113
super(message);
114
}
115
}
116
117