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

Add task#runOptions to API. #11759

Merged

Conversation

sgraband
Copy link
Contributor

@sgraband sgraband commented Oct 12, 2022

What it does

Additionally added functionality to support reevaluateOnRerun. If this flag is set to false no variables will be resolved again. Therefore lastTask can now be re-triggered without resolving all variables. For this the lastTask object was updated to contain all resolved information.

Contributed on behalf of STMicroelectronics

Resolves #11132

How to test

To test you can use the follwing tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Node Command",
      "type": "shell",
      "command": "node",
      "args": [
        "${input:node command}"
      ],
      "isBackground": true,
      "runOptions": {
        "reevaluateOnRerun": false
      }
    },
  ],
  "inputs": [
    {
      "id": "node command",
      "description": "node ${input:node command}",
      "default": "--version",
      "type": "promptString"
    },
  ]
}

When you run the node command you will be asked, which command you want to run. If you enter --version for example and then rerun the last task. You will not be asked and node --version is automatically executed.
When you change reevaluateOnRerun to true, run and rerun the task, you will need to reenter the command every time.

To test the API you can use this extension. It provides a task (custombuildscript: 32) with reevaluateOnRerun: true. When you run this task and debug, for example at task-service.ts#808 the task object should have the correct runOptions set.

Review checklist

Reminder for reviewers

@vince-fugnitto vince-fugnitto added tasks issues related to the task system vscode issues related to VSCode compatibility labels Oct 12, 2022
@JonasHelming JonasHelming requested a review from tsmaeder October 13, 2022 14:19
return;
}
const { source, taskLabel, scope } = this.lastTask;
return this.run(token, source, taskLabel, scope);
if (!this.lastTask.resolvedTask.runOptions?.reevaluateOnRerun) {
Copy link
Contributor

@colin-grant-work colin-grant-work Oct 13, 2022

Choose a reason for hiding this comment

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

If this flag is set to false no variables will be resolved again. Therefore lastTask can now be re-triggered without resolving all variables.

It appears that reevaluateOnRerun = false is being treated as the default. That's a change in the expectations for internal tasks, which in the past would always have been resolved when rerun. Is there any value in treating internal and external tasks differently in this respect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes i was wondering this as well. I would find it odd, if the default behavior is reevaluateOnRerun = true as this would mean, that we need to interpret missing options as true. I am not sure, how internal tasks are handled, but would it be a option to add this runOption to all internal tasks? This would keep the current behavior and explicitly explain for each task how it should be handled. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@colin-grant-work by "internal", do you mean tasks defined in tasks.json or contributed by non-plugin API? If we need to treat tasks different, I would much prefer putting the difference where we create the tasks (for example by setting a flag in the contructor) and not where we process the tasks. Locality of reference for teh win!

Copy link
Contributor

Choose a reason for hiding this comment

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

Re: tasks.json, we should likely follow what VSCode does, though there's scope for making our own choice there. Mostly I mean other tasks created internally, but I'm not very familiar with the behavior or UI of 'rerun' tasks (as opposed to running the same task again, but not as a rerun), so I'm not sure how disruptive it would be to change from resolving to not resolving variables in the task description.

One solution might be to modify the plugin system to supply false by default for tasks originating from plugins, and then have a flag in the task service for whether to use false or true as the default value there so that application implementers can easily toggle it if they have a use case where true is appropriate. On the other hand, it sounds like @tsmaeder favors something on the task description itself (in which case maybe setting false in the plugin system and using true as a default otherwise would be the best course?). In any case, I don't know if it really warrants too much concern.

Copy link
Contributor

@tsmaeder tsmaeder Oct 21, 2022

Choose a reason for hiding this comment

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

I thought about this some more: what I really would like to avoid is a "if tasksource = plugin, do x, else do y". I'm also not a fan of setting variables that are client API in order to simulate the "right" default behaviour: if anything, we should set a flag : task.defaultRerunOnReevaluate= false that is not part of the API in the plugin task provider implementation and default to true in clients to preserve the current behaviour.
But t.b.h, I would just make the change to the VS Code behavior: it's a breaking change, and while we try not to frivolously break API, we also should not unduly complicate the system to keep the API stable.
My vote is: put the code in as it is and make a note of it in the "breaking changes". Clients can trivially update their code if they rely on the behaviour. @colin-grant-work can you live with that?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with this approach.

packages/plugin-ext/src/plugin/types-impl.ts Outdated Show resolved Hide resolved
packages/plugin-ext/src/plugin/type-converters.ts Outdated Show resolved Hide resolved
return;
}
const { source, taskLabel, scope } = this.lastTask;
return this.run(token, source, taskLabel, scope);
if (!this.lastTask.resolvedTask.runOptions?.reevaluateOnRerun) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@colin-grant-work by "internal", do you mean tasks defined in tasks.json or contributed by non-plugin API? If we need to treat tasks different, I would much prefer putting the difference where we create the tasks (for example by setting a flag in the contructor) and not where we process the tasks. Locality of reference for teh win!

@@ -8,6 +8,8 @@

- [plugin] added support for the `InlineValues` feature [#11729](https://github.com/eclipse-theia/theia/pull/11729) - Contributed on behalf of STMicroelectronics
- [plugin] Added support for `resolveTreeItem` of `TreeDataProvider` [#11708](https://github.com/eclipse-theia/theia/pull/11708) - Contributed on behalf of STMicroelectronics
- [plugin] added `Task#runOptions` field and `RunOptions` interface [#11759](https://github.com/eclipse-theia/theia/pull/11759) - Contributed on behalf of STMicroelectronics
- [tasks] added support for `reevaluateOnRerun` run option [#11759](https://github.com/eclipse-theia/theia/pull/11759) - Contributed on behalf of STMicroelectronics
Copy link
Contributor

Choose a reason for hiding this comment

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

As suggested by @tsmaeder, please add a note about the change in behavior for tasks in the breaking changes area.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Could you recheck?

Additionally added functionality to support `reevaluateOnRerun`.
If this flag is set to false no variables will be resolved again.
Therefore lastTask can now be re-triggered without resolving all variables.
For this the lastTask object was updated to contain all resolved information.

Contributed on behalf of STMicroelectronics

Resolves eclipse-theia#11132
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.

The behavior looks good, and adopters should be adequately warned re: any effect on their current setup.

@colin-grant-work colin-grant-work merged commit 385860d into eclipse-theia:master Nov 2, 2022
@vince-fugnitto vince-fugnitto added this to the 1.32.0 milestone Nov 24, 2022
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.

[vscode] Support Task#runOptions
4 participants