1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 02:00:05 +08:00

fix(erlang): fix erlang and lsp layers

This commit is contained in:
Nikita Antonenkov 2023-03-11 13:27:28 +02:00 committed by GitHub
parent ecea7b4322
commit 5cf632446b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 28 deletions

View File

@ -33,42 +33,63 @@
" SPC l s s send selection text " SPC l s s send selection text
" < " <
" "
let s:is_erlang = SpaceVim#layers#lsp#check_filetype('erlang')
\ || SpaceVim#layers#lsp#check_server('erlang_ls')
function! SpaceVim#layers#lang#erlang#plugins() abort function! SpaceVim#layers#lang#erlang#plugins() abort
let plugins = [] let plugins = []
" call add(plugins, ['vim-erlang/vim-erlang-compiler', {'on_ft' : 'erlang'}]) call add(plugins, ['vim-erlang/vim-erlang-compiler', {'on_ft' : 'erlang'}])
call add(plugins, ['vim-erlang/vim-erlang-omnicomplete', {'on_ft' : 'erlang'}]) call add(plugins, ['vim-erlang/vim-erlang-omnicomplete', {'on_ft' : 'erlang'}])
call add(plugins, ['vim-erlang/vim-erlang-runtime', {'on_ft' : 'erlang'}]) call add(plugins, ['vim-erlang/vim-erlang-runtime', {'on_ft' : 'erlang'}])
" call add(plugins, ['vim-erlang/vim-erlang-tags', {'on_ft' : 'erlang'}]) call add(plugins, ['vim-erlang/vim-erlang-tags', {'on_ft' : 'erlang'}])
return plugins return plugins
endfunction endfunction
function! SpaceVim#layers#lang#erlang#config() abort function! SpaceVim#layers#lang#erlang#config() abort
call SpaceVim#plugins#repl#reg('erlang', 'erl') call SpaceVim#plugins#repl#reg('erlang', 'erl')
" call SpaceVim#plugins#runner#reg_runner('erlang', ['erlc -o #TEMP# %s', 'erl -pa #TEMP#']) call SpaceVim#plugins#runner#reg_runner('erlang', ['erlc -o #TEMP# %s', 'erl -pa #TEMP#'])
call SpaceVim#mapping#space#regesit_lang_mappings('erlang', function('s:language_specified_mappings')) call SpaceVim#mapping#space#regesit_lang_mappings('erlang', function('s:language_specified_mappings'))
" call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def')) call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def'))
endfunction
function! s:language_specified_mappings() abort
" call SpaceVim#mapping#space#langSPC('nmap', ['l','r'],
" \ 'call SpaceVim#plugins#runner#open()',
" \ 'execute current file', 1)
if SpaceVim#layers#lsp#check_filetype('erlang')
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], if s:is_erlang
\ 'call SpaceVim#lsp#show_doc()', 'show_document', 1) call SpaceVim#mapping#gd#add('erlang', function('SpaceVim#lsp#go_to_def'))
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], else
\ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def'))
" else
" nnoremap <silent><buffer> K :call alchemist#exdoc()<CR>
" call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
" \ 'call alchemist#exdoc()', 'show_document', 1)
" call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 't'],
" \ 'call alchemist#jump_tag_stack()', 'jump to tag stack', 1)
endif endif
endfunction
function! s:language_specified_mappings() abort
call SpaceVim#mapping#space#langSPC('nnoremap', ['l','r'],
\ 'call SpaceVim#plugins#runner#open()',
\ 'execute current file', 1)
if s:is_erlang
nnoremap <silent><buffer> K :call SpaceVim#lsp#show_doc()<CR>
nnoremap <silent><buffer> gD :<C-u>call SpaceVim#lsp#go_to_typedef()<Cr>
endif
"
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'],
\ 'call SpaceVim#lsp#show_doc()', 'show-document', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'x'],
\ 'call SpaceVim#lsp#references()', 'show-references', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'],
\ 'call SpaceVim#lsp#rename()', 'rename-symbol', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 's'],
\ 'call SpaceVim#lsp#show_line_diagnostics()', 'show-line-diagnostics', 1)
let g:_spacevim_mappings_space.l.w = {'name' : '+Workspace'}
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'l'],
\ 'call SpaceVim#lsp#list_workspace_folder()', 'list-workspace-folder', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'a'],
\ 'call SpaceVim#lsp#add_workspace_folder()', 'add-workspace-folder', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'w', 'r'],
\ 'call SpaceVim#lsp#remove_workspace_folder()', 'remove-workspace-folder', 1)
let g:_spacevim_mappings_space.l.s = {'name' : '+Send'} let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'], call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'],
\ 'call SpaceVim#plugins#repl#start("erlang")', \ 'call SpaceVim#plugins#repl#start("erlang")',
\ 'start REPL process', 1) \ 'start REPL process', 1)
@ -83,14 +104,16 @@ function! s:language_specified_mappings() abort
\ 'send selection and keep code buffer focused', 1) \ 'send selection and keep code buffer focused', 1)
endfunction endfunction
function! s:go_to_def() abort function! s:go_to_def() abort
if SpaceVim#layers#lsp#check_filetype('erlang') if s:is_erlang
call SpaceVim#lsp#go_to_def() call SpaceVim#lsp#go_to_def()
else else
normal! gd normal! gd
endif endif
endfunction endfunction
function! SpaceVim#layers#lang#erlang#health() abort function! SpaceVim#layers#lang#erlang#health() abort
call SpaceVim#layers#lang#erlang#plugins() call SpaceVim#layers#lang#erlang#plugins()
call SpaceVim#layers#lang#erlang#config() call SpaceVim#layers#lang#erlang#config()

