ale icon indicating copy to clipboard operation
ale copied to clipboard

Add initialization_options to Sorbet LSP linter

Open Tonkpils opened this issue 7 months ago • 2 comments

I started getting an error in neovim when opening ruby files with the Sorbet linter.

Error executing vim.schedule lua callback: ...nvimEllFDd/usr/share/nvim/runtime/lua/vim/lsp/client.lua:548: RPC[Error] code_name = InvalidParams, message = "Unable to deserialize LSP request: Error deserializing JSON message: Expected field `InitializeParams.initializationOptions` to have value of type `object`, but had value `[]`."
stack traceback:
        [C]: in function 'assert'
        ...nvimEllFDd/usr/share/nvim/runtime/lua/vim/lsp/cl…

Turns out Lua's uses the same underlying table data type for both arrays and dictionaries. Whenever we pass nothing or {} to neovim's LSP client, it gets serialized as an []. LSP defines the initializationOptions as anything. Unfortunately Sorbet is too strict and raises an error when anything other than an object is passed which causes the linter to fail.

Using a predefined object will ensure that Sorbet always receives an object instead of an array. This also allows users of this to set their own LSP initialization options

I'm thinking of following up with a PR to Sorbet's LSP implementation to relax that requirement a bit more or at least not crash in this situations but I figured this would be a good start.

Tonkpils avatar Apr 22 '25 13:04 Tonkpils

@w0rp 👋 after a bit of a discussion in my Sorbet PR https://github.com/sorbet/sorbet/pull/8796, it seems like the sensible thing is for ALE to not predefine an empty dictionary and instead skip sending the field altogether to the server. I'm happy with leaving the default presented in this PR but let me know if there's a different approach you'd like to take

Tonkpils avatar Apr 25 '25 17:04 Tonkpils

👋 @w0rp any thoughts on this?

Tonkpils avatar May 13 '25 04:05 Tonkpils

This pull request has been automatically marked as stale because it has not been updated recently. Make sure to write tests and document your changes. See :help ale-dev for information on writing tests. If your pull request is good to merge, bother w0rp or another maintainer again, and get them to merge it.

stale[bot] avatar Jul 18 '25 23:07 stale[bot]

I think Appveyor got stuck here so this never got merged. I'll force it in and fix Appyeyor if it fails later.

w0rp avatar Jul 20 '25 10:07 w0rp