summaryrefslogtreecommitdiff
path: root/ale_linters/java/javalsp.vim
blob: fa3b0e2c1eadb8c72eb14f68b505dd09cae8f634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
" 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_executable', '')
call ale#Set('java_javalsp_config', {})

function! ale_linters#java#javalsp#Executable(buffer) abort
    return ale#Var(a:buffer, 'java_javalsp_executable')
endfunction

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

function! ale_linters#java#javalsp#Command(buffer) abort
    let l:executable = ale_linters#java#javalsp#Executable(a:buffer)

    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
endfunction

call ale#linter#Define('java', {
\   'name': 'javalsp',
\   'aliases': ['java_language_server'],
\   'lsp': 'stdio',
\   'executable': function('ale_linters#java#javalsp#Executable'),
\   'command': function('ale_linters#java#javalsp#Command'),
\   'language': 'java',
\   'project_root': function('ale#java#FindProjectRoot'),
\   'lsp_config': function('ale_linters#java#javalsp#Config')
\})