未验证 提交 ab89935f 编写于 作者: A Alex Ross 提交者: GitHub

First pass at resolving task definition and passing back to custom execution (#83764)

First pass at resolving task definition and passing back to custom execution. It only currently resolves simple predefined variables, no input, command, or defaultBuildTask.

Part of #81007
上级 ebe8e1e1
...@@ -811,6 +811,18 @@ declare module 'vscode' { ...@@ -811,6 +811,18 @@ declare module 'vscode' {
detail?: string; detail?: string;
} }
export class CustomExecution2 extends CustomExecution {
/**
* Constructs a CustomExecution task object. The callback will be executed the task is run, at which point the
* extension should return the Pseudoterminal it will "run in". The task should wait to do further execution until
* [Pseudoterminal.open](#Pseudoterminal.open) is called. Task cancellation should be handled using
* [Pseudoterminal.close](#Pseudoterminal.close). When the task is complete fire
* [Pseudoterminal.onDidClose](#Pseudoterminal.onDidClose).
* @param callback The callback that will be called when the task is started by a user.
*/
constructor(callback: (resolvedDefinition?: TaskDefinition) => Thenable<Pseudoterminal>);
}
export interface TaskPresentationOptions { export interface TaskPresentationOptions {
/** /**
* Controls whether the task is executed in a specific terminal group using split panes. * Controls whether the task is executed in a specific terminal group using split panes.
......
...@@ -865,6 +865,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I ...@@ -865,6 +865,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
EventEmitter: Emitter, EventEmitter: Emitter,
ExtensionKind: extHostTypes.ExtensionKind, ExtensionKind: extHostTypes.ExtensionKind,
CustomExecution: extHostTypes.CustomExecution, CustomExecution: extHostTypes.CustomExecution,
CustomExecution2: extHostTypes.CustomExecution,
FileChangeType: extHostTypes.FileChangeType, FileChangeType: extHostTypes.FileChangeType,
FileSystemError: extHostTypes.FileSystemError, FileSystemError: extHostTypes.FileSystemError,
FileType: files.FileType, FileType: files.FileType,
......
...@@ -457,6 +457,10 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { ...@@ -457,6 +457,10 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape {
return this._onDidExecuteTask.event; return this._onDidExecuteTask.event;
} }
protected async resolveDefinition(uri: number | UriComponents | undefined, definition: vscode.TaskDefinition | undefined): Promise<vscode.TaskDefinition | undefined> {
return definition;
}
public async $onDidStartTask(execution: tasks.TaskExecutionDTO, terminalId: number): Promise<void> { public async $onDidStartTask(execution: tasks.TaskExecutionDTO, terminalId: number): Promise<void> {
const customExecution: types.CustomExecution | undefined = this._providedCustomExecutions2.get(execution.id); const customExecution: types.CustomExecution | undefined = this._providedCustomExecutions2.get(execution.id);
if (customExecution) { if (customExecution) {
...@@ -466,7 +470,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape { ...@@ -466,7 +470,7 @@ export abstract class ExtHostTaskBase implements ExtHostTaskShape {
// Clone the custom execution to keep the original untouched. This is important for multiple runs of the same task. // Clone the custom execution to keep the original untouched. This is important for multiple runs of the same task.
this._activeCustomExecutions2.set(execution.id, customExecution); this._activeCustomExecutions2.set(execution.id, customExecution);
this._terminalService.attachPtyToTerminal(terminalId, await customExecution.callback()); this._terminalService.attachPtyToTerminal(terminalId, await customExecution.callback(await this.resolveDefinition(execution.task?.source.scope, execution.task?.definition)));
} }
this._lastStartedTask = execution.id; this._lastStartedTask = execution.id;
......
...@@ -1777,20 +1777,20 @@ export enum TaskScope { ...@@ -1777,20 +1777,20 @@ export enum TaskScope {
Workspace = 2 Workspace = 2
} }
export class CustomExecution implements vscode.CustomExecution { export class CustomExecution implements vscode.CustomExecution2 {
private _callback: () => Thenable<vscode.Pseudoterminal>; private _callback: (resolvedDefintion?: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>;
constructor(callback: () => Thenable<vscode.Pseudoterminal>) { constructor(callback: (resolvedDefintion?: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
this._callback = callback; this._callback = callback;
} }
public computeId(): string { public computeId(): string {
return 'customExecution' + generateUuid(); return 'customExecution' + generateUuid();
} }
public set callback(value: () => Thenable<vscode.Pseudoterminal>) { public set callback(value: (resolvedDefintion?: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
this._callback = value; this._callback = value;
} }
public get callback(): (() => Thenable<vscode.Pseudoterminal>) { public get callback(): ((resolvedDefintion?: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal>) {
return this._callback; return this._callback;
} }
} }
......
...@@ -11,6 +11,7 @@ import * as types from 'vs/workbench/api/common/extHostTypes'; ...@@ -11,6 +11,7 @@ import * as types from 'vs/workbench/api/common/extHostTypes';
import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace'; import { IExtHostWorkspace } from 'vs/workbench/api/common/extHostWorkspace';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as tasks from '../common/shared/tasks'; import * as tasks from '../common/shared/tasks';
import * as Objects from 'vs/base/common/objects';
import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService'; import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService';
import { IExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors'; import { IExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration'; import { IExtHostConfiguration } from 'vs/workbench/api/common/extHostConfiguration';
...@@ -23,6 +24,7 @@ import { ExtHostTaskBase, TaskHandleDTO, TaskDTO, CustomExecutionDTO, HandlerDat ...@@ -23,6 +24,7 @@ import { ExtHostTaskBase, TaskHandleDTO, TaskDTO, CustomExecutionDTO, HandlerDat
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
export class ExtHostTask extends ExtHostTaskBase { export class ExtHostTask extends ExtHostTaskBase {
private _variableResolver: ExtHostVariableResolverService | undefined;
constructor( constructor(
@IExtHostRpcService extHostRpc: IExtHostRpcService, @IExtHostRpcService extHostRpc: IExtHostRpcService,
...@@ -95,8 +97,41 @@ export class ExtHostTask extends ExtHostTaskBase { ...@@ -95,8 +97,41 @@ export class ExtHostTask extends ExtHostTaskBase {
return resolvedTaskDTO; return resolvedTaskDTO;
} }
public async $resolveVariables(uriComponents: UriComponents, toResolve: { process?: { name: string; cwd?: string; path?: string }, variables: string[] }): Promise<{ process?: string, variables: { [key: string]: string; } }> { private async getVariableResolver(workspaceFolders: vscode.WorkspaceFolder[]): Promise<ExtHostVariableResolverService> {
if (this._variableResolver === undefined) {
const configProvider = await this._configurationService.getConfigProvider(); const configProvider = await this._configurationService.getConfigProvider();
this._variableResolver = new ExtHostVariableResolverService(workspaceFolders, this._editorService, configProvider);
}
return this._variableResolver;
}
protected async resolveDefinition(uri: number | UriComponents | undefined, definition: vscode.TaskDefinition | undefined): Promise<vscode.TaskDefinition | undefined> {
if (!uri || (typeof uri === 'number') || !definition) {
return definition;
}
const workspaceFolder = await this._workspaceProvider.resolveWorkspaceFolder(URI.revive(uri));
const workspaceFolders = await this._workspaceProvider.getWorkspaceFolders2();
if (!workspaceFolders || !workspaceFolder) {
return definition;
}
const resolver = await this.getVariableResolver(workspaceFolders);
const ws: IWorkspaceFolder = {
uri: workspaceFolder.uri,
name: workspaceFolder.name,
index: workspaceFolder.index,
toResource: () => {
throw new Error('Not implemented');
}
};
const resolvedDefinition = Objects.deepClone(definition);
for (const key in resolvedDefinition) {
resolvedDefinition[key] = resolver.resolve(ws, resolvedDefinition[key]);
}
return resolvedDefinition;
}
public async $resolveVariables(uriComponents: UriComponents, toResolve: { process?: { name: string; cwd?: string; path?: string }, variables: string[] }): Promise<{ process?: string, variables: { [key: string]: string; } }> {
const uri: URI = URI.revive(uriComponents); const uri: URI = URI.revive(uriComponents);
const result = { const result = {
process: <unknown>undefined as string, process: <unknown>undefined as string,
...@@ -107,7 +142,7 @@ export class ExtHostTask extends ExtHostTaskBase { ...@@ -107,7 +142,7 @@ export class ExtHostTask extends ExtHostTaskBase {
if (!workspaceFolders || !workspaceFolder) { if (!workspaceFolders || !workspaceFolder) {
throw new Error('Unexpected: Tasks can only be run in a workspace folder'); throw new Error('Unexpected: Tasks can only be run in a workspace folder');
} }
const resolver = new ExtHostVariableResolverService(workspaceFolders, this._editorService, configProvider); const resolver = await this.getVariableResolver(workspaceFolders);
const ws: IWorkspaceFolder = { const ws: IWorkspaceFolder = {
uri: workspaceFolder.uri, uri: workspaceFolder.uri,
name: workspaceFolder.name, name: workspaceFolder.name,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册