PowerShell / PowerShellEditorServices

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

Only Snippets in intellisense (no modules) #2048

Closed scottmckendry closed 8 months ago

scottmckendry commented 11 months ago

Prerequisites

Steps to reproduce

Using PowerShell Editor Services in neovim with the following LSPConfig:

local bundle_path = vim.fn.stdpath("data") .. "/mason/packages/powershell-editor-services"
local command_fmt = [[& '%s/PowerShellEditorServices/Start-EditorServices.ps1' -BundledModulesPath '%s' -LogPath '%s/powershell_es.log' -SessionDetailsPath '%s/powershell_es.session.json' -FeatureFlags @() -AdditionalModules @() -HostName nvim -HostProfileId 0 -HostVersion 1.0.0 -Stdio -LogLevel Normal]]
local temp_path = vim.fn.stdpath("cache")
local command = command_fmt:format(bundle_path, bundle_path, temp_path, temp_path)
lspconfig.powershell_es.setup {
  on_attach = on_attach,
  capabilities = capabilities,
  filetypes = { "ps1" },
  bundle_path = vim.fn.stdpath("data") .. "/mason/packages/powershell-editor-services",
  cmd = { "pwsh", "-NoLogo", "-Command", command },
}

As part of troubleshooting, I set the cmd to include my profile which had this line:

Get-Module -ListAvailable | Import-Module

However, still no modules in Intellisense.

Expected behavior

Typing `Get-C` in a ps1 buffer should display Get-ChildItem in autocomplete

Actual behavior

Type `Get-C` in a ps1 buffer only shows snippets

Error details

No response

Environment data

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

Version

3.8.7 - Mason Registry

Visuals

Example of missing IntelliSense image

Output of :LspInfo image

andyleejordan commented 11 months ago

How are you setting up "IntelliSense" aka completion requests in NeoVim? The only "snippets" that should exist in the realm of using just PSES are from PSSA, which comment-help is, so at least the analysis service (PSSA) is working.

scottmckendry commented 11 months ago

I suppose that's where I'm stuck. I've checked the default config and nothing immediately stands out to me that says "this will enable code-completion".

I've not run into this problem when installing other LSPs (yet) so I was hoping to get some advice from someone who has had success with this in the past.

scottmckendry commented 11 months ago

I'm using nvim-cmp for code completion. With the default capabilities that come with NVChad here.

andyleejordan commented 11 months ago

I think you need to set it up then...from the lspconfig readme:

Manual, triggered completion is provided by Nvim's builtin omnifunc. For autocompletion, a general purpose autocompletion plugin is required.

For nvimp-cmp it looks like it must be explicitly setup to use LSP completions, the readme has an example:

sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'vsnip' }, -- For vsnip users.
      -- { name = 'luasnip' }, -- For luasnip users.
      -- { name = 'ultisnips' }, -- For ultisnips users.
      -- { name = 'snippy' }, -- For snippy users.
    }
andyleejordan commented 11 months ago

My best guess...the default configuration you're loading from https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/powershell_es.lua probably needs to be revised to advertise completion capabilities, I sort of found an example of that in https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/clangd.lua.

scottmckendry commented 11 months ago

That's what I'm doing in my config (I think). I pull in the default capabilities from the NVChad lsp config with this line:

local capabilities = require("plugins.configs.lspconfig").capabilities

Which should look something like this:

M.capabilities = vim.lsp.protocol.make_client_capabilities()

M.capabilities.textDocument.completion.completionItem = {
  documentationFormat = { "markdown", "plaintext" },
  snippetSupport = true,
  preselectSupport = true,
  insertReplaceSupport = true,
  labelDetailsSupport = true,
  deprecatedSupport = true,
  commitCharactersSupport = true,
  tagSupport = { valueSet = { 1 } },
  resolveSupport = {
    properties = {
      "documentation",
      "detail",
      "additionalTextEdits",
    },
  },
}

I've had success with this method using go and bicep LSPs but PowerShell eludes me...

andyleejordan commented 11 months ago

I think you're missing this part:

completionItemKind?: {
        /**
         * The completion item kind values the client supports. When this
         * property exists the client also guarantees that it will
         * handle values outside its set gracefully and falls back
         * to a default value when unknown.
         *
         * If this property is not present the client only supports
         * the completion items kinds from `Text` to `Reference` as defined in
         * the initial version of the protocol.
         */
        valueSet?: [CompletionItemKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemKind)[];
    };
scottmckendry commented 11 months ago

Thanks, unfortunately, no luck getting this going on my end. I've also raised this as an issue on the nvim-lsp repo: https://github.com/neovim/nvim-lspconfig/issues/2747

I did come across a log file generated by PSES with this line:

2023-08-05 21:35:20.494 +12:00 [WRN] Tried to send request or notification before initialization was completed and will be sent later {"Id":1,"Error":{"Code":-32800,"Data":null,"Message":"Request Cancelled","$type":"ErrorMessage"},"Method":"initialize","$type":"RequestCancelled"}

Not sure if this helps at all.

andyleejordan commented 11 months ago

Hm, the thing that reminds me of is https://github.com/OmniSharp/csharp-language-server-protocol/issues/588

That was a bug in our LSP library because the spec is very confusing about the ordering of the initialize and initialized requests. Might be worth looking into for nvim-lspconfig, but could also be a red herring.

ogios commented 10 months ago

same issue, any updates?

scottmckendry commented 10 months ago

same issue, any updates?

No progress on Windows 11. However, PSES on Linux is working. Tested in Ubuntu 22.04 (WSL) and Arch running essentially identical neovim configurations.

The language server starts on Windows, but doesn't attach to the active buffer. Every other LSP-compatible language I've tried on Windows works fine, but PSES does not.

I also tried turning on verbose logging to see if I could see anything that might be useful. No errors or warnings. Also I'm no longer able to replicate the error in my previous comment. Seems like to LSP implementation just isn't Windows-friendly.

andyleejordan commented 10 months ago

Hm, are there over LSP plugins for Vim that could be tried?

scottmckendry commented 10 months ago

I can confirm that coc-powershell works on Windows. But it's not as good as the native nvim lsp.

I'm not the first person to run into this issue.

Another example

scottmckendry commented 10 months ago

@andyleejordan @ogios I've opened a new issue in the nvim-lspconfig repo. If you have anything you can add that the maintainers might find helpful that would be appreciated 👍🏻