From 2ec6f65e1c3077a662e68bda93a9c4cf27dc9b6e Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 8 Feb 2021 16:08:41 +1100 Subject: [PATCH] Add args to tasks. Use venv in task resolver --- package.json | 8 ++++++++ src/djangoTaskProvider.ts | 7 +++++-- src/setupToolsTaskProvider.ts | 7 +++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 72824ad..a778ce6 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,10 @@ "file": { "type": "string", "description": "The setup.py file path that provides the command. Can be omitted and root is assumed." + }, + "args": { + "type": "array", + "description": "Optional list of arguments to the task" } } }, @@ -50,6 +54,10 @@ "file": { "type": "string", "description": "The manage.py file path that provides the command. Can be omitted and root is assumed." + }, + "args": { + "type": "array", + "description": "Optional list of arguments to the task" } } } diff --git a/src/djangoTaskProvider.ts b/src/djangoTaskProvider.ts index 3b26d3d..932e65c 100644 --- a/src/djangoTaskProvider.ts +++ b/src/djangoTaskProvider.ts @@ -29,11 +29,14 @@ export class DjangoTaskProvider implements vscode.TaskProvider { public resolveTask(_task: vscode.Task): vscode.Task | undefined { const task = _task.definition.task; - + var pythonPath = vscode.workspace.getConfiguration('python').get('pythonPath'); + if (!pythonPath){ + pythonPath = 'python'; + } if (task) { // resolveTask requires that the same definition object be used. const definition: DjangoTaskDefinition = _task.definition; - return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'django', new vscode.ShellExecution(`python ${definition.task}`)); + return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'django', new vscode.ShellExecution(`${pythonPath} ${definition.task}`)); } return undefined; } diff --git a/src/setupToolsTaskProvider.ts b/src/setupToolsTaskProvider.ts index b739d6e..3273962 100644 --- a/src/setupToolsTaskProvider.ts +++ b/src/setupToolsTaskProvider.ts @@ -29,11 +29,14 @@ export class SetupToolsTaskProvider implements vscode.TaskProvider { public resolveTask(_task: vscode.Task): vscode.Task | undefined { const task = _task.definition.task; - + var pythonPath = vscode.workspace.getConfiguration('python').get('pythonPath'); + if (!pythonPath){ + pythonPath = 'python'; + } if (task) { // resolveTask requires that the same definition object be used. const definition: SetupToolsTaskDefinition = _task.definition; - return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'setuptools', new vscode.ShellExecution(`python ${definition.task}`)); + return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'setuptools', new vscode.ShellExecution(`${pythonPath} ${definition.task}`)); } return undefined; }