2022-11-25 13:13:38 +00:00
|
|
|
" Author: Horacio Sanson <https://github.com/hsanson>
|
|
|
|
" Description: Support ansible language server https://github.com/ansible/ansible-language-server/
|
|
|
|
|
|
|
|
call ale#Set('ansible_language_server_executable', 'ansible-language-server')
|
|
|
|
call ale#Set('ansible_language_server_config', {})
|
|
|
|
|
2023-09-13 23:38:12 +00:00
|
|
|
function! ale_linters#ansible#language_server#Executable(buffer) abort
|
2022-11-25 13:13:38 +00:00
|
|
|
return ale#Var(a:buffer, 'ansible_language_server_executable')
|
|
|
|
endfunction
|
|
|
|
|
2023-09-13 23:38:12 +00:00
|
|
|
function! ale_linters#ansible#language_server#GetCommand(buffer) abort
|
|
|
|
let l:executable = ale_linters#ansible#language_server#Executable(a:buffer)
|
2022-11-25 13:13:38 +00:00
|
|
|
|
|
|
|
return ale#Escape(l:executable) . ' --stdio'
|
|
|
|
endfunction
|
|
|
|
|
2023-09-13 23:38:12 +00:00
|
|
|
function! ale_linters#ansible#language_server#FindProjectRoot(buffer) abort
|
2022-11-25 13:13:38 +00:00
|
|
|
let l:dir = fnamemodify(
|
|
|
|
\ ale#path#FindNearestFile(a:buffer, 'ansible.cfg'),
|
|
|
|
\ ':h'
|
|
|
|
\)
|
|
|
|
|
|
|
|
if l:dir isnot# '.' && isdirectory(l:dir)
|
|
|
|
return l:dir
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:dir = fnamemodify(
|
|
|
|
\ ale#path#FindNearestDirectory(a:buffer, '.git'),
|
|
|
|
\ ':h:h'
|
|
|
|
\)
|
|
|
|
|
|
|
|
if l:dir isnot# '.' && isdirectory(l:dir)
|
|
|
|
return l:dir
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('ansible', {
|
2023-09-13 23:38:12 +00:00
|
|
|
\ 'name': 'language_server',
|
|
|
|
\ 'aliases': ['ansible_language_server', 'ansible-language-server'],
|
2022-11-25 13:13:38 +00:00
|
|
|
\ 'lsp': 'stdio',
|
2023-09-13 23:38:12 +00:00
|
|
|
\ 'executable': function('ale_linters#ansible#language_server#Executable'),
|
|
|
|
\ 'command': function('ale_linters#ansible#language_server#GetCommand'),
|
|
|
|
\ 'project_root': function('ale_linters#ansible#language_server#FindProjectRoot'),
|
2022-11-25 13:13:38 +00:00
|
|
|
\ 'lsp_config': {b -> ale#Var(b, 'ansible_language_server_config')}
|
|
|
|
\})
|