Skip to content

Adopt virtual process terminals in task custom execution API #76492

Closed

Description

@Tyriar

Implemented in #70978

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

Activity

  1. added this to the July 2019 milestone on Jul 3, 2019
  2. alexr00 commented on Jul 8, 2019

    @alexr00
    Member
    	/**
    	 * 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;
    	}
  3. alexr00 commented on Jul 9, 2019

    @alexr00
    Member

    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

  4. added a commit that references this issue on Jul 10, 2019
    e84fc70
  5. locked and limited conversation to collaborators on Aug 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apiapi-proposaltasks

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions