summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/java/javalsp.vim28
-rw-r--r--autoload/ale/java.vim20
-rw-r--r--doc/ale-java.txt23
3 files changed, 71 insertions, 0 deletions
diff --git a/ale_linters/java/javalsp.vim b/ale_linters/java/javalsp.vim
new file mode 100644
index 00000000..fa1fe4cb
--- /dev/null
+++ b/ale_linters/java/javalsp.vim
@@ -0,0 +1,28 @@
+" 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
+ let l:jar = ale#VarFunc('java_javalsp_jar')(a:buffer)
+
+ if filereadable(l:jar)
+ return 'java'
+ endif
+
+ return ''
+endfunction
+
+function! ale_linters#java#javalsp#Command(buffer) abort
+ let l:jar = ale#VarFunc('java_javalsp_jar')(a:buffer)
+ return 'exec 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',
+\})
diff --git a/autoload/ale/java.vim b/autoload/ale/java.vim
new file mode 100644
index 00000000..b7fd10bd
--- /dev/null
+++ b/autoload/ale/java.vim
@@ -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
diff --git a/doc/ale-java.txt b/doc/ale-java.txt
index 4481e823..827a268c 100644
--- a/doc/ale-java.txt
+++ b/doc/ale-java.txt
@@ -76,4 +76,27 @@ g:ale_java_pmd_options *g:ale_java_pmd_options*
===============================================================================
+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: