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

Take into account that TaskResolver can return undefined #9415

Closed
wants to merge 1 commit into from

Conversation

RomanNikitenko
Copy link
Contributor

@RomanNikitenko RomanNikitenko commented Apr 29, 2021

Signed-off-by: Roman Nikitenko [email protected]

What it does

Fixes #9411

How to test

I'm able to reproduce the bug for master branch using test plugin from #9207 (comment)
Please see #9207 (review)

  1. Install test plugin
  2. Open "Test View"
  3. Click on a "test" item
  4. Task should start successfully, terminal should be open and produces output specified in task.sh

Review checklist

Reminder for reviewers

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

I think we need to handle the undefined return explicitly.

)
};
}

protected toTaskConfiguration(taskDto: TaskDto): TaskConfiguration {
protected toTaskConfiguration(taskDto?: TaskDto): TaskConfiguration | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe if we overload the signature like so:

    protected toTaskConfiguration(taskDto: TaskDto): TaskConfiguration;
    protected toTaskConfiguration(taskDto: TaskDto | undefined): TaskConfiguration | undefined;
    protected toTaskConfiguration(taskDto: any): any {

We don't have to check the return value for undefined if the parameter can't be undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would make the changes in provideTasks and $excuteTask unnecessary

@@ -791,10 +791,10 @@ export class TaskService implements TaskConfigurationClient {
this.addRecentTasks(task);
try {
const resolver = await this.taskResolverRegistry.getTaskResolver(task.type);
const resolvedTask = resolver ? await resolver.resolveTask(task) : task;
const resolvedTask = resolver && await resolver.resolveTask(task) || task;
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 not sure using the unresolved tasks is the right thing to do here: looking at the code in VS Code, they seem to treat that condition as an error.
Think about it this way: if we have a task that is not a contributed task of type 'foo', but defined in a tasks.json file, it will not have an execution set (and therefore no 'taskType' field). So looking up a runner using the taskType (undefined) and type ('foo') fields will fall back to using the ProcessTaskRunner, but executing a custom contributed task will fail in unforeseen ways. I think it's better to handle that condition explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure using the unresolved tasks is the right thing to do here: looking at the code in VS Code, they seem to treat that condition as an error.

It looks strange for me, because:

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

  • I tested the use case for VS Code using test plugin, which uses a task resolver which returns undefined. The result - a task is run successfully - no errors.

Do you have steps to reproduce which I can use to confirm that behavior you described above?

Copy link
Contributor

@tsmaeder tsmaeder Apr 30, 2021

Choose a reason for hiding this comment

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

I have looked at the vscode source. I guess the test would be a task of a contributed type that is not a customization of a contributed task. That should be achievable if you contribute only a type, but don't return anything from 'provideTasks()'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what's the goal to

contribute only a type, but don't return anything from 'provideTasks()'

?

Do you know a VS Code extension which has such behavior?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, but it's valid according to the documentation 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

The goal is to make sure we hit the failure case I was describing. If you know a simpler way to reproduce the scenario, feel free to use it.

Copy link
Contributor Author

@RomanNikitenko RomanNikitenko Apr 30, 2021

Choose a reason for hiding this comment

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

So, if I understand correctly, the your use case is:

  • a plugin contribute a type for tasks
  • don't provide any tasks
  • returns undefined when resolveTask method is called

So the plugin:

  • register task provider to provide nothing
  • register task resolver to return undefined

correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, except the part where you're configuring a task of that type in a tasks.json file.

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't tested anything so far, just inspected the code here and in VS Code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@RomanNikitenko RomanNikitenko deleted the fixTaskResolver branch February 1, 2022 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TaskResolver should respect VS Code documentation
2 participants