-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
Signed-off-by: Roman Nikitenko <[email protected]>
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- According to the VS Code documentation (please see a description for
resolveTask()
method):
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?
There was a problem hiding this comment.
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()'
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🤷
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
Review checklist
Reminder for reviewers