diff options
author | Jeffrey Lau <who.else.at.jlau.tk> | 2019-05-27 20:06:57 +0800 |
---|---|---|
committer | Jeffrey Lau <who.else.at.jlau.tk> | 2019-08-31 12:34:57 +0800 |
commit | 5fcb24bb3e5d86da394ee1ba95fa0cea8e00ffff (patch) | |
tree | a15140cc374e5799e82071499e850c843306feb5 /ale_linters/scala/metals.vim | |
parent | 73812c3e41c1c7fcf1705811f35ac4c9ccec003e (diff) | |
download | ale-5fcb24bb3e5d86da394ee1ba95fa0cea8e00ffff.zip |
Add linter for Scala Metals
https://scalameta.org/metals/
Diffstat (limited to 'ale_linters/scala/metals.vim')
-rw-r--r-- | ale_linters/scala/metals.vim | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ale_linters/scala/metals.vim b/ale_linters/scala/metals.vim new file mode 100644 index 00000000..f78c7119 --- /dev/null +++ b/ale_linters/scala/metals.vim @@ -0,0 +1,48 @@ +" Author: Jeffrey Lau - https://github.com/zoonfafer +" Description: Metals Language Server for Scala https://scalameta.org/metals/ + +call ale#Set('scala_metals_executable', 'metals-vim') +call ale#Set('scala_metals_project_root', '') + +function! ale_linters#scala#metals#GetProjectRoot(buffer) abort + let l:project_root = ale#Var(a:buffer, 'scala_metals_project_root') + + if !empty(l:project_root) + return l:project_root + endif + + let l:potential_roots = [ + \ 'build.sc', + \ 'build.sbt', + \ '.bloop', + \ '.metals', + \] + + for l:root in l:potential_roots + let l:project_root = ale#path#ResolveLocalPath( + \ a:buffer, + \ l:root, + \ '' + \) + + if !empty(l:project_root) + return fnamemodify( + \ l:project_root, + \ ':h', + \) + endif + endfor +endfunction + +function! ale_linters#scala#metals#GetCommand(buffer) abort + return '%e' . ale#Pad('stdio') +endfunction + +call ale#linter#Define('scala', { +\ 'name': 'metals', +\ 'lsp': 'stdio', +\ 'language': 'scala', +\ 'executable': {b -> ale#Var(b, 'scala_metals_executable')}, +\ 'command': function('ale_linters#scala#metals#GetCommand'), +\ 'project_root': function('ale_linters#scala#metals#GetProjectRoot'), +\}) |