View File

@ -44,6 +44,7 @@ let s:NVIM_VERSION = SpaceVim#api#import('neovim#version')
let s:FILE = SpaceVim#api#import('file') let s:FILE = SpaceVim#api#import('file')
let s:enabled_clients = [] let s:enabled_clients = []
let s:override_client_cmds = {} let s:override_client_cmds = {}
let s:use_nvim_lsp = (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0')
function! SpaceVim#layers#lsp#health() abort function! SpaceVim#layers#lsp#health() abort
call SpaceVim#layers#lsp#plugins() call SpaceVim#layers#lsp#plugins()
@ -62,7 +63,7 @@ endfunction
function! SpaceVim#layers#lsp#plugins() abort function! SpaceVim#layers#lsp#plugins() abort
let plugins = [] let plugins = []
if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0') if s:use_nvim_lsp
call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-lspconfig', {'merged' : 0, 'loadconf' : 1}]) call add(plugins, [g:_spacevim_root_dir . 'bundle/nvim-lspconfig', {'merged' : 0, 'loadconf' : 1}])
if g:spacevim_autocomplete_method ==# 'deoplete' if g:spacevim_autocomplete_method ==# 'deoplete'
call add(plugins, [g:_spacevim_root_dir . 'bundle/deoplete-lsp', {'merged' : 0}]) call add(plugins, [g:_spacevim_root_dir . 'bundle/deoplete-lsp', {'merged' : 0}])
@ -88,10 +89,9 @@ function! SpaceVim#layers#lsp#plugins() abort
endfunction endfunction
function! SpaceVim#layers#lsp#config() abort function! SpaceVim#layers#lsp#config() abort
" if nvim-lspconfig is using, do not check enabled_fts if s:use_nvim_lsp
if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0') " nvim-lspconfig is used, do not check enabled_fts
else else
for ft in s:enabled_fts for ft in s:enabled_fts
call SpaceVim#lsp#reg_server(ft, s:lsp_servers[ft]) call SpaceVim#lsp#reg_server(ft, s:lsp_servers[ft])
endfor endfor
@ -193,6 +193,7 @@ let s:lsp_servers = {
\ 'css' : ['css-languageserver', '--stdio'], \ 'css' : ['css-languageserver', '--stdio'],
\ 'dart' : ['dart_language_server'], \ 'dart' : ['dart_language_server'],
\ 'dockerfile' : ['docker-langserver', '--stdio'], \ 'dockerfile' : ['docker-langserver', '--stdio'],
\ 'erlang' : ['erlang_ls'],
\ 'go' : ['gopls'], \ 'go' : ['gopls'],
\ 'haskell' : ['hie-wrapper', '--lsp'], \ 'haskell' : ['hie-wrapper', '--lsp'],
\ 'html' : ['html-languageserver', '--stdio'], \ 'html' : ['html-languageserver', '--stdio'],
@ -216,7 +217,7 @@ let s:lsp_servers = {
\ } \ }
function! SpaceVim#layers#lsp#set_variable(var) abort function! SpaceVim#layers#lsp#set_variable(var) abort
if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0') if s:use_nvim_lsp
let s:enabled_clients = get(a:var, 'enabled_clients', s:enabled_clients) let s:enabled_clients = get(a:var, 'enabled_clients', s:enabled_clients)
let s:override_client_cmds = get(a:var, 'override_client_cmds', {}) let s:override_client_cmds = get(a:var, 'override_client_cmds', {})
else else
@ -248,7 +249,10 @@ function! SpaceVim#layers#lsp#set_variable(var) abort
endfunction endfunction
function! SpaceVim#layers#lsp#check_filetype(ft) abort function! SpaceVim#layers#lsp#check_filetype(ft) abort
return index(s:enabled_fts, a:ft) != -1 if s:use_nvim_lsp
return 1
else
return index(s:enabled_fts, a:ft) != -1
endfunction endfunction
function! SpaceVim#layers#lsp#check_server(server) abort function! SpaceVim#layers#lsp#check_server(server) abort