PowerShell / vscode-powershell

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

Cannot re-execute the script that has just been debugged using 'Up Arrow, Enter' if path contains spaces #1870

Open sba923 opened 5 years ago

sba923 commented 5 years ago

Issue Description

Take a script whose absolute path is:

C:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpaces.ps1

If I hit F5 to run/debug it (using the PowerShell Launch Current File debug configuration), then go to the TERMINAL's prompt, and hit Up Arrow I get:

PS ~> c:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpaces.ps1

so if I then hit Enter I (obviously) get:

PS ~> c:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpaces.ps1
c:\private_sba\DOC\Mes : The term 'c:\private_sba\DOC\Mes' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ c:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpac ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (c:\private_sba\DOC\Mes:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Strangely enough, if I use the PowerShell Launch Current File w/Args Prompt debug configuration, I get the expected behavior, i.e. hitting Up Arrow yields:

PS ~/DOC/Mes images> . 'c:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpaces.ps1' -foo abc

which then works when hitting Enter -- the script does get re-executed, with the correct arguments at that.

Expected Behaviour

I would expect to get the following after hitting Up Arrow:

PS ~> . 'c:\private_sba\DOC\Mes images\TestScriptInFolderWhoseNameContainsSpaces.ps1'

so that hitting Enter properly re-executes the script.

Actual Behaviour

The script can't be re-executed using Up Arrow Enter

System Details

System Details Output

### VSCode version: 1.33.0 0dd516dd412d42323fc3464531b1c715d51c4c1a x64

### VSCode extensions:
alefragnani.Bookmarks@10.4.3
anseki.vscode-color@0.4.5
anweber.vscode-tidyhtml@1.10.0
bierner.lit-html@1.11.0
christian-kohler.npm-intellisense@1.3.0
christian-kohler.path-intellisense@1.4.2
DavidAnson.vscode-markdownlint@0.26.0
DotJoshJohnson.xml@2.4.0
ecmel.vscode-html-css@0.2.0
eg2.tslint@1.0.43
eg2.vscode-npm-script@0.3.5
esbenp.prettier-vscode@1.8.1
Flixs.vs-code-http-server-and-html-preview@2.2.2
generalov.vscode-tfs@1.0.1
GrapeCity.gc-excelviewer@2.1.32
Gruntfuggly.todo-tree@0.0.126
hdg.live-html-previewer@0.3.0
hnw.vscode-auto-open-markdown-preview@0.0.4
HookyQR.beautify@1.4.11
idleberg.nsis@3.16.1
ionutvmi.reg@0.0.2
manuth.markdown-converter@1.1.2
mdickin.markdown-shortcuts@0.11.0
mechatroner.rainbow-csv@1.0.0
mikeburgh.xml-format@1.0.2
mortenhenriksen.perl-debug@0.5.0
ms-vscode.cpptools@0.22.1
ms-vscode.csharp@1.18.0
ms-vscode.powershell@1.12.0
ms-vscode.powershell-preview@2.0.1
msjsdiag.debugger-for-chrome@4.11.3
nobuhito.printcode@3.0.0
redhat.java@0.42.1
swyphcosmo.spellchecker@1.2.13
VisualStudioExptTeam.vscodeintellicode@1.1.5
vscjava.vscode-java-debug@0.17.0
vscjava.vscode-java-dependency@0.4.0
vscjava.vscode-java-pack@0.6.0
vscjava.vscode-java-test@0.16.0
vscjava.vscode-maven@0.16.1
yanz.markdown-authoring@0.1.5
yuichinukiyama.vscode-preview-server@1.2.1
yzane.markdown-pdf@1.2.0
yzhang.markdown-all-in-one@2.2.0

The variable '$pseditor' cannot be retrieved because it has not been set.
At line:1 char:145
+ ... how-versions | Out-String)"; "`n### PSES version: $($pseditor.EditorS ...
+                                                         ~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (pseditor:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined

### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.17134.590
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.590
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Attached Logs

PSESlogs-201904121429.zip

SydneyhSmith commented 5 years ago

Thanks @sba923 for reporting this, I can reproduce it in both extensions.

rjmholt commented 5 years ago

I think we've discussed this before with @rkeithhill and @TylerLeonhardt. It seems like it would be easy to convert the default over, but there may be a reason why we don't.

rkeithhill commented 5 years ago

The basic difference is that with args we call PowerShell.AddScript() but without args, we call PowerShell.AddCommand(). The later is safer to use when a path can contain wildcard chars. We can look into how that command is inserted into the command history.