Implement new extension callback execution for a task and create a terminal for it

This commit is contained in:
Gabriel DeBacker
2019-01-16 07:22:11 -08:00
parent 957f536a66
commit c73695ab2d
10 changed files with 185 additions and 27 deletions

View File

@@ -765,6 +765,7 @@ export function createApiFactory(
DocumentSymbol: extHostTypes.DocumentSymbol,
EndOfLine: extHostTypes.EndOfLine,
EventEmitter: Emitter,
ExtensionCallbackExecution: extHostTypes.ExtensionCallbackExecution,
FileChangeType: extHostTypes.FileChangeType,
FileSystemError: extHostTypes.FileSystemError,
FileType: files.FileType,

View File

@@ -19,8 +19,11 @@ import * as types from 'vs/workbench/api/node/extHostTypes';
import { ExtHostWorkspace } from 'vs/workbench/api/node/extHostWorkspace';
import * as vscode from 'vscode';
import {
TaskDefinitionDTO, TaskExecutionDTO, TaskPresentationOptionsDTO, ProcessExecutionOptionsDTO, ProcessExecutionDTO,
ShellExecutionOptionsDTO, ShellExecutionDTO, TaskDTO, TaskHandleDTO, TaskFilterDTO, TaskProcessStartedDTO, TaskProcessEndedDTO, TaskSystemInfoDTO, TaskSetDTO
TaskDefinitionDTO, TaskExecutionDTO, TaskPresentationOptionsDTO,
ProcessExecutionOptionsDTO, ProcessExecutionDTO,
ShellExecutionOptionsDTO, ShellExecutionDTO,
CallbackExecutionDTO,
TaskDTO, TaskHandleDTO, TaskFilterDTO, TaskProcessStartedDTO, TaskProcessEndedDTO, TaskSystemInfoDTO, TaskSetDTO
} from '../shared/tasks';
import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors';
@@ -74,7 +77,7 @@ namespace ProcessExecutionOptionsDTO {
}
namespace ProcessExecutionDTO {
export function is(value: ShellExecutionDTO | ProcessExecutionDTO): value is ProcessExecutionDTO {
export function is(value: ShellExecutionDTO | ProcessExecutionDTO | CallbackExecutionDTO): value is ProcessExecutionDTO {
let candidate = value as ProcessExecutionDTO;
return candidate && !!candidate.process;
}
@@ -115,7 +118,7 @@ namespace ShellExecutionOptionsDTO {
}
namespace ShellExecutionDTO {
export function is(value: ShellExecutionDTO | ProcessExecutionDTO): value is ShellExecutionDTO {
export function is(value: ShellExecutionDTO | ProcessExecutionDTO | CallbackExecutionDTO): value is ShellExecutionDTO {
let candidate = value as ShellExecutionDTO;
return candidate && (!!candidate.commandLine || !!candidate.command);
}
@@ -148,6 +151,19 @@ namespace ShellExecutionDTO {
}
}
namespace CallbackExecutionDTO {
export function is(value: ShellExecutionDTO | ProcessExecutionDTO | CallbackExecutionDTO): value is CallbackExecutionDTO {
let candidate = value as CallbackExecutionDTO;
return candidate && candidate.extensionCallback === 'extensionCallback';
}
export function from(value: vscode.ExtensionCallbackExecution): CallbackExecutionDTO {
return {
extensionCallback: 'extensionCallback'
};
}
}
namespace TaskHandleDTO {
export function from(value: types.Task): TaskHandleDTO {
let folder: UriComponents;
@@ -181,12 +197,15 @@ namespace TaskDTO {
if (value === undefined || value === null) {
return undefined;
}
let execution: ShellExecutionDTO | ProcessExecutionDTO;
let execution: ShellExecutionDTO | ProcessExecutionDTO | CallbackExecutionDTO;
if (value.execution instanceof types.ProcessExecution) {
execution = ProcessExecutionDTO.from(value.execution);
} else if (value.execution instanceof types.ShellExecution) {
execution = ShellExecutionDTO.from(value.execution);
} else if (value.execution instanceof types.ExtensionCallbackExecution) {
execution = CallbackExecutionDTO.from(value.execution);
}
let definition: TaskDefinitionDTO = TaskDefinitionDTO.from(value.definition);
let scope: number | UriComponents;
if (value.scope) {

View File

@@ -1621,8 +1621,34 @@ export enum TaskScope {
Workspace = 2
}
export class ExtensionCallbackExecution implements vscode.ExtensionCallbackExecution {
private _callback: (args: vscode.ExtensionCallbackExecutionArgs, cancellationToken: vscode.CancellationToken) => Thenable<void>;
constructor(callback: (args: vscode.ExtensionCallbackExecutionArgs, cancellationToken: vscode.CancellationToken) => Thenable<void>) {
this._callback = callback;
}
public computeId(): string {
const hash = crypto.createHash('md5');
hash.update('extensionCallback');
// TODO: How is this ID used. Not sure how to create a valid ID from a function.
// TODO: Also not clear on how the ID is used
hash.update(generateUuid());
return hash.digest('hex');
}
public set callback(value: (args: vscode.ExtensionCallbackExecutionArgs, cancellationToken: vscode.CancellationToken) => Thenable<void>) {
this._callback = value;
}
public get callback(): (args: vscode.ExtensionCallbackExecutionArgs, cancellationToken: vscode.CancellationToken) => Thenable<void> {
return this._callback;
}
}
export class Task implements vscode.Task {
private static ExtensionCallbackType: string = 'extensionCallback';
private static ProcessType: string = 'process';
private static ShellType: string = 'shell';
private static EmptyType: string = '$empty';
@@ -1632,7 +1658,7 @@ export class Task implements vscode.Task {
private _definition: vscode.TaskDefinition;
private _scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder | undefined;
private _name: string;
private _execution: ProcessExecution | ShellExecution | undefined;
private _execution: ProcessExecution | ShellExecution | ExtensionCallbackExecution | undefined;
private _problemMatchers: string[];
private _hasDefinedMatchers: boolean;
private _isBackground: boolean;
@@ -1641,8 +1667,8 @@ export class Task implements vscode.Task {
private _presentationOptions: vscode.TaskPresentationOptions;
private _runOptions: vscode.RunOptions;
constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution | ExtensionCallbackExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, scope: vscode.TaskScope.Global | vscode.TaskScope.Workspace | vscode.WorkspaceFolder, name: string, source: string, execution?: ProcessExecution | ShellExecution | ExtensionCallbackExecution, problemMatchers?: string | string[]);
constructor(definition: vscode.TaskDefinition, arg2: string | (vscode.TaskScope.Global | vscode.TaskScope.Workspace) | vscode.WorkspaceFolder, arg3: any, arg4?: any, arg5?: any, arg6?: any) {
this.definition = definition;
let problemMatchers: string | string[];
@@ -1707,6 +1733,11 @@ export class Task implements vscode.Task {
type: Task.ShellType,
id: this._execution.computeId()
};
} else if (this._execution instanceof ExtensionScriptApis) {
this._definition = {
type: Task.ExtensionCallbackType,
id: this._execution.computeId()
};
} else {
this._definition = {
type: Task.EmptyType,
@@ -1748,11 +1779,11 @@ export class Task implements vscode.Task {
this._name = value;
}
get execution(): ProcessExecution | ShellExecution | undefined {
get execution(): ProcessExecution | ShellExecution | ExtensionCallbackExecution | undefined {
return this._execution;
}
set execution(value: ProcessExecution | ShellExecution | undefined) {
set execution(value: ProcessExecution | ShellExecution | ExtensionCallbackExecution | undefined) {
if (value === null) {
value = undefined;
}