-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Horacio Sanson
committed
Apr 9, 2019
1 parent
abcefe7
commit c293971
Showing
5 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
" Author: Horacio Sanson <https://github.com/hsanson> | ||
" Description: Support for the Eclipse language server https://github.com/eclipse/eclipse.jdt.ls | ||
|
||
let s:version_cache = {} | ||
|
||
call ale#Set('java_eclipselsp_path', 'eclipse.jdt.ls/org.eclipse.jdt.ls.product/target/repository') | ||
call ale#Set('java_eclipselsp_executable', 'java') | ||
|
||
function! ale_linters#java#eclipselsp#Executable(buffer) abort | ||
return ale#Var(a:buffer, 'java_eclipselsp_executable') | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#TargetPath(buffer) abort | ||
return ale#Var(a:buffer, 'java_eclipselsp_path') | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#JarPath(buffer) abort | ||
let l:path = ale_linters#java#eclipselsp#TargetPath(a:buffer) | ||
|
||
return l:path . '/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar' | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#ConfigurationPath(buffer) abort | ||
let l:path = ale_linters#java#eclipselsp#TargetPath(a:buffer) | ||
|
||
if has('win32') | ||
return l:path . '/config_win' | ||
elseif has('macunix') | ||
return l:path . '/config_mac' | ||
else | ||
return l:path . '/config_linux' | ||
endif | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#VersionCheck(version_lines) abort | ||
return s:GetVersion('', a:version_lines) | ||
endfunction | ||
|
||
function! s:GetVersion(executable, version_lines) abort | ||
let l:version = [] | ||
|
||
for l:line in a:version_lines | ||
let l:match = matchlist(l:line, '\(\d\+\)\.\(\d\+\)\.\(\d\+\)') | ||
|
||
if !empty(l:match) | ||
let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0] | ||
let s:version_cache[a:executable] = l:version | ||
break | ||
endif | ||
endfor | ||
|
||
return l:version | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#CommandWithVersion(buffer, version_lines, meta) abort | ||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) | ||
let l:version = s:GetVersion(l:executable, a:version_lines) | ||
|
||
return ale_linters#java#eclipselsp#Command(a:buffer, l:version) | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#Command(buffer, version) abort | ||
let l:path = ale#Var(a:buffer, 'java_eclipselsp_path') | ||
|
||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) | ||
|
||
let l:cmd = [ ale#Escape(l:executable), | ||
\ '-Declipse.application=org.eclipse.jdt.ls.core.id1', | ||
\ '-Dosgi.bundles.defaultStartLevel=4', | ||
\ '-Declipse.product=org.eclipse.jdt.ls.core.product', | ||
\ '-Dlog.level=ALL', | ||
\ '-noverify', | ||
\ '-Xmx1G', | ||
\ '-jar', | ||
\ ale_linters#java#eclipselsp#JarPath(a:buffer), | ||
\ '-configuration', | ||
\ ale_linters#java#eclipselsp#ConfigurationPath(a:buffer), | ||
\ '-data', | ||
\ ale#java#FindProjectRoot(a:buffer) | ||
\ ] | ||
|
||
if ale#semver#GTE(a:version, [1, 9]) | ||
call add(l:cmd, '--add-modules=ALL-SYSTEM') | ||
call add(l:cmd, '--add-opens java.base/java.util=ALL-UNNAMED') | ||
call add(l:cmd, '--add-opens java.base/java.lang=ALL-UNNAMED') | ||
endif | ||
|
||
return join(l:cmd, ' ') | ||
endfunction | ||
|
||
function! ale_linters#java#eclipselsp#RunWithVersionCheck(buffer) abort | ||
let l:executable = ale_linters#java#eclipselsp#Executable(a:buffer) | ||
|
||
if empty(l:executable) | ||
return '' | ||
endif | ||
|
||
let l:cache = s:version_cache | ||
|
||
if has_key(s:version_cache, l:executable) | ||
return ale_linters#java#eclipselsp#Command(a:buffer, s:version_cache[l:executable]) | ||
endif | ||
|
||
let l:command = ale#Escape(l:executable) . ' -version' | ||
|
||
return ale#command#Run( | ||
\ a:buffer, | ||
\ l:command, | ||
\ function('ale_linters#java#eclipselsp#CommandWithVersion') | ||
\) | ||
endfunction | ||
|
||
call ale#linter#Define('java', { | ||
\ 'name': 'eclipselsp', | ||
\ 'lsp': 'stdio', | ||
\ 'executable': function('ale_linters#java#eclipselsp#Executable'), | ||
\ 'command': function('ale_linters#java#eclipselsp#RunWithVersionCheck'), | ||
\ 'language': 'java', | ||
\ 'project_root': function('ale#java#FindProjectRoot'), | ||
\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
test/command_callback/test_eclipselsp_command_callback.vader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
Before: | ||
call ale#assert#SetUpLinterTest('java', 'eclipselsp') | ||
let b:ale_java_eclipselsp_path = '/home/user/eclipse.dst.ls/org.eclipse.jdt.ls.product/target/repository' | ||
call ale#test#SetFilename('dummy.java') | ||
|
||
let b:cfg = '/config_linux' | ||
|
||
if has('win32') | ||
let b:cfg = '/config_win' | ||
elseif has('macunix') | ||
let b:cfg = '/config_mac' | ||
endif | ||
|
||
|
||
After: | ||
unlet b:ale_java_eclipselsp_path | ||
call ale#assert#TearDownLinterTest() | ||
|
||
Execute(VersionCheck should return correct version): | ||
|
||
" OpenJDK Java 1.8 | ||
AssertEqual [1, 8, 0], ale_linters#java#eclipselsp#VersionCheck([ | ||
\ 'openjdk version "1.8.0_191"', | ||
\ 'OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-0ubuntu0.18.04.1-b12)', | ||
\ 'OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)' | ||
\]) | ||
|
||
" OpenJDK Java 10 | ||
AssertEqual [10, 0, 2], ale_linters#java#eclipselsp#VersionCheck([ | ||
\ 'openjdk version "10.0.2" 2018-07-17', | ||
\ 'OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)', | ||
\ 'OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)' | ||
\]) | ||
|
||
" Oracle Java 1.8 | ||
AssertEqual [1, 8, 0], ale_linters#java#eclipselsp#VersionCheck([ | ||
\ 'java version "1.8.0_161"', | ||
\ 'Java(TM) SE Runtime Environment (build 1.8.0_161-b12)', | ||
\ 'Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)' | ||
\]) | ||
|
||
" Oracle Java 10 | ||
AssertEqual [10, 0, 1], ale_linters#java#eclipselsp#VersionCheck([ | ||
\ 'java version "10.0.1" 2018-04-17', | ||
\ 'Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)', | ||
\ 'Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)' | ||
\]) | ||
|
||
AssertEqual [], ale_linters#java#eclipselsp#VersionCheck(['x']) | ||
|
||
AssertEqual [], ale_linters#java#eclipselsp#VersionCheck([]) | ||
|
||
Execute(The eclipselsp callback should return the correct default value): | ||
let cmd = [ ale#Escape('java'), | ||
\ '-Declipse.application=org.eclipse.jdt.ls.core.id1', | ||
\ '-Dosgi.bundles.defaultStartLevel=4', | ||
\ '-Declipse.product=org.eclipse.jdt.ls.core.product', | ||
\ '-Dlog.level=ALL', | ||
\ '-noverify', | ||
\ '-Xmx1G', | ||
\ '-jar', | ||
\ '/home/user/eclipse.dst.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar', | ||
\ '-configuration', | ||
\ '/home/user/eclipse.dst.ls/org.eclipse.jdt.ls.product/target/repository'. b:cfg, | ||
\ '-data', | ||
\ '' | ||
\] | ||
AssertLinter 'java', join(cmd, ' ') | ||
|
||
Execute(The eclipselsp callback should allow custom executable): | ||
let b:ale_java_eclipselsp_executable='/bin/foobar' | ||
let cmd = [ ale#Escape('/bin/foobar'), | ||
\ '-Declipse.application=org.eclipse.jdt.ls.core.id1', | ||
\ '-Dosgi.bundles.defaultStartLevel=4', | ||
\ '-Declipse.product=org.eclipse.jdt.ls.core.product', | ||
\ '-Dlog.level=ALL', | ||
\ '-noverify', | ||
\ '-Xmx1G', | ||
\ '-jar', | ||
\ '/home/user/eclipse.dst.ls/org.eclipse.jdt.ls.product/target/repository/plugins/org.eclipse.equinox.launcher_1.5.200.v20180922-1751.jar', | ||
\ '-configuration', | ||
\ '/home/user/eclipse.dst.ls/org.eclipse.jdt.ls.product/target/repository' . b:cfg, | ||
\ '-data', | ||
\ '' | ||
\] | ||
AssertLinter '/bin/foobar', join(cmd, ' ') | ||
|