Skip to content

command 'PowerShell.RunSelection' not found #4135

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
6 tasks done
D1StrX opened this issue Aug 16, 2022 · 9 comments · Fixed by #4140
Closed
6 tasks done

command 'PowerShell.RunSelection' not found #4135

D1StrX opened this issue Aug 16, 2022 · 9 comments · Fixed by #4140
Assignees
Labels

Comments

@D1StrX
Copy link

D1StrX commented Aug 16, 2022

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all open and closed 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.
  • If this is a security issue, I have read the security issue reporting guidance.

Summary

Since specifically version 2022.7.2 the Powershell Extention is having some issues on my end. My 2 workstations (sharing the same account ofc) getting the following errors:
When pressing F8: command 'PowerShell.RunSelection' not found
When pressing F5:
image

Trying to upload a bug from within VSCode:
image

Found some similar issues from the past, e.g.: #2526
Also not getting logs in the Logs folder, when setting the log level to diagnostic.

Version 2022.6.3 is still working fine. Works with Powershell 7.2.5 and 7.2.6 & vscode 1.70/1.70.1.
Reinstalling VSCode and/or the PowerShell extension didn't solve the issue.

My debug profile contains this for PowerShell:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "PowerShell: Launch Current File",
      "type": "PowerShell",
      "request": "launch",
      "script": "${file}",
      "cwd": "${file}"
    }
  ]
}

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
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.70.1
6d9b74a70ca9c7733b29f0456fd8195364076dda
x64

Extension Version

Steps to Reproduce

Any piece of powershell code will trigger the issue when pressing F5 or F8 for a single row in a new
$token = Read-Host -Prompt "Enter Authentication token"

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "PowerShell: Launch Current File",
      "type": "PowerShell",
      "request": "launch",
      "script": "${file}",
      "cwd": "${file}"
    }
  ]
}

Visuals

No response

Logs

None available.

@D1StrX D1StrX added the Issue-Bug A bug to squash. label Aug 16, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Aug 16, 2022
@andyleejordan
Copy link
Member

Also not getting logs in the Logs folder, when setting the log level to diagnostic.

For this part, the logs were moved to Code's extension global storage. If you are simply accessing the old location manually, that would be why they're not there. Please run: PowerShell: Open PowerShell Extension Logs Folder to get the correct folder. It'll be something like:

~/Library/Application Support/Code/User/globalStorage/ms-vscode.powershell-preview/logs/1660666818-163c253e-a60d-42c9-b209-1112099593bb1660666816450/<log files>

When pressing F8: command 'PowerShell.RunSelection' not found etc.

Do you have this command bound to F8 manually? It won't be found if the extension has not yet activated, and it only activates if you say open a PowerShell file or trigger one of these events:

  "activationEvents": [
    "onDebugResolve:PowerShell",
    "onLanguage:powershell",
    "onCommand:PowerShell.NewProjectFromTemplate",
    "onCommand:PowerShell.OpenExamplesFolder",
    "onCommand:PowerShell.PickPSHostProcess",
    "onCommand:PowerShell.PickRunspace",
    "onCommand:PowerShell.SpecifyScriptArgs",
    "onCommand:PowerShell.ShowSessionConsole",
    "onCommand:PowerShell.ShowSessionMenu",
    "onCommand:PowerShell.RestartSession",
    "onCommand:PowerShell.ShowLogs",
    "onCommand:PowerShell.OpenLogFolder",
    "onCommand:PowerShell.GenerateBugReport",
    "onCommand:PowerShell.OpenExamplesFolder",
    "onCommand:PowerShell.EnableISEMode",
    "onCommand:PowerShell.DisableISEMode",
    "onView:PowerShellCommands"
  ],

If you are using PowerShell.RunSelection in a file that isn't recognized as a PowerShell file, can I ask what the use case is? We could certainly add that command as well. However, the strange thing is PowerShell.GenerateBugReport is in the activation events and so should have activated the extension and worked...

@andyleejordan
Copy link
Member

The latest code is available in the PowerShell Preview for VS Code, and includes a myriad of fixes. Could you verify if this issue still reproduces using the preview extension? Please note that this preview is likely to include other bugs, and you should feel free to file new issues for those so we can work through them. Thanks again!

@D1StrX
Copy link
Author

D1StrX commented Aug 16, 2022

I managed to solve and found the issue. Apparently 2022.7.2 does actually 'read' the .workspace file?
I had a faulty json config (missing a ',').
Tried to figure it out by doing the following: Opening a new VSCode Window -> new file -> PowerShell -> PowerShell code (whatever you want) -> F5/F8
That was working fine, reason for me to look at the workspace file. Fixed it, and PowerShell was running again after confirming '"powershell.cwd":' question.

I guess that that the reason is why it couldn't start PowerShell. It tries to write "powershell.cwd": to the settings section, but faulty json config (folder configurations) above it stops it from doing so.

@D1StrX D1StrX closed this as completed Aug 16, 2022
@andyleejordan
Copy link
Member

Woah, very interesting. Thanks so much @D1StrX. As we're working to resolve #2153, we started utilizing the workspace file in startup. I'll try to repro this and see if there's an error we can catch and ignore rather than hang.

@andyleejordan
Copy link
Member

I couldn't get this to repro, but I added a try/catch around where we update the setting which should take care of it.

Repository owner moved this from In Progress to Done in American Pharoah Aug 18, 2022
@andyleejordan
Copy link
Member

Ok, new preview will be out momentarily. Could you please confirm you can no longer repro this?

@D1StrX
Copy link
Author

D1StrX commented Aug 18, 2022

I'll try to test it. Will misconfigure the workspace file and install the preview version.

@D1StrX
Copy link
Author

D1StrX commented Aug 18, 2022

Good news, it does indeed not hang on the cwd part. It ignores it and continues.
Perhaps nice if a popup could be displayed, that something is skipped and you should check your workspace file?

@andyleejordan
Copy link
Member

Awesome, thanks for testing! And that's a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants