Skip to content

Register-EditorCommand appears broken in preview release #3691

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

Closed
5 tasks done
ghost opened this issue Nov 16, 2021 · 11 comments · Fixed by PowerShell/PowerShellEditorServices#1725
Closed
5 tasks done
Assignees
Labels
Area-Engine Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash.

Comments

@ghost
Copy link

ghost commented Nov 16, 2021

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

I am using the Register-EditorCommand in my "Microsoft.VSCode_profile.ps1" profile and assigning it to the alt-f2 in my key bindings file. When I try this with the latest preview, nothing happens. No error, nothing.

If I add a simple "Register-EditorCommand" to my profile file and then try to execute it with the "PowerShell: Show Additional Commands from PowerShell Modules" it appears to hang and/or never return control to the terminal window.

For example if I have something like this in my profile:
Register-EditorCommand -Name TestCommand -DisplayName "Test Command" -ScriptBlock {Write-Host "Test"}

It would normally display "Test" in the terminal and then return control to the terminal. In the preview version it displays "Test" but never returns control. Not sure if you can tell from the screen shots....the first one is the problem (preview version) and the second one is the older release version that works.
image

image

So I am not sure if this is the same problem that is happening with the actual script block I am trying to get to work. But it seems odd that it never returns control to the terminal, but in the release version it does. So at this point I am assuming it is related to the problem.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Microsoft Windows 10.0.19043
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.2
3a6960b964327f0e3882ce18fcebd07ed191b316
x64

Extension Version

Steps to Reproduce

  • Create a VSCode profile file.
  • Add code to profile file to register an editor command:
    Register-EditorCommand -Name TestCommand -DisplayName "Test Command" -ScriptBlock {Write-Host "Test"}
  • Open a PS1 file in VSCode and try to execute the editor command:
    "PowerShell: Show Additional Commands from PowerShell Modules"

Visuals

No response

Logs

No response

@ghost ghost added Issue-Bug A bug to squash. Needs: Triage Maintainer attention needed! labels Nov 16, 2021
@andyleejordan andyleejordan added the Bug: Pre-release Bugs reproducing only in the pre-release extension. label Nov 16, 2021
@StevenBucher98 StevenBucher98 removed the Needs: Triage Maintainer attention needed! label Nov 16, 2021
@StevenBucher98 StevenBucher98 added this to the Consider-vNext milestone Nov 16, 2021
@StevenBucher98
Copy link
Contributor

Thanks for the detailed information! @NJK-HOME We appreciate the screenshots and steps to repro! We will investigate fixing this

@andyleejordan
Copy link
Member

@SydneyhSmith we need to determine if this is still reproducing, if so, we need to fix it.

@SydneyhSmith
Copy link
Collaborator

@andschwa I can reproduce this on latest preview, although I wonder if there's a chance the other host work you have done will cause the command to return--if I have time I'll test on lastest build

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

@JustinGrote I wonder if solving this will solve #3807

@andyleejordan andyleejordan changed the title Register-EditorCommand appears broken in preview release Register-EditorCommand appears broken in preview release Feb 23, 2022
@andyleejordan
Copy link
Member

@SeeminglyScience Easy enough fix, need to interrupt the current prompt lol.

Repository owner moved this from In Progress to Done in Sea Biscuit Feb 24, 2022
@ghost
Copy link
Author

ghost commented Feb 24, 2022

Thank you.

@andyleejordan
Copy link
Member

You're welcome! Trying to get a preview out right now in fact.

@andyleejordan
Copy link
Member

The fix for this is out in PowerShell Preview v2022.2.2!

@ghost
Copy link
Author

ghost commented Feb 25, 2022

I am not sure what is going on now, but I cannot get my test case to work in either new preview version or the existing production version anymore. Which is weird because I have the above screen shots showing that it did work at one time. The hang is not happening anymore, so I think you fixed that. But I cannot get "Test" to write the screen in any version of the extension now.

For my actual use case - that definitely still works in the current version and definitely still fails in the latest release (2022.2.2). But I cannot get the test case of writing "Test" to the terminal to work anywhere now. Between my original post and now, I know that VSCode was updated to version 1.64.x - so maybe that upgrade is partially causing the test case to fail across the board?? At least I have the screen shots to show I am not completely losing my mind :)

I might try installing an older version of VSCode to see if I can get it work again...

@ghost
Copy link
Author

ghost commented Feb 25, 2022

OK, for whatever reason my above test case must be flawed and what I originally tried and used for the screenshot is different from what I typed above. Now, I changed it to write a text file to my desktop instead of relying on output to the terminal:

Register-EditorCommand -Name SignCurrentScript -DisplayName "Test Command" -ScriptBlock {New-Item -Path $HOME\Desktop\Test.txt -ItemType File}

This test case now works in all versions. It successfully creates a text file to the desktop.

So now I see the actual problem. In the original version, whenever you ran an editor command it would display "PowerShell" text in the bottom left corner of VSCode. That was my indicator it was running. In the new version, it no longer shows "PowerShell" text so there is no feedback to indicate it is working or not. So I assumed it was failing without doing more investigation to see if it actually worked. This is my fault and offer my apologies :(

image

That being said, can we get the "PowerShell" text back as an indicator it is running :)

Thanks!
NK

@andyleejordan
Copy link
Member

Yay! Glad to see everything is working for you. The indicator is interesting, I'm not sure how that was wired up in the past. We have some pending work to revamp that whole interface as VS Code is coming out with more explicit APIs for it so that all extensions can match; I imagine we could make it indicate anytime some PowerShell code is running!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Engine Bug: Pre-release Bugs reproducing only in the pre-release extension. Issue-Bug A bug to squash.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants