2018-02-19 22:07:04 +08:00
|
|
|
"=============================================================================
|
|
|
|
" lsp.vim --- SpaceVim lsp layer
|
2019-06-09 14:11:17 +08:00
|
|
|
" Copyright (c) 2016-2019 Wang Shidong & Contributors
|
2018-02-19 22:07:04 +08:00
|
|
|
" Author: Wang Shidong < wsdjeg at 163.com >
|
|
|
|
" URL: https://spacevim.org
|
|
|
|
" License: GPLv3
|
|
|
|
"=============================================================================
|
|
|
|
|
2017-11-19 22:35:28 +08:00
|
|
|
function! SpaceVim#layers#lsp#plugins() abort
|
|
|
|
let plugins = []
|
|
|
|
|
2019-01-28 22:12:37 +08:00
|
|
|
if SpaceVim#layers#isLoaded('autocomplete') && get(g:, 'spacevim_autocomplete_method') ==# 'coc'
|
2019-01-08 22:59:27 +08:00
|
|
|
" nop
|
|
|
|
elseif has('nvim')
|
2018-06-26 21:29:48 +08:00
|
|
|
call add(plugins, ['autozimu/LanguageClient-neovim',
|
2018-08-30 21:39:55 +08:00
|
|
|
\ { 'merged': 0, 'if': has('python3'), 'build' : 'bash install.sh' }])
|
2017-12-23 22:02:15 +08:00
|
|
|
else
|
|
|
|
call add(plugins, ['prabirshrestha/async.vim', {'merged' : 0}])
|
|
|
|
call add(plugins, ['prabirshrestha/vim-lsp', {'merged' : 0}])
|
2017-11-19 22:35:28 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
return plugins
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! SpaceVim#layers#lsp#config() abort
|
2018-01-16 10:40:16 +08:00
|
|
|
" SpaceVim/LanguageClient-neovim {{{
|
|
|
|
let g:LanguageClient_diagnosticsDisplay = {
|
|
|
|
\ 1: {
|
|
|
|
\ 'name': 'Error',
|
|
|
|
\ 'signText': g:spacevim_error_symbol,
|
|
|
|
\ },
|
|
|
|
\ 2: {
|
|
|
|
\ 'name': 'Warning',
|
|
|
|
\ 'signText': g:spacevim_warning_symbol,
|
|
|
|
\ },
|
|
|
|
\ 3: {
|
|
|
|
\ 'name': 'Information',
|
|
|
|
\ 'signText': g:spacevim_info_symbol,
|
|
|
|
\ },
|
|
|
|
\ 4: {
|
|
|
|
\ 'name': 'Hint',
|
|
|
|
\ 'signText': g:spacevim_info_symbol,
|
|
|
|
\ },
|
|
|
|
\ }
|
|
|
|
|
|
|
|
if g:spacevim_enable_neomake
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[1].texthl = 'NeomakeError'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[1].signTexthl = 'NeomakeErrorSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[2].texthl = 'NeomakeWarning'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[2].signTexthl =
|
|
|
|
\ 'NeomakeWarningSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[3].texthl = 'NeomakeInfo'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[3].signTexthl = 'NeomakeInfoSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[4].texthl = 'NeomakeMessage'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[4].signTexthl =
|
|
|
|
\ 'NeomakeMessageSign'
|
|
|
|
elseif g:spacevim_enable_ale
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[1].texthl = 'ALEError'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[1].signTexthl = 'ALEErrorSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[2].texthl = 'ALEWarning'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[2].signTexthl = 'ALEWarningSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[3].texthl = 'ALEInfo'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[3].signTexthl = 'ALEInfoSign'
|
|
|
|
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[4].texthl = 'ALEInfo'
|
|
|
|
let g:LanguageClient_diagnosticsDisplay[4].signTexthl = 'ALEInfoSign'
|
|
|
|
endif
|
|
|
|
|
2019-04-28 20:44:47 +08:00
|
|
|
|
|
|
|
if !SpaceVim#layers#isLoaded('checkers')
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'c'], 'call call('
|
|
|
|
\ . string(s:_function('s:clear_errors')) . ', [])',
|
|
|
|
\ 'clear all errors', 1)
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'n'], 'call call('
|
|
|
|
\ . string(s:_function('s:jump_to_next_error')) . ', [])',
|
|
|
|
\ 'next-error', 1)
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'p'], 'call call('
|
|
|
|
\ . string(s:_function('s:jump_to_previous_error')) . ', [])',
|
|
|
|
\ 'previous-error', 1)
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'N'], 'call call('
|
|
|
|
\ . string(s:_function('s:jump_to_previous_error')) . ', [])',
|
|
|
|
\ 'previous-error', 1)
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'l'], 'call call('
|
|
|
|
\ . string(s:_function('s:toggle_show_error')) . ', [0])',
|
|
|
|
\ 'toggle showing the error list', 1)
|
|
|
|
call SpaceVim#mapping#space#def('nnoremap', ['e', 'L'], 'call call('
|
|
|
|
\ . string(s:_function('s:toggle_show_error')) . ', [1])',
|
|
|
|
\ 'toggle showing the error list', 1)
|
|
|
|
endif
|
|
|
|
|
2018-01-16 10:40:16 +08:00
|
|
|
let g:LanguageClient_autoStart = 1
|
2017-12-25 21:56:33 +08:00
|
|
|
let g:lsp_async_completion = 1
|
2017-11-19 22:35:28 +08:00
|
|
|
" }}}
|
2017-12-22 22:02:36 +08:00
|
|
|
for ft in s:enabled_fts
|
|
|
|
call SpaceVim#lsp#reg_server(ft, s:lsp_servers[ft])
|
|
|
|
endfor
|
2017-11-19 22:35:28 +08:00
|
|
|
endfunction
|
|
|
|
|
2017-12-22 21:20:35 +08:00
|
|
|
let s:enabled_fts = []
|
|
|
|
|
|
|
|
let s:lsp_servers = {
|
2017-12-24 15:50:20 +08:00
|
|
|
\ 'c' : ['clangd'],
|
|
|
|
\ 'cpp' : ['clangd'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'css' : ['css-languageserver', '--stdio'],
|
2018-01-02 21:40:21 +08:00
|
|
|
\ 'dart' : ['dart_language_server'],
|
2018-07-30 23:34:44 +08:00
|
|
|
\ 'dockerfile' : ['docker-langserver', '--stdio'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'go' : ['go-langserver', '-mode', 'stdio'],
|
|
|
|
\ 'haskell' : ['hie-wrapper', '--lsp'],
|
2018-01-19 00:00:53 +08:00
|
|
|
\ 'html' : ['html-languageserver', '--stdio'],
|
2018-08-18 16:41:50 +08:00
|
|
|
\ 'javascript' : ['javascript-typescript-stdio'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'julia' : ['julia', '--startup-file=no', '--history-file=no', '-e', 'using LanguageServer; server = LanguageServer.LanguageServerInstance(STDIN, STDOUT, false); server.runlinter = true; run(server);'],
|
|
|
|
\ 'objc' : ['clangd'],
|
|
|
|
\ 'objcpp' : ['clangd'],
|
|
|
|
\ 'php' : ['php', g:spacevim_plugin_bundle_dir . 'repos/github.com/felixfbecker/php-language-server/bin/php-language-server.php'],
|
2018-09-09 13:13:55 +08:00
|
|
|
\ 'purescript' : ['purescript-language-server', '--stdio'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'python' : ['pyls'],
|
2019-10-02 22:06:11 +08:00
|
|
|
\ 'crystal' : ['scry'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'rust' : ['rustup', 'run', 'nightly', 'rls'],
|
2019-05-30 21:13:52 +08:00
|
|
|
\ 'scala' : ['metals-vim'],
|
2019-01-29 23:27:59 +08:00
|
|
|
\ 'sh' : ['bash-language-server', 'start'],
|
|
|
|
\ 'typescript' : ['typescript-language-server', '--stdio'],
|
2019-02-26 01:18:21 +08:00
|
|
|
\ 'ruby' : ['solargraph.BAT', 'stdio'],
|
2018-09-09 13:13:55 +08:00
|
|
|
\ 'vue' : ['vls']
|
2017-12-22 21:20:35 +08:00
|
|
|
\ }
|
|
|
|
|
|
|
|
function! SpaceVim#layers#lsp#set_variable(var) abort
|
2017-12-22 22:02:36 +08:00
|
|
|
let override = get(a:var, 'override_cmd', {})
|
|
|
|
if !empty(override)
|
|
|
|
call extend(s:lsp_servers, override, 'force')
|
|
|
|
endif
|
2017-12-22 21:20:35 +08:00
|
|
|
for ft in get(a:var, 'filetypes', [])
|
2017-12-22 21:42:18 +08:00
|
|
|
let cmd = get(s:lsp_servers, ft, [''])[0]
|
|
|
|
if empty(cmd)
|
|
|
|
call SpaceVim#logger#warn('Failed to find the lsp server command for ' . ft)
|
2017-12-22 21:20:35 +08:00
|
|
|
else
|
2017-12-22 21:42:18 +08:00
|
|
|
if executable(cmd)
|
|
|
|
call add(s:enabled_fts, ft)
|
|
|
|
else
|
2018-01-24 11:26:15 +08:00
|
|
|
call SpaceVim#logger#warn('Failed to enable lsp for ' . ft . ', ' . cmd . ' is not executable!')
|
2017-12-22 21:42:18 +08:00
|
|
|
endif
|
2017-12-22 21:20:35 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! SpaceVim#layers#lsp#check_filetype(ft) abort
|
|
|
|
return index(s:enabled_fts, a:ft) != -1
|
|
|
|
endfunction
|
2019-04-28 20:44:47 +08:00
|
|
|
|
|
|
|
function! s:jump_to_next_error() abort
|
|
|
|
try
|
|
|
|
lnext
|
|
|
|
catch
|
|
|
|
try
|
|
|
|
cnext
|
|
|
|
catch
|
|
|
|
echohl WarningMsg
|
|
|
|
echon 'There is no errors!'
|
|
|
|
echohl None
|
|
|
|
endtry
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:jump_to_previous_error() abort
|
|
|
|
try
|
|
|
|
lprevious
|
|
|
|
catch
|
|
|
|
try
|
|
|
|
cprevious
|
|
|
|
catch
|
|
|
|
echohl WarningMsg
|
|
|
|
echon 'There is no errors!'
|
|
|
|
echohl None
|
|
|
|
endtry
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:toggle_show_error(...) abort
|
|
|
|
try
|
|
|
|
botright lopen
|
|
|
|
catch
|
|
|
|
try
|
|
|
|
if len(getqflist()) == 0
|
|
|
|
echohl WarningMsg
|
|
|
|
echon 'There is no errors!'
|
|
|
|
echohl None
|
|
|
|
else
|
|
|
|
botright copen
|
|
|
|
endif
|
|
|
|
catch
|
|
|
|
endtry
|
|
|
|
endtry
|
|
|
|
if a:1 == 1
|
|
|
|
wincmd w
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
if v:version > 703 || v:version == 703 && has('patch1170')
|
|
|
|
function! s:_function(fstr) abort
|
|
|
|
return function(a:fstr)
|
|
|
|
endfunction
|
|
|
|
else
|
|
|
|
function! s:_SID() abort
|
|
|
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
|
|
|
endfunction
|
|
|
|
let s:_s = '<SNR>' . s:_SID() . '_'
|
|
|
|
function! s:_function(fstr) abort
|
|
|
|
return function(substitute(a:fstr, 's:', s:_s, 'g'))
|
|
|
|
endfunction
|
|
|
|
endif
|
|
|
|
|
|
|
|
" TODO clear errors
|
|
|
|
function! s:clear_errors() abort
|
|
|
|
sign unplace *
|
|
|
|
endfunction
|