Skip to content

Commit

Permalink
Allow custom arguments to provided "func host start" task (#1136)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba authored Mar 28, 2019
1 parent dbad338 commit 1200241
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 23 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/pickFuncProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/debug/FuncDebugProviderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class FuncDebugProviderBase implements DebugConfigurationProvide

private readonly _debugPorts: Map<WorkspaceFolder | undefined, number | undefined> = new Map();

public abstract getShellExecution(folder: WorkspaceFolder): Promise<ShellExecution>;
public abstract getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise<ShellExecution>;

public async provideDebugConfigurations(folder: WorkspaceFolder | undefined, _token?: CancellationToken): Promise<DebugConfiguration[]> {
// tslint:disable-next-line: no-this-assignment
Expand Down
10 changes: 6 additions & 4 deletions src/debug/FuncTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {};
}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/debug/JavaDebugProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<ShellExecution> {
public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise<ShellExecution> {
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);
}
}
6 changes: 3 additions & 3 deletions src/debug/NodeDebugProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<ShellExecution> {
public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise<ShellExecution> {
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);
}
}
6 changes: 3 additions & 3 deletions src/debug/PowerShellDebugProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<ShellExecution> {
public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise<ShellExecution> {
const port: string | number = this.getDebugPortOrPipeName(folder);
const options: ShellExecutionOptions = { env: { PSWorkerCustomPipeName: `${port}` } };
return new ShellExecution(funcHostStartCommand, options);
return new ShellExecution(commandLine, options);
}
}
8 changes: 4 additions & 4 deletions src/debug/PythonDebugProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<ShellExecution> {
const command: string = venvUtils.convertToVenvCommand(funcHostStartCommand, folder.uri.fsPath);
public async getShellExecution(folder: WorkspaceFolder, commandLine: string): Promise<ShellExecution> {
commandLine = venvUtils.convertToVenvCommand(commandLine, folder.uri.fsPath);
const port: number = <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);
}
}

Expand Down
45 changes: 45 additions & 0 deletions src/debug/getFuncTaskCommand.ts
Original file line number Diff line number Diff line change
@@ -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<IFuncTaskDefinition[]>('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;
}

0 comments on commit 1200241

Please sign in to comment.