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

Run Launch config on unsaved File is broken #3655

Closed
5 tasks done
JustinGrote opened this issue Oct 29, 2021 · 11 comments · Fixed by PowerShell/PowerShellEditorServices#1702
Closed
5 tasks done

Run Launch config on unsaved File is broken #3655

JustinGrote opened this issue Oct 29, 2021 · 11 comments · Fixed by PowerShell/PowerShellEditorServices#1702
Assignees
Labels
Area-Debugging Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.

Comments

@JustinGrote
Copy link
Collaborator

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

Currently when you invoke an unsaved script with this launch config:

        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PowerShell: Current File",
            "script": "${file}",
            "args": [],
            "cwd": "${file}"
        },
        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PowerShell: Current File w/ Args",
            "script": "${file}",
            "args": [
                "${command:SpecifyScriptArgs}"
            ],
            "cwd": "${file}"
        },

Given a simple unsaved script that says:

"This is a {0} test" -f $args[0]

The run occurs like this:

. $args[0] "This is a test -f $args[0]"

(Note the first args[0] isn't specified in the script)
And produces no output.

Instead it should be using either the call operator or the '.' operator (this should be a configurable preference to determine if variables remain in scope of the PSIC or not):
.{<scriptGoesHere>} <argsGoHere>

So for this example, running the script with the 'fun' arg should result in the command:
.{"This is a {0} test" -f $args[0]} fun

Which produces the intended result.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.62.0-insider
dc1a6699060423b8c4d2ced736ad70195378fddf
x64

Extension Version

Steps to Reproduce

See description

Visuals

No response

Logs

No response

@JustinGrote JustinGrote added the Issue-Bug A bug to squash. label Oct 29, 2021
@ghost ghost added the Needs: Triage Maintainer attention needed! label Oct 29, 2021
@andyleejordan andyleejordan added the Bug: Pre-release Bugs reproducing only in the pre-release extension. label Oct 29, 2021
@andyleejordan andyleejordan changed the title [Preview] Run Launch config on unsaved File is broken Run Launch config on unsaved File is broken Oct 29, 2021
@andyleejordan
Copy link
Member

@JustinGrote Looks like this may be fixed by PowerShell/PowerShellEditorServices#1609?

@andyleejordan andyleejordan added Needs: Author Feedback Please give us the requested feedback! and removed Needs: Triage Maintainer attention needed! labels Nov 1, 2021
@andyleejordan andyleejordan added this to the Committed-vNext milestone Nov 1, 2021
@JustinGrote
Copy link
Collaborator Author

@JustinGrote Looks like this may be fixed by PowerShell/PowerShellEditorServices#1609?

It doesn't, this is a separate issue.

@ghost ghost added Needs: Maintainer Attention Maintainer attention needed! and removed Needs: Author Feedback Please give us the requested feedback! labels Nov 1, 2021
@andyleejordan
Copy link
Member

Oh dang, ok! Thanks for the confirmation.

@andyleejordan
Copy link
Member

Oh this looks like a breakage due to the buggy behavior in #3666.

@andyleejordan
Copy link
Member

This is weird since I don't think the extant behavior in the stable channel is correct either, it produces the output:

> This is a  test
PS> 

@andyleejordan andyleejordan moved this from Todo to In Progress in Sea Biscuit Feb 3, 2022
@andyleejordan
Copy link
Member

@JustinGrote Sooo upon digging, the logic around this hasn't changed in two years...

@andyleejordan
Copy link
Member

This is super broken in general. Might punt from the next stable release because it was already broken.

@andyleejordan
Copy link
Member

@JustinGrote Can you verify that your scenario is just as broken in the stable channel too?

@JustinGrote
Copy link
Collaborator Author

@andschwa haven't verified but I do know that the new Powershell: Run seems to work on unsaved files just fine, so that's a good enough workaround to punt to the next "sprint"

@andyleejordan
Copy link
Member

I have a stashed change that definitely makes your scenario work better with respect to running the untitled script as . {<contents>} <args> without shifting the args array around with the hack...but this breaks debugging it (as in, any set breakpoints don't work because they're set on lines that aren't actually being run). The current hack (it's literally labeled "hack") is just untenable. Sure it kind of got untitled script debugging working...but not in a sustainable way.

@andyleejordan
Copy link
Member

@JamesWTruher is ruminating on potential solutions for us 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Issue-Bug A bug to squash. Resolution-Fixed Will close automatically.
Projects
No open projects
Status: Done
2 participants