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

Clean up handling of 'taskType' field #9377

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

tsmaeder
Copy link
Contributor

Signed-off-by: Thomas Mäder tmader@redhat.com

What it does

This PR cleans up a couple of the issues introduced by Implement CustomExecution extension API #9189 while retaining the custom execution API.

The approach is to strictly use the "taskType" field in a task configuration to mean the "task execution type". The magic in types-impl.ts (Task#updateTypeBasedOnExecution) has been removed and the translation of Task.execution into TaskDTO.taskType and vice-versa has been moved to the type converter.

I have removed a couple of instances where taskType was used erroneously when the declared type was meant and not the execution type.

I have removed some filtering of dependent tasks based on "source". It did not work (configured tasks have the folder they are in as "source") and I don't think the source field should be considered part of the task identity.

I have also removed the "garbage collection" of callback functions for custom executions. There is no explicit lifecycle for those callback functions that I could find in the VS Code API. I believe there are supposed to be only a fixed, small number of callback functions. So I'm retaining these functions based on identity. We could clean up the callbacks whenever we call provideTasks and after call to the executeTask API, but I don't think it is necessary. Convince me otherwise :-)

How to test

Make sure non-contributed tasks still work, aka process and shell tasks.

Make sure we can run and configure both custom execution tasks (see gradle tasks: #8767) and the shell tasks contributed by @vince-fugnitto's test plugin (see #9366)

Make sure we can run dependent tasks based on label as well as based on structured task identifier.

Review checklist

Reminder for reviewers

Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsmaeder
thank you for the provided fix, I tested the changes and found that they don't fix #9207 (review).
It looks like we still have some problem with provided tasks:

test_task_bug

The use case works well with these changes #9373:

test_task_no_bug

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 20, 2021

Also, there is still a problem from #9365.
It's number 3 in #9365:

It looks like after configuring a task the configuration from tasks.json file is not taken into account at all - so a user select a configured configuration for running, but the corresponding detected configuration is used instead.

configured_task_bug

So, I have configured a task, changed the configuration, but task system runs the corresponding detected task, not configured task configuration...

@tsmaeder
Copy link
Contributor Author

@RomanNikitenko there is https://github.com/eclipse-theia/theia/pull/9207/files for the problem matchers.

@RomanNikitenko
Copy link
Contributor

@RomanNikitenko there is https://github.com/eclipse-theia/theia/pull/9207/files for the problem matchers.

What do you mean?
is it related to my first comment #9377 (review)?
If so - I have checked that behavior for your changes and the same for these changes #9373

@tsmaeder
Copy link
Contributor Author

is it related to my first comment #9377 (review)?

Yes, there is an open PR for that issue.

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 20, 2021

is it related to my first comment #9377 (review)?

Yes, there is an open PR for that issue.

I don't understand what you mean.
I tested the use case described here #9207 (review) using:

Maybe someone could check it as well - to confirm that behavior...

@tsmaeder
Copy link
Contributor Author

@RomanNikitenko so you're doing this:

  1. Configure the "tsc: build" task in a workspace containing theia source
  2. Run the task.
  3. Observe you get output in a terminal named 'npm'
  4. Add a "presentation" object to the configuration
  5. Change "panel" to "new"
  6. Change "echo" to "false"
  7. Run the task
  8. Observe: the output of the command is shown in the same terminal as before

You expectation would be that there is no output or that there is a new terminal being opened and that the command line being executed is not shown in the terminal?

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 20, 2021

@RomanNikitenko so you're doing this:

  1. Configure the "tsc: build" task in a workspace containing theia source
  2. Run the task.
  3. Observe you get output in a terminal named 'npm'
  4. Add a "presentation" object to the configuration
  5. Change "panel" to "new"
  6. Change "echo" to "false"
  7. Run the task
  8. Observe: the output of the command is shown in the same terminal as before

You expectation would be that there is no output or that there is a new terminal being opened and that the command line being executed is not shown in the terminal?

My expectation is: the configured task (not detected) is running when I run configured task

In the use case above:

  • the new panel should be used for running
  • no echo

as such changes I provided for the configured task, you can use another way to check it

Copy link
Contributor

@colin-grant-work colin-grant-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need a bit of time to get a better understanding of all of the contingencies in play, but here are a couple of very minor comments from my first read-through of the changes.

this.providedCustomExecutions = new Map<number, CustomExecution>();
this.notProvidedCustomExecutions = new Set<number>();
this.activeCustomExecutions = new Map<number, CustomExecution>();
this.customExecutionIds = new Map();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor]: some map fields are initialized as properties above (adaptersMap, executions); others are initialized here. I'd vote for moving these three, which don't need information from the constructor arguments, up with the rest and initializing with the property syntax.

@@ -234,6 +234,7 @@ export class TasksMainImpl implements TasksMain, Disposable {
return {
...common,
...partialDto,
taskType: taskType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Minor]: Could be just taskType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, it looks like we don't need the change here

@tsmaeder tsmaeder mentioned this pull request Apr 20, 2021
1 task
@tsmaeder
Copy link
Contributor Author

tsmaeder commented Apr 20, 2021

@RomanNikitenko

My expectation is: the configured task (not detected) is running when I run configured task

We are running the configured task. However, we pass the configured task to taskProvider.resolve() of the typescript built-in extension, which returns a new task which has an empty presentation object.

I suspect this "worked" before because we were using the "taskType" based on the task execution (which is process or shell) to look up the task resolver. We would then not get the plugin task resolver, but the fallback "ProcessTaskResolver", which doesn't empty the presentation field.

Not sure what the right thing is here: I suspect that TaskProvider#resolve() and TaskResolver#resolve() are not the same thing.

@tsmaeder
Copy link
Contributor Author

Turns out that VSCode overrides the configured properties after calling the task resolver: https://github.com/microsoft/vscode/blob/10c56b598de01119b80a5c53871003f868fd41fb/src/vs/workbench/parts/tasks/node/taskConfiguration.ts#L1473

@alvsan09
Copy link
Contributor

I found the following issue when testing with;
https://github.com/microsoft/vscode-extension-samples/tree/main/task-provider-sample

The output from custom task e.g. task 'custombuildscript: 32 -incremental' does not show the extensions output in the terminal,
you can compare the expected and actual results in the following images when running the task twice in a row.

task32_incremental

task-32-incremental-no-output

@alvsan09
Copy link
Contributor

I have tried @RomanNikitenko case but using "gradle: clean", I updated the presentation options under the configured task (tasks.json) and confirmed that the presentation options don't take effect.

Copy link
Contributor

@alvsan09 alvsan09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement !
it would be great to rename all taskType instances that mean execution type, so taskType names that refer to actual TaskDefintion.type would not be confused with execution type.

@@ -219,7 +219,7 @@ export class TasksMainImpl implements TasksMain, Disposable {
}

protected fromTaskConfiguration(task: TaskConfiguration): TaskDto {
const { group, presentation, _scope, _source, ...common } = task;
const { group, presentation, _scope, _source, taskType, ...common } = task;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taskType does not seem to be converted, so we can leave it as part of ...comon, right ?

@tsmaeder
Copy link
Contributor Author

TaskProvider.resolveTask() is not invoked with the changes in https://github.com/eclipse-theia/theia/pull/9373/files, so it's broken in both cases.

@tsmaeder
Copy link
Contributor Author

I checked that in master, the presentation options of the configured tsc: build task are not used either. So at least it's no worse.

@tsmaeder
Copy link
Contributor Author

I found the following issue when testing with;
https://github.com/microsoft/vscode-extension-samples/tree/main/task-provider-sample

@alvsan09 Sorry, but I don't understand what issue you're describing here: could you give steps to reproduce?

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 21, 2021

I checked that in master, the presentation options of the configured tsc: build task are not used either.

I believe it worked well before merging #9189.

We have a lot of regressions in master after merging #9189:

@tsmaeder
Copy link
Contributor Author

I believe all of those are fixed, except #9207 (review) (for which there is a separate PR already open).

As for the presentation options not being used, IMO that only ever worked because TaskProvider#resolve() was never invoked. So it was not working, just broken in a different way.

see #9377 (comment)

@alvsan09
Copy link
Contributor

I found the following issue when testing with;
https://github.com/microsoft/vscode-extension-samples/tree/main/task-provider-sample

@alvsan09 Sorry, but I don't understand what issue you're describing here: could you give steps to reproduce?

  • Install the extension mentioned above
  • In theia (any project) run the plugin provided task 'custombuildscript: 32 incremental' i.e. Terminal -> Run task ...
  • run it twice and see that the output in terminal is not complete i.e. it does not show the expected plugin provided messages highlighted in the red square.

image

@alvsan09
Copy link
Contributor

As for the presentation options not being used, IMO that only ever worked because TaskProvider#resolve() was never invoked. So it was not working, just broken in a different way.

@tsmaeder, could you please clarify what you mean with it was broken in a different way ?
From a user's perspective it's a regression, right ?

@tsmaeder
Copy link
Contributor Author

@tsmaeder, could you please clarify what you mean with it was broken in a different way ?
From a user's perspective it's a regression, right ?

Well, if you cared about configuring the presentation options, it was a regression, but if you cared about TaskProvider.resolve() bein called, it was a bugfix :-) But anyway...with my latest commits, I believe both codepaths are covered now.

@alvsan09
Copy link
Contributor

@tsmaeder, could you please clarify what you mean with it was broken in a different way ?
From a user's perspective it's a regression, right ?

Well, if you cared about configuring the presentation options, it was a regression, but if you cared about TaskProvider.resolve() bein called, it was a bugfix :-) But anyway...with my latest commits, I believe both codepaths are covered now.

I can confirm that the presentation options work for me taken the latest branch of this PR

@tsmaeder
Copy link
Contributor Author

I've added two commits that do the following:

  1. Reapply task customisations after calling TaskProvider.resolve(). This should take care of the case where customising a tsc: build task was not working.
  2. Introduced the concept of the TaskExcecutionResolver. This came from the observation that we want to apply the ProcessTaskResolver to any task that has a shell or process task execution, not just the ones that have the shell|process task type. ProcessTaskResolver is responsible for doing stuff like substituting variables in for the cwd option, for example.

To test the latest change, try configuring the cwd option for a tsc: build task.

I'm re-requesting reviews, since the latest two changes are non-trivial and should be looked at.

@RomanNikitenko RomanNikitenko self-requested a review April 27, 2021 05:58
Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the changes and can confirm that they fix the following issues for me:

But I still not able to run a task according to #9207 (review)
The error is: task ERROR Error resolving task 'test': TypeError: Cannot read property 'group' of undefined

resolving_tasks

@alvsan09
Copy link
Contributor

I found the following issue when testing with;
https://github.com/microsoft/vscode-extension-samples/tree/main/task-provider-sample

@alvsan09 Sorry, but I don't understand what issue you're describing here: could you give steps to reproduce?

* Install the extension mentioned above

* In theia (any project) run the plugin provided task 'custombuildscript: 32 incremental' i.e. Terminal -> Run task ...

* run it twice and see that the output in terminal is not complete i.e. it does not show the expected plugin provided messages highlighted in the red square.

image

Any news on this issue ?

@vince-fugnitto
Copy link
Member

@tsmaeder with the release tentatively scheduled for tomorrow (29th), how far are we from fixing regressions caused by #9189? Should we think about preparing a revert, or perhaps delaying the release?

cc @marcdumais-work

@tsmaeder
Copy link
Contributor Author

IMO, the PR as it stands now is closer to a correct implementation than reverting the change.

@tsmaeder
Copy link
Contributor Author

Any news on this issue ?

The problem here is that we're not registering custom execution callbacks for custom executions added during the resolveTask phase. I have pushed a fix.

@alvsan09
Copy link
Contributor

Any news on this issue ?

The problem here is that we're not registering custom execution callbacks for custom executions added during the resolveTask phase. I have pushed a fix.

I can confirm that the fix is for this issue works !!, Thanks Thomas !

Copy link
Contributor

@alvsan09 alvsan09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see only a pending issue for #9207 which is still under review
I know my vote does not count for the merge, but I would like to reflect my opinion
as this fixes many outstanding issues present in master.

