Skip to content

fix: Remove incorrectly filtering VS Code cargo task execution resolution by scope #10093

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

Merged
merged 3 commits into from
Sep 8, 2021

Conversation

oeed
Copy link
Contributor

@oeed oeed commented Aug 31, 2021

This fixes #9093 ​introduced by #8995.

A filter was present on the function that adds the execution definition to Cargo tasks. This would mean Cargo tasks defined in workspaces (i.e. .code-workspace files) would not be given an execution, leading to a There is no task provider registered for tasks of type "cargo". error as descibed in #9093. I have made a minimum reproduction setup here.

This PR essentially removes that check. The if (scope) { ... } is to handle the case where task.scope === undefined using a deprecated constructor. I'm not sure if that is ever likely to occur and can remove if not needed.

There is some discussion about whether it's necessary to filter the tasks before building them. From my understanding, it shouldn't be needed as we should provide an execution for all cargo tasks; but I'm not overly familiar with VS Code internals so I could be wrong. For more info please see the discussion on #8995

@oeed oeed changed the title Remove incorrectly filtering VS Code cargo task execution resolution by scope fix: Remove incorrectly filtering VS Code cargo task execution resolution by scope Aug 31, 2021
@matklad
Copy link
Member

matklad commented Aug 31, 2021

r? @SomeoneToIgnore

@oeed
Copy link
Contributor Author

oeed commented Aug 31, 2021

It's worth noting that I've never touched VS Code extensions before; so take these changes with an huge grain of salt. There's definitely an issue, but maybe isWorkspaceFolder just needs to account for workspace scopes instead? I'm not familiar enough to know.

}
else {
// if the original task did not provide a scope retain the original lack of scope
return new vscode.Task(
Copy link
Contributor

Choose a reason for hiding this comment

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

This constructor is considered deprecated: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/vscode/index.d.ts#L6743

  • @deprecated Use the new constructors that allow specifying a scope for the task.

So looks like VSCode forces everybody to explicitly define a workspace folder for every task.

I'm not entirely thrilled to start using deprecated APIs, so would personally concentrate on deriving the folder instead.
Seems unfair to block you too, so if somebody else feels fine, he can merge the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, so was your comment here:

Now, the biggest task is to determine the folder that should apply for your custom configuration since I did not take such cases into account.

about how to handle scope === undefined?

In that case I assumed that it should simply 'add on' the necessary parts to the task, and if the original task didn't have a scope then simply leave it undefined. From what I've seen, the function doesn't need to use the scope and so if it doesn't have one it just passes that lack of scope onwards. But once again, I've little understanding of what's going on here.

Alternatively could the check instead be if (scope === undefined)?

Copy link
Contributor

Choose a reason for hiding this comment

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

You've got the idea right: it's all about the scope === undefined for tasks that come from user configurations (in your case).

The fix logic can be anything that fixes things for you and preferrably is not deprecated/super hacky 🙂
I see that the scope can be scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace so I wonder, if the TaskScope.Workspace variant a right thing to fix your issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TaskScope.Workspace is indeed the scope that the tasks are given, the comments on TaskScope.Global seem to imply it's not used currently.

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Aug 31, 2021

I've tried to elaborate more on the changes that caused this: #8995 (comment)

So looks like VSCode pushes everybody to explicitly specify the workspace folder for every task the plugins create (as it seems from the constructor deprecation mentioned above).

With this requirement, for user defined rust tasks and multiworkspace project, we have to default to some workspace folder, either picking the first (which effectively negates part of the #8995 reason behind described in #8955 (comment)) or find a better way to get that folder somehow.

I'm also not greatly familiar with the VSCode internals (and not able to investigate it closely this year unfortunately), but in general it all feels weird, as if we miss something very simple as "get the current workspace" method in the API for such cases. Or this can be an API design issue too.

@oeed
Copy link
Contributor Author

oeed commented Sep 5, 2021

Any further thoughts on this one? Happy to modify to skip tasks that have an undefined scope if that's the right path?

@matklad
Copy link
Member

matklad commented Sep 6, 2021

Not dug deep into this, but here's what I'd do:

  • return undefined if the scope is undefined, as per resolveTask docs
  • if that causes real problems, raise vscode issue asking why VS Code calls us with undefined scopes at all.

Alternatively, why we are returning a new task here? Can't we just set the fields of the task we are given?

@oeed
Copy link
Contributor Author

oeed commented Sep 6, 2021

My intention with using the deprecated constructor was to essentially only modify the task's exec.

That's a great point though, there's no reason the function can't just set the exec on the existing task to my eyes. Can change it to do that if in agreement.

@matklad
Copy link
Member

matklad commented Sep 6, 2021 via email

@oeed
Copy link
Contributor Author

oeed commented Sep 7, 2021

Setting task.execution clears the scope and results in the same error.

The official docs on the subject explicitly make a new task rather and use task.scope ?? vscode.TaskScope.Workspace to compensate for an undefined scope. I've implemented this in the above commit and from my testing works correctly without needing deprecated functions.

So this should be good for a final check I believe.

@SomeoneToIgnore
Copy link
Contributor

So, looks like we've ended up with pretty much what was suggested in #10093 (comment) , great that it was as simple as expected.

Thank you for looking into that.
One last thing, if you want to: we can add a comment somewhere around buildCargoTask function to explain what is happening with the scope and why we set it so (your case may not so clear for people who had never dealt with predefined configs, better warn them before they twist the logic on the next refactoring)

But this is minor, feel free to r+ and merge the current changes if you've had enough of this already.

bors d+

@bors
Copy link
Contributor

bors bot commented Sep 8, 2021

✌️ oeed can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@oeed
Copy link
Contributor Author

oeed commented Sep 8, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 8, 2021

@bors bors bot merged commit 22162aa into rust-lang:master Sep 8, 2021
@oeed oeed deleted the fix-9093-task-resolution branch September 9, 2021 00:04
spookyvision pushed a commit to spookyvision/rust-analyzer that referenced this pull request Sep 9, 2021
10093: fix: Remove incorrectly filtering VS Code cargo task execution resolution by scope r=oeed a=oeed

This fixes rust-lang#9093 ​introduced by rust-lang#8995.

A filter was present on the function that adds the execution definition to Cargo tasks. This would mean Cargo tasks defined in workspaces (i.e. `.code-workspace` files) would not be given an execution, leading to a `There is no task provider registered for tasks of type "cargo".` error as descibed in rust-lang#9093. I have made a minimum reproduction setup [here](https://github.com/oeed/ra-workspace).

This PR essentially removes that check. The `if (scope) { ... }` is to handle the case where `task.scope === undefined` using a deprecated constructor. I'm not sure if that is ever likely to occur and can remove if not needed.

There is some discussion about whether it's necessary to filter the tasks before building them. From my understanding, it shouldn't be needed as we should provide an execution for all `cargo` tasks; but I'm not overly familiar with VS Code internals so I could be wrong. For more info please see [the discussion](rust-lang#8995 (comment)) on rust-lang#8995

Co-authored-by: Oliver Cooper <[email protected]>
@lnicola
Copy link
Member

lnicola commented Sep 9, 2021

changelog fix (first contribution) fix cargo task filtering in Code workspaces

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.

'There is no task provider registered for tasks of type "cargo".' in VS Code code-workspaces
4 participants