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

InlayHints not working on neovim #2550

Closed
codeprefect opened this issue Jul 12, 2023 · 12 comments · Fixed by #2604
Closed

InlayHints not working on neovim #2550

codeprefect opened this issue Jul 12, 2023 · 12 comments · Fixed by #2604

Comments

@codeprefect
Copy link

codeprefect commented Jul 12, 2023

Description

The source code indicates that omnisharp-roslyn already supports InlayHint, but testing from neovim reports that omnisharp does not support textDocument/inlayHint

How to reproduce

Start omnisharp using the following command

omnisharp -z --hostPID {neovimPID} DotNet:enablePackageRestore=false --encoding utf-8 --languageserver \
    FormattingOptions:EnableEditorConfigSupport=true FormattingOptions:OrganizeImports=true \
    MsBuild:LoadProjectsOnDemand=true RoslynExtensionsOptions:EnableAnalyzersSupport=true \
    RoslynExtensionsOptions:EnableImportCompletion=true Sdk:IncludePrereleases=true \
    RoslynExtensionsOptions:InlayHintsOptions:EnableForParameters=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForLiteralParameters=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForIndexerParameters=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForObjectCreationParameters=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForOtherParameters=true \
    RoslynExtensionsOptions:InlayHintsOptions:SuppressForParametersThatDifferOnlyBySuffix=false \
    RoslynExtensionsOptions:InlayHintsOptions:SuppressForParametersThatMatchMethodIntent=false \
    RoslynExtensionsOptions:InlayHintsOptions:SuppressForParametersThatMatchArgumentName=false \
    RoslynExtensionsOptions:InlayHintsOptions:EnableForTypes=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForImplicitVariableTypes=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForLambdaParameterTypes=true \
    RoslynExtensionsOptions:InlayHintsOptions:ForImplicitObjectCreation=true

I use a fork of nvim-lspconfig that adds the necessary command-line parameters to enable inlayHint

LSP Log (original)

[WARN][2023-07-12 18:55:36] .../lua/vim/lsp.lua:100	"method textDocument/inlayHint is not supported by any of the servers registered for the current buffer"
[WARN][2023-07-12 18:55:36] .../lua/vim/lsp.lua:100	"method textDocument/inlayHint is not supported by any of the servers registered for the current buffer"

LSP Log (pretending that the server supports inlayHint, so that client can at least send the request)

[DEBUG][2023-07-12 18:59:54] .../vim/lsp/rpc.lua:259	"rpc.send"	{  id = 3,  jsonrpc = "2.0",  method = "textDocument/inlayHint",  params = {    range = {      ["end"] = {        character = 0,        line = 43      },      start = {        character = 0,        line = 12      }    },    textDocument = {      uri = "file:///Users/*.cs"    }  }}
[DEBUG][2023-07-12 18:59:54] .../lua/vim/lsp.lua:1489	"LSP[omnisharp]"	"client.request"	1	"textDocument/inlayHint"	{  range = {    ["end"] = {      character = 0,      line = 106    },    start = {      character = 0,      line = 0    }  },  textDocument = {    uri = "file:///..*.cs"  }}	<function 1>	14
[DEBUG][2023-07-12 18:59:54] .../vim/lsp/rpc.lua:259	"rpc.send"	{  id = 4,  jsonrpc = "2.0",  method = "textDocument/inlayHint",  params = {    range = {      ["end"] = {        character = 0,        line = 106      },      start = {        character = 0,        line = 0      }    },    textDocument = {      uri = "file:///....*.cs"    }  }}
[DEBUG][2023-07-12 18:59:54] .../vim/lsp/rpc.lua:362	"rpc.receive"	{  error = {    code = -32601,    message = "Method not found - textDocument/inlayHint"  },  id = 3,  jsonrpc = "2.0"}
[DEBUG][2023-07-12 18:59:54] .../vim/lsp/rpc.lua:362	"rpc.receive"	{  error = {    code = -32601,    message = "Method not found - textDocument/inlayHint"  },  id = 4,  jsonrpc = "2.0"}

System Details

OS: MacOS Ventura
Neovim: NVIM v0.10.0-dev-4683+g06694203e-Homebrew
Omnisharp: 1.39.7
@madiele
Copy link
Contributor

madiele commented Aug 14, 2023

I have the same problem with neovim on Windows

@JorgeHerreraU
Copy link

I second this, neovim is not triggering any inlay hints regardless

@JoeRobich
Copy link
Member

To support inlay hints we will need a release of https://github.com/OmniSharp/csharp-language-server-protocol with updates from the 3.17 spec.

@codeprefect
Copy link
Author

The configuration in lsp-config does not pass in the necessary arguments for inlayHints, but even with my patch (where I added the necessary configuration), I get responses that it is not implemented.
neovim/nvim-lspconfig@master...codeprefect:nvim-lspconfig:master

@bmvi-kinver
Copy link

bmvi-kinver commented Oct 5, 2023

EDIT: Never mind! I built the newest version of Neovim (NVIM v0.10.0-dev-1283+g0ff13a6a5) and inlay hints now appear to work! I think this issue can be closed.

Original text:
I tried the new version of omnisharp (1.39.9) using NVIM v0.10.0-dev-958+gb641fc387, but whenever my client tries to get inlay hints I get the following error (or similar):

omnisharp: -32603: Internal Error - System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index')
   at Microsoft.CodeAnalysis.Text.SourceText.LineInfo.get_Item(Int32 index)
   at OmniSharp.Extensions.TextExtensions.GetPositionFromLineAndOffset(SourceText text, Int32 lineNumber, Int32 offset) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 28
   at OmniSharp.Extensions.TextExtensions.GetSpanFromRange(SourceText text, Range range) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 55
   at OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService.Handle(InlayHintRequest request) in /home/vsts/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/InlayHints/InlayHintService.cs:line 60
   at OmniSharp.LanguageServerProtocol.Handlers.OmniSharpInlayHintHandler.Handle(InlayHintParams request, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/OmniSharp.LanguageServerProtocol/Handle
rs/OmniSharpInlayHintHandler.cs:line 56
   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token,
 ILogger logger)
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)
   at OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>c__DisplayClass10_0.<<RouteRequest>b__5>d.MoveNext()

This is my omnisharp.json config:

{
  "RoslynExtensionsOptions": {
    "inlayHintsOptions": {
        "enableForParameters": true,
        "forLiteralParameters": true,
        "forIndexerParameters": true,
        "forObjectCreationParameters": true,
        "forOtherParameters": true,
        "suppressForParametersThatDifferOnlyBySuffix": false,
        "suppressForParametersThatMatchMethodIntent": false,
        "suppressForParametersThatMatchArgumentName": false,
        "enableForTypes": true,
        "forImplicitVariableTypes": true,
        "forLambdaParameterTypes": true,
        "forImplicitObjectCreation": true
    }
  }
}

Here is an excerpt from the LSP interaction logs:

[ERROR][2023-10-05 10:10:03] ...lsp/handlers.lua:543	"OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker: Failed to handle request textDocument/inlayHint 11 - System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index')\n   at Microsoft.CodeAnalysis.Text.SourceText.LineInfo.get_Item(Int32 index)\n   at OmniSharp.Extensions.TextExtensions.GetPositionFromLineAndOffset(SourceText text, Int32 lineNumber, Int32 offset) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 28\n   at OmniSharp.Extensions.TextExtensions.GetSpanFromRange(SourceText text, Range range) in /home/vsts/work/1/s/src/OmniSharp.Roslyn/Extensions/TextExtensions.cs:line 55\n   at OmniSharp.Roslyn.CSharp.Services.InlayHints.InlayHintService.Handle(InlayHintRequest request) in /home/vsts/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/InlayHints/InlayHintService.cs:line 60\n   at OmniSharp.LanguageServerProtocol.Handlers.OmniSharpInlayHintHandler.Handle(InlayHintParams request, CancellationToken cancellationToken) in /home/vsts/work/1/s/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs:line 56\n   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)\n   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)\n   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)\n   at OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>c__DisplayClass10_0.<<RouteRequest>b__5>d.MoveNext() | Method='textDocument/inlayHint' RequestId='11'"

I lack the knowledge to debug this issue effectively, unfortunately. Any ideas as to what might be wrong? Is the problem my configuration, or is the problem on omnisharp's side?

@codeprefect
Copy link
Author

I will verify this fix later today. Thanks @JoeRobich

@tanordheim
Copy link

@bmvi-kinver would you be able to share more about your setup if you have this working? I snooped on your profile but didn't find any dotfiles there :)

I'm running neovim nightly (v0.10.0-dev-6823fdb) with Omnisharp v1.39.10 and my neovim native inlay hints are not working. The LSP server does not seem to report supporting inlay hints (ciient.server_capabilities.inlayHintProvider == false) and when I enable it for a buffer manually (vim.lsp.inlay_hint(0, true)) I get this:

omnisharp: -32603: Internal Error - System.NullReferenceException: Object reference not set to an instance of an object.                                                                                                                                                                                                                                                       
   at OmniSharp.LanguageServerProtocol.Helpers.ToTextEdits(LinePositionSpanTextChange[] textChanges)+MoveNext() in /Users/runner/work/1/s/src/OmniSharp.LanguageServerProtocol/Helpers.cs:line 246                                                                                                                                                                             
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)                                                                                                                                                                                                                                                                                             
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)                                                                                                                                                                                                                                                                                            
   at OmniSharp.Extensions.LanguageServer.Protocol.Models.ContainerBase`1..ctor(IEnumerable`1 items)                                                                                                                                                                                                                                                                           
   at OmniSharp.Extensions.LanguageServer.Protocol.Models.Container`1..ctor(IEnumerable`1 items)                                                                                                                                                                                                                                                                               
   at OmniSharp.LanguageServerProtocol.Handlers.OmniSharpInlayHintHandler.ToLSPInlayHint(InlayHint hint) in /Users/runner/work/1/s/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs:line 77                                                                                                                                                          
   at System.Linq.Enumerable.SelectListIterator`2.ToArray()                                                                                                                                                                                                                                                                                                                    
   at OmniSharp.Extensions.LanguageServer.Protocol.Models.ContainerBase`1..ctor(IEnumerable`1 items)                                                                                                                                                                                                                                                                           
   at OmniSharp.Extensions.LanguageServer.Protocol.Models.InlayHintContainer..ctor(IEnumerable`1 items)                                                                                                                                                                                                                                                                        
   at OmniSharp.LanguageServerProtocol.Handlers.OmniSharpInlayHintHandler.Handle(InlayHintParams request, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs:line 58                                                                                                                    
   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.SemanticTokensDeltaPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                          
   at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                               
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                              
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                             
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                        
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                        
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                  
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)                                                                                                                                                                                                                  
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.<RouteRequest>g__InnerRoute|7_0(IServiceScopeFactory serviceScopeFactory, Request request, TDescriptor descriptor, Object params, CancellationToken token, ILogger logger)                                                                                                                                              
   at OmniSharp.Extensions.JsonRpc.RequestRouterBase`1.RouteRequest(IRequestDescriptor`1 descriptors, Request request, CancellationToken token)                                                                                                                                                                                                                                
   at OmniSharp.Extensions.JsonRpc.DefaultRequestInvoker.<>c__DisplayClass10_0.<<RouteRequest>b__5>d.MoveNext()                                    

@bmvi-kinver
Copy link

bmvi-kinver commented Oct 11, 2023

@tanordheim I can certainly share my config, but it seems that I was too quick to pull the trigger as I'm now experiencing the same problem as you are -- but only for particular files, while for other files it appears to be working properly. In my own project, it looks like inlay hints don't work for any files that has using Pulumi.SomeIdentifier statements, and I don't really understand why.

@ppebb
Copy link

ppebb commented Nov 21, 2023

Inlay hints work fine for me about half of the time (otherwise spitting out the above object reference not set error), although both textDocument_inlayHint AND textDocument_hover are incorrectly reported. As long as I hardcode them as enabled for omnisharp instead of checking client.supportsMethod, it works. This is on neovim master.

@shortc
Copy link

shortc commented Jan 7, 2024

I get that same object reference error in both Helix, and VSCode (c# extension installed, OmniSharp enabled, and LSP drivers enabled)

madiele added a commit to madiele/omnisharp-roslyn that referenced this issue Feb 17, 2024
madiele added a commit to madiele/omnisharp-roslyn that referenced this issue Feb 17, 2024
@madiele
Copy link
Contributor

madiele commented Feb 17, 2024

In the end I decided to try to build the repo locally and try to find the bug, the problem will happen always when there is a lambda as a parameter of a function (so very common if you use LINQ as an example)

I've successfully made a change to fix the problem! I opened a PR, hopefully it gets merged if I did not miss any detail while debugging the code, in the meanwhile you can build my branch with build.ps1 and set omnisharp cmd like this somewhere in your config (edit options as needed to you)

(note that I'm using neovim on windows x64, edit the path based on where you build)

cmd = {
  "C:\\path\\to\\repo\\omnisharp-roslyn\\artifacts\\publish\\OmniSharp.Stdio.Driver\\win7-x64\\net6.0\\OmniSharp.exe",
  "-z",
  "--hostPID",
  tostring(vim.fn.getpid()),
  "DotNet:enablePackageRestore=false",
  "--encoding",
  "utf-8",
  "--languageserver",
  "FormattingOptions:EnableEditorConfigSupport=true",
  "FormattingOptions:OrganizeImports=true",
  "RoslynExtensionsOptions:EnableAnalyzersSupport=true",
  "RoslynExtensionsOptions:EnableImportCompletion=true",
  "Sdk:IncludePrereleases=true",
},

JoeRobich added a commit that referenced this issue Feb 22, 2024
fix #2550 inlay hints lambdas parameter type null reference exception
@muhayli
Copy link

muhayli commented Aug 23, 2024

just update your nvim to 0.10 and add omnisharp.json file in your project directory with this
{ "RoslynExtensionsOptions": { "inlayHintsOptions": { "enableForParameters": true, "forLiteralParameters": true, "forIndexerParameters": true, "forObjectCreationParameters": true, "forOtherParameters": true, "suppressForParametersThatDifferOnlyBySuffix": false, "suppressForParametersThatMatchMethodIntent": false, "suppressForParametersThatMatchArgumentName": false, "enableForTypes": true, "forImplicitVariableTypes": true, "forLambdaParameterTypes": true, "forImplicitObjectCreation": true } } }

and then in nvim run :lua vim.lsp.inlay_hint.enable(true)

you can set keymap to toggle inlay hint with
lua vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())

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

Successfully merging a pull request may close this issue.

9 participants