Skip to content

Commit

Permalink
Merge pull request #77839 from microsoft/tyriar/task_vp_fix
Browse files Browse the repository at this point in the history
Add CustomExecution2 test and make start fire after onDidOpenTerminal
  • Loading branch information
Tyriar committed Jul 24, 2019
2 parents 7674039 + b060301 commit 36e08fe
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as assert from 'assert';
import * as vscode from 'vscode';

suite.only('workspace-namespace', () => {

suite('Tasks', () => {

test('CustomExecution2 task should start and shutdown successfully', (done) => {
interface CustomTestingTaskDefinition extends vscode.TaskDefinition {
/**
* One of the task properties. This can be used to customize the task in the tasks.json
*/
customProp1: string;
}
const taskType: string = 'customTesting';
const taskName = 'First custom task';
const reg1 = vscode.window.onDidOpenTerminal(term => {
reg1.dispose();
const reg2 = term.onDidWriteData(e => {
reg2.dispose();
assert.equal(e, 'testing\r\n');
term.dispose();
});
});
const taskProvider = vscode.tasks.registerTaskProvider(taskType, {
provideTasks: () => {
const result: vscode.Task[] = [];
const kind: CustomTestingTaskDefinition = {
type: taskType,
customProp1: 'testing task one'
};
const writeEmitter = new vscode.EventEmitter<string>();
const execution = new vscode.CustomExecution2((): Thenable<vscode.TerminalVirtualProcess> => {
return Promise.resolve(<vscode.TerminalVirtualProcess>{
onDidWrite: writeEmitter.event,
start: () => {
writeEmitter.fire('testing\r\n');
},
shutdown: () => {
taskProvider.dispose();
done();
}
});
});
const task = new vscode.Task2(kind, vscode.TaskScope.Workspace, taskName, taskType, execution);
result.push(task);
return result;
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
assert.fail('resolveTask should not trigger during the test');
return undefined;
}
});
vscode.commands.executeCommand('workbench.action.tasks.runTask', `${taskType}: ${taskName}`);
});
});
});
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export class ExtHostTask implements ExtHostTaskShape {

// Clone the custom execution to keep the original untouched. This is important for multiple runs of the same task.
this._activeCustomExecutions2.set(execution.id, execution2);
this._terminalService.attachVirtualProcessToTerminal(terminalId, await execution2.callback());
await this._terminalService.attachVirtualProcessToTerminal(terminalId, await execution2.callback());
}

// Once a terminal is spun up for the custom execution task this event will be fired.
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/api/node/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
return terminal;
}

public attachVirtualProcessToTerminal(id: number, virtualProcess: vscode.TerminalVirtualProcess) {
const terminal = this._getTerminalById(id);
public async attachVirtualProcessToTerminal(id: number, virtualProcess: vscode.TerminalVirtualProcess): Promise<void> {
const terminal = this._getTerminalByIdEventually(id);
if (!terminal) {
throw new Error(`Cannot resolve terminal with id ${id} for virtual process`);
}
Expand Down Expand Up @@ -619,6 +619,10 @@ export class ExtHostTerminalService implements ExtHostTerminalServiceShape {
}

public async $startVirtualProcess(id: number, initialDimensions: ITerminalDimensionsDto | undefined): Promise<void> {
// Make sure the ExtHostTerminal exists so onDidOpenTerminal has fired before we call
// TerminalVirtualProcess.start
await this._getTerminalByIdEventually(id);

// Processes should be initialized here for normal virtual process terminals, however for
// tasks they are responsible for attaching the virtual process to a terminal so this
// function may be called before tasks is able to attach to the terminal.
Expand Down

0 comments on commit 36e08fe

Please sign in to comment.