Skip to content

Commit 22162aa

Browse files
bors[bot]oeed
andauthored
Merge #10093
10093: fix: Remove incorrectly filtering VS Code cargo task execution resolution by scope r=oeed a=oeed 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](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](#8995 (comment)) on #8995 Co-authored-by: Oliver Cooper <[email protected]>
2 parents 6a80620 + d246a5f commit 22162aa

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

editors/code/src/tasks.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,15 @@ class CargoTaskProvider implements vscode.TaskProvider {
5858

5959
if (definition.type === TASK_TYPE && definition.command) {
6060
const args = [definition.command].concat(definition.args ?? []);
61-
if (isWorkspaceFolder(task.scope)) {
62-
return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner);
63-
}
61+
return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner);
6462
}
6563

6664
return undefined;
6765
}
6866
}
6967

70-
function isWorkspaceFolder(scope?: any): scope is vscode.WorkspaceFolder {
71-
return (scope as vscode.WorkspaceFolder).name !== undefined;
72-
}
73-
7468
export async function buildCargoTask(
75-
target: vscode.WorkspaceFolder,
69+
scope: vscode.WorkspaceFolder | vscode.TaskScope | undefined,
7670
definition: CargoTaskDefinition,
7771
name: string,
7872
args: string[],
@@ -117,7 +111,9 @@ export async function buildCargoTask(
117111

118112
return new vscode.Task(
119113
definition,
120-
target,
114+
// scope can sometimes be undefined. in these situations we default to the workspace taskscope as
115+
// recommended by the official docs: https://code.visualstudio.com/api/extension-guides/task-provider#task-provider)
116+
scope ?? vscode.TaskScope.Workspace,
121117
name,
122118
TASK_SOURCE,
123119
exec,

0 commit comments

Comments
 (0)