PowerShell / vscode-powershell

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

Wish: Is there a way to show Variables when executing line (F5) or block (F8) #1204

Open logg-sar opened 6 years ago

logg-sar commented 6 years ago

Hi there maybe I´m working different then any other or I´m working wrong, but thats the way im doing it.

Defining a variable is mostly one line. For example: $proc=(Get-WmiObject win32_processor).LoadPercentage

After writing I mark the line and execute it via F5, so the variable is filled. If I want to see how its filled I have to mark it and press again F5. It would be easyier to see it as its filled.

I hope I could clarify what I mean - or is somewhere already a setting I didn´t found yet.

Thanks

rkeithhill commented 6 years ago

You can display variable contents in the PowerShell Integrated Console. After executing a line like the one you show above, switch to the PowerShell Integrated Console terminal and type $proc and press enter. That will display the contents of the $proc variable. Unfortunately, display of variables in the VSCode debug view is controlled by VSCode and it only displays variables if it thinks there is a debug session in progress. In the case of F8, a line is executed and not debugged.

In the case of F5, that starts a debug session but if you haven't set a breakpoint and the script is short, it will end before you have a chance to examine variables. To prevent this, set a breakpoint (F9) on some line of your script. Then the debugger will pause at that breakpoint and then you will be able to inspect variables in the debug view.

rjmholt commented 6 years ago

Hi @logg-sar, are the currently extant features that @rkeithhill described suitable? Or is there a different functionality you were looking for? If it's the second one, could you maybe describe it in more detail or give an example?

rk-h commented 6 years ago

Thanks to @rkeithhill for the detailed explanation. This behavior of the debugger bothers me a lot at work. What needs to be done (and by whom) to change this behavior? I am currently creating scripts with ISE in connection with the ISESteroids extension. There the variables remain visible until I end the ISE session, delete the variables or until the variable is overwritten. I like the behavior much more.

rkeithhill commented 6 years ago

You should consider creating an issue on the https://github.com/Microsoft/vscode repo to allow for debug adapters request that the Variables window remain live when not debugging. That this is handy for environments that provide access to their debug adapter/language server via a live terminal inside VSCode - like PowerShell does.

logg-sar commented 6 years ago

@rjmholt

to be honest, the described way is not so suitable. At least for me It would be - in fact it is(!) - easier to mark a variable an press F8 - so i can see the value of the variable in the terminal window.

But I have now an example. There exist a tool called PowerGUI Script Editor from Quest Software (last version is back in 2013 - and unfortunately its not been developed further...) OT - the last version is still available via chocolatey

clipboard02

In this screenshot I marked the lines as seen and pressed F8 - the code is executed and I´m able to see the variables. I can see if and how they are filled.

With the suggested way from rk-h i would need to change into the console and type at least 5 variables and press enter. In my way I would have to mark 5 variables and press F8 and in this screenshot I don´t have to press anything and I can see the variables -> as I said before if and how they are filled.

IMHO the waaaay easiest way to see if my code/variables are correct.

Also IMHO it shouldn´t be to complicate to implement. With execution of the code the variable is in the (script)memory. The script 'knows' it and it could be shown. For example inside this red frame

clipboard04

@rk-h & @rjmholt what do you think about it? Would you also say thats the easiest way to see the variables.

One more thing - as you can see this isn't my native language. Maybe I cant explain so clearly what I meen, but I´m hoping now its clearer.

Thank you

TylerLeonhardt commented 6 years ago

@logg-sar I think what you're requesting would be perfect in a custom view container!

https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributesviewscontainers

We could have a view for variables, cmdlets, remote machines, etc. All in a PowerShell view container.

timkerans commented 5 years ago

@logg-sar I think what you're requesting would be perfect in a custom view container!

https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributesviewscontainers

We could have a view for variables, cmdlets, remote machines, etc. All in a PowerShell view container.

Any traction on this effort?

corbob commented 5 years ago

Well we've got a command explorer now. I'm working on coming up with a way to display the options when trying to insert the command.

I do have a variables pane on my list of things to add, but haven't started down that probably more complex road.

SydneyhSmith commented 5 years ago

from @tbone4711 : Explore the content of variables all the time

At the moment you can only view the content of variables in debugger by setting a breakpoint and run the code. There is no way to select multiple lines and run them by pressing F8 and see the value of all variables like in debugger. Or run a small script by pressing F5. I suggest a pane like the "Variables" in debug but visible all the time(F5 and F8). This helps beginners to get a feeling what's going on during execution, without to start an debug session. It could be like the "PowerShell Command Explorer". An good proposal was posted by logg-sar in issue 1204 "Wish: Is there a way to show Variables when executing line (F5) or block (F8)"

kryten68 commented 4 years ago

Has there been any movement on this? I'm a long time user of Powershell and have used PowerGUI forever, mostly because I can see what I'm doing thanks to the variables explorer. It's just part of my workflow and using VSC - as nice as it is- feels like flying blind. Its a PIA to have to go through a debug session just to see what $a contains. I really wish and hope that this functionality can be brought to VSC.

rk-h commented 4 years ago

Why do you love your product PowerShell so little? Or is the problem technically not solvable? I must honestly say that I am actively discouraging my colleagues from using PowerShell code at the moment. The main reason is that we only use VS code internally and this unsolved variable problem is a showstopper. Please solve it!

kryten68 commented 4 years ago

I agree. A way to see your variables as the script is running - without having to mess around with breakpoints and the debugger would be fantastic. I am using Powershell Pro Tools now - which has this, so it IS possible...it just does not seem to exist either the core product or any free plugins.

SteveL-MSFT commented 4 years ago

The team that works on this feature area is basically 1 engineer's time split across 2 engineers. The unfortunate reality is that we have limited team members to address issues across PowerShell, PowerShellGallery, tooling (PowerShellGet, VSCode-PowerShell, etc...), and OpenSSH. We would all like to have this feature, but as noted above there is currently a workaround by using the interactive console. We do welcome PullRequests for anyone willing to put in the work and submit the code and we'll spend time reviewing that code. In the meantime, just this repo has 300 issues and we're prioritizing issues that block customers at this time. I appreciate your patience on this. Thanks.

kryten68 commented 4 years ago

Fair point. I'm going through some Azure exams over next couple of weeks, but after that I'm very much inclined to take a crack at getting this going as some sort of plugin.

logg-sar commented 4 years ago

The team that works on this feature area is basically 1 engineer's time split across 2 engineers. The unfortunate reality is that we have limited team members to address issues across PowerShell, PowerShellGallery, tooling (PowerShellGet, VSCode-PowerShell, etc...), and OpenSSH. We would all like to have this feature

...

johnjlo commented 3 years ago

I also would love this feature. It's the one major feature from the old powergui that never really made it into newer editors and was critical to the way i scripted. The old programmer Adam Driscoll who worked on powergui did adapt this to the paid vscode addon "powershell pro tools" for vscode as noted in a prior comment. For me, it would literally be the only feature i would be interested from pro tools which is why the cost of it is hard to bite but it seems like an obvious way to use any editor and its functionality for scripting is highly beneficial.

pcgeek86 commented 3 years ago

I'd love the ability to explore variables that are defined in the PowerShell Terminal, without the debugging context. I frequently use this technique to learn various PowerShell APIs for web services.