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

feat(layer): Add vimspector to debug layer

Add vimspector plugin instead of vim-debug if layer option
debugger_plugin is 'vimspector'. It is not used by default.
This commit is contained in:
Grafcube 2021-12-29 09:02:16 +05:30 committed by GitHub
parent 594e0516d1
commit 176261652e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,10 +7,21 @@
"============================================================================= "=============================================================================
scriptencoding utf-8 scriptencoding utf-8
function! SpaceVim#layers#debug#set_variable(var) abort
let s:debugger_plugin = get(a:var, 'debugger_plugin', '')
endfunction
function! SpaceVim#layers#debug#plugins() abort function! SpaceVim#layers#debug#plugins() abort
let plugins = [] let plugins = []
" @todo fork verbugger " @todo fork verbugger
call add(plugins,['wsdjeg/vim-debug', {'merged' : 0}])
if s:debugger_plugin ==# 'vimspector'
call add(plugins,['puremourning/vimspector', {'merged' : 0}])
else
call add(plugins,['wsdjeg/vim-debug', {'merged' : 0}])
endif
if g:spacevim_filemanager !=# 'vimfiler' if g:spacevim_filemanager !=# 'vimfiler'
call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}]) call add(plugins, ['Shougo/vimproc.vim', {'build' : [(executable('gmake') ? 'gmake' : 'make')]}])
endif endif
@ -24,23 +35,42 @@ function! SpaceVim#layers#debug#health() abort
endfunction endfunction
function! SpaceVim#layers#debug#config() abort function! SpaceVim#layers#debug#config() abort
call SpaceVim#mapping#space#def('nnoremap', ['d', 'l'], 'call SpaceVim#layers#debug#launching(&ft)', 'launching-debugger', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'b'], 'VBGtoggleBreakpointThisLine', 'toggle-line-breakpoint', 1) if s:debugger_plugin ==# 'vimspector'
call SpaceVim#mapping#space#def('nnoremap', ['d', 'B'], 'VBGclearBreakpoints', 'clear-all-breakpoints', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'c'], 'call vimspector#Continue()', 'launch-or-continue-debugger', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'c'], 'VBGcontinue', 'continue-the-execution', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'r'], 'call vimspector#Restart()', 'restart-debugger-with-the-same-config', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'o'], 'VBGstepOver', 'step-over', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'x'], 'call vimspector#RunToCursor()', 'run-to-cursor', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'i'], 'VBGstepIn', 'step-into-functions', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'p'], 'call vimspector#Pause()', 'pause-debugger', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'O'], 'VBGstepOut', 'step-out-of-current-function', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'b'], 'call vimspector#ToggleBreakpoint()', 'toggle-line-breakpoint', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'k'], 'VBGkill', 'terminates-the-debugger', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'B'], 'call vimspector#ClearBreakpoints()', 'clear-all-breakpoints', 1)
let g:_spacevim_mappings_space.d.e = {'name' : '+Evaluate/Execute'} call SpaceVim#mapping#space#def('nnoremap', ['d', 'o'], 'call vimspector#StepOver()', 'step-over', 1)
call SpaceVim#mapping#space#def('vnoremap', ['d', 'e', 's'], 'VBGevalSelectedText', 'evaluate-selected-text', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'i'], 'call vimspector#StepInto()', 'step-into-functions', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'e', 'e'], 'VBGevalWordUnderCursor', 'evaluate-cursor-symbol', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'O'], 'call vimspector#StepOut()', 'step-out-of-current-function', 1)
call SpaceVim#mapping#space#def('vnoremap', ['d', 'e', 'S'], 'VBGexecuteSelectedText', 'execute-selected-text', 1) call SpaceVim#mapping#space#def('nnoremap', ['d', 'u'], 'call vimspector#UpFrame()', 'move-up-a-frame', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'd'], 'call vimspector#DownFrame()', 'move-down-a-frame', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'k'], 'call vimspector#Stop() | VimspectorReset', 'terminate-the-debugger', 1)
call SpaceVim#mapping#space#def('nmap', ['d', 'e'], '<Plug>VimspectorBalloonEval', 'evaluate-cursor-symbol-or-selection', 0)
call SpaceVim#mapping#space#def('xmap', ['d', 'e'], '<Plug>VimspectorBalloonEval', 'evaluate-cursor-symbol-or-selection', 0)
else
call SpaceVim#mapping#space#def('nnoremap', ['d', 'l'], 'call SpaceVim#layers#debug#launching(&ft)', 'launching-debugger', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'b'], 'VBGtoggleBreakpointThisLine', 'toggle-line-breakpoint', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'B'], 'VBGclearBreakpoints', 'clear-all-breakpoints', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'c'], 'VBGcontinue', 'continue-the-execution', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'o'], 'VBGstepOver', 'step-over', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'i'], 'VBGstepIn', 'step-into-functions', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'O'], 'VBGstepOut', 'step-out-of-current-function', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'k'], 'VBGkill', 'terminates-the-debugger', 1)
let g:_spacevim_mappings_space.d.e = {'name' : '+Evaluate/Execute'}
call SpaceVim#mapping#space#def('vnoremap', ['d', 'e', 's'], 'VBGevalSelectedText', 'evaluate-selected-text', 1)
call SpaceVim#mapping#space#def('nnoremap', ['d', 'e', 'e'], 'VBGevalWordUnderCursor', 'evaluate-cursor-symbol', 1)
call SpaceVim#mapping#space#def('vnoremap', ['d', 'e', 'S'], 'VBGexecuteSelectedText', 'execute-selected-text', 1)
let g:vebugger_breakpoint_text = '->'
let g:vebugger_currentline_text = '++'
endif
call SpaceVim#mapping#space#def('nnoremap', ['d', '.'], 'call call(' call SpaceVim#mapping#space#def('nnoremap', ['d', '.'], 'call call('
\ . string(s:_function('s:debug_transient_state')) . ', [])', \ . string(s:_function('s:debug_transient_state')) . ', [])',
\ 'debug-transient-state', 1) \ 'debug-transient-state', 1)
let g:vebugger_breakpoint_text = '->'
let g:vebugger_currentline_text = '++'
endfunction endfunction
function! SpaceVim#layers#debug#launching(ft) abort function! SpaceVim#layers#debug#launching(ft) abort
@ -60,43 +90,105 @@ endfunction
function! s:debug_transient_state() abort function! s:debug_transient_state() abort
let state = SpaceVim#api#import('transient_state') let state = SpaceVim#api#import('transient_state')
call state.set_title('Debug Transient State') call state.set_title('Debug Transient State')
call state.defind_keys(
\ { if s:debugger_plugin ==# 'vimspector'
\ 'layout' : 'vertical split', call state.defind_keys(
\ 'left' : [ \ {
\ { \ 'layout' : 'vertical split',
\ 'key' : 'o', \ 'left' : [
\ 'desc' : 'step over', \ {
\ 'func' : '', \ 'key' : 'c',
\ 'cmd' : 'VBGstepOver', \ 'desc' : 'Continue execution',
\ 'exit' : 0, \ 'func' : '',
\ }, \ 'cmd' : 'call vimspector#Continue()',
\ { \ 'exit' : 0,
\ 'key' : 'i', \ },
\ 'desc' : 'step into functions', \ {
\ 'func' : '', \ 'key' : 'u',
\ 'cmd' : 'VBGstepIn', \ 'desc' : 'Move up a frame',
\ 'exit' : 0, \ 'func' : '',
\ }, \ 'cmd' : 'call vimspector#UpFrame()',
\ ], \ 'exit' : 0,
\ 'right' : [ \ },
\ { \ {
\ 'key' : 'O', \ 'key' : 'd',
\ 'desc' : 'step out of current function', \ 'desc' : 'Move down a frame',
\ 'func' : '', \ 'func' : '',
\ 'cmd' : 'VBGstepOut', \ 'cmd' : 'call vimspector#DownFrame()',
\ 'exit' : 0, \ 'exit' : 0,
\ }, \ },
\ { \ ],
\ 'key' : 'k', \ 'right' : [
\ 'desc' : 'Terminates the debugger', \ {
\ 'func' : '', \ 'key' : 'o',
\ 'cmd' : 'VBGkill', \ 'desc' : 'step over',
\ 'exit' : 1, \ 'func' : '',
\ }, \ 'cmd' : 'call vimspector#StepOver()',
\ ], \ 'exit' : 0,
\ } \ },
\ ) \ {
\ 'key' : 'i',
\ 'desc' : 'step into functions',
\ 'func' : '',
\ 'cmd' : 'call vimspector#StepInto()',
\ 'exit' : 0,
\ },
\ {
\ 'key' : 'O',
\ 'desc' : 'step out of current function',
\ 'func' : '',
\ 'cmd' : 'call vimspector#StepOut()',
\ 'exit' : 0,
\ },
\ {
\ 'key' : 'k',
\ 'desc' : 'Terminates the debugger',
\ 'func' : '',
\ 'cmd' : 'call vimspector#Stop() | VimspectorReset',
\ 'exit' : 1,
\ },
\ ],
\ }
\ )
else
call state.defind_keys(
\ {
\ 'layout' : 'vertical split',
\ 'left' : [
\ {
\ 'key' : 'o',
\ 'desc' : 'step over',
\ 'func' : '',
\ 'cmd' : 'VBGstepOver',
\ 'exit' : 0,
\ },
\ {
\ 'key' : 'i',
\ 'desc' : 'step into functions',
\ 'func' : '',
\ 'cmd' : 'VBGstepIn',
\ 'exit' : 0,
\ },
\ ],
\ 'right' : [
\ {
\ 'key' : 'O',
\ 'desc' : 'step out of current function',
\ 'func' : '',
\ 'cmd' : 'VBGstepOut',
\ 'exit' : 0,
\ },
\ {
\ 'key' : 'k',
\ 'desc' : 'Terminates the debugger',
\ 'func' : '',
\ 'cmd' : 'VBGkill',
\ 'exit' : 1,
\ },
\ ],
\ }
\ )
endif
call state.open() call state.open()
endfunction endfunction