diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | ale_linters/scala/sbtserver.vim | 37 | ||||
-rw-r--r-- | autoload/ale/linter.vim | 2 | ||||
-rw-r--r-- | doc/ale-scala.txt | 29 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rwxr-xr-x | replace.sh | 3 | ||||
-rw-r--r-- | test/command_callback/test_scala_sbtserver.vader | 25 | ||||
-rw-r--r-- | test/scala_fixtures/invalid_sbt_project/Main.scala | 5 | ||||
-rw-r--r-- | test/scala_fixtures/invalid_sbt_project/project/build.properties | 1 | ||||
-rw-r--r-- | test/scala_fixtures/invalid_sbt_project/project/target/active.json | 1 | ||||
-rw-r--r-- | test/scala_fixtures/no_active_sbt_project/Main.scala | 5 | ||||
-rw-r--r-- | test/scala_fixtures/no_active_sbt_project/build.sbt | 3 | ||||
-rw-r--r-- | test/scala_fixtures/no_active_sbt_project/project/build.properties | 1 | ||||
-rw-r--r-- | test/scala_fixtures/valid_sbt_project/Main.scala | 5 | ||||
-rw-r--r-- | test/scala_fixtures/valid_sbt_project/build.sbt | 3 | ||||
-rw-r--r-- | test/scala_fixtures/valid_sbt_project/project/build.properties | 1 | ||||
-rw-r--r-- | test/scala_fixtures/valid_sbt_project/project/target/active.json | 1 |
17 files changed, 124 insertions, 3 deletions
@@ -171,7 +171,7 @@ formatting. | Rust | cargo !! (see `:help ale-integration-rust` for configuration instructions), [rls](https://github.com/rust-lang-nursery/rls), [rustc](https://www.rust-lang.org/), [rustfmt](https://github.com/rust-lang-nursery/rustfmt) | | SASS | [sass-lint](https://www.npmjs.com/package/sass-lint), [stylelint](https://github.com/stylelint/stylelint) | | SCSS | [prettier](https://github.com/prettier/prettier), [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint) | -| Scala | [fsc](https://www.scala-lang.org/old/sites/default/files/linuxsoft_archives/docu/files/tools/fsc.html), [scalac](http://scala-lang.org), [scalafmt](https://scalameta.org/scalafmt/), [scalastyle](http://www.scalastyle.org) | +| Scala | [fsc](https://www.scala-lang.org/old/sites/default/files/linuxsoft_archives/docu/files/tools/fsc.html), [sbtserver](https://www.scala-sbt.org/1.x/docs/sbt-server.html), [scalac](http://scala-lang.org), [scalafmt](https://scalameta.org/scalafmt/), [scalastyle](http://www.scalastyle.org)| | Slim | [slim-lint](https://github.com/sds/slim-lint) | | SML | [smlnj](http://www.smlnj.org/) | | Solidity | [solhint](https://github.com/protofire/solhint), [solium](https://github.com/duaraghav8/Solium) | diff --git a/ale_linters/scala/sbtserver.vim b/ale_linters/scala/sbtserver.vim new file mode 100644 index 00000000..3092dc13 --- /dev/null +++ b/ale_linters/scala/sbtserver.vim @@ -0,0 +1,37 @@ +" Author: ophirr33 <coghlan.ty@gmail.com> +" Description: TCP lsp client for sbt Server + +call ale#Set('scala_sbtserver_address', '') +call ale#Set('scala_sbtserver_project_root', '') + +function! ale_linters#scala#sbtserver#GetProjectRoot(buffer) abort + let l:project_root = ale#Var(a:buffer, 'scala_sbtserver_project_root') + if l:project_root is? '' + let l:project_root = ale#path#FindNearestFile(a:buffer, 'build.sbt') + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' + endif + return l:project_root +endfunction + +function! ale_linters#scala#sbtserver#GetAddress(buffer) abort + let l:address = ale#Var(a:buffer, 'scala_sbtserver_address') + if l:address is? '' + let l:project_root = ale_linters#scala#sbtserver#GetProjectRoot(a:buffer) + let l:active_file = l:project_root . '/project/target/active.json' + if !empty(glob(l:active_file)) + let l:active = json_decode(join(readfile(l:project_root . '/project/target/active.json'))) + if has_key(l:active, 'uri') + return substitute(l:active.uri, 'tcp://', '', '') + endif + endif + endif + return l:address +endfunction + +call ale#linter#Define('scala', { +\ 'name': 'sbtserver', +\ 'lsp': 'socket', +\ 'address_callback': 'ale_linters#scala#sbtserver#GetAddress', +\ 'language': 'scala', +\ 'project_root_callback': 'ale_linters#scala#sbtserver#GetProjectRoot', +\}) diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index aad386aa..336dfcd0 100644 --- a/autoload/ale/linter.vim +++ b/autoload/ale/linter.vim @@ -99,7 +99,7 @@ function! ale#linter#PreProcess(filetype, linter) abort endif if index(['', 'socket', 'stdio', 'tsserver'], l:obj.lsp) < 0 - throw '`lsp` must be either `''lsp''` or `''tsserver''` if defined' + throw '`lsp` must be either `''lsp''`, `''stdio''` or `''tsserver''` if defined' endif if !l:needs_executable diff --git a/doc/ale-scala.txt b/doc/ale-scala.txt index b992d428..a50f6267 100644 --- a/doc/ale-scala.txt +++ b/doc/ale-scala.txt @@ -3,6 +3,35 @@ ALE Scala Integration *ale-scala-options* =============================================================================== +sbtserver *ale-scala-sbtserver* + +`sbtserver` requires a running ^1.1.x sbt shell to connect to. It will look +for this shell by searching upwards from the current working directory for +the `project/target/active.json` file. This will only work when `sbtserver` is +configured to listen via tcp. An easy way to accomplish that is to put +`serverConnectionType := ConnectionType.Tcp` in `~/.sbt/1.0/global.sbt`. + + +g:ale_scala_sbtserver_address *g:ale_scala_sbtserver_address* + *b:ale_scala_sbtserver_address* + Type: |String| + Default: `''` + + By default the address is found by parsing `active.json`. If the server is + running elsewhere, you can override the address here to `host:port`. + + +g:ale_scala_sbtserver_project_root *g:ale_scala_sbtserver_project_root* + *b:ale_scala_sbtserver_project_root* + Type: |String| + Default: `''` + + By default the project root is found by searching upwards for `active.json`. + If the project root is elsewhere, you can override the project root + directory. + + +=============================================================================== scalafmt *ale-scala-scalafmt* If Nailgun is used, override `g:ale_scala_scalafmt_executable` like so: > diff --git a/doc/ale.txt b/doc/ale.txt index 2c018a10..4334510f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -249,6 +249,7 @@ CONTENTS *ale-contents* sass..................................|ale-sass-options| stylelint...........................|ale-sass-stylelint| scala.................................|ale-scala-options| + sbtserver...........................|ale-scala-sbtserver| scalafmt............................|ale-scala-scalafmt| scalastyle..........................|ale-scala-scalastyle| scss..................................|ale-scss-options| @@ -430,7 +431,7 @@ Notes: * Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|), `rustfmt` * SASS: `sass-lint`, `stylelint` * SCSS: `prettier`, `sass-lint`, `scss-lint`, `stylelint` -* Scala: `fsc`, `scalac`, `scalafmt`, `scalastyle` +* Scala: `fsc`, `sbtserver`, `scalac`, `scalafmt`, `scalastyle` * Slim: `slim-lint` * SML: `smlnj` * Solidity: `solhint`, `solium` diff --git a/replace.sh b/replace.sh new file mode 100755 index 00000000..ae9786c2 --- /dev/null +++ b/replace.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +rm -rf ~/.vim/plugged/ale +cp -r . ~/.vim/plugged/ale diff --git a/test/command_callback/test_scala_sbtserver.vader b/test/command_callback/test_scala_sbtserver.vader new file mode 100644 index 00000000..40aacaf4 --- /dev/null +++ b/test/command_callback/test_scala_sbtserver.vader @@ -0,0 +1,25 @@ +" Author: ophirr33 <coghlan.ty@gmail.com> +" Description: Tests for the sbt Server lsp linter + +Before: + call ale#assert#SetUpLinterTest('scala', 'sbtserver') +After: + call ale#assert#TearDownLinterTest() +Execute(should set sbtserver for sbt project with active.json): + call ale#test#SetFilename('../scala_fixtures/valid_sbt_project/Main.scala') + AssertLSPLanguage 'scala' + AssertLSPOptions {} + AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../scala_fixtures/valid_sbt_project') + AssertLSPAddress '127.0.0.1:5211' +Execute(should not set sbtserver for sbt project without active.json): + call ale#test#SetFilename('../scala_fixtures/no_active_sbt_project/Main.scala') + AssertLSPLanguage 'scala' + AssertLSPOptions {} + AssertLSPProject ale#path#Simplify(g:dir . 'command_callback/../scala_fixtures/no_active_sbt_project') + AssertLSPAddress '' +Execute(should not set sbtserver for sbt project without build.sbt): + call ale#test#SetFilename('../scala_fixtures/invalid_sbt_project/Main.scala') + AssertLSPLanguage 'scala' + AssertLSPOptions {} + AssertLSPProject '' + AssertLSPAddress '' diff --git a/test/scala_fixtures/invalid_sbt_project/Main.scala b/test/scala_fixtures/invalid_sbt_project/Main.scala new file mode 100644 index 00000000..8431ac25 --- /dev/null +++ b/test/scala_fixtures/invalid_sbt_project/Main.scala @@ -0,0 +1,5 @@ +object HelloAle { + def main(args: Array[String]): Int = { + println("Hello, ale!") + } +} diff --git a/test/scala_fixtures/invalid_sbt_project/project/build.properties b/test/scala_fixtures/invalid_sbt_project/project/build.properties new file mode 100644 index 00000000..5620cc50 --- /dev/null +++ b/test/scala_fixtures/invalid_sbt_project/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.2.1 diff --git a/test/scala_fixtures/invalid_sbt_project/project/target/active.json b/test/scala_fixtures/invalid_sbt_project/project/target/active.json new file mode 100644 index 00000000..0ecdb533 --- /dev/null +++ b/test/scala_fixtures/invalid_sbt_project/project/target/active.json @@ -0,0 +1 @@ +{"uri":"tcp://127.0.0.1:5211"} diff --git a/test/scala_fixtures/no_active_sbt_project/Main.scala b/test/scala_fixtures/no_active_sbt_project/Main.scala new file mode 100644 index 00000000..8431ac25 --- /dev/null +++ b/test/scala_fixtures/no_active_sbt_project/Main.scala @@ -0,0 +1,5 @@ +object HelloAle { + def main(args: Array[String]): Int = { + println("Hello, ale!") + } +} diff --git a/test/scala_fixtures/no_active_sbt_project/build.sbt b/test/scala_fixtures/no_active_sbt_project/build.sbt new file mode 100644 index 00000000..f50b72d2 --- /dev/null +++ b/test/scala_fixtures/no_active_sbt_project/build.sbt @@ -0,0 +1,3 @@ +name := "ale-scala-valid" +version := "1.0" +scalaVersion := "2.12.6" diff --git a/test/scala_fixtures/no_active_sbt_project/project/build.properties b/test/scala_fixtures/no_active_sbt_project/project/build.properties new file mode 100644 index 00000000..5620cc50 --- /dev/null +++ b/test/scala_fixtures/no_active_sbt_project/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.2.1 diff --git a/test/scala_fixtures/valid_sbt_project/Main.scala b/test/scala_fixtures/valid_sbt_project/Main.scala new file mode 100644 index 00000000..8431ac25 --- /dev/null +++ b/test/scala_fixtures/valid_sbt_project/Main.scala @@ -0,0 +1,5 @@ +object HelloAle { + def main(args: Array[String]): Int = { + println("Hello, ale!") + } +} diff --git a/test/scala_fixtures/valid_sbt_project/build.sbt b/test/scala_fixtures/valid_sbt_project/build.sbt new file mode 100644 index 00000000..f50b72d2 --- /dev/null +++ b/test/scala_fixtures/valid_sbt_project/build.sbt @@ -0,0 +1,3 @@ +name := "ale-scala-valid" +version := "1.0" +scalaVersion := "2.12.6" diff --git a/test/scala_fixtures/valid_sbt_project/project/build.properties b/test/scala_fixtures/valid_sbt_project/project/build.properties new file mode 100644 index 00000000..5620cc50 --- /dev/null +++ b/test/scala_fixtures/valid_sbt_project/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.2.1 diff --git a/test/scala_fixtures/valid_sbt_project/project/target/active.json b/test/scala_fixtures/valid_sbt_project/project/target/active.json new file mode 100644 index 00000000..0ecdb533 --- /dev/null +++ b/test/scala_fixtures/valid_sbt_project/project/target/active.json @@ -0,0 +1 @@ +{"uri":"tcp://127.0.0.1:5211"} |