Add initialization_options to Sorbet LSP linter (#4954)

* Add initialization_options to Sorbet LSP linter

Using a predefined object will ensure that Sorbet always receives an
object instead of an array. 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

* Document empty objects will prevent Sorbet from properly initializing
This commit is contained in:
Leo Correa
2025-07-20 12:13:33 +02:00
committed by GitHub
parent 9abe393961
commit c8890af8d4
3 changed files with 29 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
call ale#Set('ruby_sorbet_executable', 'srb') call ale#Set('ruby_sorbet_executable', 'srb')
call ale#Set('ruby_sorbet_options', '') call ale#Set('ruby_sorbet_options', '')
call ale#Set('ruby_sorbet_enable_watchman', 0) call ale#Set('ruby_sorbet_enable_watchman', 0)
call ale#Set('ruby_sorbet_initialization_options', { 'highlightUntyped': v:false })
function! ale_linters#ruby#sorbet#GetCommand(buffer) abort function! ale_linters#ruby#sorbet#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_sorbet_executable') let l:executable = ale#Var(a:buffer, 'ruby_sorbet_executable')
@@ -21,6 +22,6 @@ call ale#linter#Define('ruby', {
\ 'language': 'ruby', \ 'language': 'ruby',
\ 'executable': {b -> ale#Var(b, 'ruby_sorbet_executable')}, \ 'executable': {b -> ale#Var(b, 'ruby_sorbet_executable')},
\ 'command': function('ale_linters#ruby#sorbet#GetCommand'), \ 'command': function('ale_linters#ruby#sorbet#GetCommand'),
\ 'project_root': function('ale#ruby#FindProjectRoot') \ 'project_root': function('ale#ruby#FindProjectRoot'),
\ 'initialization_options': {b -> ale#Var(b, 'ruby_sorbet_initialization_options')}
\}) \})

View File

@@ -267,6 +267,23 @@ g:ale_ruby_sorbet_enable_watchman
to files from outside of vim. Defaults to disable watchman because it to files from outside of vim. Defaults to disable watchman because it
requires watchman to be installed separately from sorbet. requires watchman to be installed separately from sorbet.
*ale-options.ruby_sorbet_initialization_options*
*g:ale_ruby_sorbet_initialization_options*
*b:ale_ruby_sorbet_initialization_options*
ruby_sorbet_initialization_options
g:ale_ruby_sorbet_initialization_options
Type: |Dictionary|
Default: `{ 'highlightUntyped': v:false }`
This variable can be changed to modify initialization options provided to
the Sorbet language server. By default, a minimal object with defaults is
provided to ensure proper LSP initialization.
Setting this variable to a an empty object will cause sorbet LSP to
fail during initialization.
See https://sorbet.org/docs/lsp#initialize-request for available options.
=============================================================================== ===============================================================================
standardrb *ale-ruby-standardrb* standardrb *ale-ruby-standardrb*

View File

@@ -6,6 +6,7 @@ Before:
let g:ale_ruby_sorbet_executable = 'srb' let g:ale_ruby_sorbet_executable = 'srb'
let g:ale_ruby_sorbet_options = '' let g:ale_ruby_sorbet_options = ''
let g:ale_ruby_sorbet_enable_watchman = 0 let g:ale_ruby_sorbet_enable_watchman = 0
let g:ale_ruby_sorbet_initialization_options = { 'highlightUntyped': v:false }
After: After:
call ale#assert#TearDownLinterTest() call ale#assert#TearDownLinterTest()
@@ -32,3 +33,11 @@ Execute(Setting bundle appends 'exec srb tc'):
AssertLinter 'path to/bundle', ale#Escape('path to/bundle') AssertLinter 'path to/bundle', ale#Escape('path to/bundle')
\ . ' exec srb' \ . ' exec srb'
\ . ' tc --lsp --disable-watchman' \ . ' tc --lsp --disable-watchman'
Execute(Should use predetermined initialization_options by default):
AssertLSPOptions { 'highlightUntyped': v:false }
Execute(Should be able to set custom initialization_options):
let g:ale_ruby_sorbet_initialization_options = {'enableTypedFalse': v:true}
AssertLSPOptions {'enableTypedFalse': v:true}