Omnisharp-roslyn: [LSP] Failed to handle notification initialize

Created on 18 May 2019  路  8Comments  路  Source: OmniSharp/omnisharp-roslyn

I'm working on integrating vim-ale directly with omnisharp-roslyn's LSP server, as omnisharp-vim does not use the LSP as far as I can tell. This is so I can get auto-completion through vim-ale and LSP and not through omnicomplete itself.

In doing so, I've been getting errors back from omnisharp's LSP server. More specifically:

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"Failed to handle notification initialize - System.NullReferenceException: Object reference not set to an instance of an object\n  at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.OmniSharp.Extensions.Embedded.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle (OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams request, System.Threading.CancellationToken token) [0x0022d] in <c33e73e38fa14bf293bda2f62d3759c4>:0 \n  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, OmniSharp.Extensions.Embedded.MediatR.RequestHandlerDelegate`1[TResponse] next) [0x000e1] in <c33e73e38fa14bf293bda2f62d3759c4>:0 \n  at OmniSharp.Extensions.LanguageServer.Server.LspRequestRouter.RouteRequest (OmniSharp.Extensions.JsonRpc.IHandlerDescriptor descriptor, OmniSharp.Extensions.JsonRpc.Server.Request request) [0x002e2] in <c33e73e38fa14bf293bda2f62d3759c4>:0 "}}Content-Length: 129

{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Finished: Routing Request (1) initialize in 1000ms"}}Content-Length: 1158

{"jsonrpc":"2.0","id":"1","error":{"code":-32602,"message":"Internal Error - System.NullReferenceException: Object reference not set to an instance of an object\n  at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.OmniSharp.Extensions.Embedded.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle (OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams request, System.Threading.CancellationToken token) [0x0022d] in <c33e73e38fa14bf293bda2f62d3759c4>:0 \n  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, OmniSharp.Extensions.Embedded.MediatR.RequestHandlerDelegate`1[TResponse] next) [0x000e1] in <c33e73e38fa14bf293bda2f62d3759c4>:0 \n  at OmniSharp.Extensions.LanguageServer.Server.LspRequestRouter.RouteRequest (OmniSharp.Extensions.JsonRpc.IHandlerDescriptor descriptor, OmniSharp.Extensions.JsonRpc.Server.Request request) [0x002e2] in <c33e73e38fa14bf293bda2f62d3759c4>:0 "}}

In other words, this is the exception that omnisharp-roslyn is giving me during initialization:

System.NullReferenceException: Object reference not set to an instance of an object
  at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.OmniSharp.Extensions.Embedded.MediatR.IRequestHandler<OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams,OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeResult>.Handle (OmniSharp.Extensions.LanguageServer.Protocol.Models.InitializeParams request, System.Threading.CancellationToken token) [0x0022d] in <c33e73e38fa14bf293bda2f62d3759c4>:0 
  at OmniSharp.Extensions.LanguageServer.Server.Pipelines.ResolveCommandPipeline`2[TRequest,TResponse].Handle (TRequest request, System.Threading.CancellationToken cancellationToken, OmniSharp.Extensions.Embedded.MediatR.RequestHandlerDelegate`1[TResponse] next) [0x000e1] in <c33e73e38fa14bf293bda2f62d3759c4>:0 
  at OmniSharp.Extensions.LanguageServer.Server.LspRequestRouter.RouteRequest (OmniSharp.Extensions.JsonRpc.IHandlerDescriptor descriptor, OmniSharp.Extensions.JsonRpc.Server.Request request) [0x002e2] in <c33e73e38fa14bf293bda2f62d3759c4>:0

For reference, this seems to be the command that vim-ale is sending to initialize the LSP:

{"method": "initialize", "jsonrpc": "2.0", "id": 1, "params": {"initializationOptions": {}, "rootUri": "file:///Users/luiz/projects/mgsb", "capabilities": {}, "rootPath": "/Users/luiz/projects/mgsb", "processId": 28524}}

Any idea what's up?

lsp

Most helpful comment

Some capabilities are now sent by ALE, but you should also allow clients to connect to the server without sending any capabilities. All of the keys are optional.

All 8 comments

@luizribeiro I think this is most likely because you don't send any client capabilities in your initialization request. Try to add at least support for text synchronization in your client implementation.

Thanks @mholo65, you are right! Looks like vim-ale doesn't send any capabilities because of a TODO that was left behind:

https://github.com/w0rp/ale/blob/3b7c86e401eb488acd8713f7c9ee81344095080d/autoload/ale/lsp/message.vim#L32-L40

Aren't all these fields optional on the LSP spec?

LSP should announce the capabilities it supports, but this is the first server I encounter that doesn't work with vim-ale because of this.

Either way, sending this as the capabilities made me get past the initialize message:

{  
   "workspace":{},
   "textDocument":{  
      "completion":{  
         "completionItem":{  
            "snippetSupport":false
         }
      }
   }
}

When I tried sending the text synchronization, I ran into #1403.

Some capabilities are now sent by ALE, but you should also allow clients to connect to the server without sending any capabilities. All of the keys are optional.

@w0rp yes, that鈥檚 a bug in the LSP implementation we are using. We are currently seeing other issues regarding initialization (and capabilities) and will put this on the list of things to do. //cc @david-driscoll

Just got hit by this using omnisharp-mono.tar.gz from v1.34.0. I guess the fix hasn't been incorporated here yet.

I worked around it by adding "workspace": {} to my request. Thank you @luizribeiro for sharing your code.

I'm pretty sure we can close this. I've been using omnisharp-roslyn successfully with vim-ale.

Thanks for all your work on this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

natemcmaster picture natemcmaster  路  5Comments

carlossanlop picture carlossanlop  路  6Comments

bradwilson picture bradwilson  路  3Comments

k-ode picture k-ode  路  7Comments

jrieken picture jrieken  路  7Comments