PowerShell / vscode-powershell

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

Language Server Becomes Unresponsive After Opening Command Explorer #4992

Open andria-dev opened 5 months ago

andria-dev commented 5 months ago

Prerequisites

Summary

PowerShell intellisense works until I open the command explorer once. The command explorer never populates, and I have to close the command explorer and restart the PowerShell session to get intellisense working again.

PowerShell Version

PS> $PSVersionTable; $Host                                                                                                                                                                                             

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

Name             : Visual Studio Code Host
Version          : 2024.2.2
InstanceId       : 99850762-31fb-4299-8d83-da801db98e37
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Visual Studio Code Version

PS> code --version                                                                                                                                                                                                     
1.89.1
dc96b837cf6bb4af9
x64

Extension Version

PS> code --list-extensions --show-versions | sls powershell                                                                                                                                                            

ms-vscode.powershell@2024.2.2

Steps to Reproduce

  1. Open a folder as a workspace.
  2. Create a PowerShell script.
  3. Type in the first half of a command.
  4. See intellisense working (or press Ctrl + Space to trigger it).
  5. Open PowerShell Command Explorer.
  6. Click on the end of the command you were just typing.
  7. Press Ctrl + Space to trigger intellisense.
  8. See indefinite "Loading..." status.

Visuals

https://github.com/PowerShell/vscode-powershell/assets/19195374/1a661185-ee5b-42fa-8a61-4f2572ea86e4

Logs

PowerShell Editor Services Client logs just after opening Command Explorer

``` [Trace - 11:17:18 PM] Sending request 'powerShell/getCommand - (15)'. [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finding descriptors for powerShell/getCommand | Method='powerShell/getCommand'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finding descriptors for powerShell/getCommand | Method='powerShell/getCommand' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.JsonRpc.ProcessScheduler: Queueing Serial:powerShell/getCommand:15 request for processing | Type='Serial' Name='powerShell/getCommand:15'" } OmniSharp.Extensions.JsonRpc.ProcessScheduler: Queueing Serial:powerShell/getCommand:15 request for processing | Type='Serial' Name='powerShell/getCommand:15' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Starting: Processing request powerShell/getCommand 15 | Method='powerShell/getCommand' ResponseId='15'" } OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Starting: Processing request powerShell/getCommand 15 | Method='powerShell/getCommand' ResponseId='15' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Starting: Routing Request (15) powerShell/getCommand | Id='15' Method='powerShell/getCommand'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Starting: Routing Request (15) powerShell/getCommand | Id='15' Method='powerShell/getCommand' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Request (15) powerShell/getCommand to Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams | Id='15' Method='powerShell/getCommand' Type='Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Request (15) powerShell/getCommand to Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams | Id='15' Method='powerShell/getCommand' Type='Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Notification powerShell/getCommand to Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams | Method='powerShell/getCommand' Type='Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Converting params for Notification powerShell/getCommand to Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams | Method='powerShell/getCommand' Type='Microsoft.PowerShell.EditorServices.Handlers.GetCommandParams' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Response value was System.Collections.Generic.List`1[[Microsoft.PowerShell.EditorServices.Handlers.PSCommandMessage, Microsoft.PowerShell.EditorServices, Version=3.20.1.0, Culture=neutral, PublicKeyToken=null]] | Type='System.Collections.Generic.List`1[[Microsoft.PowerShell.EditorServices.Handlers.PSCommandMessage, Microsoft.PowerShell.EditorServices, Version=3.20.1.0, Culture=neutral, PublicKeyToken=null]]'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Response value was System.Collections.Generic.List`1[[Microsoft.PowerShell.EditorServices.Handlers.PSCommandMessage, Microsoft.PowerShell.EditorServices, Version=3.20.1.0, Culture=neutral, PublicKeyToken=null]] | Type='System.Collections.Generic.List`1[[Microsoft.PowerShell.EditorServices.Handlers.PSCommandMessage, Microsoft.PowerShell.EditorServices, Version=3.20.1.0, Culture=neutral, PublicKeyToken=null]]' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finished: Routing Request (15) powerShell/getCommand in 382ms | Id='15' Method='powerShell/getCommand' ElapsedMilliseconds='382'" } OmniSharp.Extensions.LanguageServer.Shared.LspRequestRouter: Finished: Routing Request (15) powerShell/getCommand in 382ms | Id='15' Method='powerShell/getCommand' ElapsedMilliseconds='382' [Trace - 11:17:18 PM] Received notification 'window/logMessage'. Params: { "type": 4, "message": "OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Finished: Processing request powerShell/getCommand 15 in 382ms | Method='powerShell/getCommand' ResponseId='15' ElapsedMilliseconds='382'" } OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Finished: Processing request powerShell/getCommand 15 in 382ms | Method='powerShell/getCommand' ResponseId='15' ElapsedMilliseconds='382' ``` It will then send a `textDocument/completion` message when I do Ctrl + Space, but it will never receive any response, even after several minutes of waiting.

Grosner300 commented 3 months ago

I see same issue. Command Explorer never populates. When I run code.exe as different user, on same computer, Command Explorer and Intellisense work as expected.

After removing the Environment variable “Path” element, pointing to a folder containing PowerShell scripts, the Command Explorer and Intellisense worked as expected.

Additional information: See: Script Content Triggers unhandled Newtonsoft.Json.JsonSerializationException #2165

The root cause appears to be caused by the actual script code I included in my PowerShell script as outlined in the above issue. Rewriting the code fixes the issue.

win 11, Powershell 7.4.3, vscode 1.9.0, powershell extension 2024.2.2.