2018-09-24 20:40:17 -04:00
|
|
|
" Author: Horacio Sanson <https://github.com/hsanson>
|
|
|
|
" Description: Support for the Java language server https://github.com/georgewfraser/vscode-javac
|
|
|
|
|
2019-08-22 11:36:17 -04:00
|
|
|
call ale#Set('java_javalsp_executable', '')
|
|
|
|
call ale#Set('java_javalsp_config', {})
|
2018-09-24 20:40:17 -04:00
|
|
|
|
|
|
|
function! ale_linters#java#javalsp#Executable(buffer) abort
|
2018-12-17 06:28:27 -05:00
|
|
|
return ale#Var(a:buffer, 'java_javalsp_executable')
|
2018-09-24 20:40:17 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-08-22 11:36:17 -04:00
|
|
|
function! ale_linters#java#javalsp#Config(buffer) abort
|
|
|
|
let l:defaults = { 'java': { 'classPath': [], 'externalDependencies': [] } }
|
|
|
|
let l:config = ale#Var(a:buffer, 'java_javalsp_config')
|
|
|
|
|
|
|
|
" Ensure the config dictionary contains both classPath and
|
|
|
|
" externalDependencies keys to avoid a NPE crash on Java Language Server.
|
|
|
|
call extend(l:config, l:defaults, 'keep')
|
|
|
|
call extend(l:config['java'], l:defaults['java'], 'keep')
|
|
|
|
|
|
|
|
return l:config
|
|
|
|
endfunction
|
|
|
|
|
2018-09-24 20:40:17 -04:00
|
|
|
function! ale_linters#java#javalsp#Command(buffer) abort
|
2018-12-17 06:28:27 -05:00
|
|
|
let l:executable = ale_linters#java#javalsp#Executable(a:buffer)
|
2018-09-24 20:40:17 -04:00
|
|
|
|
2019-08-22 11:36:17 -04:00
|
|
|
if fnamemodify(l:executable, ':t') is# 'java'
|
|
|
|
" For backward compatibility.
|
|
|
|
let l:cmd = [
|
|
|
|
\ ale#Escape(l:executable),
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.api=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.code=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.comp=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.main=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.tree=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.model=javacs',
|
|
|
|
\ '--add-exports jdk.compiler/com.sun.tools.javac.util=javacs',
|
|
|
|
\ '--add-opens jdk.compiler/com.sun.tools.javac.api=javacs',
|
|
|
|
\ '-m javacs/org.javacs.Main',
|
|
|
|
\]
|
|
|
|
|
|
|
|
return join(l:cmd, ' ')
|
|
|
|
else
|
|
|
|
return ale#Escape(l:executable)
|
|
|
|
endif
|
2018-09-24 20:40:17 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('java', {
|
|
|
|
\ 'name': 'javalsp',
|
2024-01-07 10:14:20 -05:00
|
|
|
\ 'aliases': ['java_language_server'],
|
2018-09-24 20:40:17 -04:00
|
|
|
\ 'lsp': 'stdio',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': function('ale_linters#java#javalsp#Executable'),
|
|
|
|
\ 'command': function('ale_linters#java#javalsp#Command'),
|
2018-09-24 20:40:17 -04:00
|
|
|
\ 'language': 'java',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'project_root': function('ale#java#FindProjectRoot'),
|
2019-08-22 11:36:17 -04:00
|
|
|
\ 'lsp_config': function('ale_linters#java#javalsp#Config')
|
2018-09-24 20:40:17 -04:00
|
|
|
\})
|