Skip to content

Commit 4d8bc56

Browse files
committed
Fix PowerShell.Debug.Start to just launch current file
This command previously used a private API `workbench.action.debug.start` which led to bad behavior. Namely it meant that while a PowerShell file was opened, if the triangular "Start" button was pressed, it would start Code's currently selected launch configuration which is often not what the user intended. 1. If there was no `launch.json` this worked accidentally in that we resolved a default configuration to launch the current file. 2. If a working PowerShell configuration was selected, it may work as intended, unless that configuration was to attach. 3. If any other configuration was selected, the user would be left bewildered as to why, say, a Python debugger was started for a PowerShell file. Instead we call the public API to start the debugger and give it a copy of our "Launch Current File" configuration, which is what the user intended do when clicking the "Start" button on a PowerShell file. This may introduce some breaking behavior if the user was relying on this button to start their current correctly configured (and selected) launch configuration with possible extra customizations. However, in that the case the user can use Code's built-in options to call the private API we were calling preivously, namely F5 or the triangular start button in the debugger workbench (instead of our button).
1 parent 6e9ac34 commit 4d8bc56

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/features/ExtensionCommands.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,25 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
215215
});
216216

217217
this.command3 = vscode.commands.registerCommand('PowerShell.ClosePanel',
218-
async () => { await vscode.commands.executeCommand('workbench.action.closePanel'); }),
218+
() => { vscode.commands.executeCommand('workbench.action.closePanel'); }),
219219

220220
this.command4 = vscode.commands.registerCommand('PowerShell.PositionPanelLeft',
221-
async () => { await vscode.commands.executeCommand('workbench.action.positionPanelLeft'); }),
221+
() => { vscode.commands.executeCommand('workbench.action.positionPanelLeft'); }),
222222

223223
this.command5 = vscode.commands.registerCommand('PowerShell.PositionPanelBottom',
224-
async () => { await vscode.commands.executeCommand('workbench.action.positionPanelBottom'); }),
224+
() => { vscode.commands.executeCommand('workbench.action.positionPanelBottom'); }),
225225

226226
this.command6 = vscode.commands.registerCommand('PowerShell.Debug.Start',
227-
async () => { await vscode.commands.executeCommand('workbench.action.debug.start'); })
227+
() => {
228+
// TODO: Use a named debug configuration.
229+
vscode.debug.startDebugging(undefined, {
230+
name: "PowerShell: Launch Current File",
231+
type: "PowerShell",
232+
request: "launch",
233+
script: "${file}",
234+
cwd: "${file}",
235+
})
236+
})
228237
}
229238

230239
public setLanguageClient(languageclient: LanguageClient) {

0 commit comments

Comments
 (0)