Skip to content
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

Enable debugging of untitled script files #555

Closed
daviwil opened this issue Mar 15, 2017 · 6 comments
Closed

Enable debugging of untitled script files #555

daviwil opened this issue Mar 15, 2017 · 6 comments
Labels
Issue-Enhancement A feature request (enhancement).
Milestone

Comments

@daviwil
Copy link
Contributor

daviwil commented Mar 15, 2017

VS Code will soon be gaining the ability to launch the debugger on untitled, unsaved files. Since this is a scenario that works in the ISE, we should leverage VS Code's new feature to provide it in the PowerShell extension too.

microsoft/vscode#19415

/cc @dfinke

@daviwil daviwil added the Issue-Enhancement A feature request (enhancement). label Mar 15, 2017
@daviwil daviwil added this to the 0.11.0 milestone Mar 15, 2017
@daviwil daviwil modified the milestones: 0.11.0, 0.12.0 Mar 22, 2017
daviwil added a commit to daviwil/PowerShellEditorServices that referenced this issue Mar 31, 2017
This change enables the debugging of untitled script files by executing
their contents directly, not as a script file.  Since the language server
has already received the contents of the untitled file, we can easily
access them in the server for execution purposes.

Part of PowerShell/vscode-powershell#555.
daviwil added a commit to daviwil/vscode-powershell that referenced this issue Mar 31, 2017
This change enables untitled files to be debugged when they are set to the
'powershell' language mode.

Fixes PowerShell#555.
@grumpkin
Copy link

grumpkin commented Jul 6, 2017

VsCode Verion: 1.13.1
PS Extension Version: 1.4.1
OS: Windows 10 1607

I'm sure this is me not understanding, but how do you do this type of debugging? I have a new untitled, unsaved file (language mode set to PowerShell) with a function defined and then a line that runs that function. When I press F5 it just runs everything without breaking into the debugger. I can't set a breakpoint because the file isn't saved so how do you go about debugging an untitled, unsaved file?

@rkeithhill
Copy link
Contributor

rkeithhill commented Jul 6, 2017

ISE does not allow you to set a breakpoint in an unsaved file. The same applies to the VSCode PowerShell extension. Internally, it uses the Set-PSBreakpoint command which, for a line breakpoint, requires a path.

You can set a command breakpoint and the debugger will hit that e.g.:

 function foo {}
 
 foo
 $a = 7
 $b = 36
 $c = 42

Set a command breakpoint on foo and the debugger will break there and then you can single step through the rest of the code.

It would be nice if this feature supported a "break on entry" option. Then you wouldn't need the dummy function hack to get the debugger to break. That said, it can be challenging to debug without line breakpoints so it is best to just save the file.

@rkeithhill
Copy link
Contributor

Wait a tic, if I hit the command breakpoint I see another editor window open that uses a temp (saved) file so you can set line breakpoints. The bug here @daviwil is that this script listing.ps1 file isn't showing up by default. It doesn't show up if I don't have the command breakpoint set. Ideally it should show up when you start the debugger. Maybe this is a case where the script is so short it completes before this other windows opens?

@grumpkin
Copy link

grumpkin commented Jul 6, 2017

Maybe I'm still doing this wrong but I still can't get it to break. I have the unsaved script file that, creates a dummy function called foo, calls that function, then does what I actually want. In the PowerShell Integrated Console I run Set-PSBreakpoint -Command foo (I don't know if that is actually what you meant by "Set a command breakpoint"), press F5 and it still just runs the entire script.

Edit: Ok, I can get it to break by setting the command breakpoint and then running the function from within the PowerShell Integrated Console rather than pressing F5. Only seems to work once as if I run the function again it doesn't break. It does if I set the breakpoint again.

A "break on entry" option would be awesome for debugging simple test scripts that I'd rather not have to save.

@rkeithhill
Copy link
Contributor

Trying setting the breakpoint in the VSCode Debug panel. At the bottom, open the Breakpoints view, press the + button and type in foo:

image

@grumpkin
Copy link

grumpkin commented Jul 6, 2017

That worked. Thanks very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

3 participants