PowerShell / vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
https://marketplace.visualstudio.com/items/ms-vscode.PowerShell
MIT License
1.7k stars 490 forks source link

Running debugger against module manifest (psd1) file results in confusing error message #503

Closed pcgeek86 closed 7 years ago

pcgeek86 commented 7 years ago

If you hit F5 to invoke the debugger, and currently have a PowerShell module manifest file open, a confusing exception is thrown, and captured in the Visual Studio Code Debug Console.

Cannot run a document in the middle of a pipeline: c:\redacted\redacted.psd1.
At line:0 char:0

It'd be great to be able to set up multiple launch configurations, similar to how NPM works, so that hitting F5 isn't dependent on having the right file selected. For example, you might set up a launch configuration to invoke unit tests, or a separate one to publish the module to the PowerShell Gallery, etc. etc.

Cheers, Trevor Sullivan Docker Captain Microsoft MVP: Cloud & Data Center Management https://trevorsullivan.net https://twitter.com/pcgeek86

daviwil commented 7 years ago

You can already set up multiple launch configurations that launch specific file paths, but launching .psd1 files isn't currently supported. I'll either add support for it or add an appropriate error message.

rkeithhill commented 7 years ago

You can set up multiple configurations. In the Debug view, press the gear icon to open your launch.json file. Now press the Add Configuration button and pick the "PowerShell: Launch Script" and fill in the script you want to launch.

rkeithhill commented 7 years ago

Also, be sure to check out my Scripting Guys Debugging in VS Code Part 2 blog post that goes live on Monday. It covers this in a fair amount of detail.

rkeithhill commented 7 years ago

And for launching Pester tests - see #487. It can be made to work now but I'm not sure I would rely on it - which is why I didn't add support yet.

pcgeek86 commented 7 years ago

Sounds good, thanks. I'd suggest keeping this open for the purposes of tracking "launching" a .psd1 file. What exactly would that do? I would maybe throw an exception, saying that you can't launch a .psd1, maybe? Not sure I have the best solution, but the current exception certainly isn't immediately helpful.

daviwil commented 7 years ago

Ideally it'd just call Import-Module with that path and drop you into the console.

rkeithhill commented 7 years ago

On the extension, do we have a chance to inspect the "script": arg before it gets sent to PSES? Either in VSCode or PSES we could test that A) the file exists (in case we allow an arg like Invoke-Pester which isn't a file) and if it is a file that exists B) has to have certain extension: .ps1, .psd1, .psm1 etc. Right now, it will try to launch against any file type (.md, .yml, .json, etc).

daviwil commented 7 years ago

Yep, check out this function:

https://github.com/PowerShell/vscode-powershell/blob/develop/src/features/DebugSession.ts#L26

If you want to stop execution from happening, skip the vscode.commands.executeCommand('vscode.startDebug'...) call.

rkeithhill commented 7 years ago

Should we initially not allow debugging of a .psd1 file? It's more of a data file and it might not even be a module manifest. It might be a string localization file. We could always come back later and enable .psd1 debugging.

daviwil commented 7 years ago

Hmmm, good point. We can probably figure out whether it's a module manifest file, but not necessarily worth doing right now.

gabriel-vanca commented 2 months ago

Why is this still not supported?