parent
73812c3e41
commit
5fcb24bb3e
6 changed files with 97 additions and 0 deletions
48
ale_linters/scala/metals.vim
Normal file
48
ale_linters/scala/metals.vim
Normal file
|
@ -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'),
|
||||||
|
\})
|
|
@ -2,6 +2,32 @@
|
||||||
ALE Scala Integration *ale-scala-options*
|
ALE Scala Integration *ale-scala-options*
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
metals *ale-scala-metals*
|
||||||
|
|
||||||
|
`metals` requires either an SBT project, a Mill project, or a running Bloop
|
||||||
|
server.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_scala_metals_executable *g:ale_scala_metals_executable*
|
||||||
|
*b:ale_scala_metals_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'metals-vim'`
|
||||||
|
|
||||||
|
Override the invoked `metals` binary.
|
||||||
|
|
||||||
|
|
||||||
|
g:ale_scala_metals_project_root *g:ale_scala_metals_project_root*
|
||||||
|
*b:ale_scala_metals_project_root*
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
By default the project root is found by searching upwards for `build.sbt`,
|
||||||
|
`build.sc`, `.bloop` or `.metals`.
|
||||||
|
If the project root is elsewhere, you can override the project root
|
||||||
|
directory.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
sbtserver *ale-scala-sbtserver*
|
sbtserver *ale-scala-sbtserver*
|
||||||
|
|
||||||
|
|
|
@ -406,6 +406,7 @@ Notes:
|
||||||
* `stylelint`
|
* `stylelint`
|
||||||
* Scala
|
* Scala
|
||||||
* `fsc`
|
* `fsc`
|
||||||
|
* `metals`
|
||||||
* `sbtserver`
|
* `sbtserver`
|
||||||
* `scalac`
|
* `scalac`
|
||||||
* `scalafmt`
|
* `scalafmt`
|
||||||
|
|
|
@ -2298,6 +2298,7 @@ documented in additional help files.
|
||||||
sasslint..............................|ale-sass-sasslint|
|
sasslint..............................|ale-sass-sasslint|
|
||||||
stylelint.............................|ale-sass-stylelint|
|
stylelint.............................|ale-sass-stylelint|
|
||||||
scala...................................|ale-scala-options|
|
scala...................................|ale-scala-options|
|
||||||
|
metals................................|ale-scala-metals|
|
||||||
sbtserver.............................|ale-scala-sbtserver|
|
sbtserver.............................|ale-scala-sbtserver|
|
||||||
scalafmt..............................|ale-scala-scalafmt|
|
scalafmt..............................|ale-scala-scalafmt|
|
||||||
scalastyle............................|ale-scala-scalastyle|
|
scalastyle............................|ale-scala-scalastyle|
|
||||||
|
|
|
@ -415,6 +415,7 @@ formatting.
|
||||||
* [stylelint](https://github.com/stylelint/stylelint)
|
* [stylelint](https://github.com/stylelint/stylelint)
|
||||||
* Scala
|
* Scala
|
||||||
* [fsc](https://www.scala-lang.org/old/sites/default/files/linuxsoft_archives/docu/files/tools/fsc.html)
|
* [fsc](https://www.scala-lang.org/old/sites/default/files/linuxsoft_archives/docu/files/tools/fsc.html)
|
||||||
|
* [metals](https://scalameta.org/metals/)
|
||||||
* [sbtserver](https://www.scala-sbt.org/1.x/docs/sbt-server.html)
|
* [sbtserver](https://www.scala-sbt.org/1.x/docs/sbt-server.html)
|
||||||
* [scalac](http://scala-lang.org)
|
* [scalac](http://scala-lang.org)
|
||||||
* [scalafmt](https://scalameta.org/scalafmt/)
|
* [scalafmt](https://scalameta.org/scalafmt/)
|
||||||
|
|
20
test/command_callback/test_scala_metals.vader
Normal file
20
test/command_callback/test_scala_metals.vader
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
" Author: Jeffrey Lau https://github.com/zoonfafer
|
||||||
|
" Description: Tests for the Scala Metals linter
|
||||||
|
|
||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('scala', 'metals')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
Execute(should set metals for sbt project with build.sbt):
|
||||||
|
call ale#test#SetFilename('../scala_fixtures/valid_sbt_project/Main.scala')
|
||||||
|
AssertLSPLanguage 'scala'
|
||||||
|
AssertLSPOptions {}
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../scala_fixtures/valid_sbt_project')
|
||||||
|
Execute(should not set metals for sbt project without build.sbt):
|
||||||
|
call ale#test#SetFilename('../scala_fixtures/invalid_sbt_project/Main.scala')
|
||||||
|
AssertLSPLanguage 'scala'
|
||||||
|
AssertLSPOptions {}
|
||||||
|
AssertLSPConfig {}
|
||||||
|
AssertLSPProject ''
|
Reference in a new issue