PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
613 stars 207 forks source link

The server never answers to a `initialize` request on Windows over stdio (but it does on Linux) (takes too long loading libraries on Windows) #2092

Closed TheLeoP closed 8 months ago

TheLeoP commented 8 months ago

Prerequisites

Steps to reproduce

I'm using Neovim as my editor, so I'm using the minimal reproduction of this issue (but using the Diagnostic log level for powershellEditorServices).

  1. Open neovim on windows
  2. Open the file a.ps1
  3. Nothing happens (the server never answers the initiliaze request. There is more info on the logs)

If the same things are done on linux, everything works as expected.

Expected behavior

PowershellEditorServices should answer the `initialize` request in both windows and linux.

Actual behavior

PowershellEditorServices does not answer the `initiliaze` request on Windows (there is more info in the logs)

Error details

No response

Environment data

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

Version

3.13

Visuals

Powershell logs on Linux (everything works fine here): pwsh_linux.log

Neovim LSP logs on Linux (everything works fine here): neovim_linux.log

Powershell logs on Windows (it looks like the server takes too long loading some libraries and then cancels the initialize request): pwsh_windows.log

Neovim logs on Windows (there is never a response for the initialize requets) neovim_windows.log

andyleejordan commented 8 months ago

You know, I think maybe it's getting stuck loading your profile on Windows? Because I see this line:

2023-10-20 11:54:05.097 -05:00 [DBG] Loading profiles...

but never the accompanying line:

                _logger.LogDebug("Profiles loaded!");

which means it never finishes initializing (and therefore doesn't answer the request).

TheLeoP commented 8 months ago

@andyleejordan

I'm new to powershell, so sorry for my lack of knowledge. I guess that using the parameter -NoProfile has no effect on this, right? Do you have any idea about why it would be stuck loading my profiles? Or how I could test this without my profiles to check if that's the problem?

Because, on the issue I linked (this one) people are having the same problem on Windows when everything works fine on Linux.

andyleejordan commented 8 months ago

That's right. I would try setting enableProfileLoading to false in the initialization options you're setting the server up with. -NoProfile is parsed by the pwsh executable, which is in essence just the host program that runs the LSP server, and that server has its own logic to enable (or disable) profile loading. Users on Linux don't usually have anything in any of the multiple profile paths that are checked, but often do on Windows because some of them are shared.

scottmckendry commented 8 months ago

@andyleejordan confirming that this is the same issue I was having on #2048. Removing my profile, the LSP starts and works as expected. However, I'm not sure how I go about setting the value of enableProfileLoading.

It seems that neovim's LSP doesn't implement it. Is there a way I can pass it in as a parameter to Start-EditorServices? Or some other config file?

TheLeoP commented 8 months ago

@andyleejordan Thaaaaaaaaaaaaaanks, that was it.

@scottmckendry You only need to do the following:

      require("lspconfig").powershell_es.setup {
        bundle_path = "path/to/your/bundle_path",
        init_options = {
          enableProfileLoading = false,
        },
      }
andyleejordan commented 8 months ago

Glad to help and happy it's working for you! I'm sorry the setup for PSES for Vim/Emacs etc. is not the greatest. It's been on our docket to simplify and clean up for a long time but I keep getting pulled into other work.