mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
plugins update
This commit is contained in:
137
sources_non_forked/ale/ale_linters/java/eclipselsp.vim
Normal file
137
sources_non_forked/ale/ale_linters/java/eclipselsp.vim
Normal file
@ -0,0 +1,137 @@
|
||||
" 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', ale#path#Simplify($HOME . '/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)
|
||||
|
||||
" Search jar file within repository path when manually built using mvn
|
||||
let l:repo_path = l:path . '/org.eclipse.jdt.ls.product/target/repository'
|
||||
let l:files = globpath(l:repo_path, '**/plugins/org.eclipse.equinox.launcher_\d\.\d\.\d\d\d\.*\.jar', 1, 1)
|
||||
|
||||
if len(l:files) == 1
|
||||
return l:files[0]
|
||||
endif
|
||||
|
||||
" Search jar file within VSCode extensions folder.
|
||||
let l:files = globpath(l:path, '**/plugins/org.eclipse.equinox.launcher_\d\.\d\.\d\d\d\.*\.jar', 1, 1)
|
||||
|
||||
if len(l:files) == 1
|
||||
return l:files[0]
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#java#eclipselsp#ConfigurationPath(buffer) abort
|
||||
let l:path = fnamemodify(ale_linters#java#eclipselsp#JarPath(a:buffer), ':p:h:h')
|
||||
|
||||
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'),
|
||||
\})
|
@ -7,21 +7,29 @@ call ale#Set('java_javac_executable', 'javac')
|
||||
call ale#Set('java_javac_options', '')
|
||||
call ale#Set('java_javac_classpath', '')
|
||||
|
||||
function! ale_linters#java#javac#GetImportPaths(buffer) abort
|
||||
function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
|
||||
let l:command = ''
|
||||
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
|
||||
|
||||
if !empty(l:pom_path) && executable('mvn')
|
||||
return ale#path#CdString(fnamemodify(l:pom_path, ':h'))
|
||||
let l:command = ale#path#CdString(fnamemodify(l:pom_path, ':h'))
|
||||
\ . 'mvn dependency:build-classpath'
|
||||
endif
|
||||
|
||||
let l:classpath_command = ale#gradle#BuildClasspathCommand(a:buffer)
|
||||
|
||||
if !empty(l:classpath_command)
|
||||
return l:classpath_command
|
||||
" Try to use Gradle if Maven isn't available.
|
||||
if empty(l:command)
|
||||
let l:command = ale#gradle#BuildClasspathCommand(a:buffer)
|
||||
endif
|
||||
|
||||
return ''
|
||||
if empty(l:command)
|
||||
return ale_linters#java#javac#GetCommand(a:buffer, [], {})
|
||||
endif
|
||||
|
||||
return ale#command#Run(
|
||||
\ a:buffer,
|
||||
\ l:command,
|
||||
\ function('ale_linters#java#javac#GetCommand')
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! s:BuildClassPathOption(buffer, import_paths) abort
|
||||
@ -37,7 +45,7 @@ function! s:BuildClassPathOption(buffer, import_paths) abort
|
||||
\ : ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
|
||||
function! ale_linters#java#javac#GetCommand(buffer, import_paths, meta) abort
|
||||
let l:cp_option = s:BuildClassPathOption(a:buffer, a:import_paths)
|
||||
let l:sp_option = ''
|
||||
|
||||
@ -91,7 +99,7 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort
|
||||
" Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated
|
||||
" Main.java:16: error: ';' expected
|
||||
let l:directory = expand('#' . a:buffer . ':p:h')
|
||||
let l:pattern = '\v^(.*):(\d+): (.+):(.+)$'
|
||||
let l:pattern = '\v^(.*):(\d+): (.{-1,}):(.+)$'
|
||||
let l:col_pattern = '\v^(\s*\^)$'
|
||||
let l:symbol_pattern = '\v^ +symbol: *(class|method) +([^ ]+)'
|
||||
let l:output = []
|
||||
@ -120,9 +128,7 @@ endfunction
|
||||
call ale#linter#Define('java', {
|
||||
\ 'name': 'javac',
|
||||
\ 'executable': {b -> ale#Var(b, 'java_javac_executable')},
|
||||
\ 'command_chain': [
|
||||
\ {'callback': 'ale_linters#java#javac#GetImportPaths', 'output_stream': 'stdout'},
|
||||
\ {'callback': 'ale_linters#java#javac#GetCommand', 'output_stream': 'stderr'},
|
||||
\ ],
|
||||
\ 'command': function('ale_linters#java#javac#RunWithImportPaths'),
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'callback': 'ale_linters#java#javac#Handle',
|
||||
\})
|
||||
|
Reference in New Issue
Block a user