From 0517247bbc30f7f72f4c2f993fe345d3c0634c57 Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Tue, 31 Aug 2021 20:35:22 +1200 Subject: [PATCH 1/3] Don't filter cargo tasks by scope Fixes #9093 --- editors/code/src/tasks.ts | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts index 1d50d03800..6481822eb4 100644 --- a/editors/code/src/tasks.ts +++ b/editors/code/src/tasks.ts @@ -58,21 +58,15 @@ class CargoTaskProvider implements vscode.TaskProvider { if (definition.type === TASK_TYPE && definition.command) { const args = [definition.command].concat(definition.args ?? []); - if (isWorkspaceFolder(task.scope)) { - return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner); - } + return await buildCargoTask(task.scope, definition, task.name, args, this.config.cargoRunner); } return undefined; } } -function isWorkspaceFolder(scope?: any): scope is vscode.WorkspaceFolder { - return (scope as vscode.WorkspaceFolder).name !== undefined; -} - export async function buildCargoTask( - target: vscode.WorkspaceFolder, + scope: vscode.WorkspaceFolder | vscode.TaskScope | undefined, definition: CargoTaskDefinition, name: string, args: string[], @@ -115,14 +109,26 @@ export async function buildCargoTask( exec = new vscode.ProcessExecution(fullCommand[0], fullCommand.slice(1), definition); } - return new vscode.Task( - definition, - target, - name, - TASK_SOURCE, - exec, - ['$rustc'] - ); + if (scope) { + return new vscode.Task( + definition, + scope, + name, + TASK_SOURCE, + exec, + ['$rustc'] + ); + } + else { + // if the original task did not provide a scope retain the original lack of scope + return new vscode.Task( + definition, + name, + TASK_SOURCE, + exec, + ['$rustc'] + ); + } } export function activateTaskProvider(config: Config): vscode.Disposable { From 001608914b2ee39b38ca919e41a8c8f4e4b70655 Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Wed, 8 Sep 2021 10:46:31 +1200 Subject: [PATCH 2/3] Removed deprecated Task constructor --- editors/code/src/tasks.ts | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts index 6481822eb4..02b4d34ff6 100644 --- a/editors/code/src/tasks.ts +++ b/editors/code/src/tasks.ts @@ -109,26 +109,14 @@ export async function buildCargoTask( exec = new vscode.ProcessExecution(fullCommand[0], fullCommand.slice(1), definition); } - if (scope) { - return new vscode.Task( - definition, - scope, - name, - TASK_SOURCE, - exec, - ['$rustc'] - ); - } - else { - // if the original task did not provide a scope retain the original lack of scope - return new vscode.Task( - definition, - name, - TASK_SOURCE, - exec, - ['$rustc'] - ); - } + return new vscode.Task( + definition, + scope ?? vscode.TaskScope.Workspace, + name, + TASK_SOURCE, + exec, + ['$rustc'] + ); } export function activateTaskProvider(config: Config): vscode.Disposable { From d246a5f58b825d5113b75a68e6e424035243dcad Mon Sep 17 00:00:00 2001 From: Oliver Cooper Date: Thu, 9 Sep 2021 08:50:24 +1200 Subject: [PATCH 3/3] Undefined scope comment --- editors/code/src/tasks.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editors/code/src/tasks.ts b/editors/code/src/tasks.ts index 02b4d34ff6..99edd9ae9d 100644 --- a/editors/code/src/tasks.ts +++ b/editors/code/src/tasks.ts @@ -111,6 +111,8 @@ export async function buildCargoTask( return new vscode.Task( definition, + // scope can sometimes be undefined. in these situations we default to the workspace taskscope as + // recommended by the official docs: https://code.visualstudio.com/api/extension-guides/task-provider#task-provider) scope ?? vscode.TaskScope.Workspace, name, TASK_SOURCE,