mirror of https://github.com/amix/vimrc.git
parent
2f164fee9b
commit
cc997dc3d0
@ -0,0 +1,38 @@ |
||||
" Author: t_t <jamestthompson3@gmail.com> |
||||
" Description: Integrate ALE with flow-language-server. |
||||
|
||||
call ale#Set('javascript_flow_ls_executable', 'flow') |
||||
call ale#Set('javascript_flow_ls_use_global', |
||||
\ get(g:, 'ale_use_global_executables', 0) |
||||
\) |
||||
|
||||
function! ale_linters#javascript#flow_ls#GetExecutable(buffer) abort |
||||
return ale#node#FindExecutable(a:buffer, 'javascript_flow_ls', [ |
||||
\ 'node_modules/.bin/flow', |
||||
\]) |
||||
endfunction |
||||
|
||||
function! ale_linters#javascript#flow_ls#GetCommand(buffer) abort |
||||
let l:executable = ale_linters#javascript#flow_ls#GetExecutable(a:buffer) |
||||
|
||||
return ale#Escape(l:executable) . ' lsp --from ale-lsp' |
||||
endfunction |
||||
|
||||
function! ale_linters#javascript#flow_ls#FindProjectRoot(buffer) abort |
||||
let l:flow_config = ale#path#FindNearestFile(a:buffer, '.flowconfig') |
||||
|
||||
if !empty(l:flow_config) |
||||
return fnamemodify(l:flow_config, ':h') |
||||
endif |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('javascript', { |
||||
\ 'name': 'flow-language-server', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable_callback': 'ale_linters#javascript#flow_ls#GetExecutable', |
||||
\ 'command_callback': 'ale_linters#javascript#flow_ls#GetCommand', |
||||
\ 'project_root_callback': 'ale_linters#javascript#flow_ls#FindProjectRoot', |
||||
\ 'language': 'javascript', |
||||
\}) |
@ -0,0 +1,38 @@ |
||||
" Author: MTDL9 <https://github.com/MTDL9> |
||||
" Description: Support for the Kotlin language server https://github.com/fwcd/KotlinLanguageServer |
||||
|
||||
call ale#Set('kotlin_languageserver_executable', 'kotlin-language-server') |
||||
|
||||
function! ale_linters#kotlin#languageserver#GetExecutable(buffer) abort |
||||
return ale#Var(a:buffer, 'kotlin_languageserver_executable') |
||||
endfunction |
||||
|
||||
function! ale_linters#kotlin#languageserver#GetCommand(buffer) abort |
||||
let l:executable = ale_linters#kotlin#languageserver#GetExecutable(a:buffer) |
||||
return ale#Escape(l:executable) |
||||
endfunction |
||||
|
||||
function! ale_linters#kotlin#languageserver#GetProjectRoot(buffer) abort |
||||
let l:gradle_root = ale#gradle#FindProjectRoot(a:buffer) |
||||
|
||||
if !empty(l:gradle_root) |
||||
return l:gradle_root |
||||
endif |
||||
|
||||
let l:maven_pom_file = ale#path#FindNearestFile(a:buffer, 'pom.xml') |
||||
|
||||
if !empty(l:maven_pom_file) |
||||
return fnamemodify(l:maven_pom_file, ':h') |
||||
endif |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('kotlin', { |
||||
\ 'name': 'languageserver', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable_callback': 'ale_linters#kotlin#languageserver#GetExecutable', |
||||
\ 'command_callback': 'ale_linters#kotlin#languageserver#GetCommand', |
||||
\ 'language': 'kotlin', |
||||
\ 'project_root_callback': 'ale_linters#kotlin#languageserver#GetProjectRoot', |
||||
\}) |
@ -0,0 +1,45 @@ |
||||
" Author: Alexander Olofsson <alexander.olofsson@liu.se> |
||||
" Description: Puppet Language Server integration for ALE |
||||
|
||||
call ale#Set('puppet_languageserver_executable', 'puppet-languageserver') |
||||
|
||||
function! ale_linters#puppet#languageserver#GetExecutable(buffer) abort |
||||
return ale#Var(a:buffer, 'puppet_languageserver_executable') |
||||
endfunction |
||||
|
||||
function! ale_linters#puppet#languageserver#GetCommand(buffer) abort |
||||
let l:exe = ale#Escape(ale_linters#puppet#languageserver#GetExecutable(a:buffer)) |
||||
|
||||
return l:exe . ' --stdio' |
||||
endfunction |
||||
|
||||
function! ale_linters#puppet#languageserver#GetProjectRoot(buffer) abort |
||||
" Note: The metadata.json file is recommended for Puppet 4+ modules, but |
||||
" there's no requirement to have it, so fall back to the other possible |
||||
" Puppet module directories |
||||
let l:root_path = ale#path#FindNearestFile(a:buffer, 'metadata.json') |
||||
if !empty(l:root_path) |
||||
return fnamemodify(l:root_path, ':h') |
||||
endif |
||||
|
||||
for l:test_path in [ |
||||
\ 'manifests', |
||||
\ 'templates', |
||||
\] |
||||
let l:root_path = ale#path#FindNearestDirectory(a:buffer, l:test_path) |
||||
if !empty(l:root_path) |
||||
return fnamemodify(l:root_path, ':h:h') |
||||
endif |
||||
endfor |
||||
|
||||
return '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('puppet', { |
||||
\ 'name': 'languageserver', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable_callback': 'ale_linters#puppet#languageserver#GetExecutable', |
||||
\ 'command_callback': 'ale_linters#puppet#languageserver#GetCommand', |
||||
\ 'language': 'puppet', |
||||
\ 'project_root_callback': 'ale_linters#puppet#languageserver#GetProjectRoot', |
||||
\}) |
@ -0,0 +1,32 @@ |
||||
" Author: Alexander Olofsson <alexander.olofsson@liu.se> |
||||
" Description: Vue vls Language Server integration for ALE |
||||
|
||||
call ale#Set('vue_vls_executable', 'vls') |
||||
call ale#Set('vue_vls_use_global', get(g:, 'ale_use_global_executables', 0)) |
||||
|
||||
function! ale_linters#vue#vls#GetExecutable(buffer) abort |
||||
return ale#node#FindExecutable(a:buffer, 'vue_vls', [ |
||||
\ 'node_modules/.bin/vls', |
||||
\]) |
||||
endfunction |
||||
|
||||
function! ale_linters#vue#vls#GetCommand(buffer) abort |
||||
let l:exe = ale#Escape(ale_linters#vue#vls#GetExecutable(a:buffer)) |
||||
|
||||
return l:exe . ' --stdio' |
||||
endfunction |
||||
|
||||
function! ale_linters#vue#vls#GetProjectRoot(buffer) abort |
||||
let l:package_path = ale#path#FindNearestFile(a:buffer, 'package.json') |
||||
|
||||
return !empty(l:package_path) ? fnamemodify(l:package_path, ':h') : '' |
||||
endfunction |
||||
|
||||
call ale#linter#Define('vue', { |
||||
\ 'name': 'vls', |
||||
\ 'lsp': 'stdio', |
||||
\ 'executable_callback': 'ale_linters#vue#vls#GetExecutable', |
||||
\ 'command_callback': 'ale_linters#vue#vls#GetCommand', |
||||
\ 'language': 'vue', |
||||
\ 'project_root_callback': 'ale_linters#vue#vls#GetProjectRoot', |
||||
\}) |
@ -0,0 +1,159 @@ |
||||
let s:chain_results = [] |
||||
|
||||
function! ale#assert#WithChainResults(...) abort |
||||
let s:chain_results = a:000 |
||||
endfunction |
||||
|
||||
function! s:GetLinter() abort |
||||
let l:linters = ale#linter#GetLintersLoaded() |
||||
let l:filetype_linters = get(values(l:linters), 0, []) |
||||
|
||||
if len(l:linters) is 0 || len(l:filetype_linters) is 0 |
||||
throw 'No linters were loaded' |
||||
endif |
||||
|
||||
if len(l:linters) > 1 || len(l:filetype_linters) > 1 |
||||
throw 'More than one linter was loaded' |
||||
endif |
||||
|
||||
return l:filetype_linters[0] |
||||
endfunction |
||||
|
||||
" Load the currently loaded linter for a test case, and check that the command |
||||
" matches the given string. |
||||
function! ale#assert#Linter(expected_executable, expected_command) abort |
||||
let l:buffer = bufnr('') |
||||
let l:linter = s:GetLinter() |
||||
let l:executable = ale#linter#GetExecutable(l:buffer, l:linter) |
||||
|
||||
if has_key(l:linter, 'command_chain') |
||||
let l:callbacks = map(copy(l:linter.command_chain), 'v:val.callback') |
||||
|
||||
" If the expected command is a string, just check the last one. |
||||
if type(a:expected_command) is type('') |
||||
if len(l:callbacks) is 1 |
||||
let l:command = call(l:callbacks[0], [l:buffer]) |
||||
else |
||||
let l:input = get(s:chain_results, len(l:callbacks) - 2, []) |
||||
let l:command = call(l:callbacks[-1], [l:buffer, l:input]) |
||||
endif |
||||
else |
||||
let l:command = [] |
||||
let l:chain_index = 0 |
||||
|
||||
for l:Callback in l:callbacks |
||||
if l:chain_index is 0 |
||||
call add(l:command, call(l:Callback, [l:buffer])) |
||||
else |
||||
let l:input = get(s:chain_results, l:chain_index - 1, []) |
||||
call add(l:command, call(l:Callback, [l:buffer, l:input])) |
||||
endif |
||||
|
||||
let l:chain_index += 1 |
||||
endfor |
||||
endif |
||||
else |
||||
let l:command = ale#linter#GetCommand(l:buffer, l:linter) |
||||
" Replace %e with the escaped executable, so tests keep passing after |
||||
" linters are changed to use %e. |
||||
let l:command = substitute(l:command, '%e', '\=ale#Escape(l:executable)', 'g') |
||||
endif |
||||
|
||||
AssertEqual |
||||
\ [a:expected_executable, a:expected_command], |
||||
\ [l:executable, l:command] |
||||
endfunction |
||||
|
||||
function! ale#assert#LinterNotExecuted() abort |
||||
let l:buffer = bufnr('') |
||||
let l:linter = s:GetLinter() |
||||
let l:executable = ale#linter#GetExecutable(l:buffer, l:linter) |
||||
|
||||
Assert empty(l:executable), "The linter will be executed when it shouldn't be" |
||||
endfunction |
||||
|
||||
function! ale#assert#LSPOptions(expected_options) abort |
||||
let l:buffer = bufnr('') |
||||
let l:linter = s:GetLinter() |
||||
let l:initialization_options = ale#lsp_linter#GetOptions(l:buffer, l:linter) |
||||
|
||||
AssertEqual a:expected_options, l:initialization_options |
||||
endfunction |
||||
|
||||
function! ale#assert#LSPLanguage(expected_language) abort |
||||
let l:buffer = bufnr('') |
||||
let l:linter = s:GetLinter() |
||||
let l:language = ale#util#GetFunction(l:linter.language_callback)(l:buffer) |
||||
|
||||
AssertEqual a:expected_language, l:language |
||||
endfunction |
||||
|
||||
function! ale#assert#LSPProject(expected_root) abort |
||||
let l:buffer = bufnr('') |
||||
let l:linter = s:GetLinter() |
||||
let l:root = ale#util#GetFunction(l:linter.project_root_callback)(l:buffer) |
||||
|
||||
AssertEqual a:expected_root, l:root |
||||
endfunction |
||||
|
||||
" A dummy function for making sure this module is loaded. |
||||
function! ale#assert#SetUpLinterTest(filetype, name) abort |
||||
" Set up a marker so ALE doesn't create real random temporary filenames. |
||||
let g:ale_create_dummy_temporary_file = 1 |
||||
|
||||
" Remove current linters. |
||||
call ale#linter#Reset() |
||||
call ale#linter#PreventLoading(a:filetype) |
||||
|
||||
let l:prefix = 'ale_' . a:filetype . '_' . a:name |
||||
let b:filter_expr = 'v:val[: len(l:prefix) - 1] is# l:prefix' |
||||
|
||||
Save g:ale_c_build_dir |
||||
unlet! g:ale_c_build_dir |
||||
|
||||
" Save and clear linter variables. |
||||
" We'll load the runtime file to reset them to defaults. |
||||
for l:key in filter(keys(g:), b:filter_expr) |
||||
execute 'Save g:' . l:key |
||||
unlet g:[l:key] |
||||
endfor |
||||
|
||||
unlet! b:ale_c_build_dir |
||||
|
||||
for l:key in filter(keys(b:), b:filter_expr) |
||||
unlet b:[l:key] |
||||
endfor |
||||
|
||||
execute 'runtime ale_linters/' . a:filetype . '/' . a:name . '.vim' |
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/command_callback') |
||||
|
||||
command! -nargs=+ WithChainResults :call ale#assert#WithChainResults(<args>) |
||||
command! -nargs=+ AssertLinter :call ale#assert#Linter(<args>) |
||||
command! -nargs=0 AssertLinterNotExecuted :call ale#assert#LinterNotExecuted() |
||||
command! -nargs=+ AssertLSPOptions :call ale#assert#LSPOptions(<args>) |
||||
command! -nargs=+ AssertLSPLanguage :call ale#assert#LSPLanguage(<args>) |
||||
command! -nargs=+ AssertLSPProject :call ale#assert#LSPProject(<args>) |
||||
endfunction |
||||
|
||||
function! ale#assert#TearDownLinterTest() abort |
||||
unlet! g:ale_create_dummy_temporary_file |
||||
let s:chain_results = [] |
||||
|
||||
delcommand WithChainResults |
||||
delcommand AssertLinter |
||||
delcommand AssertLinterNotExecuted |
||||
delcommand AssertLSPOptions |
||||
delcommand AssertLSPLanguage |
||||
delcommand AssertLSPProject |
||||
|
||||
call ale#test#RestoreDirectory() |
||||
|
||||
Restore |
||||
|
||||
call ale#linter#Reset() |
||||
|
||||
if exists('*ale#semver#ResetVersionCache') |
||||
call ale#semver#ResetVersionCache() |
||||
endif |
||||
endfunction |