提交 d2e8c846 编写于 作者: G Gabriel DeBacker

Cleanup round one

上级 db7766c4
......@@ -30,9 +30,8 @@ import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostC
import { ExtHostContext, MainThreadTaskShape, ExtHostTaskShape, MainContext, IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import {
TaskDefinitionDTO, TaskExecutionDTO, ProcessExecutionOptionsDTO, TaskPresentationOptionsDTO,
ProcessExecutionDTO, ShellExecutionDTO, ShellExecutionOptionsDTO, TaskDTO, TaskSourceDTO, TaskHandleDTO, TaskFilterDTO, TaskProcessStartedDTO, TaskProcessEndedDTO, TaskSystemInfoDTO,
RunOptionsDTO,
CustomTaskExecutionDTO
ProcessExecutionDTO, ShellExecutionDTO, ShellExecutionOptionsDTO, CustomTaskExecutionDTO, TaskDTO, TaskSourceDTO, TaskHandleDTO, TaskFilterDTO, TaskProcessStartedDTO, TaskProcessEndedDTO, TaskSystemInfoDTO,
RunOptionsDTO
} from 'vs/workbench/api/shared/tasks';
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
......@@ -252,7 +251,7 @@ namespace CustomTaskExecutionDTO {
export function to(value: CustomTaskExecutionDTO): CommandConfiguration {
return {
runtime: RuntimeType.ExtensionCallback,
runtime: RuntimeType.CustomTaskExecution,
presentation: undefined
};
}
......@@ -519,12 +518,12 @@ export class MainThreadTask implements MainThreadTaskShape {
});
}
public $extensionCallbackTaskComplete(id: string): Promise<void> {
public $customTaskExecutionComplete(id: string, result: number | undefined): Promise<void> {
return new Promise<void>((resolve, reject) => {
this._taskService.getActiveTasks().then((tasks) => {
for (let task of tasks) {
if (id === task._id) {
this._taskService.extensionCallbackTaskComplete(task).then((value) => {
this._taskService.extensionCallbackTaskComplete(task, result).then((value) => {
resolve(undefined);
}, (error) => {
reject(error);
......
......@@ -196,10 +196,10 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
private _onTerminalOpened(terminalInstance: ITerminalInstance): void {
if (terminalInstance.title) {
this._proxy.$acceptTerminalOpened(terminalInstance.id, terminalInstance.title, terminalInstance.shellLaunchConfig.isRendererOnly, terminalInstance.cols, terminalInstance.rows);
this._proxy.$acceptTerminalOpened(terminalInstance.id, terminalInstance.title, !!terminalInstance.shellLaunchConfig.isRendererOnly, terminalInstance.cols, terminalInstance.rows);
} else {
terminalInstance.waitForTitle().then(title => {
this._proxy.$acceptTerminalOpened(terminalInstance.id, title, terminalInstance.shellLaunchConfig.isRendererOnly, terminalInstance.cols, terminalInstance.rows);
this._proxy.$acceptTerminalOpened(terminalInstance.id, title, !!terminalInstance.shellLaunchConfig.isRendererOnly, terminalInstance.cols, terminalInstance.rows);
});
}
}
......
......@@ -548,7 +548,7 @@ export interface MainThreadTaskShape extends IDisposable {
$executeTask(task: TaskHandleDTO | TaskDTO): Promise<TaskExecutionDTO>;
$terminateTask(id: string): Promise<void>;
$registerTaskSystem(scheme: string, info: TaskSystemInfoDTO): void;
$extensionCallbackTaskComplete(id: string): Promise<void>;
$customTaskExecutionComplete(id: string, result: number | undefined): Promise<void>;
}
export interface MainThreadExtensionServiceShape extends IDisposable {
......
......@@ -336,12 +336,13 @@ interface HandlerData {
extension: IExtensionDescription;
}
class ExtensionCallbackExecutionData implements IDisposable {
class CustomTaskExecutionData implements IDisposable {
private _cancellationSource?: CancellationTokenSource;
private readonly _onTaskExecutionComplete: Emitter<ExtensionCallbackExecutionData> = new Emitter<ExtensionCallbackExecutionData>();
private readonly _onTaskExecutionComplete: Emitter<CustomTaskExecutionData> = new Emitter<CustomTaskExecutionData>();
private readonly _disposables: IDisposable[] = [];
private terminal?: vscode.Terminal;
private terminalId?: number;
public result: number | undefined;
constructor(
private readonly callbackData: vscode.CustomTaskExecution,
......@@ -352,7 +353,7 @@ class ExtensionCallbackExecutionData implements IDisposable {
dispose(this._disposables);
}
public get onTaskExecutionComplete(): Event<ExtensionCallbackExecutionData> {
public get onTaskExecutionComplete(): Event<CustomTaskExecutionData> {
return this._onTaskExecutionComplete.event;
}
......@@ -405,6 +406,7 @@ class ExtensionCallbackExecutionData implements IDisposable {
// Regardless of how the task completes, we are done with this extension callback task execution.
this.callbackData.callback(terminalRenderer, this._cancellationSource.token).then(
(success) => {
this.result = success;
this._onTaskExecutionComplete.fire(this);
}, (rejected) => {
this._onTaskExecutionComplete.fire(this);
......@@ -422,8 +424,8 @@ export class ExtHostTask implements ExtHostTaskShape {
private _handleCounter: number;
private _handlers: Map<number, HandlerData>;
private _taskExecutions: Map<string, TaskExecutionImpl>;
private _providedExtensionCallbacks: Map<string, ExtensionCallbackExecutionData>;
private _activeExtensionCallbacks: Map<string, ExtensionCallbackExecutionData>;
private _providedCustomTaskExecutions: Map<string, CustomTaskExecutionData>;
private _activeCustomTaskExecutions: Map<string, CustomTaskExecutionData>;
private readonly _onDidExecuteTask: Emitter<vscode.TaskStartEvent> = new Emitter<vscode.TaskStartEvent>();
private readonly _onDidTerminateTask: Emitter<vscode.TaskEndEvent> = new Emitter<vscode.TaskEndEvent>();
......@@ -445,8 +447,8 @@ export class ExtHostTask implements ExtHostTaskShape {
this._handleCounter = 0;
this._handlers = new Map<number, HandlerData>();
this._taskExecutions = new Map<string, TaskExecutionImpl>();
this._providedExtensionCallbacks = new Map<string, ExtensionCallbackExecutionData>();
this._activeExtensionCallbacks = new Map<string, ExtensionCallbackExecutionData>();
this._providedCustomTaskExecutions = new Map<string, CustomTaskExecutionData>();
this._activeCustomTaskExecutions = new Map<string, CustomTaskExecutionData>();
}
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable {
......@@ -517,15 +519,16 @@ export class ExtHostTask implements ExtHostTaskShape {
// this event will be fired.
// At that point, we need to actually start the callback, but
// only if it hasn't already begun.
const extensionCallback: ExtensionCallbackExecutionData | undefined = this._providedExtensionCallbacks.get(execution.id);
const extensionCallback: CustomTaskExecutionData | undefined = this._providedCustomTaskExecutions.get(execution.id);
if (extensionCallback) {
// TODO: Verify whether this can ever happen???
if (this._activeExtensionCallbacks.get(execution.id) === undefined) {
this._activeExtensionCallbacks.set(execution.id, extensionCallback);
if (this._activeCustomTaskExecutions.get(execution.id) !== undefined) {
throw new Error('We should not be trying to start the same custom task executions twice.');
}
this._activeCustomTaskExecutions.set(execution.id, extensionCallback);
const taskExecutionComplete: IDisposable = extensionCallback.onTaskExecutionComplete(() => {
this.extensionCallbackTaskComplete(execution);
this.customTaskExecutionComplete(execution);
taskExecutionComplete.dispose();
});
......@@ -546,7 +549,7 @@ export class ExtHostTask implements ExtHostTaskShape {
const workspaceProvider = await this._workspaceService.getWorkspaceProvider();
const _execution = this.getTaskExecution(execution, workspaceProvider);
this._taskExecutions.delete(execution.id);
this.extensionCallbackTaskComplete(execution);
this.customTaskExecutionComplete(execution);
this._onDidTerminateTask.fire({
execution: _execution
});
......@@ -591,7 +594,7 @@ export class ExtHostTask implements ExtHostTaskShape {
// For extension callback tasks, we need to store the execution objects locally
// since we obviously cannot send callback functions through the proxy.
// So, clear out any existing ones.
this._providedExtensionCallbacks.clear();
this._providedCustomTaskExecutions.clear();
// Set up a list of task ID promises that we can wait on
// before returning the provided tasks. The ensures that
......@@ -615,8 +618,10 @@ export class ExtHostTask implements ExtHostTaskShape {
if (CustomTaskExecutionDTO.is(taskDTO.execution)) {
taskIdPromises.push(new Promise((resolve) => {
// The ID is calculated on the main thread task side, so, let's call into it here.
// We need the task id's pre-computed for custom task executions because when OnDidStartTask
// is invoked, we have to be able to map it back to our data.
this._proxy.$createTaskId(taskDTO).then((taskId) => {
this._providedExtensionCallbacks.set(taskId, new ExtensionCallbackExecutionData(<vscode.CustomTaskExecution>(<vscode.TaskWithCustomTaskExecution>task).executionWithExtensionCallback, this._terminalService));
this._providedCustomTaskExecutions.set(taskId, new CustomTaskExecutionData(<vscode.CustomTaskExecution>(<vscode.TaskWithCustomTaskExecution>task).executionWithExtensionCallback, this._terminalService));
resolve();
});
}));
......@@ -694,12 +699,12 @@ export class ExtHostTask implements ExtHostTaskShape {
return result;
}
private extensionCallbackTaskComplete(execution: TaskExecutionDTO): void {
const extensionCallback: ExtensionCallbackExecutionData | undefined = this._activeExtensionCallbacks.get(execution.id);
private customTaskExecutionComplete(execution: TaskExecutionDTO): void {
const extensionCallback: CustomTaskExecutionData | undefined = this._activeCustomTaskExecutions.get(execution.id);
if (extensionCallback) {
this._activeCustomTaskExecutions.delete(execution.id);
this._proxy.$customTaskExecutionComplete(execution.id, extensionCallback.result);
extensionCallback.dispose();
this._activeExtensionCallbacks.delete(execution.id);
this._proxy.$extensionCallbackTaskComplete(execution.id);
}
}
}
......@@ -83,5 +83,5 @@ export interface ITaskService {
registerTaskSystem(scheme: string, taskSystemInfo: TaskSystemInfo): void;
extensionCallbackTaskComplete(task: Task): Promise<void>;
extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void>;
}
......@@ -136,5 +136,5 @@ export interface ITaskSystem {
terminate(task: Task): Promise<TaskTerminateResponse>;
terminateAll(): Promise<TaskTerminateResponse[]>;
revealTask(task: Task): boolean;
extensionCallbackTaskComplete(task: Task): Promise<void>;
extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void>;
}
\ No newline at end of file
......@@ -230,7 +230,7 @@ export namespace PresentationOptions {
export enum RuntimeType {
Shell = 1,
Process = 2,
ExtensionCallback = 3
CustomTaskExecution = 3
}
export namespace RuntimeType {
......@@ -241,7 +241,7 @@ export namespace RuntimeType {
case 'process':
return RuntimeType.Process;
case 'customTaskExecution':
return RuntimeType.ExtensionCallback;
return RuntimeType.CustomTaskExecution;
default:
return RuntimeType.Process;
}
......@@ -607,7 +607,7 @@ export class CustomTask extends CommonTask {
type = 'process';
break;
case RuntimeType.ExtensionCallback:
case RuntimeType.CustomTaskExecution:
type = 'customTaskExecution';
break;
......
......@@ -706,11 +706,11 @@ class TaskService extends Disposable implements ITaskService {
this._taskSystemInfos.set(key, info);
}
public extensionCallbackTaskComplete(task: Task): Promise<void> {
public extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void> {
if (!this._taskSystem) {
return Promise.resolve();
}
return this._taskSystem.extensionCallbackTaskComplete(task);
return this._taskSystem.extensionCallbackTaskComplete(task, result);
}
public getTask(folder: IWorkspaceFolder | string, identifier: string | TaskIdentifier, compareId: boolean = false): Promise<Task | undefined> {
......
......@@ -266,14 +266,14 @@ export class TerminalTaskSystem implements ITaskSystem {
return Object.keys(this.activeTasks).map(key => this.activeTasks[key].task);
}
public extensionCallbackTaskComplete(task: Task): Promise<void> {
public extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void> {
let activeTerminal = this.activeTasks[task.getMapKey()];
if (!activeTerminal) {
return Promise.reject(new Error('Expected to have a terminal for an extension callback task'));
}
return new Promise<void>((resolve) => {
activeTerminal.terminal.finishedWithRenderer();
activeTerminal.terminal.finishedWithRenderer(result);
resolve();
});
}
......@@ -550,7 +550,7 @@ export class TerminalTaskSystem implements ITaskSystem {
let processStartedSignaled = false;
terminal.processReady.then(() => {
if (!processStartedSignaled) {
if (task.command.runtime !== RuntimeType.ExtensionCallback) {
if (task.command.runtime !== RuntimeType.CustomTaskExecution) {
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.processId!));
}
processStartedSignaled = true;
......@@ -622,7 +622,7 @@ export class TerminalTaskSystem implements ITaskSystem {
let processStartedSignaled = false;
terminal.processReady.then(() => {
if (!processStartedSignaled) {
if (task.command.runtime !== RuntimeType.ExtensionCallback) {
if (task.command.runtime !== RuntimeType.CustomTaskExecution) {
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.ProcessStarted, task, terminal!.processId!));
}
processStartedSignaled = true;
......@@ -826,7 +826,7 @@ export class TerminalTaskSystem implements ITaskSystem {
}
}
} else {
let commandExecutable = task.command.runtime !== RuntimeType.ExtensionCallback ? CommandString.value(command) : undefined;
let commandExecutable = task.command.runtime !== RuntimeType.CustomTaskExecution ? CommandString.value(command) : undefined;
let executable = !isShellCommand
? this.resolveVariable(variableResolver, '${' + TerminalTaskSystem.ProcessVarName + '}')
: commandExecutable;
......@@ -906,7 +906,7 @@ export class TerminalTaskSystem implements ITaskSystem {
let command: CommandString | undefined;
let args: CommandString[] | undefined;
if (task.command.runtime === RuntimeType.ExtensionCallback) {
if (task.command.runtime === RuntimeType.CustomTaskExecution) {
this.currentTask.shellLaunchConfig = {
isRendererOnly: true,
waitOnExit,
......@@ -1126,7 +1126,7 @@ export class TerminalTaskSystem implements ITaskSystem {
private collectCommandVariables(variables: Set<string>, command: CommandConfiguration, task: CustomTask | ContributedTask): void {
// An extension callback should have everything it needs already as it provided
// the callback.
if (command.runtime === RuntimeType.ExtensionCallback) {
if (command.runtime === RuntimeType.CustomTaskExecution) {
return;
}
......
......@@ -105,7 +105,7 @@ export class ProcessTaskSystem implements ITaskSystem {
return true;
}
public extensionCallbackTaskComplete(task: Task): Promise<void> {
public extensionCallbackTaskComplete(task: Task, result: number | undefined): Promise<void> {
throw new TaskError(Severity.Error, 'Extension callback task completion is never expected in the process task system.', TaskErrors.UnknownError);
}
......
......@@ -432,7 +432,7 @@ export interface ITerminalInstance {
/**
* Indicates that a consumer of a renderer only terminal is finished with it.
*/
finishedWithRenderer(): void;
finishedWithRenderer(result: number | undefined): void;
/**
* Forces the terminal to redraw its viewport.
......
......@@ -754,7 +754,7 @@ export class TerminalInstance implements ITerminalInstance {
this._disposables = lifecycle.dispose(this._disposables);
}
public finishedWithRenderer(): void {
public finishedWithRenderer(result: number | undefined): void {
// The use of this API is for cases where there is no backing process
// behind a terminal instance (such as when executing an extension callback task).
// There is no associated string, error text, etc, as the consumer of the renderer
......@@ -764,7 +764,7 @@ export class TerminalInstance implements ITerminalInstance {
return;
}
return this._onProcessOrExtensionCallbackExit();
return this._onProcessOrExtensionCallbackExit(result);
}
public forceRedraw(): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册