diff options
author | Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com> | 2022-10-29 14:58:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-29 20:58:30 +0900 |
commit | 06efbdd25a3a8cccf17692f7bd4eac71ae7d6e05 (patch) | |
tree | 1dd9b115516660f1f6cf3659ac87f2b8328b5b76 /ale_linters/erlang/erlang_ls.vim | |
parent | d02e58b4043001c8338583070fb2d85f52f232d6 (diff) | |
download | ale-06efbdd25a3a8cccf17692f7bd4eac71ae7d6e05.zip |
Add erlang_ls linter for Erlang files (#4346)
Diffstat (limited to 'ale_linters/erlang/erlang_ls.vim')
-rw-r--r-- | ale_linters/erlang/erlang_ls.vim | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ale_linters/erlang/erlang_ls.vim b/ale_linters/erlang/erlang_ls.vim new file mode 100644 index 00000000..b747e454 --- /dev/null +++ b/ale_linters/erlang/erlang_ls.vim @@ -0,0 +1,49 @@ +" Author: Dmitri Vereshchagin <dmitri.vereshchagin@gmail.com> +" Description: LSP linter for Erlang files + +call ale#Set('erlang_erlang_ls_executable', 'erlang_ls') +call ale#Set('erlang_erlang_ls_log_dir', '') +call ale#Set('erlang_erlang_ls_log_level', 'info') + +function! s:GetCommand(buffer) abort + let l:log_dir = ale#Var(a:buffer, 'erlang_erlang_ls_log_dir') + let l:log_level = ale#Var(a:buffer, 'erlang_erlang_ls_log_level') + + let l:command = '%e' + + if !empty(l:log_dir) + let l:command .= ' --log-dir=' . ale#Escape(l:log_dir) + endif + + let l:command .= ' --log-level=' . ale#Escape(l:log_level) + + return l:command +endfunction + +function! s:FindProjectRoot(buffer) abort + let l:markers = ['_build/', 'erlang_ls.config', 'rebar.lock'] + + " This is a way to find Erlang/OTP root (the one that is managed + " by kerl or asdf). Useful if :ALEGoToDefinition takes us there. + let l:markers += ['.kerl_config'] + + for l:marker in l:markers + let l:path = l:marker[-1:] is# '/' + \ ? ale#path#FindNearestDirectory(a:buffer, l:marker) + \ : ale#path#FindNearestFile(a:buffer, l:marker) + + if !empty(l:path) + return ale#path#Dirname(l:path) + endif + endfor + + return '' +endfunction + +call ale#linter#Define('erlang', { +\ 'name': 'erlang_ls', +\ 'executable': {b -> ale#Var(b, 'erlang_erlang_ls_executable')}, +\ 'command': function('s:GetCommand'), +\ 'lsp': 'stdio', +\ 'project_root': function('s:FindProjectRoot'), +\}) |