Fix eclipse.jdt.ls workspace data path.

We were setting the -data parameter to the project root but this caused
the language server to fail initialization and synch of gradle
dependencies. As consequence ALE failed to work fully on gradle
projects.

This fix sets the workspace to the parent folder of the project root.
Normally this corresponds to the correct Eclipse workspace path.

When this is not the case, this fix also allows users to explicitly set
the absolute path to the workspace via configuration variable.
This commit is contained in:
Horacio Sanson 2019-05-21 13:33:47 +09:00
parent 67d49c75a8
commit 5a8ba75265
3 changed files with 36 additions and 13 deletions

View File

@ -5,6 +5,7 @@ let s:version_cache = {}
call ale#Set('java_eclipselsp_path', ale#path#Simplify($HOME . '/eclipse.jdt.ls')) call ale#Set('java_eclipselsp_path', ale#path#Simplify($HOME . '/eclipse.jdt.ls'))
call ale#Set('java_eclipselsp_config_path', '') call ale#Set('java_eclipselsp_config_path', '')
call ale#Set('java_eclipselsp_workspace_path', '')
call ale#Set('java_eclipselsp_executable', 'java') call ale#Set('java_eclipselsp_executable', 'java')
function! ale_linters#java#eclipselsp#Executable(buffer) abort function! ale_linters#java#eclipselsp#Executable(buffer) abort
@ -89,6 +90,16 @@ function! ale_linters#java#eclipselsp#CommandWithVersion(buffer, version_lines,
return ale_linters#java#eclipselsp#Command(a:buffer, l:version) return ale_linters#java#eclipselsp#Command(a:buffer, l:version)
endfunction endfunction
function! ale_linters#java#eclipselsp#WorkspacePath(buffer) abort
let l:wspath = ale#Var(a:buffer, 'java_eclipselsp_workspace_path')
if !empty(l:wspath)
return l:wspath
endif
return ale#path#Dirname(ale#java#FindProjectRoot(a:buffer))
endfunction
function! ale_linters#java#eclipselsp#Command(buffer, version) abort function! ale_linters#java#eclipselsp#Command(buffer, version) abort
let l:path = ale#Var(a:buffer, 'java_eclipselsp_path') let l:path = ale#Var(a:buffer, 'java_eclipselsp_path')
@ -102,11 +113,11 @@ function! ale_linters#java#eclipselsp#Command(buffer, version) abort
\ '-noverify', \ '-noverify',
\ '-Xmx1G', \ '-Xmx1G',
\ '-jar', \ '-jar',
\ ale_linters#java#eclipselsp#JarPath(a:buffer), \ ale#Escape(ale_linters#java#eclipselsp#JarPath(a:buffer)),
\ '-configuration', \ '-configuration',
\ ale_linters#java#eclipselsp#ConfigurationPath(a:buffer), \ ale#Escape(ale_linters#java#eclipselsp#ConfigurationPath(a:buffer)),
\ '-data', \ '-data',
\ ale#java#FindProjectRoot(a:buffer) \ ale#Escape(ale_linters#java#eclipselsp#WorkspacePath(a:buffer))
\ ] \ ]
if ale#semver#GTE(a:version, [1, 9]) if ale#semver#GTE(a:version, [1, 9])

View File

@ -130,7 +130,7 @@ g:ale_java_eclipselsp_path *g:ale_java_eclipselsp_path*
Absolute path to the location of the eclipse.jdt.ls repository folder. Or if Absolute path to the location of the eclipse.jdt.ls repository folder. Or if
you have VSCode extension installed the absolute path to the VSCode extensions you have VSCode extension installed the absolute path to the VSCode extensions
folder (e.g. $HOME/.vscode/extensions in Linux). folder (e.g. $HOME/.vscode/extensions/redhat.java-0.4x.0 in Linux).
g:ale_java_eclipselsp_executable *g:ale_java_eclipse_executable* g:ale_java_eclipselsp_executable *g:ale_java_eclipse_executable*
@ -154,6 +154,18 @@ g:ale_java_eclipselsp_config_path *g:ale_java_eclipse_config_path
non-writable directory like `/usr/share/java/jdtls`, as is the case when non-writable directory like `/usr/share/java/jdtls`, as is the case when
installed via system package. installed via system package.
g:ale_java_eclipselsp_workspace_path *g:ale_java_eclipselsp_workspace_path*
*b:ale_java_eclipselsp_workspace_path*
Type: |String|
Default: `''`
If you have Eclipse installed is good idea to set this variable to the
absolute path of the Eclipse workspace. If not set this value will be set to
the parent folder of the project root.
=============================================================================== ===============================================================================
uncrustify *ale-java-uncrustify* uncrustify *ale-java-uncrustify*

View File

@ -61,11 +61,11 @@ Execute(The eclipselsp callback should return the correct default value):
\ '-noverify', \ '-noverify',
\ '-Xmx1G', \ '-Xmx1G',
\ '-jar', \ '-jar',
\ '', \ ale#Escape(''),
\ '-configuration', \ '-configuration',
\ b:cfg, \ ale#Escape(b:cfg),
\ '-data', \ '-data',
\ '' \ ale#Escape(ale#path#Simplify(''))
\] \]
AssertLinter 'java', join(cmd, ' ') AssertLinter 'java', join(cmd, ' ')
@ -79,11 +79,11 @@ Execute(The eclipselsp callback should allow custom executable):
\ '-noverify', \ '-noverify',
\ '-Xmx1G', \ '-Xmx1G',
\ '-jar', \ '-jar',
\ '', \ ale#Escape(''),
\ '-configuration', \ '-configuration',
\ b:cfg, \ ale#Escape(b:cfg),
\ '-data', \ '-data',
\ '' \ ale#Escape(ale#path#Simplify(''))
\] \]
AssertLinter '/bin/foobar', join(cmd, ' ') AssertLinter '/bin/foobar', join(cmd, ' ')
@ -97,10 +97,10 @@ Execute(The eclipselsp callback should allow custom configuration path):
\ '-noverify', \ '-noverify',
\ '-Xmx1G', \ '-Xmx1G',
\ '-jar', \ '-jar',
\ '', \ ale#Escape(''),
\ '-configuration', \ '-configuration',
\ ale#path#Simplify('/home/config'), \ ale#Escape(ale#path#Simplify('/home/config')),
\ '-data', \ '-data',
\ '' \ ale#Escape(ale#path#Simplify(''))
\] \]
AssertLinter 'java', join(cmd, ' ') AssertLinter 'java', join(cmd, ' ')