@vince-fugnitto vince-fugnitto added tasks issues related to the task system vscode issues related to VSCode compatibility labels Apr 28, 2021
@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 29, 2021

As workaround for the use case #9377 (review)
we could consider these changes 2aa654d

You can use my branch for testing - it contains all commits from the current PR + my workaround.

Update:
VS Code considers that resolveTask method can return undefined, you can see it here, for example.
The documentation says the same (please see a description for resolveTask() method):

A valid default implementation for the resolveTask method is to return undefined

I created a separate issue for that problem: #9411

So, maybe more clear solution is: 5d1efe3
The branch for testing is: https://github.com/eclipse-theia/theia/compare/fixTaskResolver

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Apr 29, 2021

Just by the way...the doc for resolveTask also says that:

Note that when filling in the properties of task, you must be sure to use the exact same TaskDefinition and not create a new one. Other properties may be changed.

So the implementation in the task provider sample from the vscode-examples project is actually bogus: it returns new task objects. The fix still applies, though: customized tasks may have their execution replaced.

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 29, 2021

@tsmaeder

Just by the way...the doc for resolveTask also says that:

Note that when filling in the properties of task, you must be sure to use the exact same TaskDefinition and not create a new one. Other properties may be changed.

So the implementation in the task provider sample from the vscode-examples project is actually bogus: it returns new task objects. The fix still applies, though: customized tasks may have their execution replaced.

Do you mean that there is no problem for the use case if it it returns:

the exact same TaskDefinition and not create a new one

?

Sorry, I didn't have a lot of time for a deep investigation, but for me it looks like it's a separate problem.
I found that resolveTask method can return undefined and tasks system doesn't take it in account.
I provided a fix for that.

It's true that there is a note in the VS Code documentation

Note that when filling in the properties of task, you must be sure to use the exact same TaskDefinition and not create a new one. Other properties may be changed.

But for me it looks like it's not related to undefined and the fix that I provided.
Please be more precise, what influence that has within Theia tasks system.
I'll really appreciate if you provide some steps to reproduce or a use case.

@tsmaeder
Copy link
Contributor Author

@RomanNikitenko it's a completely unrelated problem. I just wanted to point out that we should not take the vscode samples as our bible: we should stick to what the documentation says, not what the samples do.

@RomanNikitenko
Copy link
Contributor

@RomanNikitenko it's a completely unrelated problem. I just wanted to point out that we should not take the vscode samples as our bible: we should stick to what the documentation says, not what the samples do.

I see, thank you!

Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the changes and can confirm that they fix the following issues for me:

I'm able to run a task according to #9207 (review) using current PR changes + my changes: 5d1efe3, please see #9377 (comment)

@tsmaeder
Copy link
Contributor Author

@colin-grant-work @RomanNikitenko @alvsan09 if no-one has any last minute objections, I would go ahead and clean up and merge this one then. Thanks for the reviews & testing.

@colin-grant-work
Copy link
Contributor

@colin-grant-work @RomanNikitenko @alvsan09 if no-one has any last minute objections, I would go ahead and clean up and merge this one then. Thanks for the reviews & testing.

I think that sounds good to me, as long as @RomanNikitenko code suggestions are taken into account.

@RomanNikitenko
Copy link
Contributor

as long as @RomanNikitenko code suggestions are taken into account.

Do you mean these changes 5d1efe3 ?
if so - they were not reviewed/tested.

I can not open a separate PR for them as the changes depend on the current PR.
So, maybe the true way is:

  • squash and merge the current PR
  • I align my branch with master
  • I open the PR for 5d1efe3
  • review ^
  • merge if it looks good

If you mean something else or have a better way - please let me know

@vince-fugnitto
Copy link
Member

  • squash and merge the current PR
  • I align my branch with master
  • I open the PR for 5d1efe3
  • review ^
  • merge if it looks good

@RomanNikitenko @tsmaeder I propose we go forward with that approach, let's squash the current pull-request and merge (for today's release) and continue with 5d1efe3 in a separate pull-request.

Signed-off-by: Thomas Mäder <tmader@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tasks issues related to the task system vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants