Allow overriding the variables/stack trace mappings in config
This commit is contained in:
parent
ec9122284e
commit
26452289a8
4 changed files with 106 additions and 26 deletions
|
|
@ -134,21 +134,43 @@ function! vimspector#internal#balloon#MouseFilter( winid, key ) abort
|
|||
return handled
|
||||
endfunction
|
||||
|
||||
function! s:MatchKey( key, candidates ) abort
|
||||
let mapped = ''
|
||||
for candidate in a:candidates
|
||||
try
|
||||
" Try and expand the key code
|
||||
execute 'let mapped = "\' . candidate . '"'
|
||||
if mapped ==# a:key
|
||||
return v:true
|
||||
endif
|
||||
endtry
|
||||
endfor
|
||||
|
||||
return v:false
|
||||
endfunction
|
||||
|
||||
function! vimspector#internal#balloon#CursorFilter( winid, key ) abort
|
||||
if a:key ==? "\<CR>"
|
||||
let mappings = py3eval(
|
||||
\ "__import__( 'vimspector',"
|
||||
\." fromlist = [ 'settings' ] ).settings.Dict("
|
||||
\." 'mappings' )[ 'variables' ]" )
|
||||
|
||||
if index( [ "\<LeftMouse>", "\<2-LeftMouse>" ], a:key ) >= 0
|
||||
return vimspector#internal#balloon#MouseFilter( a:winid, a:key )
|
||||
endif
|
||||
|
||||
if s:MatchKey( a:key, mappings.expand_collapse )
|
||||
call py3eval( '_vimspector_session.ExpandVariable('
|
||||
\ . 'buf = vim.buffers[ ' . winbufnr( a:winid ) . ' ],'
|
||||
\ . 'line_num = ' . line( '.', a:winid )
|
||||
\ . ')' )
|
||||
return 1
|
||||
elseif a:key ==? "\<C-CR>"
|
||||
elseif s:MatchKey( a:key, mappings.set_value )
|
||||
call py3eval( '_vimspector_session.SetVariableValue('
|
||||
\ . 'buf = vim.buffers[ ' . winbufnr( a:winid ) . ' ],'
|
||||
\ . 'line_num = ' . line( '.', a:winid )
|
||||
\ . ')' )
|
||||
return 1
|
||||
elseif index( [ "\<LeftMouse>", "\<2-LeftMouse>" ], a:key ) >= 0
|
||||
return vimspector#internal#balloon#MouseFilter( a:winid, a:key )
|
||||
endif
|
||||
|
||||
return popup_filter_menu( a:winid, a:key )
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
import vim
|
||||
import builtins
|
||||
from vimspector import utils
|
||||
from collections.abc import Mapping
|
||||
|
||||
DEFAULTS = {
|
||||
# UI
|
||||
|
|
@ -38,6 +39,19 @@ DEFAULTS = {
|
|||
|
||||
# Installer
|
||||
'install_gadgets': [],
|
||||
|
||||
# Mappings
|
||||
'mappings': {
|
||||
'variables': {
|
||||
'expand_collapse': [ '<CR>', '<2-LeftMouse>' ],
|
||||
'delete': [ '<Del>' ],
|
||||
'set_value': [ '<C-CR>' ]
|
||||
},
|
||||
'stack_trace': {
|
||||
'expand_or_jump': [ '<CR>', '<2-LeftMouse>' ],
|
||||
'focus_thread': [ '<leader><CR>' ],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -69,9 +83,46 @@ if hasattr( vim, 'Dictionary' ):
|
|||
DICT_TYPE = vim.Dictionary
|
||||
|
||||
|
||||
def Dict( option: str ):
|
||||
d = DICT_TYPE( DEFAULTS.get( option, {} ) )
|
||||
d.update( utils.GetVimValue( vim.vars,
|
||||
f'vimspector_{ option }',
|
||||
{} ) )
|
||||
return d
|
||||
def Dict( option ):
|
||||
return _UpdateDict( DICT_TYPE( DEFAULTS.get( option, {} ) ),
|
||||
utils.GetVimValue( vim.vars,
|
||||
f'vimspector_{ option }',
|
||||
{} ) )
|
||||
|
||||
|
||||
def _UpdateDict( target, override ):
|
||||
"""Apply the updates in |override| to the dict |target|. This is like
|
||||
dict.update, but recursive. i.e. if the existing element is a dict, then
|
||||
override elements of the sub-dict rather than wholesale replacing.
|
||||
e.g.
|
||||
UpdateDict(
|
||||
{
|
||||
'outer': { 'inner': { 'key': 'oldValue', 'existingKey': True } }
|
||||
},
|
||||
{
|
||||
'outer': { 'inner': { 'key': 'newValue' } },
|
||||
'newKey': { 'newDict': True },
|
||||
}
|
||||
)
|
||||
yields:
|
||||
{
|
||||
'outer': {
|
||||
'inner': {
|
||||
'key': 'newValue',
|
||||
'existingKey': True
|
||||
}
|
||||
},
|
||||
'newKey': { newDict: True }
|
||||
}
|
||||
"""
|
||||
|
||||
for key, value in override.items():
|
||||
current_value = target.get( key )
|
||||
if not isinstance( current_value, Mapping ):
|
||||
target[ key ] = value
|
||||
elif isinstance( value, Mapping ):
|
||||
target[ key ] = _UpdateDict( current_value, value )
|
||||
else:
|
||||
target[ key ] = value
|
||||
|
||||
return target
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import os
|
|||
import logging
|
||||
import typing
|
||||
|
||||
from vimspector import utils, signs
|
||||
from vimspector import utils, signs, settings
|
||||
|
||||
|
||||
class Thread:
|
||||
|
|
@ -107,13 +107,16 @@ class StackTraceView( object ):
|
|||
utils.SetUpHiddenBuffer( self._buf, 'vimspector.StackTrace' )
|
||||
utils.SetUpUIWindow( win )
|
||||
|
||||
mappings = settings.Dict( 'mappings' )[ 'stack_trace' ]
|
||||
|
||||
with utils.LetCurrentWindow( win ):
|
||||
vim.command( 'nnoremap <silent> <buffer> <CR> '
|
||||
':<C-U>call vimspector#GoToFrame()<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <leader><CR> '
|
||||
':<C-U>call vimspector#SetCurrentThread()<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <2-LeftMouse> '
|
||||
':<C-U>call vimspector#GoToFrame()<CR>' )
|
||||
for mapping in utils.GetVimList( mappings, 'expand_or_jump' ):
|
||||
vim.command( f'nnoremap <silent> <buffer> { mapping } '
|
||||
':<C-U>call vimspector#GoToFrame()<CR>' )
|
||||
|
||||
for mapping in utils.GetVimList( mappings, 'focus_thread' ):
|
||||
vim.command( f'nnoremap <silent> <buffer> { mapping } '
|
||||
':<C-U>call vimspector#SetCurrentThread()<CR>' )
|
||||
|
||||
if utils.UseWinBar():
|
||||
vim.command( 'nnoremenu <silent> 1.1 WinBar.Pause/Continue '
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import logging
|
|||
from functools import partial
|
||||
import typing
|
||||
|
||||
from vimspector import utils
|
||||
from vimspector import utils, settings
|
||||
|
||||
|
||||
class Expandable:
|
||||
|
|
@ -165,13 +165,16 @@ class VariablesView( object ):
|
|||
self._variable_eval: Scope = None
|
||||
self._variable_eval_view: View = None
|
||||
|
||||
mappings = settings.Dict( 'mappings' )[ 'variables' ]
|
||||
|
||||
def AddExpandMappings():
|
||||
vim.command( 'nnoremap <silent> <buffer> <CR> '
|
||||
':<C-u>call vimspector#ExpandVariable()<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <2-LeftMouse> '
|
||||
':<C-u>call vimspector#ExpandVariable()<CR>' )
|
||||
vim.command( 'nnoremap <silent> <buffer> <C-CR> '
|
||||
':<C-u>call vimspector#SetVariableValue()<CR>' )
|
||||
for mapping in utils.GetVimList( mappings, 'expand_collapse' ):
|
||||
vim.command( f'nnoremap <silent> <buffer> { mapping } '
|
||||
':<C-u>call vimspector#ExpandVariable()<CR>' )
|
||||
|
||||
for mapping in utils.GetVimList( mappings, 'set_value' ):
|
||||
vim.command( f'nnoremap <silent> <buffer> { mapping } '
|
||||
':<C-u>call vimspector#SetVariableValue()<CR>' )
|
||||
|
||||
# Set up the "Variables" buffer in the variables_win
|
||||
self._scopes: typing.List[ Scope ] = []
|
||||
|
|
@ -194,8 +197,9 @@ class VariablesView( object ):
|
|||
'vimspector#OmniFuncWatch' )
|
||||
with utils.LetCurrentWindow( watches_win ):
|
||||
AddExpandMappings()
|
||||
vim.command(
|
||||
'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' )
|
||||
for mapping in utils.GetVimList( mappings, 'delete' ):
|
||||
vim.command(
|
||||
f'nnoremap <buffer> { mapping } :call vimspector#DeleteWatch()<CR>' )
|
||||
|
||||
if utils.UseWinBar():
|
||||
vim.command( 'nnoremenu <silent> 1.1 WinBar.New '
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue