summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2019-04-13 12:48:20 +0100
committerGitHub <noreply@github.com>2019-04-13 12:48:20 +0100
commitf0f0cc3c186c46f437d62e6b3e01a45d2a3aaf47 (patch)
treed164e8023e6e94229fb0c8ba4f4c63d2b0ecbaec /ale_linters
parent784d1a9a622a0c30c26a17a835943593d036a4cd (diff)
parentf02e2ec54cb39e6fcc73bbaf553cbfb0111944d4 (diff)
downloadale-f0f0cc3c186c46f437d62e6b3e01a45d2a3aaf47.zip
Merge pull request #2121 from hsanson/1996-add-support-for-eclipse-jdt-ls
WIP Fix 1996 - Add eclipse LSP support.
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/java/eclipselsp.vim130
1 files changed, 130 insertions, 0 deletions
diff --git a/ale_linters/java/eclipselsp.vim b/ale_linters/java/eclipselsp.vim
new file mode 100644
index 00000000..af9a325e
--- /dev/null
+++ b/ale_linters/java/eclipselsp.vim
@@ -0,0 +1,130 @@
+" 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')
+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)
+ let l:path = l:path . '/org.eclipse.jdt.ls.product/target/repository/plugins'
+
+ let l:files = globpath(l:path, 'org.eclipse.equinox.launcher_*.jar', 1, 1)
+
+ if empty(l:files)
+ return ''
+ endif
+
+ return l:files[0]
+endfunction
+
+function! ale_linters#java#eclipselsp#ConfigurationPath(buffer) abort
+ let l:path = ale_linters#java#eclipselsp#TargetPath(a:buffer)
+ let l:path = l:path . '/org.eclipse.jdt.ls.product/target/repository'
+
+ if has('win32')
+ let l:path = l:path . '/config_win'
+ elseif has('macunix')
+ let l:path = l:path . '/config_mac'
+ else
+ let l:path = l:path . '/config_linux'
+ endif
+
+ return ale#path#Simplify(l:path)
+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'),
+\})