Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt virtual process terminals in task custom execution API #76492

Closed
Tyriar opened this issue Jul 3, 2019 · 2 comments · Fixed by #76852
Closed

Adopt virtual process terminals in task custom execution API #76492

Tyriar opened this issue Jul 3, 2019 · 2 comments · Fixed by #76852
Assignees
Labels
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Jul 3, 2019

Implemented in #70978

There's a proposal for how it would work there.

@alexr00
Copy link
Member

alexr00 commented Jul 8, 2019

	/**
	 * Class used to execute an extension callback as a task.
	 */
	export class CustomExecution2 {
		/**
		 * @param process The [TerminalVirtualProcess](#TerminalVirtualProcess) to be used by the task to display output.
		 * @param callback The callback that will be called when the task is started by a user.
		 */
		constructor(process: TerminalVirtualProcess, callback: (thisArg?: any) => Thenable<void>);

		/**
		 * The callback used to execute the task. Cancellation should be handled using the [TerminalVirtualProcess](#TerminalVirtualProcess).
		 * When the task is complete, onDidExit should be fired on the TerminalVirtualProcess with the exit code with '0' for success and a non-zero value for failure.
		 */
		callback: (thisArg?: any) => Thenable<void>;

		/**
		 * The [TerminalVirtualProcess](#TerminalVirtualProcess) will be attached to a terminal when the task is started.
		 * At that point it can be used to show output and accept input. process.shutdown() should be implemented to handle interruption of the task
		 */
		process: TerminalVirtualProcess;
	}

@alexr00
Copy link
Member

alexr00 commented Jul 9, 2019

Updated API:

	/**
	 * Class used to execute an extension callback as a task.
	 */
	export class CustomExecution2 {
		/**
		 * @param process The [TerminalVirtualProcess](#TerminalVirtualProcess) to be used by the task to display output.
		 * @param callback The callback that will be called when the task is started by a user.
		 */
		constructor(callback: (thisArg?: any) => Thenable<TerminalVirtualProcess>);

		/**
		 * The callback used to execute the task. Cancellation should be handled using the shutdown method of [TerminalVirtualProcess](#TerminalVirtualProcess).
		 * When the task is complete, onDidExit should be fired on the TerminalVirtualProcess with the exit code with '0' for success and a non-zero value for failure.
		 */
		callback: (thisArg?: any) => Thenable<TerminalVirtualProcess>;
	}

This also requires a start on the TerminalVirtualProcess because:

const execution =  new vscode.CustomExecution2(
						async (): Promise<vscode.TerminalVirtualProcess> => {
							return new TestTerminalProcess();
						});
...
class TestTerminalProcess implements vscode.TerminalVirtualProcess {

	private writeEmitter = new vscode.EventEmitter<string>();
	onDidWrite = this.writeEmitter.event;
	private exitEmitter = new vscode.EventEmitter<number>();
	onDidExit = this.exitEmitter.event;

	constructor() {
		// Can't start emitting things here, no one is listening. 
	}

	start() {
		this.writeEmitter.fire('Hello, terminal');
		setTimeout(() => {
			this.writeEmitter.fire('Goodbye!');
			this.exitEmitter.fire(0);
		}, 3000);
	}

	shutdown() {
		console.log("Shutting down");
	}

	input(data: string): void {
		console.log('There was input');
	}

	setDimensions?(dimensions: vscode.TerminalDimensions): void {
		console.log('Dims changed');
	}
}

I've added the start in the PR: 83c08e4

alexr00 added a commit that referenced this issue Jul 10, 2019
* Adopt TerminalVirtualProcess for Custom task execution

* Update Custom task execution API to return TerminalVirtualProcess in callback

This also required the addtion of a start on the virtual terminal process

* Clarify start API

Fixes #76492
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants