Skip to content

Fix running untitled scripts with arguments (but break line breakpoints) #1702

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 4 commits into from
Feb 15, 2022

Conversation

andyleejordan
Copy link
Member

@andyleejordan andyleejordan commented Feb 9, 2022

So the extant hack that enabled debugging untitled scripts is really
untenable. It shifted the user's args by one since it ran the untitled
script as the first arg to the dot-source operator. Unfortunately, there
doesn't seem to be a clear way to break on lines in an untitled script.
However, Wait-Debugger and command breakpoints should still work.

Fixes PowerShell/vscode-powershell#3655
Fixes PowerShell/vscode-powershell#3770

@andyleejordan andyleejordan force-pushed the andschwa/untitled-with-args branch from 83c078c to 62f81c8 Compare February 15, 2022 00:59
@andyleejordan
Copy link
Member Author

This essentially reverts #1611 and stops attempting to quote arguments given to the script launcher.

@andyleejordan andyleejordan force-pushed the andschwa/untitled-with-args branch 2 times, most recently from 5687a9e to 13b5cbb Compare February 15, 2022 19:58
@andyleejordan andyleejordan marked this pull request as ready for review February 15, 2022 20:19
Copy link
Collaborator

@JustinGrote JustinGrote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. RIP argumentescapingtests 🪦

Attempting to be "helpful" by escaping arguments proved to cause more
issues than it solved. We can instead massively simplify our script
launching logic (and fix yet another test that had a "maybe bug") by
just launching what the user gave us. This should also be easier for the
user to debug.
The extant hack that enabled line breakpoints in untitled scripts is
untenable. It shifted the user's args by one since it ran the untitled
script as the first arg to an inline script `. $args[0]` with `$args[0]`
being the script contents, instead of the expected `.  {<script>}`. This
hack that conflicted with the correct passing of arguments to the
debugged script. We are prioritizing the latter over the former, as
command breakpoints and `Wait-Debugger` work as expected, and the extant
behavior was rather unique (and unexpected) in the world of VS Code
extensions, to the point that the extension can now automatically prompt
to save untitled files.
Since the pipeline rewrite, it is no longer necessary for the
`ConfigurationDoneHandler` to manually start the debug loop when
temporary consoles are created for debug sessions. Because of this, we
can stop plumbing this information all the way through from the top.
@andyleejordan andyleejordan force-pushed the andschwa/untitled-with-args branch from 13b5cbb to 29b56ce Compare February 15, 2022 21:32
@andyleejordan andyleejordan changed the title Fix running untitled scripts with arguments (but break debugging) Fix running untitled scripts with arguments (but break line breakpoints) Feb 15, 2022
@andyleejordan andyleejordan merged commit 3ad0f39 into master Feb 15, 2022
@andyleejordan andyleejordan deleted the andschwa/untitled-with-args branch February 15, 2022 22:33
@TylerLeonhardt
Copy link
Member

darn :( I really liked untitled script debugging

@andyleejordan
Copy link
Member Author

You can still debug it, just not with line breakpoints. We cannot support both that and passing arguments to the script. Wait-Debugger in your script works, as does command breakpoints.

@ALIENQuake
Copy link

@andschwa
This seems like an outstanding feature for day-to-day development and I don't agree that it should be removed over 'passing parameters'. Passing parameters are meant for actual files. You can also wrap script content as a function and pass parameters. You can also provide default values for parameter variables at the beginning of the file. But since this is a lost cause already, can you please add an option to restore old behavior?

Also, I reverted to the previous version of the Preview extension and I'm not able to perform 'untitled script debugging'. This is the code I'm using:

Get-ChildItem 'C:\'
$a = Get-Verb | select -First 3 # <- the line breakpoint
Get-item '.'

What I'm missing? What is the latest extension version that has this feature enabled?

@andyleejordan
Copy link
Member Author

@ALIENQuake We are indeed looking to see if we can keep both behaviors. We don't want to keep the hack that previously supported the feature, but are trying to find a way to do it in a less hacky manner. Thing is, in my experience the line breakpoints were frequently off by one in untitled files because it was not a file being passed but the parsed AST.

@andyleejordan
Copy link
Member Author

The fix for this is out in PowerShell Preview! Line breakpoints were re-enabled and arguments are supported! Please note that the code that's run looks funky ('cause it is) but it works!

@ALIENQuake
Copy link

ALIENQuake commented Feb 25, 2022

@andschwa Wonderfull! Many thanks for your extra effort 👍🏻

EDIT: It works only on PowerShell 6+, it's by design? Not that it's any problem for me, just asking.

@andyleejordan
Copy link
Member Author

andyleejordan commented Feb 25, 2022

To be totally clear I would say in PowerShell 7+ by design (where the APIs to do this are available). PowerShell 6 isn't supported by us or even by itself any more 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants