summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2023-02-08 01:14:47 +0000
committerw0rp <devw0rp@gmail.com>2023-02-08 01:14:47 +0000
commitf2a21c960aba61d4ab0a0b50051b29ab8c893249 (patch)
treeb2e338dc61f0e3da1e43a3cd1eb121e441eecc60
parentda5fa17df1182c3a4a30cc537b21df981f9bf93c (diff)
downloadale-f2a21c960aba61d4ab0a0b50051b29ab8c893249.zip
Add support for lua-language-server
-rw-r--r--ale_linters/lua/lua_language_server.vim15
-rw-r--r--autoload/ale/lua.vim28
-rw-r--r--doc/ale-lua.txt24
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/linter/test_lua_language_server.vader16
7 files changed, 86 insertions, 0 deletions
diff --git a/ale_linters/lua/lua_language_server.vim b/ale_linters/lua/lua_language_server.vim
new file mode 100644
index 00000000..ebddd4b5
--- /dev/null
+++ b/ale_linters/lua/lua_language_server.vim
@@ -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')},
+\})
diff --git a/autoload/ale/lua.vim b/autoload/ale/lua.vim
new file mode 100644
index 00000000..cda81aac
--- /dev/null
+++ b/autoload/ale/lua.vim
@@ -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
diff --git a/doc/ale-lua.txt b/doc/ale-lua.txt
index 7ee60d0e..62d67324 100644
--- a/doc/ale-lua.txt
+++ b/doc/ale-lua.txt
@@ -28,6 +28,30 @@ g:ale_lua_lua_format_options *g:ale_lua_lua_format_options*
===============================================================================
+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*
g:ale_lua_luac_executable *g:ale_lua_luac_executable*
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 705eef41..b84fbdae 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -341,6 +341,7 @@ Notes:
* Lua
* `cspell`
* `lua-format`
+ * `lua-language-server`
* `luac`
* `luacheck`
* `luafmt`
diff --git a/doc/ale.txt b/doc/ale.txt
index afaf098c..1ed74ec5 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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|
diff --git a/supported-tools.md b/supported-tools.md
index a3008b5c..408bbce1 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -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)
diff --git a/test/linter/test_lua_language_server.vader b/test/linter/test_lua_language_server.vader
new file mode 100644
index 00000000..c4529835
--- /dev/null
+++ b/test/linter/test_lua_language_server.vader
@@ -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'}