diff --git a/examples/.vscode/launch.json b/examples/.vscode/launch.json index 264dd97dd2..846f6ab009 100644 --- a/examples/.vscode/launch.json +++ b/examples/.vscode/launch.json @@ -4,7 +4,7 @@ { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch (current file)", + "name": "PowerShell Launch Current File", "script": "${file}", "args": [], "cwd": "${file}" @@ -12,7 +12,15 @@ { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch (DebugTest.ps1)", + "name": "PowerShell Launch Current File w/Args Prompt", + "script": "${file}", + "args": [ "${command:SpecifyScriptArgs}" ], + "cwd": "${file}" + }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Launch DebugTest.ps1", "script": "${workspaceRoot}/DebugTest.ps1", "args": ["-Count 55 -DelayMilliseconds 250"], "cwd": "${workspaceRoot}" diff --git a/package.json b/package.json index c29dbb81dc..c23e77de8f 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "onCommand:PowerShell.NewProjectFromTemplate", "onCommand:PowerShell.OpenExamplesFolder", "onCommand:PowerShell.StartDebugSession", - "onCommand:PowerShell.PickPSHostProcess" + "onCommand:PowerShell.PickPSHostProcess", + "onCommand:PowerShell.SpecifyScriptArgs" ], "dependencies": { "vscode-languageclient": "1.3.1" @@ -175,7 +176,8 @@ "program": "./out/debugAdapter.js", "runtime": "node", "variables": { - "PickPSHostProcess": "PowerShell.PickPSHostProcess" + "PickPSHostProcess": "PowerShell.PickPSHostProcess", + "SpecifyScriptArgs": "PowerShell.SpecifyScriptArgs" }, "languages": [ "powershell" @@ -183,12 +185,24 @@ "startSessionCommand": "PowerShell.StartDebugSession", "configurationSnippets": [ { - "label": "PowerShell: Launch (current file)", + "label": "PowerShell: Launch Current File", "description": "Launch current file (in active editor window) under debugger", "body": { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch (current file)", + "name": "PowerShell Launch Current File", + "script": "^\"\\${file}\"", + "args": [], + "cwd": "^\"\\${file}\"" + } + }, + { + "label": "PowerShell: Launch - Current File w/Args Prompt", + "description": "Launch current file (in active editor window) under debugger, prompting first for script arguments", + "body": { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Launch Current File w/Args Prompt", "script": "^\"\\${file}\"", "args": [], "cwd": "^\"\\${file}\"" @@ -196,11 +210,11 @@ }, { "label": "PowerShell: Launch Script", - "description": "Launch specified script under debugger", + "description": "Launch specified script or path to script under debugger", "body": { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch (${Script})", + "name": "PowerShell Launch ${Script}", "script": "^\"\\${workspaceRoot}/${Script}\"", "args": [], "cwd": "^\"\\${workspaceRoot}\"" @@ -289,11 +303,19 @@ { "type": "PowerShell", "request": "launch", - "name": "PowerShell Launch (current file)", + "name": "PowerShell Launch Current File", "script": "${file}", "args": [], "cwd": "${file}" }, + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Launch Current File w/Args Prompt", + "script": "${file}", + "args": [ "${command:SpecifyScriptArgs}" ], + "cwd": "${file}" + }, { "type": "PowerShell", "request": "attach", diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 17a94ce899..ca694b0fc5 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -106,6 +106,69 @@ export class DebugSessionFeature implements IFeature { } } +export class SpecifyScriptArgsFeature implements IFeature { + + private command: vscode.Disposable; + private languageClient: LanguageClient; + private context: vscode.ExtensionContext; + private emptyInputBoxBugFixed: boolean; + + constructor(context: vscode.ExtensionContext) { + this.context = context; + + let vscodeVersionArray = vscode.version.split('.'); + let editorVersion = { + major: Number(vscodeVersionArray[0]), + minor: Number(vscodeVersionArray[1]), + } + + this.emptyInputBoxBugFixed = + ((editorVersion.major > 1) || + ((editorVersion.major == 1) && (editorVersion.minor > 12))); + + this.command = + vscode.commands.registerCommand('PowerShell.SpecifyScriptArgs', () => { + return this.specifyScriptArguments(); + }); + } + + public setLanguageClient(languageclient: LanguageClient) { + this.languageClient = languageclient; + } + + public dispose() { + this.command.dispose(); + } + + private specifyScriptArguments(): Thenable { + const powerShellDbgScriptArgsKey = 'powerShellDebugScriptArgs'; + + let options: vscode.InputBoxOptions = { + ignoreFocusOut: true, + placeHolder: "Enter script arguments or leave empty to pass no args" + } + + if (this.emptyInputBoxBugFixed) { + let prevArgs = this.context.workspaceState.get(powerShellDbgScriptArgsKey, ''); + if (prevArgs.length > 0) { + options.value = prevArgs; + } + } + + return vscode.window.showInputBox(options).then(text => { + // When user cancel's the input box (by pressing Esc), the text value is undefined. + if (text !== undefined) { + if (this.emptyInputBoxBugFixed) { + this.context.workspaceState.update(powerShellDbgScriptArgsKey, text); + } + return new Array(text); + } + + return text; + }); + } +} + interface ProcessItem extends vscode.QuickPickItem { pid: string; // payload for the QuickPick UI } diff --git a/src/main.ts b/src/main.ts index 14f8ccf7de..bd90b614f3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,6 +21,7 @@ import { CodeActionsFeature } from './features/CodeActions'; import { RemoteFilesFeature } from './features/RemoteFiles'; import { DebugSessionFeature } from './features/DebugSession'; import { PickPSHostProcessFeature } from './features/DebugSession'; +import { SpecifyScriptArgsFeature } from './features/DebugSession'; import { SelectPSSARulesFeature } from './features/SelectPSSARules'; import { FindModuleFeature } from './features/PowerShellFindModule'; import { NewFileOrProjectFeature } from './features/NewFileOrProject'; @@ -113,7 +114,8 @@ export function activate(context: vscode.ExtensionContext): void { new DocumentFormatterFeature(), new RemoteFilesFeature(), new DebugSessionFeature(), - new PickPSHostProcessFeature() + new PickPSHostProcessFeature(), + new SpecifyScriptArgsFeature(context) ]; sessionManager =