From 3d016f1697dd25443852d18a29a20c42c753dee1 Mon Sep 17 00:00:00 2001 From: Ty Coghlan Date: Sat, 1 Sep 2018 20:59:36 -0400 Subject: [PATCH] Changed sbtserver to just work off of the address variable --- ale_linters/scala/sbtserver.vim | 12 +--------- autoload/ale/linter.vim | 2 +- doc/ale-scala.txt | 22 +++++++++++-------- replace.sh | 3 --- .../test_scala_sbtserver.vader | 12 +++------- .../invalid_sbt_project/Main.scala | 5 ----- .../project/build.properties | 1 - .../project/target/active.json | 1 - .../no_active_sbt_project/Main.scala | 5 ----- .../no_active_sbt_project/build.sbt | 3 --- .../project/build.properties | 1 - .../valid_sbt_project/Main.scala | 5 ----- .../valid_sbt_project/build.sbt | 3 --- .../project/build.properties | 1 - .../project/target/active.json | 1 - 15 files changed, 18 insertions(+), 59 deletions(-) delete mode 100755 replace.sh delete mode 100644 test/scala_fixtures/invalid_sbt_project/project/build.properties delete mode 100644 test/scala_fixtures/invalid_sbt_project/project/target/active.json delete mode 100644 test/scala_fixtures/no_active_sbt_project/Main.scala delete mode 100644 test/scala_fixtures/no_active_sbt_project/build.sbt delete mode 100644 test/scala_fixtures/no_active_sbt_project/project/build.properties delete mode 100644 test/scala_fixtures/valid_sbt_project/project/build.properties delete mode 100644 test/scala_fixtures/valid_sbt_project/project/target/active.json diff --git a/ale_linters/scala/sbtserver.vim b/ale_linters/scala/sbtserver.vim index 3092dc13..d75c38ca 100644 --- a/ale_linters/scala/sbtserver.vim +++ b/ale_linters/scala/sbtserver.vim @@ -1,7 +1,7 @@ " Author: ophirr33 " Description: TCP lsp client for sbt Server -call ale#Set('scala_sbtserver_address', '') +call ale#Set('scala_sbtserver_address', '127.0.0.1:4273') call ale#Set('scala_sbtserver_project_root', '') function! ale_linters#scala#sbtserver#GetProjectRoot(buffer) abort @@ -15,16 +15,6 @@ 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 diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index 336dfcd0..06bc5e80 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''`, `''stdio''` or `''tsserver''` if defined' + throw '`lsp` must be either `''lsp''`, `''stdio''`, `''socket''` or `''tsserver''` if defined' endif if !l:needs_executable diff --git a/doc/ale-scala.txt b/doc/ale-scala.txt index a50f6267..ff43cd6c 100644 --- a/doc/ale-scala.txt +++ b/doc/ale-scala.txt @@ -5,20 +5,24 @@ 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`. +`sbtserver` requires a running ^1.1.x sbt shell to connect to. It will attempt +to connect via TCP to the address defined in `g:ale_scala_sbtserver_address`. +As `sbt` defaults to listening via unix sockets, place these settings into +your `~/.sbt/1.0/global.sbt` to ensure that ale will always attempt to connect +to the right socket: + +`serverConnectionType := ConnectionType.Tcp` and `serverPort := 4273` g:ale_scala_sbtserver_address *g:ale_scala_sbtserver_address* *b:ale_scala_sbtserver_address* Type: |String| - Default: `''` + Default: `'127.0.0.1:4273'` - 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`. + By default the address is found by parsing `active.json`, however, reading a + file is a blocking operation which should be avoided in ale. The easy way + around this is to configure sbt to always connect to the same port, which + the instructions above describe. g:ale_scala_sbtserver_project_root *g:ale_scala_sbtserver_project_root* @@ -26,7 +30,7 @@ g:ale_scala_sbtserver_project_root *g:ale_scala_sbtserver_project_root* Type: |String| Default: `''` - By default the project root is found by searching upwards for `active.json`. + By default the project root is found by searching upwards for `build.sbt`. If the project root is elsewhere, you can override the project root directory. diff --git a/replace.sh b/replace.sh deleted file mode 100755 index ae9786c2..00000000 --- a/replace.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/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 index 40aacaf4..1b708bd9 100644 --- a/test/command_callback/test_scala_sbtserver.vader +++ b/test/command_callback/test_scala_sbtserver.vader @@ -5,21 +5,15 @@ Before: call ale#assert#SetUpLinterTest('scala', 'sbtserver') After: call ale#assert#TearDownLinterTest() -Execute(should set sbtserver for sbt project with active.json): +Execute(should set sbtserver for sbt project with build.sbt): 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 '' + AssertLSPAddress '127.0.0.1:4273' 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 '' + AssertLSPAddress '127.0.0.1:4273' diff --git a/test/scala_fixtures/invalid_sbt_project/Main.scala b/test/scala_fixtures/invalid_sbt_project/Main.scala index 8431ac25..e69de29b 100644 --- a/test/scala_fixtures/invalid_sbt_project/Main.scala +++ b/test/scala_fixtures/invalid_sbt_project/Main.scala @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 5620cc50..00000000 --- a/test/scala_fixtures/invalid_sbt_project/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 0ecdb533..00000000 --- a/test/scala_fixtures/invalid_sbt_project/project/target/active.json +++ /dev/null @@ -1 +0,0 @@ -{"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 deleted file mode 100644 index 8431ac25..00000000 --- a/test/scala_fixtures/no_active_sbt_project/Main.scala +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index f50b72d2..00000000 --- a/test/scala_fixtures/no_active_sbt_project/build.sbt +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 5620cc50..00000000 --- a/test/scala_fixtures/no_active_sbt_project/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -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 index 8431ac25..e69de29b 100644 --- a/test/scala_fixtures/valid_sbt_project/Main.scala +++ b/test/scala_fixtures/valid_sbt_project/Main.scala @@ -1,5 +0,0 @@ -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 index f50b72d2..e69de29b 100644 --- a/test/scala_fixtures/valid_sbt_project/build.sbt +++ b/test/scala_fixtures/valid_sbt_project/build.sbt @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 5620cc50..00000000 --- a/test/scala_fixtures/valid_sbt_project/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 0ecdb533..00000000 --- a/test/scala_fixtures/valid_sbt_project/project/target/active.json +++ /dev/null @@ -1 +0,0 @@ -{"uri":"tcp://127.0.0.1:5211"}