1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:30:04 +08:00

feat(mapping): add gD to go to declaration

This commit is contained in:
sisynb 2022-03-15 10:34:54 +08:00 committed by GitHub
parent e1d68de4c2
commit d94bdb6f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 2 deletions

View File

@ -150,6 +150,10 @@ endfunction
" config {{{
function! SpaceVim#layers#lang#c#config() abort
call SpaceVim#mapping#g_capital_d#add('c',
\ function('s:go_to_declaration'))
call SpaceVim#mapping#g_capital_d#add('cpp',
\ function('s:go_to_declaration'))
call SpaceVim#mapping#gd#add('c',
\ function('s:go_to_def'))
call SpaceVim#mapping#gd#add('cpp',
@ -309,7 +313,6 @@ function! s:language_specified_mappings() abort
\ 'call SpaceVim#lsp#go_to_typedef()', 'type definition', 1)
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'R'],
\ 'call SpaceVim#lsp#refactor()', 'refactor', 1)
" TODO this should be gD
call SpaceVim#mapping#space#langSPC('nnoremap', ['l', 'D'],
\ 'call SpaceVim#lsp#go_to_declaration()', 'declaration', 1)
@ -452,6 +455,16 @@ function! s:update_neoinclude(argv, fts) abort
endfunction
" }}}
" local function: go_to_declaration {{{
function! s:go_to_declaration() abort
if !SpaceVim#layers#lsp#check_filetype(&ft)
execute "norm! g\<c-]>"
else
call SpaceVim#lsp#go_to_declaration()
endif
endfunction
" }}}
" local function: go_to_def {{{
function! s:go_to_def() abort
if !SpaceVim#layers#lsp#check_filetype(&ft)

View File

@ -106,6 +106,14 @@ function! SpaceVim#mapping#enter() abort
return SpaceVim#mapping#enter#i_enter()
endfunction
function! SpaceVim#mapping#g_capital_d() abort
if !empty(SpaceVim#mapping#g_capital_d#get())
call call(SpaceVim#mapping#g_capital_d#get(), [])
else
normal! gD
endif
endfunction
function! SpaceVim#mapping#gd() abort
if !empty(SpaceVim#mapping#gd#get())
call call(SpaceVim#mapping#gd#get(), [])

View File

@ -107,8 +107,10 @@ function! SpaceVim#mapping#g#init() abort
nnoremap gv gv
let g:_spacevim_mappings_g['<C-]>'] = ['call feedkeys("g<c-]>", "n")', 'jump-to-tag-under-cursor']
nnoremap g<c-]> g<c-]>
let g:_spacevim_mappings_g['D'] = ['call SpaceVim#mapping#g_capital_d()', 'goto-declaration']
call SpaceVim#mapping#def('nnoremap <silent>', 'gD', ':call SpaceVim#mapping#g_capital_d()<CR>', 'Goto declaration', '')
let g:_spacevim_mappings_g['d'] = ['call SpaceVim#mapping#gd()', 'goto-definition']
call SpaceVim#mapping#def('nnoremap <silent>', 'gd', ':call SpaceVim#mapping#gd()<CR>', 'Goto declaration', '')
call SpaceVim#mapping#def('nnoremap <silent>', 'gd', ':call SpaceVim#mapping#gd()<CR>', 'Goto definition', '')
let g:_spacevim_mappings_g['='] = ['call SpaceVim#mapping#format()', 'format-current-buffer']
call SpaceVim#mapping#def('nnoremap <silent>','g=',':call SpaceVim#mapping#format()<cr>','format current buffer','call SpaceVim#mapping#format()')

View File

@ -0,0 +1,16 @@
"=============================================================================
" g_capital_d.vim --- gD key binding
" Copyright (c) 2016-2022 Wang Shidong & Contributors
" Author: sisynb < bsixxxx at gmail.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
let s:g_capital_d = {}
function! SpaceVim#mapping#g_capital_d#add(ft, func) abort
call extend(s:g_capital_d,{a:ft : a:func})
endfunction
function! SpaceVim#mapping#g_capital_d#get() abort
return get(s:g_capital_d, &filetype, '')
endfunction