Merge pull request #1871 from Ophirr33/master

added sbtserver linter
This commit is contained in:
w0rp 2018-09-04 11:22:57 +01:00 committed by GitHub
commit 8f2e1c393f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 83 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,27 @@
" Author: ophirr33 <coghlan.ty@gmail.com>
" Description: TCP lsp client for sbt Server
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
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')
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''`, `''socket''` or `''tsserver''` if defined'
endif endif
if !l:needs_executable if !l:needs_executable

View File

@ -2,6 +2,39 @@
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 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: `'127.0.0.1:4273'`
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*
*b:ale_scala_sbtserver_project_root*
Type: |String|
Default: `''`
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.
=============================================================================== ===============================================================================
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`

View File

@ -0,0 +1,19 @@
" 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 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: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 '127.0.0.1:4273'