提交 4a8dc15b 编写于 作者: A Alex Ross

Enable inputs in user tasks

Fixes #91660
上级 1f720ae4
...@@ -33,6 +33,7 @@ import { ...@@ -33,6 +33,7 @@ import {
RunOptionsDTO RunOptionsDTO
} from 'vs/workbench/api/common/shared/tasks'; } from 'vs/workbench/api/common/shared/tasks';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
namespace TaskExecutionDTO { namespace TaskExecutionDTO {
export function from(value: TaskExecution): TaskExecutionDTO { export function from(value: TaskExecution): TaskExecutionDTO {
...@@ -604,7 +605,7 @@ export class MainThreadTask implements MainThreadTaskShape { ...@@ -604,7 +605,7 @@ export class MainThreadTask implements MainThreadTaskShape {
return URI.parse(`${info.scheme}://${info.authority}${path}`); return URI.parse(`${info.scheme}://${info.authority}${path}`);
}, },
context: this._extHostContext, context: this._extHostContext,
resolveVariables: (workspaceFolder: IWorkspaceFolder, toResolve: ResolveSet): Promise<ResolvedVariables> => { resolveVariables: (workspaceFolder: IWorkspaceFolder, toResolve: ResolveSet, target: ConfigurationTarget): Promise<ResolvedVariables> => {
const vars: string[] = []; const vars: string[] = [];
toResolve.variables.forEach(item => vars.push(item)); toResolve.variables.forEach(item => vars.push(item));
return Promise.resolve(this._proxy.$resolveVariables(workspaceFolder.uri, { process: toResolve.process, variables: vars })).then(values => { return Promise.resolve(this._proxy.$resolveVariables(workspaceFolder.uri, { process: toResolve.process, variables: vars })).then(values => {
...@@ -613,7 +614,7 @@ export class MainThreadTask implements MainThreadTaskShape { ...@@ -613,7 +614,7 @@ export class MainThreadTask implements MainThreadTaskShape {
partiallyResolvedVars.push(entry.value); partiallyResolvedVars.push(entry.value);
}); });
return new Promise<ResolvedVariables>((resolve, reject) => { return new Promise<ResolvedVariables>((resolve, reject) => {
this._configurationResolverService.resolveWithInteraction(workspaceFolder, partiallyResolvedVars, 'tasks').then(resolvedVars => { this._configurationResolverService.resolveWithInteraction(workspaceFolder, partiallyResolvedVars, 'tasks', undefined, target).then(resolvedVars => {
const result: ResolvedVariables = { const result: ResolvedVariables = {
process: undefined, process: undefined,
variables: new Map<string, string>() variables: new Map<string, string>()
......
...@@ -33,7 +33,7 @@ import { IOutputService } from 'vs/workbench/contrib/output/common/output'; ...@@ -33,7 +33,7 @@ import { IOutputService } from 'vs/workbench/contrib/output/common/output';
import { StartStopProblemCollector, WatchingProblemCollector, ProblemCollectorEventKind, ProblemHandlingStrategy } from 'vs/workbench/contrib/tasks/common/problemCollectors'; import { StartStopProblemCollector, WatchingProblemCollector, ProblemCollectorEventKind, ProblemHandlingStrategy } from 'vs/workbench/contrib/tasks/common/problemCollectors';
import { import {
Task, CustomTask, ContributedTask, RevealKind, CommandOptions, ShellConfiguration, RuntimeType, PanelKind, Task, CustomTask, ContributedTask, RevealKind, CommandOptions, ShellConfiguration, RuntimeType, PanelKind,
TaskEvent, TaskEventKind, ShellQuotingOptions, ShellQuoting, CommandString, CommandConfiguration, ExtensionTaskSource, TaskScope, RevealProblemKind, DependsOrder TaskEvent, TaskEventKind, ShellQuotingOptions, ShellQuoting, CommandString, CommandConfiguration, ExtensionTaskSource, TaskScope, RevealProblemKind, DependsOrder, TaskSourceKind
} from 'vs/workbench/contrib/tasks/common/tasks'; } from 'vs/workbench/contrib/tasks/common/tasks';
import { import {
ITaskSystem, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, ITaskResolver, ITaskSystem, ITaskSummary, ITaskExecuteResult, TaskExecuteKind, TaskError, TaskErrors, ITaskResolver,
...@@ -545,7 +545,7 @@ export class TerminalTaskSystem implements ITaskSystem { ...@@ -545,7 +545,7 @@ export class TerminalTaskSystem implements ITaskSystem {
resolveSet.process.path = envPath; resolveSet.process.path = envPath;
} }
} }
resolvedVariables = taskSystemInfo.resolveVariables(workspaceFolder, resolveSet).then(async (resolved) => { resolvedVariables = taskSystemInfo.resolveVariables(workspaceFolder, resolveSet, TaskSourceKind.toConfigurationTarget(task._source.kind)).then(async (resolved) => {
this.mergeMaps(alreadyResolved, resolved.variables); this.mergeMaps(alreadyResolved, resolved.variables);
resolved.variables = new Map(alreadyResolved); resolved.variables = new Map(alreadyResolved);
if (isProcess) { if (isProcess) {
...@@ -563,7 +563,7 @@ export class TerminalTaskSystem implements ITaskSystem { ...@@ -563,7 +563,7 @@ export class TerminalTaskSystem implements ITaskSystem {
unresolved.forEach(variable => variablesArray.push(variable)); unresolved.forEach(variable => variablesArray.push(variable));
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.configurationResolverService.resolveWithInteraction(workspaceFolder, variablesArray, 'tasks').then(async (resolvedVariablesMap: Map<string, string> | undefined) => { this.configurationResolverService.resolveWithInteraction(workspaceFolder, variablesArray, 'tasks', undefined, TaskSourceKind.toConfigurationTarget(task._source.kind)).then(async (resolvedVariablesMap: Map<string, string> | undefined) => {
if (resolvedVariablesMap) { if (resolvedVariablesMap) {
this.mergeMaps(alreadyResolved, resolvedVariablesMap); this.mergeMaps(alreadyResolved, resolvedVariablesMap);
resolvedVariablesMap = new Map(alreadyResolved); resolvedVariablesMap = new Map(alreadyResolved);
......
...@@ -10,6 +10,7 @@ import { Event } from 'vs/base/common/event'; ...@@ -10,6 +10,7 @@ import { Event } from 'vs/base/common/event';
import { Platform } from 'vs/base/common/platform'; import { Platform } from 'vs/base/common/platform';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { Task, TaskEvent, KeyedTaskIdentifier } from './tasks'; import { Task, TaskEvent, KeyedTaskIdentifier } from './tasks';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
export const enum TaskErrors { export const enum TaskErrors {
NotConfigured, NotConfigured,
...@@ -118,7 +119,7 @@ export interface TaskSystemInfo { ...@@ -118,7 +119,7 @@ export interface TaskSystemInfo {
platform: Platform; platform: Platform;
context: any; context: any;
uriProvider: (this: void, path: string) => URI; uriProvider: (this: void, path: string) => URI;
resolveVariables(workspaceFolder: IWorkspaceFolder, toResolve: ResolveSet): Promise<ResolvedVariables>; resolveVariables(workspaceFolder: IWorkspaceFolder, toResolve: ResolveSet, target: ConfigurationTarget): Promise<ResolvedVariables>;
getDefaultShellAndArgs(): Promise<{ shell: string, args: string[] | string | undefined }>; getDefaultShellAndArgs(): Promise<{ shell: string, args: string[] | string | undefined }>;
} }
......
...@@ -15,6 +15,7 @@ import { IWorkspaceFolder, IWorkspace } from 'vs/platform/workspace/common/works ...@@ -15,6 +15,7 @@ import { IWorkspaceFolder, IWorkspace } from 'vs/platform/workspace/common/works
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry'; import { TaskDefinitionRegistry } from 'vs/workbench/contrib/tasks/common/taskDefinitionRegistry';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
export const TASK_RUNNING_STATE = new RawContextKey<boolean>('taskRunning', false); export const TASK_RUNNING_STATE = new RawContextKey<boolean>('taskRunning', false);
...@@ -377,6 +378,14 @@ export namespace TaskSourceKind { ...@@ -377,6 +378,14 @@ export namespace TaskSourceKind {
export const InMemory: 'inMemory' = 'inMemory'; export const InMemory: 'inMemory' = 'inMemory';
export const WorkspaceFile: 'workspaceFile' = 'workspaceFile'; export const WorkspaceFile: 'workspaceFile' = 'workspaceFile';
export const User: 'user' = 'user'; export const User: 'user' = 'user';
export function toConfigurationTarget(kind: string): ConfigurationTarget {
switch (kind) {
case TaskSourceKind.User: return ConfigurationTarget.USER;
case TaskSourceKind.WorkspaceFile: return ConfigurationTarget.WORKSPACE;
default: return ConfigurationTarget.WORKSPACE_FOLDER;
}
}
} }
export interface TaskSourceConfigElement { export interface TaskSourceConfigElement {
......
...@@ -11,7 +11,7 @@ import { Schemas } from 'vs/base/common/network'; ...@@ -11,7 +11,7 @@ import { Schemas } from 'vs/base/common/network';
import { toResource } from 'vs/workbench/common/editor'; import { toResource } from 'vs/workbench/common/editor';
import { IStringDictionary, forEach, fromMap } from 'vs/base/common/collections'; import { IStringDictionary, forEach, fromMap } from 'vs/base/common/collections';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkspaceFolder, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder, IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
...@@ -86,12 +86,12 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR ...@@ -86,12 +86,12 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
}, envVariables); }, envVariables);
} }
public async resolveWithInteractionReplace(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>): Promise<any> { public 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 // resolve any non-interactive variables and any contributed variables
config = this.resolveAny(folder, config); config = this.resolveAny(folder, config);
// resolve input variables in the order in which they are encountered // resolve input variables in the order in which they are encountered
return this.resolveWithInteraction(folder, config, section, variables).then(mapping => { return this.resolveWithInteraction(folder, config, section, variables, target).then(mapping => {
// finally substitute evaluated command variables (if there are any) // finally substitute evaluated command variables (if there are any)
if (!mapping) { if (!mapping) {
return null; return null;
...@@ -103,14 +103,14 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR ...@@ -103,14 +103,14 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
}); });
} }
public async resolveWithInteraction(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>): Promise<Map<string, string> | undefined> { public async resolveWithInteraction(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<Map<string, string> | undefined> {
// resolve any non-interactive variables and any contributed variables // resolve any non-interactive variables and any contributed variables
const resolved = await this.resolveAnyMap(folder, config); const resolved = await this.resolveAnyMap(folder, config);
config = resolved.newConfig; config = resolved.newConfig;
const allVariableMapping: Map<string, string> = resolved.resolvedVariables; const allVariableMapping: Map<string, string> = resolved.resolvedVariables;
// resolve input and command variables in the order in which they are encountered // resolve input and command variables in the order in which they are encountered
return this.resolveWithInputAndCommands(folder, config, variables, section).then(inputOrCommandMapping => { return this.resolveWithInputAndCommands(folder, config, variables, section, target).then(inputOrCommandMapping => {
if (this.updateMapping(inputOrCommandMapping, allVariableMapping)) { if (this.updateMapping(inputOrCommandMapping, allVariableMapping)) {
return allVariableMapping; return allVariableMapping;
} }
...@@ -139,7 +139,7 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR ...@@ -139,7 +139,7 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
* *
* @param variableToCommandMap Aliases for commands * @param variableToCommandMap Aliases for commands
*/ */
private async resolveWithInputAndCommands(folder: IWorkspaceFolder | undefined, configuration: any, variableToCommandMap?: IStringDictionary<string>, section?: string): Promise<IStringDictionary<string> | undefined> { private async resolveWithInputAndCommands(folder: IWorkspaceFolder | undefined, configuration: any, variableToCommandMap?: IStringDictionary<string>, section?: string, target?: ConfigurationTarget): Promise<IStringDictionary<string> | undefined> {
if (!configuration) { if (!configuration) {
return Promise.resolve(undefined); return Promise.resolve(undefined);
...@@ -148,9 +148,13 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR ...@@ -148,9 +148,13 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
// get all "inputs" // get all "inputs"
let inputs: ConfiguredInput[] = []; let inputs: ConfiguredInput[] = [];
if (folder && this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY && section) { if (folder && this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY && section) {
let result = this.configurationService.getValue<any>(section, { resource: folder.uri }); let result = this.configurationService.inspect(section, { resource: folder.uri });
if (result) { if (result) {
inputs = result.inputs; switch (target) {
case ConfigurationTarget.USER: inputs = (<any>result.userValue)?.inputs; break;
case ConfigurationTarget.WORKSPACE: inputs = (<any>result.workspaceValue)?.inputs; break;
default: inputs = (<any>result.workspaceFolderValue)?.inputs;
}
} }
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import { IStringDictionary } from 'vs/base/common/collections'; import { IStringDictionary } from 'vs/base/common/collections';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
export const IConfigurationResolverService = createDecorator<IConfigurationResolverService>('configurationResolverService'); export const IConfigurationResolverService = createDecorator<IConfigurationResolverService>('configurationResolverService');
...@@ -29,13 +30,13 @@ export interface IConfigurationResolverService { ...@@ -29,13 +30,13 @@ export interface IConfigurationResolverService {
* @param section For example, 'tasks' or 'debug'. Used for resolving inputs. * @param section For example, 'tasks' or 'debug'. Used for resolving inputs.
* @param variables Aliases for commands. * @param variables Aliases for commands.
*/ */
resolveWithInteractionReplace(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>): Promise<any>; resolveWithInteractionReplace(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<any>;
/** /**
* Similar to resolveWithInteractionReplace, except without the replace. Returns a map of variables and their resolution. * Similar to resolveWithInteractionReplace, except without the replace. Returns a map of variables and their resolution.
* Keys in the map will be of the format input:variableName or command:variableName. * Keys in the map will be of the format input:variableName or command:variableName.
*/ */
resolveWithInteraction(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>): Promise<Map<string, string> | undefined>; resolveWithInteraction(folder: IWorkspaceFolder | undefined, config: any, section?: string, variables?: IStringDictionary<string>, target?: ConfigurationTarget): Promise<Map<string, string> | undefined>;
/** /**
* Contributes a variable that can be resolved later. Consumers that use resolveAny, resolveWithInteraction, * Contributes a variable that can be resolved later. Consumers that use resolveAny, resolveWithInteraction,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册