Skip to content

Clear-Host causes cursor position state issues with PSReadLine #2408

Closed
PowerShell/PowerShellEditorServices
#1162

Description

System Details

System Details Output

### VSCode version: 1.41.1 26076a4de974ead31f97692a0d32f90d735645c0 x64

### VSCode extensions:
[email protected]


### PSES version: 2.0.0.0

### PowerShell version:

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

Issue Description

Trying to get the directory of the current script using Split-Path -Path $PSScriptRoot -Parent.

Expected Behaviour

image
Running the same script in ISE gives the expected result.

Actual Behaviour

image

As you can see, in VSCode, the result is not the parent. It's returned the whole file.

I have tried other variations such as

$RootPath = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
$RootPath

# or

(Get-ChildItem -Path $PSScriptRoot).Parent

It always returns the full path.

Attached Logs

Follow the instructions in the troubleshooting docs
about capturing and sending logs.

Activity

  1. ghost added
    Needs: Triage
    on Jan 10, 2020
  2. TylerLeonhardt commented on Jan 10, 2020

    @TylerLeonhardt
    Member

    Ok so this is a very interesting issue. For starters:

    Your script is running properly and the Split-Path cmdlet is working fine

    The problem here is purely visual output and is related to the PSReadLine support in the PS Integrated Console.

    To prove it to you, you can do the following things:

    • hit ENTER until you start to scroll, then run the script again...
    • Restart the current session...
    • Enable the setting "powershell.integratedConsole.useLegacyReadLine": true and run it again
    • output everything from your script to a file using . { ... } > foo.txt

    The bug shows up after you run Clear-Host so there's some state that PSReadLine & the PowerShell extension share that is not being updated properly.

  3. added
    Issue-Bug
    and removed
    Needs: Triage
    on Jan 10, 2020
  4. changed the title [-]Split-Path -Path $PSScriptRoot -Parent returns file name[/-] [+]Clear-Host causes cursor position state issues with PSReadLine[/+] on Jan 10, 2020
  5. ghost added
    Needs: Maintainer Attention
    on Jan 11, 2020
  6. TylerLeonhardt commented on Jan 11, 2020

    @TylerLeonhardt
    Member

    Yeah the prompt change is something I've noticed when doing console debugging in PowerShell as well so that's likely an issue there.

    Did you try the first suggestion? Hitting enter until it scrolls? Curious if that works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-PSReadLineIssue-Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions