OmniSharp/omnisharp-roslyn

InlayHints not working on neovim

codeprefect opened this issue · 11 comments

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

I have the same problem with neovim on Windows

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

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.

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

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?

I will verify this fix later today. Thanks @JoeRobich

@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()                                    

@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 commented

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 commented

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