diff --git a/autoload/SpaceVim/layers/lang/erlang.vim b/autoload/SpaceVim/layers/lang/erlang.vim index e96aff843..fcf97ccb5 100644 --- a/autoload/SpaceVim/layers/lang/erlang.vim +++ b/autoload/SpaceVim/layers/lang/erlang.vim @@ -33,42 +33,63 @@ " 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 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-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 endfunction function! SpaceVim#layers#lang#erlang#config() abort 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#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 K :call SpaceVim#lsp#show_doc() + call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def')) - call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'd'], - \ 'call SpaceVim#lsp#show_doc()', 'show_document', 1) - call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'e'], - \ 'call SpaceVim#lsp#rename()', 'rename symbol', 1) - " else - " nnoremap K :call alchemist#exdoc() - " 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) + if s:is_erlang + call SpaceVim#mapping#gd#add('erlang', function('SpaceVim#lsp#go_to_def')) + else + call SpaceVim#mapping#gd#add('erlang', function('s:go_to_def')) 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 K :call SpaceVim#lsp#show_doc() + nnoremap gD :call SpaceVim#lsp#go_to_typedef() + 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'} + call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'], \ 'call SpaceVim#plugins#repl#start("erlang")', \ 'start REPL process', 1) @@ -83,14 +104,16 @@ function! s:language_specified_mappings() abort \ 'send selection and keep code buffer focused', 1) endfunction + function! s:go_to_def() abort - if SpaceVim#layers#lsp#check_filetype('erlang') + if s:is_erlang call SpaceVim#lsp#go_to_def() else normal! gd endif endfunction + function! SpaceVim#layers#lang#erlang#health() abort call SpaceVim#layers#lang#erlang#plugins() call SpaceVim#layers#lang#erlang#config() diff --git a/autoload/SpaceVim/layers/lsp.vim b/autoload/SpaceVim/layers/lsp.vim index ea4cff642..f886386fc 100644 --- a/autoload/SpaceVim/layers/lsp.vim +++ b/autoload/SpaceVim/layers/lsp.vim @@ -44,6 +44,7 @@ let s:NVIM_VERSION = SpaceVim#api#import('neovim#version') let s:FILE = SpaceVim#api#import('file') let s:enabled_clients = [] 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 call SpaceVim#layers#lsp#plugins() @@ -62,7 +63,7 @@ endfunction function! SpaceVim#layers#lsp#plugins() abort 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}]) if g:spacevim_autocomplete_method ==# 'deoplete' call add(plugins, [g:_spacevim_root_dir . 'bundle/deoplete-lsp', {'merged' : 0}]) @@ -88,10 +89,9 @@ function! SpaceVim#layers#lsp#plugins() abort endfunction function! SpaceVim#layers#lsp#config() abort - " if nvim-lspconfig is using, do not check enabled_fts - if (has('nvim-0.5.0') && s:NVIM_VERSION.is_release_version()) || has('nvim-0.6.0') + if s:use_nvim_lsp + " nvim-lspconfig is used, do not check enabled_fts else - for ft in s:enabled_fts call SpaceVim#lsp#reg_server(ft, s:lsp_servers[ft]) endfor @@ -193,6 +193,7 @@ let s:lsp_servers = { \ 'css' : ['css-languageserver', '--stdio'], \ 'dart' : ['dart_language_server'], \ 'dockerfile' : ['docker-langserver', '--stdio'], + \ 'erlang' : ['erlang_ls'], \ 'go' : ['gopls'], \ 'haskell' : ['hie-wrapper', '--lsp'], \ 'html' : ['html-languageserver', '--stdio'], @@ -216,7 +217,7 @@ let s:lsp_servers = { \ } 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:override_client_cmds = get(a:var, 'override_client_cmds', {}) else @@ -248,7 +249,10 @@ function! SpaceVim#layers#lsp#set_variable(var) abort endfunction 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 function! SpaceVim#layers#lsp#check_server(server) abort