#517 Support linter settings needed for LSP, undocumented for now
This commit is contained in:
parent
d8d96fb0eb
commit
04190cbcfe
@ -51,6 +51,7 @@ function! ale#linter#PreProcess(linter) abort
|
||||
|
||||
let l:obj = {
|
||||
\ 'name': get(a:linter, 'name'),
|
||||
\ 'lsp': get(a:linter, 'lsp', ''),
|
||||
\ 'callback': get(a:linter, 'callback'),
|
||||
\}
|
||||
|
||||
@ -62,7 +63,27 @@ function! ale#linter#PreProcess(linter) abort
|
||||
throw '`callback` must be defined with a callback to accept output'
|
||||
endif
|
||||
|
||||
if has_key(a:linter, 'executable_callback')
|
||||
let l:needs_executable = 0
|
||||
let l:needs_address = 0
|
||||
let l:needs_command = 0
|
||||
|
||||
if l:obj.lsp ==# 'tsserver'
|
||||
let l:needs_executable = 1
|
||||
elseif l:obj.lsp ==# 'lsp'
|
||||
let l:needs_address = 1
|
||||
elseif !empty(l:obj.lsp)
|
||||
throw '`lsp` must be either `''lsp''` or `''tsserver''` if defined'
|
||||
else
|
||||
let l:needs_executable = 1
|
||||
let l:needs_command = 1
|
||||
endif
|
||||
|
||||
if !l:needs_executable
|
||||
if has_key(a:linter, 'executable')
|
||||
\|| has_key(a:linter, 'executable_callback')
|
||||
throw '`executable` and `executable_callback` cannot be used when lsp == ''lsp'''
|
||||
endif
|
||||
elseif has_key(a:linter, 'executable_callback')
|
||||
let l:obj.executable_callback = a:linter.executable_callback
|
||||
|
||||
if !s:IsCallback(l:obj.executable_callback)
|
||||
@ -78,7 +99,13 @@ function! ale#linter#PreProcess(linter) abort
|
||||
throw 'Either `executable` or `executable_callback` must be defined'
|
||||
endif
|
||||
|
||||
if has_key(a:linter, 'command_chain')
|
||||
if !l:needs_command
|
||||
if has_key(a:linter, 'command')
|
||||
\|| has_key(a:linter, 'command_callback')
|
||||
\|| has_key(a:linter, 'command_chain')
|
||||
throw '`command` and `command_callback` and `command_chain` cannot be used when `lsp` is set'
|
||||
endif
|
||||
elseif has_key(a:linter, 'command_chain')
|
||||
let l:obj.command_chain = a:linter.command_chain
|
||||
|
||||
if type(l:obj.command_chain) != type([])
|
||||
@ -138,6 +165,20 @@ function! ale#linter#PreProcess(linter) abort
|
||||
\ . 'should be set'
|
||||
endif
|
||||
|
||||
if !l:needs_address
|
||||
if has_key(a:linter, 'address_callback')
|
||||
throw '`address_callback` cannot be used when lsp != ''lsp'''
|
||||
endif
|
||||
elseif has_key(a:linter, 'address_callback')
|
||||
let l:obj.address_callback = a:linter.address_callback
|
||||
|
||||
if !s:IsCallback(l:obj.address_callback)
|
||||
throw '`address_callback` must be a callback if defined'
|
||||
endif
|
||||
else
|
||||
throw '`address_callback` must be defined for getting the LSP address'
|
||||
endif
|
||||
|
||||
let l:obj.output_stream = get(a:linter, 'output_stream', 'stdout')
|
||||
|
||||
if type(l:obj.output_stream) != type('')
|
||||
|
@ -365,3 +365,74 @@ Execute(PreProcess should accept `aliases` lists):
|
||||
let g:linter.aliases = ['foo', 'bar']
|
||||
|
||||
AssertEqual ['foo', 'bar'], ale#linter#PreProcess(g:linter).aliases
|
||||
|
||||
Execute(PreProcess should accept tsserver LSP configuration):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'executable': 'x',
|
||||
\ 'lsp': 'tsserver',
|
||||
\ 'callback': 'x',
|
||||
\}
|
||||
|
||||
AssertEqual 'tsserver', ale#linter#PreProcess(g:linter).lsp
|
||||
|
||||
call remove(g:linter, 'executable')
|
||||
let g:linter.executable_callback = 'X'
|
||||
|
||||
call ale#linter#PreProcess(g:linter).lsp
|
||||
|
||||
Execute(PreProcess should complain about commands being set for LSP configurations):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'executable': 'x',
|
||||
\ 'lsp': 'tsserver',
|
||||
\ 'command': 'x',
|
||||
\ 'callback': 'x',
|
||||
\}
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`command` and `command_callback` and `command_chain` cannot be used when `lsp` is set', g:vader_exception
|
||||
|
||||
call remove(g:linter, 'command')
|
||||
let g:linter.command_callback = 'X'
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`command` and `command_callback` and `command_chain` cannot be used when `lsp` is set', g:vader_exception
|
||||
|
||||
call remove(g:linter, 'command_callback')
|
||||
let g:linter.command_chain = []
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`command` and `command_callback` and `command_chain` cannot be used when `lsp` is set', g:vader_exception
|
||||
|
||||
Execute(PreProcess should accept LSP server configurations):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'lsp': 'lsp',
|
||||
\ 'callback': 'x',
|
||||
\ 'address_callback': 'X',
|
||||
\}
|
||||
|
||||
AssertEqual 'lsp', ale#linter#PreProcess(g:linter).lsp
|
||||
|
||||
Execute(PreProcess should require an address_callback for LSP server configurations):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'lsp': 'lsp',
|
||||
\ 'callback': 'x',
|
||||
\}
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`address_callback` must be defined for getting the LSP address', g:vader_exception
|
||||
|
||||
Execute(PreProcess should complain about address_callback for non-LSP linters):
|
||||
let g:linter = {
|
||||
\ 'name': 'x',
|
||||
\ 'callback': 'SomeFunction',
|
||||
\ 'executable': 'echo',
|
||||
\ 'command': 'echo',
|
||||
\ 'address_callback': 'X',
|
||||
\}
|
||||
|
||||
AssertThrows call ale#linter#PreProcess(g:linter)
|
||||
AssertEqual '`address_callback` cannot be used when lsp != ''lsp''', g:vader_exception
|
||||
|
@ -1,8 +1,8 @@
|
||||
Before:
|
||||
Save g:ale_linters, g:ale_linter_aliases
|
||||
|
||||
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0, 'aliases': []}
|
||||
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1, 'aliases': []}
|
||||
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': ''}
|
||||
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1, 'aliases': [], 'lsp': ''}
|
||||
call ale#linter#Reset()
|
||||
|
||||
After:
|
||||
@ -105,4 +105,4 @@ Execute (The local alias option shouldn't completely replace the global one):
|
||||
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')
|
||||
|
||||
Execute (Linters should be loaded from disk appropriately):
|
||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0, 'aliases': []}], ale#linter#Get('testft')
|
||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': ''}], ale#linter#Get('testft')
|
||||
|
Loading…
Reference in New Issue
Block a user