Skip to content

Add optional UI to prompt for script args. #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
{
"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 (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}"
Expand Down
36 changes: 29 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -175,32 +176,45 @@
"program": "./out/debugAdapter.js",
"runtime": "node",
"variables": {
"PickPSHostProcess": "PowerShell.PickPSHostProcess"
"PickPSHostProcess": "PowerShell.PickPSHostProcess",
"SpecifyScriptArgs": "PowerShell.SpecifyScriptArgs"
},
"languages": [
"powershell"
],
"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}\""
}
},
{
"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}\""
Expand Down Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
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
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 =
Expand Down