Support zls language server for zig

This commit is contained in:
Sheheryar Parvaz 2020-07-10 20:14:12 -04:00
parent 106c27644b
commit 23c58e63d4
7 changed files with 74 additions and 0 deletions

20
ale_linters/zig/zls.vim Normal file
View File

@ -0,0 +1,20 @@
" Author: CherryMan <skipper308@hotmail.ca>
" Description: A language server for Zig
call ale#Set('zig_zls_executable', 'zls')
call ale#Set('zig_zls_config', {})
function! ale_linters#zig#zls#GetProjectRoot(buffer) abort
let l:build_rs = ale#path#FindNearestFile(a:buffer, 'build.zig')
return !empty(l:build_rs) ? fnamemodify(l:build_rs, ':h') : ''
endfunction
call ale#linter#Define('zig', {
\ 'name': 'zls',
\ 'lsp': 'stdio',
\ 'lsp_config': {b -> ale#Var(b, 'zig_zls_config')},
\ 'executable': {b -> ale#Var(b, 'zig_zls_executable')},
\ 'command': '%e',
\ 'project_root': function('ale_linters#zig#zls#GetProjectRoot'),
\})

View File

@ -510,3 +510,5 @@ Notes:
* `yamllint`
* YANG
* `yang-lsp`
* Zig
* `zls`

33
doc/ale-zig.txt Normal file
View File

@ -0,0 +1,33 @@
===============================================================================
ALE Zig Integration *ale-zig-options*
*ale-integration-zig*
===============================================================================
Integration Information
Currently, the only supported linter for zig is zls.
===============================================================================
zls *ale-zig-zls*
g:ale_zig_zls_executable *g:ale_zig_zls_executable*
*b:ale_zig_zls_executable*
Type: |String|
Default: `'zls'`
This variable can be modified to change the executable path for `zls`.
g:ale_zig_zls_config *g:ale_zig_zls_config*
*b:ale_zig_zls_config*
Type: |Dictionary|
Default: `{}`
WARNING: As of writing, zls does not support receiving configuration
from the client. This variable is a PLACEHOLDER until it does.
Dictionary with configuration settings for zls.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -2676,6 +2676,8 @@ documented in additional help files.
yamllint..............................|ale-yaml-yamllint|
yang....................................|ale-yang-options|
yang-lsp..............................|ale-yang-lsp|
zig.....................................|ale-zig-options|
zls...................................|ale-zig-zls|
===============================================================================

View File

@ -519,3 +519,5 @@ formatting.
* [yamllint](https://yamllint.readthedocs.io/)
* YANG
* [yang-lsp](https://github.com/theia-ide/yang-lsp)
* Zig
* [zls](https://github.com/zigtools/zls)

View File

@ -0,0 +1,15 @@
Before:
call ale#assert#SetUpLinterTest('zig', 'zls')
After:
call ale#assert#TearDownLinterTest()
Execute(The default executable path should be correct):
AssertLinter 'zls', ale#Escape('zls')
Execute(The project root should be detected correctly):
AssertLSPProject ''
call ale#test#SetFilename('zig-zls-project/main.zig')
AssertLSPProject ale#path#Simplify(g:dir . '/zig-zls-project')