From 1200241b475bad976204892b68c3949f33a7db8b Mon Sep 17 00:00:00 2001 From: Eric Jizba Date: Thu, 28 Mar 2019 12:02:54 -0700 Subject: [PATCH] Allow custom arguments to provided "func host start" task (#1136) --- package-lock.json | 6 ++-- package.json | 2 +- src/commands/pickFuncProcess.ts | 2 +- src/debug/FuncDebugProviderBase.ts | 2 +- src/debug/FuncTaskProvider.ts | 10 ++++--- src/debug/JavaDebugProvider.ts | 6 ++-- src/debug/NodeDebugProvider.ts | 6 ++-- src/debug/PowerShellDebugProvider.ts | 6 ++-- src/debug/PythonDebugProvider.ts | 8 ++--- src/debug/getFuncTaskCommand.ts | 45 ++++++++++++++++++++++++++++ 10 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 src/debug/getFuncTaskCommand.ts diff --git a/package-lock.json b/package-lock.json index ea86bee66..b491a3776 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9590,9 +9590,9 @@ } }, "vscode-azureextensionui": { - "version": "0.22.1", - "resolved": "https://registry.npmjs.org/vscode-azureextensionui/-/vscode-azureextensionui-0.22.1.tgz", - "integrity": "sha512-5OGIhGQC0SD0V192pbPADmwe53TxS/hYQyUxB+wqciBdbK4O5e7Dt+IgMJv+NX4j68LCGpL6pfi0z5RUJ+02cQ==", + "version": "0.22.2", + "resolved": "https://registry.npmjs.org/vscode-azureextensionui/-/vscode-azureextensionui-0.22.2.tgz", + "integrity": "sha512-j/RfJs/grWHDgGmVCcUhEDSrbSfxGqF0DCdBJk8PZ9e6jLStl1KE6wdxmSrB6TAkieqSg+GbTjGc+e+7z5ha+g==", "requires": { "azure-arm-resource": "^3.0.0-preview", "azure-arm-storage": "^3.1.0", diff --git a/package.json b/package.json index bc71e956a..7298d83e1 100644 --- a/package.json +++ b/package.json @@ -891,7 +891,7 @@ "request-promise": "^4.2.2", "semver": "^5.5.0", "vscode-azureappservice": "^0.34.1", - "vscode-azureextensionui": "^0.22.1", + "vscode-azureextensionui": "^0.22.2", "vscode-azurekudu": "^0.1.8", "vscode-nls": "^4.0.0", "websocket": "^1.0.25", diff --git a/src/commands/pickFuncProcess.ts b/src/commands/pickFuncProcess.ts index 5f19d93bf..1127adee7 100644 --- a/src/commands/pickFuncProcess.ts +++ b/src/commands/pickFuncProcess.ts @@ -29,7 +29,7 @@ export async function pickFuncProcess(this: IActionContext, debugConfig: vscode. }); if (!funcTask) { - throw new Error(localize('noFuncTask', 'Failed to find "{0}" task.', funcHostStartCommand)); + throw new Error(localize('noFuncTask', 'Failed to find "{0}" task.', preLaunchTaskName || funcHostStartCommand)); } const settingKey: string = 'pickProcessTimeout'; diff --git a/src/debug/FuncDebugProviderBase.ts b/src/debug/FuncDebugProviderBase.ts index 3edf54061..65c3fa975 100644 --- a/src/debug/FuncDebugProviderBase.ts +++ b/src/debug/FuncDebugProviderBase.ts @@ -15,7 +15,7 @@ export abstract class FuncDebugProviderBase implements DebugConfigurationProvide private readonly _debugPorts: Map = new Map(); - public abstract getShellExecution(folder: WorkspaceFolder): Promise; + public abstract getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise; public async provideDebugConfigurations(folder: WorkspaceFolder | undefined, _token?: CancellationToken): Promise { // tslint:disable-next-line: no-this-assignment diff --git a/src/debug/FuncTaskProvider.ts b/src/debug/FuncTaskProvider.ts index 964ffdc25..684b0a9b6 100644 --- a/src/debug/FuncTaskProvider.ts +++ b/src/debug/FuncTaskProvider.ts @@ -6,9 +6,10 @@ import { CancellationToken, ShellExecution, Task, TaskProvider, workspace, WorkspaceFolder } from 'vscode'; import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azureextensionui'; import { tryGetFunctionProjectRoot } from '../commands/createNewProject/verifyIsProject'; -import { extInstallCommand, func, funcExtInstallCommand, funcHostStartCommand, funcWatchProblemMatcher, hostStartCommand, ProjectLanguage, projectLanguageSetting } from '../constants'; +import { extInstallCommand, func, funcExtInstallCommand, funcWatchProblemMatcher, hostStartCommand, ProjectLanguage, projectLanguageSetting } from '../constants'; import { getFuncExtensionSetting } from '../ProjectSettings'; import { FuncDebugProviderBase } from './FuncDebugProviderBase'; +import { getFuncTaskCommand, IFuncTaskCommand } from './getFuncTaskCommand'; import { getPythonTasks } from './getPythonTasks'; import { JavaDebugProvider } from './JavaDebugProvider'; import { NodeDebugProvider } from './NodeDebugProvider'; @@ -93,7 +94,8 @@ export class FuncTaskProvider implements TaskProvider { default: } - const shellExecution: ShellExecution = debugProvider ? await debugProvider.getShellExecution(folder) : new ShellExecution(funcHostStartCommand); + const funcCommand: IFuncTaskCommand = getFuncTaskCommand(folder, hostStartCommand, /^\s*(host )?start/i); + const shellExecution: ShellExecution = debugProvider ? await debugProvider.getShellExecution(folder, funcCommand.commandLine) : new ShellExecution(funcCommand.commandLine); if (!shellExecution.options) { shellExecution.options = {}; } @@ -102,10 +104,10 @@ export class FuncTaskProvider implements TaskProvider { return new Task( { type: func, - command: hostStartCommand + command: funcCommand.taskName }, folder, - hostStartCommand, + funcCommand.taskName, func, shellExecution, funcWatchProblemMatcher diff --git a/src/debug/JavaDebugProvider.ts b/src/debug/JavaDebugProvider.ts index 3d4fe7c5a..d6c28549d 100644 --- a/src/debug/JavaDebugProvider.ts +++ b/src/debug/JavaDebugProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { DebugConfiguration, ShellExecution, ShellExecutionOptions, WorkspaceFolder } from 'vscode'; -import { funcHostStartCommand, hostStartTaskName, localhost } from '../constants'; +import { hostStartTaskName, localhost } from '../constants'; import { localize } from '../localize'; import { FuncDebugProviderBase } from './FuncDebugProviderBase'; @@ -23,9 +23,9 @@ export class JavaDebugProvider extends FuncDebugProviderBase { protected readonly defaultPortOrPipeName: number = defaultJavaDebugPort; protected readonly debugConfig: DebugConfiguration = javaDebugConfig; - public async getShellExecution(folder: WorkspaceFolder): Promise { + public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise { const port: string | number = this.getDebugPortOrPipeName(folder); const options: ShellExecutionOptions = { env: { languageWorkers__java__arguments: `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${port}` } }; - return new ShellExecution(funcHostStartCommand, options); + return new ShellExecution(commandLine, options); } } diff --git a/src/debug/NodeDebugProvider.ts b/src/debug/NodeDebugProvider.ts index 4d8027d0f..033807cb6 100644 --- a/src/debug/NodeDebugProvider.ts +++ b/src/debug/NodeDebugProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { DebugConfiguration, ShellExecution, ShellExecutionOptions, WorkspaceFolder } from 'vscode'; -import { funcHostStartCommand, hostStartTaskName } from '../constants'; +import { hostStartTaskName } from '../constants'; import { localize } from '../localize'; import { FuncDebugProviderBase } from './FuncDebugProviderBase'; @@ -22,9 +22,9 @@ export class NodeDebugProvider extends FuncDebugProviderBase { protected readonly defaultPortOrPipeName: number = defaultNodeDebugPort; protected readonly debugConfig: DebugConfiguration = nodeDebugConfig; - public async getShellExecution(folder: WorkspaceFolder): Promise { + public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise { const port: string | number = this.getDebugPortOrPipeName(folder); const options: ShellExecutionOptions = { env: { languageWorkers__node__arguments: `--inspect=${port}` } }; - return new ShellExecution(funcHostStartCommand, options); + return new ShellExecution(commandLine, options); } } diff --git a/src/debug/PowerShellDebugProvider.ts b/src/debug/PowerShellDebugProvider.ts index 741229451..81cf2a71e 100644 --- a/src/debug/PowerShellDebugProvider.ts +++ b/src/debug/PowerShellDebugProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { DebugConfiguration, ShellExecution, ShellExecutionOptions, WorkspaceFolder } from 'vscode'; -import { funcHostStartCommand, hostStartTaskName } from '../constants'; +import { hostStartTaskName } from '../constants'; import { localize } from '../localize'; import { FuncDebugProviderBase } from './FuncDebugProviderBase'; @@ -23,9 +23,9 @@ export class PowerShellDebugProvider extends FuncDebugProviderBase { protected defaultPortOrPipeName: string | number = defaultCustomPipeName; protected readonly debugConfig: DebugConfiguration = powershellDebugConfig; - public async getShellExecution(folder: WorkspaceFolder): Promise { + public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise { const port: string | number = this.getDebugPortOrPipeName(folder); const options: ShellExecutionOptions = { env: { PSWorkerCustomPipeName: `${port}` } }; - return new ShellExecution(funcHostStartCommand, options); + return new ShellExecution(commandLine, options); } } diff --git a/src/debug/PythonDebugProvider.ts b/src/debug/PythonDebugProvider.ts index b3251f158..42aa74478 100644 --- a/src/debug/PythonDebugProvider.ts +++ b/src/debug/PythonDebugProvider.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { DebugConfiguration, Extension, extensions, ShellExecution, ShellExecutionOptions, WorkspaceFolder } from 'vscode'; -import { funcHostStartCommand, hostStartTaskName, localhost } from '../constants'; +import { hostStartTaskName, localhost } from '../constants'; import { localize } from '../localize'; import { venvUtils } from '../utils/venvUtils'; import { FuncDebugProviderBase } from './FuncDebugProviderBase'; @@ -23,11 +23,11 @@ export class PythonDebugProvider extends FuncDebugProviderBase { protected readonly defaultPortOrPipeName: number = defaultPythonDebugPort; protected readonly debugConfig: DebugConfiguration = pythonDebugConfig; - public async getShellExecution(folder: WorkspaceFolder): Promise { - const command: string = venvUtils.convertToVenvCommand(funcHostStartCommand, folder.uri.fsPath); + public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise { + commandLine = venvUtils.convertToVenvCommand(commandLine, folder.uri.fsPath); const port: number = this.getDebugPortOrPipeName(folder); const options: ShellExecutionOptions = { env: { languageWorkers__python__arguments: await getPythonCommand(localhost, port) } }; - return new ShellExecution(command, options); + return new ShellExecution(commandLine, options); } } diff --git a/src/debug/getFuncTaskCommand.ts b/src/debug/getFuncTaskCommand.ts new file mode 100644 index 000000000..13c4e114b --- /dev/null +++ b/src/debug/getFuncTaskCommand.ts @@ -0,0 +1,45 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { TaskDefinition, workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode'; +import { func } from '../constants'; + +interface IFuncTaskDefinition extends TaskDefinition { + command?: string; +} + +/** + * Gets the exact command line (aka with any user-specified args) to be used in our provided task + */ +export function getFuncTaskCommand(folder: WorkspaceFolder, defaultCommand: string, commandsToMatch: RegExp): IFuncTaskCommand { + let command: string = defaultCommand; + try { + const config: WorkspaceConfiguration = workspace.getConfiguration('tasks', folder.uri); + // tslint:disable-next-line: strict-boolean-expressions + const tasks: IFuncTaskDefinition[] = config.get('tasks') || []; + const funcTask: IFuncTaskDefinition | undefined = tasks.find(t => t.type === func && !!t.command && commandsToMatch.test(t.command)); + if (funcTask && funcTask.command) { + command = funcTask.command; + } + } catch { + // ignore and use default + } + return { + taskName: command, + commandLine: `func ${command}` + }; +} + +export interface IFuncTaskCommand { + /** + * Used to identify the task. It matches the command as defined in the task by the user and is the same as commandLine, except without 'func' at the beginning. + */ + taskName: string; + + /** + * The actual command line to run + */ + commandLine: string; +}