added sbtserver linter

This commit is contained in:
Ty Coghlan 2018-08-27 01:12:56 -04:00
parent ea01cc708b
commit 8e3bf10592
17 changed files with 124 additions and 3 deletions

View File

@ -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) | | 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) | | 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) | | 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) | | Slim | [slim-lint](https://github.com/sds/slim-lint) |
| SML | [smlnj](http://www.smlnj.org/) | | SML | [smlnj](http://www.smlnj.org/) |
| Solidity | [solhint](https://github.com/protofire/solhint), [solium](https://github.com/duaraghav8/Solium) | | Solidity | [solhint](https://github.com/protofire/solhint), [solium](https://github.com/duaraghav8/Solium) |

View File

@ -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',
\})

View File

@ -99,7 +99,7 @@ function! ale#linter#PreProcess(filetype, linter) abort
endif endif
if index(['', 'socket', 'stdio', 'tsserver'], l:obj.lsp) < 0 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 endif
if !l:needs_executable if !l:needs_executable

View File

@ -2,6 +2,35 @@
ALE Scala Integration *ale-scala-options* 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* scalafmt *ale-scala-scalafmt*

View File

@ -249,6 +249,7 @@ CONTENTS *ale-contents*
sass..................................|ale-sass-options| sass..................................|ale-sass-options|
stylelint...........................|ale-sass-stylelint| stylelint...........................|ale-sass-stylelint|
scala.................................|ale-scala-options| scala.................................|ale-scala-options|
sbtserver...........................|ale-scala-sbtserver|
scalafmt............................|ale-scala-scalafmt| scalafmt............................|ale-scala-scalafmt|
scalastyle..........................|ale-scala-scalastyle| scalastyle..........................|ale-scala-scalastyle|
scss..................................|ale-scss-options| scss..................................|ale-scss-options|
@ -430,7 +431,7 @@ Notes:
* Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|), `rustfmt` * Rust: `cargo`!!, `rls`, `rustc` (see |ale-integration-rust|), `rustfmt`
* SASS: `sass-lint`, `stylelint` * SASS: `sass-lint`, `stylelint`
* SCSS: `prettier`, `sass-lint`, `scss-lint`, `stylelint` * SCSS: `prettier`, `sass-lint`, `scss-lint`, `stylelint`
* Scala: `fsc`, `scalac`, `scalafmt`, `scalastyle` * Scala: `fsc`, `sbtserver`, `scalac`, `scalafmt`, `scalastyle`
* Slim: `slim-lint` * Slim: `slim-lint`
* SML: `smlnj` * SML: `smlnj`
* Solidity: `solhint`, `solium` * Solidity: `solhint`, `solium`

3
replace.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
rm -rf ~/.vim/plugged/ale
cp -r . ~/.vim/plugged/ale

View File

@ -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 ''

View File

@ -0,0 +1,5 @@
object HelloAle {
def main(args: Array[String]): Int = {
println("Hello, ale!")
}
}

View File

@ -0,0 +1 @@
sbt.version=1.2.1

View File

@ -0,0 +1 @@
{"uri":"tcp://127.0.0.1:5211"}

View File

@ -0,0 +1,5 @@
object HelloAle {
def main(args: Array[String]): Int = {
println("Hello, ale!")
}
}

View File

@ -0,0 +1,3 @@
name := "ale-scala-valid"
version := "1.0"
scalaVersion := "2.12.6"

View File

@ -0,0 +1 @@
sbt.version=1.2.1

View File

@ -0,0 +1,5 @@
object HelloAle {
def main(args: Array[String]): Int = {
println("Hello, ale!")
}
}

View File

@ -0,0 +1,3 @@
name := "ale-scala-valid"
version := "1.0"
scalaVersion := "2.12.6"

View File

@ -0,0 +1 @@
sbt.version=1.2.1

View File

@ -0,0 +1 @@
{"uri":"tcp://127.0.0.1:5211"}