mirror of
https://github.com/dense-analysis/ale
synced 2024-12-17 20:05:31 +00:00
Add support for lua-language-server
This commit is contained in:
parent
da5fa17df1
commit
f2a21c960a
15
ale_linters/lua/lua_language_server.vim
Normal file
15
ale_linters/lua/lua_language_server.vim
Normal file
@ -0,0 +1,15 @@
|
||||
" Author: w0rp <dev@w0rp.com>
|
||||
" Description: lua-language-server integration (https://github.com/LuaLS/lua-language-server)
|
||||
|
||||
call ale#Set('lua_language_server_executable', 'lua-language-server')
|
||||
call ale#Set('lua_language_server_config', {})
|
||||
|
||||
call ale#linter#Define('lua', {
|
||||
\ 'name': 'lua_language_server',
|
||||
\ 'aliases': ['lua-language-server'],
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'lua_language_server_executable')},
|
||||
\ 'command': '%e',
|
||||
\ 'project_root': function('ale#lua#FindProjectRoot'),
|
||||
\ 'lsp_config': {b -> ale#Var(b, 'lua_language_server_config')},
|
||||
\})
|
28
autoload/ale/lua.vim
Normal file
28
autoload/ale/lua.vim
Normal file
@ -0,0 +1,28 @@
|
||||
" Author: w0rp <dev@w0rp.com>
|
||||
" Description: Functions for integrating with Lua linters.
|
||||
|
||||
" Find project root for a Lua language server.
|
||||
function! ale#lua#FindProjectRoot(buffer) abort
|
||||
let l:possible_project_roots = [
|
||||
\ '.git',
|
||||
\ bufname(a:buffer),
|
||||
\]
|
||||
|
||||
for l:possible_root in l:possible_project_roots
|
||||
let l:project_root = ale#path#FindNearestFile(a:buffer, l:possible_root)
|
||||
|
||||
if empty(l:project_root)
|
||||
let l:project_root = ale#path#FindNearestDirectory(a:buffer, l:possible_root)
|
||||
endif
|
||||
|
||||
if !empty(l:project_root)
|
||||
" dir:p expands to /full/path/to/dir/ whereas
|
||||
" file:p expands to /full/path/to/file (no trailing slash)
|
||||
" Appending '/' ensures that :h:h removes the path's last segment
|
||||
" regardless of whether it is a directory or not.
|
||||
return fnamemodify(l:project_root . '/', ':p:h:h')
|
||||
endif
|
||||
endfor
|
||||
|
||||
return ''
|
||||
endfunction
|
@ -27,6 +27,30 @@ g:ale_lua_lua_format_options *g:ale_lua_lua_format_options*
|
||||
This variable can be set to pass additional options to lua-format.
|
||||
|
||||
|
||||
===============================================================================
|
||||
lua-language-server *ale-lua-lua-language-server*
|
||||
*ale-lua-language-server*
|
||||
|
||||
g:ale_lua_language_server_executable *g:ale_lua_language_server_executable*
|
||||
*b:ale_lua_language_server_executable*
|
||||
Type: |String|
|
||||
Default: `'lua-language-server'`
|
||||
|
||||
This variable can be changed to set the path to lua-language-server.
|
||||
|
||||
If you have compiled the language server yourself in `/some/path`, the path
|
||||
will be `'/some/path/bin/lua-language-server'`.
|
||||
|
||||
|
||||
g:ale_lua_lua_language_server_config *g:ale_lua_lua_language_server_config*
|
||||
*b:ale_lua_lua_language_server_config*
|
||||
Type: |Dictionary|
|
||||
Default: `{}`
|
||||
|
||||
Dictionary containing configuration settings that will be passed to the
|
||||
language server.
|
||||
|
||||
|
||||
===============================================================================
|
||||
luac *ale-lua-luac*
|
||||
|
||||
|
@ -341,6 +341,7 @@ Notes:
|
||||
* Lua
|
||||
* `cspell`
|
||||
* `lua-format`
|
||||
* `lua-language-server`
|
||||
* `luac`
|
||||
* `luacheck`
|
||||
* `luafmt`
|
||||
|
@ -3068,6 +3068,7 @@ documented in additional help files.
|
||||
lua.....................................|ale-lua-options|
|
||||
cspell................................|ale-lua-cspell|
|
||||
lua-format............................|ale-lua-lua-format|
|
||||
lua-language-server...................|ale-lua-lua-language-server|
|
||||
luac..................................|ale-lua-luac|
|
||||
luacheck..............................|ale-lua-luacheck|
|
||||
luafmt................................|ale-lua-luafmt|
|
||||
|
@ -350,6 +350,7 @@ formatting.
|
||||
* Lua
|
||||
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
||||
* [lua-format](https://github.com/Koihik/LuaFormatter)
|
||||
* [lua-language-server](https://github.com/LuaLS/lua-language-server)
|
||||
* [luac](https://www.lua.org/manual/5.1/luac.html)
|
||||
* [luacheck](https://github.com/mpeterv/luacheck)
|
||||
* [luafmt](https://github.com/trixnz/lua-fmt)
|
||||
|
16
test/linter/test_lua_language_server.vader
Normal file
16
test/linter/test_lua_language_server.vader
Normal file
@ -0,0 +1,16 @@
|
||||
Before:
|
||||
call ale#assert#SetUpLinterTest('lua', 'lua_language_server')
|
||||
|
||||
After:
|
||||
call ale#assert#TearDownLinterTest()
|
||||
|
||||
Execute(The default lua-language-server settings should be correct):
|
||||
AssertLinter 'lua-language-server', ale#Escape('lua-language-server')
|
||||
AssertLSPConfig {}
|
||||
|
||||
Execute(lua-language-server should be configurable):
|
||||
let b:ale_lua_language_server_executable = 'billy'
|
||||
let b:ale_lua_language_server_config = {'x': 'y'}
|
||||
|
||||
AssertLinter 'billy', ale#Escape('billy')
|
||||
AssertLSPConfig {'x': 'y'}
|
Loading…
Reference in New Issue
Block a user