Skip to content
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

Completion doesn't work in Neovim #104

Closed
rudiejd opened this issue May 24, 2024 · 15 comments
Closed

Completion doesn't work in Neovim #104

rudiejd opened this issue May 24, 2024 · 15 comments

Comments

@rudiejd
Copy link

rudiejd commented May 24, 2024

Hello! Thank you for your awesome project! I'm trying to use it on neovim. For the most part, everything works out of the box... other than completion.

Completion won't work for any well-known tasks/properties or any imports. I see some errors about the plugin ignoring my repositories from work because they don't support the NuGet V3 API, but no other logs, even when I run on Debug log level. I'll keep messing with the server and update here if I figure things out. I'm guessing there might be some other pipe over which the server is sending completion information.

@tintoy
Copy link
Owner

tintoy commented May 24, 2024

Hi - sorry to it’s not working for you; there are a couple of environment variables you can set for the language server process to enable verbose logging

  • MSBUILD_PROJECT_TOOLS_VERBOSE_LOGGING=1
  • MSBUILD_PROJECT_TOOLS_LOG_FILE=/x/y/z
  • MSBUILD_PROJECT_TOOLS_LOGGING_TO_STDERR=1

You can also (depending on your LSP client implementation) turn on LSP request tracing:

https://github.com/tintoy/msbuild-project-tools-vscode/blob/a92231c68dfe0a4b8a13d4468ff6268ceed75b7c/src/extension.ts#L83

@rudiejd
Copy link
Author

rudiejd commented May 24, 2024

thank you!! I was trying to enable logging via the init params and/or configuration instead of environment variables.

So it looks like the server handles the initialization request from neovim fine, and I'm even getting some NuGet completion results such as:

[ERROR][2024-05-24 19:41:01] .../vim/lsp/rpc.lua:789	"rpc"	"/usr/bin/dotnet"	"stderr"	'[Debug/OnDidOpenTextDocument] Found 1 suggestions from 3 package source(s) for NuGet package Ids matching prefix "Newtonsoft.Json" (include pre-release: False).\n'

But all those requests are from OnDidOpenTextDocument. I'll try to enable request tracing and post the results here. I'm guessing it's not handling the completion request somehow

@rudiejd
Copy link
Author

rudiejd commented May 26, 2024

okay, I turned on request tracing in neovim, and it appears the language server does not respond to the request for completion. Neovim is sending the textDocument/completion request, and sometimes getting a reply from copilot, but not from this language server

[TRACE][2024-05-26 10:15:55] ...m/lsp/client.lua:996	"notification"	"LogMessage"	{  extra = { 'Requesting completion at position 9:110, between "  <ItemGroup>\\n    <ProjectReference Include=\\"..\\\\Example.Project.Contracts\\\\Example.Project.Contracts.csproj\\" Includ" and "/>\\n    <ProjectReference Include=\\"..\\\\Example.Project.Domain\\\\Example.Project.Domain.csproj\\" />\\n".' },  level = 0,  message = '[DEBUG] [getCompletions] [2024-05-26T14:15:55.215Z] Requesting completion at position 9:110, between "  <ItemGroup>\\n    <ProjectReference Include=\\"..\\\\Example.Project.Contracts\\\\Example.Project.Contracts.csproj\\" Includ" and "/>\\n    <ProjectReference Include=\\"..\\\\Example.Project.Domain\\\\Example.Project.Domain.csproj\\" />\\n".',  metadataStr = "[DEBUG] [getCompletions] [2024-05-26T14:15:55.215Z]"}

I'll see if I can debug this server

@tintoy
Copy link
Owner

tintoy commented May 26, 2024

Try turning the server log level up to verbose and you should see messages about handlers running (you can pass logging config when sending the init message sequence to the language server.

@tintoy
Copy link
Owner

tintoy commented May 26, 2024

(

languageServer.OnInitialize(initializationParameters =>
)

@rudiejd
Copy link
Author

rudiejd commented May 26, 2024

I struggled for a while figuring out which section of the init parameters I should send config on, but I eventually used

        init_options = {
          msbuildProjectToolsServer = {
            logging = {
              level = "verbose",
            }
          }
        }

(in case someone else wants to try this).

Here's the log file. I redacted some URLs, but essentially it seems like the language server never gets the completion requests from neovim. I haven't been able to figure out how to debug the server yet.
log-for-lsp.log

@tintoy
Copy link
Owner

tintoy commented May 26, 2024

In VSCode there is the concept of trigger characters for a language; when typing <, for example, it will automatically trigger completion. Otherwise you have to press Ctrl-Space. Does NeoVim have a key combo to manually trigger completion?

@rudiejd
Copy link
Author

rudiejd commented May 26, 2024

yep, people bind it to different things depending on the plugin but you can manually trigger completion. Your post gave me the idea to try this by directly calling vim.lsp.buf.completion() in a csproj file to trigger completion in the current buffer. I got a response indicating that

method textDocument/completion is not supported by any of the servers registered for the current buffer

so now I'm thinking that somehow neovim might not be getting the correct set of capabilities for the server

@rudiejd
Copy link
Author

rudiejd commented May 26, 2024

Neovim resolves the following capabilities (from running :lua =vim.lsp.get_clients()[1].server_capabilities):

image

@rudiejd
Copy link
Author

rudiejd commented May 26, 2024

When I manually set the capabilities of the server to include completionProvider, it works! 🎉
image

For any neovim users following this thread, I used the following command:

lua vim.lsp.get_clients()[3].server_capabilities.completionProvider = { resolveProvider = true, triggerCharacters = {" "} } 

This could potentially be a workaround until I figure out how to get Neovim/this language server to agree about capabilities. For reference, Omnisharp works, and here is how they register completion capabilities: https://github.com/OmniSharp/omnisharp-roslyn/blob/ac7b9b8509356e39583de2b9fdf363005e6c8595/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs#L87

Which seems very similar to how this project sets the capability:

CompletionRegistrationOptions IRegistration<CompletionRegistrationOptions>.GetRegistrationOptions() => CompletionRegistrationOptions;
. 🤔

@rudiejd
Copy link
Author

rudiejd commented May 27, 2024

The logging isn't really helpful on initialization:

[ERROR][2024-05-27 10:20:11] .../vim/lsp/rpc.lua:789	"rpc"	"/usr/bin/dotnet"	"stderr"	'[Debug/] Result was "System.Threading.Tasks.Task`1[[OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult, OmniSharp.Extensions.LanguageProtocol, Version=0.7.9.0, Culture=neutral, PublicKeyToken=null]]"\n'
[ERROR][2024-05-27 10:20:11] .../vim/lsp/rpc.lua:789	"rpc"	"/usr/bin/dotnet"	"stderr"	'[Debug/] Response value was "OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult"\n'

But I think this is an issue upstream in https://github.com/OmniSharp/csharp-language-server-protocol

@rudiejd
Copy link
Author

rudiejd commented May 27, 2024

on a second pass-through, seems I was mistakenly looking at the wrong language server client as a red-herring. The capabilities for msbuild-project-tools-server are fine:

:lua =vim.lsp.get_clients()[2].server_capabilities.completionProvider
{ 
    resolveProvider = false, 
    triggerCharacters = { "<" }                                                                                                                                                                                    }                                                                                                                                                                                                               

It's just that completion can only be triggered manually, and in some cases no results are returned. I'll go ahead and close out this issue, since it seems like that problem is already mentioned in #52. My PR to include this server in neovim's default set of language server configurations was also just merged in case you wanted to take a look neovim/nvim-lspconfig#3176

@rudiejd rudiejd closed this as completed May 27, 2024
@tintoy
Copy link
Owner

tintoy commented May 27, 2024

Just out of curiosity, which language identifier are you using - XML or MSBuild?

@rudiejd
Copy link
Author

rudiejd commented May 27, 2024

by language identifier, do you mean languageId on the TextDocumentItem? I was using xml, but I tried overriding it to msbuild with no luck.

I seem to only get completions when I manually trigger them, and even then they only show up when I manually trigger on an empty line. For other LSPs, I get competions while I'm typing

@tintoy
Copy link
Owner

tintoy commented May 27, 2024

I wonder if it’s because our implementation of LSP
is a little older… one thing that might help is to try loading the same project into VSCode with LSP tracing enabled and compare the messages exchanged… OmniSharp LSP changed how their host works a while ago and we haven’t had time to refactor our language service to use it. Until we do, our implemented protocol version isn’t the latest and greatest 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants