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

Stabilize CustomExecution task API #80375

Closed
alexr00 opened this issue Sep 5, 2019 · 9 comments
Closed

Stabilize CustomExecution task API #80375

alexr00 opened this issue Sep 5, 2019 · 9 comments
Assignees
Labels
api api-finalization feature-request Request for new features or functionality on-testplan tasks Task system issues
Milestone

Comments

@alexr00
Copy link
Member

alexr00 commented Sep 5, 2019

No description provided.

@alexr00 alexr00 self-assigned this Sep 5, 2019
@alexr00 alexr00 added api api-finalization feature-request Request for new features or functionality tasks Task system issues labels Sep 5, 2019
@alexr00
Copy link
Member Author

alexr00 commented Sep 5, 2019

@GabeDeBacker FYI

@GabeDeBacker
Copy link
Contributor

One thing to note that I hit while consuming this proposed API which could be improved.

This onDidClose part of the PseudoTerminal interface is optional.

	interface Pseudoterminal {
		onDidClose?: Event<void | number>;

At some point while that API was in the proposed state, it was renamed. And since it was optional, the TypeScript compiler did not inform me I was doing something wrong. Also took me a while to figure out what the issue was.

I think it would be good to make sure developers really understand that in normal circumstances they should be firing the onDidClose event.

Since PseudoTerminal is already public, we could do this for CustomExecution

	 /**
	  * Make onDidClose required for tasks so developers realize they should
	  * implement this to have their tasks complete and it is enforced
	  * by the TypeScript compiler.
	  * If they want to have a task run forever (which is probably a small case),
	  * they simply don't fire the event.
	  */
	 export interface TaskPseudoterminal extends Pseudoterminal {
		onDidClose: Event<void | number>;
	}

	/**
	 * Class used to execute an extension callback as a task.
	 */
	export class CustomExecution2 {
		/**
		 * @param process The [Pseudoterminal](#Pseudoterminal) 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: () => Thenable<TaskPseudoterminal>);

		/**
		 * The callback used to execute the task. Cancellation should be handled using
		 * [Pseudoterminal.close](#Pseudoterminal.close). When the task is complete fire
		 * [Pseudoterminal.onDidClose](#PseudoterminalForTask.onDidClose).
		 */
		callback: () => Thenable<TaskPseudoterminal>;
	}

@GabeDeBacker
Copy link
Contributor

One final note: If an extension fires onDidClose, will close get called?

Vice versa is also a question, if close is called, should onDidClose be called?

@alexr00
Copy link
Member Author

alexr00 commented Sep 23, 2019

@Tyriar for the intended behavior around close when onDidClose is called and the reverse.
The behavior I'm seeing is close is not called when onDidClose is fired and onDidClose isn't fired when close is called.

@alexr00
Copy link
Member Author

alexr00 commented Sep 23, 2019

Since we still have more to discuss for this API we'll continue in October. Leaving the Milestone as September for now though so we don't forget to keep discussing it.

@alexr00 alexr00 modified the milestones: September 2019, October 2019 Sep 23, 2019
@alexr00
Copy link
Member Author

alexr00 commented Sep 23, 2019

My thoughts on making onDidClose required for custom execution tasks is that, while it adds nice guidance, it also increase our API surface by basically duplicating an event. There are also cases where a task might never need to fire onDidClose (perhaps someone wants to have a task that never ends). I'll keep considering it and post an update with where we come out.

@Tyriar
Copy link
Member

Tyriar commented Sep 23, 2019

@Tyriar for the intended behavior around close when onDidClose is called and the reverse.
The behavior I'm seeing is close is not called when onDidClose is fired and onDidClose isn't fired when close is called.

This is by design, if you read close's comment carefully it hints at this:

Implement to handle when the terminal is closed by an act of the user.

close is called exclusively when the user somehow kills it, which you may want to handle differently to a regular close. You can always just call close from the onDidClose handler if not.


My thoughts on making onDidClose required for custom execution tasks is that, while it adds nice guidance, it also increase our API surface by basically duplicating an event.

👎 to making onDidClose mandatory just for tasks as it could be optional.

@bwateratmsft
Copy link
Contributor

This will work for us, it will be a huge benefit. I would support coming up with some simplified examples somewhere as the CustomExecution+PseudoTerminal is significantly more complicated than ShellExecution/ProcessExecution are.

The only thing we really want in addition is #2809, an API to resolve task variables; but this can come later.

@alexr00
Copy link
Member Author

alexr00 commented Sep 24, 2019

The task provider extension sample has an example of how to use CustomExecution: https://github.com/microsoft/vscode-extension-samples/tree/master/task-provider-sample
Once we stabilize I will also add it to the documentation.

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-finalization feature-request Request for new features or functionality on-testplan tasks Task system issues
Projects
None yet
Development

No branches or pull requests

4 participants