Merge pull request #1849 from hsanson/1848-add-support-for-java-lsp

Add vscode-java-language-server linter
This commit is contained in:
w0rp 2018-08-28 22:53:11 +01:00 committed by GitHub
commit d4ce201cc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 2 deletions

View file

@ -132,7 +132,7 @@ formatting.
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stylish-haskell](https://github.com/jaspervdj/stylish-haskell), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt), [hie](https://github.com/haskell/haskell-ide-engine) |
| HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) |
| Idris | [idris](http://www.idris-lang.org/) |
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) |
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/), [javalsp](https://github.com/georgewfraser/vscode-javac) |
| JavaScript | [eslint](http://eslint.org/), [flow](https://flowtype.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/), [prettier](https://github.com/prettier/prettier), [prettier-eslint](https://github.com/prettier/prettier-eslint-cli), [prettier-standard](https://github.com/sheerun/prettier-standard), [standard](http://standardjs.com/), [xo](https://github.com/sindresorhus/xo)
| JSON | [fixjson](https://github.com/rhysd/fixjson), [jsonlint](http://zaa.ch/jsonlint/), [jq](https://stedolan.github.io/jq/), [prettier](https://github.com/prettier/prettier) |
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !!, [languageserver](https://github.com/fwcd/KotlinLanguageServer) see `:help ale-integration-kotlin` for configuration instructions |

View file

@ -0,0 +1,22 @@
" Author: Horacio Sanson <https://github.com/hsanson>
" Description: Support for the Java language server https://github.com/georgewfraser/vscode-javac
call ale#Set('java_javalsp_jar', 'javacs.jar')
function! ale_linters#java#javalsp#Executable(buffer) abort
return 'java'
endfunction
function! ale_linters#java#javalsp#Command(buffer) abort
let l:jar = ale#Var(a:buffer, 'java_javalsp_jar')
return ale#Escape('java -cp ' . l:jar . ' -Xverify:none org.javacs.Main')
endfunction
call ale#linter#Define('java', {
\ 'name': 'javalsp',
\ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#java#javalsp#Executable',
\ 'command_callback': 'ale_linters#java#javalsp#Command',
\ 'language': 'java',
\ 'project_root_callback': 'ale#java#FindProjectRoot',
\})

20
autoload/ale/java.vim Normal file
View file

@ -0,0 +1,20 @@
" Author: Horacio Sanson https://github.com/hsanson
" Description: Functions for integrating with Java tools
" Find the nearest dir contining a gradle or pom file and asume it
" the root of a java app.
function! ale#java#FindProjectRoot(buffer) abort
let l:gradle_root = ale#gradle#FindProjectRoot(a:buffer)
if !empty(l:gradle_root)
return l:gradle_root
endif
let l:maven_pom_file = ale#path#FindNearestFile(a:buffer, 'pom.xml')
if !empty(l:maven_pom_file)
return fnamemodify(l:maven_pom_file, ':h')
endif
return ''
endfunction

View file

@ -75,5 +75,28 @@ g:ale_java_pmd_options *g:ale_java_pmd_options*
and -d. They are added automatically.
===============================================================================
javalsp *ale-java-javalsp*
To enable Java LSP linter you need to download and build the vscode-javac
language server from https://github.com/georgewfraser/vscode-javac. Simply
download the source code and then build the plugin using maven:
mvn package
This generates a out/fat-jar.jar file that contains the language server. To
let ALE use this language server you need to set the g:ale_java_javalsp_jar
variable to the absolute path of this jar file.
g:ale_java_javalsp_jar *g:ale_java_javalsp_jar*
*b:ale_java_javalsp_jar*
Type: String
Default: 'fat-jar.jar
Path to the location of the vscode-javac language server plugin.
and -d. They are added automatically.
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -127,6 +127,7 @@ CONTENTS *ale-contents*
javac...............................|ale-java-javac|
google-java-format..................|ale-java-google-java-format|
pmd.................................|ale-java-pmd|
javalsp.............................|ale-java-javalsp|
javascript............................|ale-javascript-options|
eslint..............................|ale-javascript-eslint|
flow................................|ale-javascript-flow|
@ -388,7 +389,7 @@ Notes:
* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stylish-haskell`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`, `hie`
* HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good`
* Idris: `idris`
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`, `javalsp`
* JavaScript: `eslint`, `flow`, `jscs`, `jshint`, `prettier`, `prettier-eslint`, `prettier-standard`, `standard`, `xo`
* JSON: `fixjson`, `jsonlint`, `jq`, `prettier`
* Kotlin: `kotlinc`!!, `ktlint`!!, `languageserver`

View file

@ -0,0 +1,10 @@
Before:
call ale#assert#SetUpLinterTest('java', 'javalsp')
After:
call ale#assert#TearDownLinterTest()
Execute(The javalsp callback should return the correct default value):
AssertLinter 'java', ale#Escape('java -cp javacs.jar -Xverify:none org.javacs.Main')