Allow customisation of the signs

Too many plugins use the default priority of 10 so they race/chase.
Allow uses to configure the priorities and make sure that the defaults
are documented.
This commit is contained in:
Ben Jackson 2020-09-01 13:37:45 +01:00
commit c1b544fb3c
12 changed files with 370 additions and 113 deletions

View file

@ -53,14 +53,16 @@ function! Test_Signs_Placed_Using_API_Are_Shown()
call assert_true( exists( '*vimspector#ToggleBreakpoint' ) )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ line( '.' ),
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" Disable breakpoint
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ line( '.' ),
\ 'vimspectorBPDisabled' )
\ 'vimspectorBPDisabled',
\ 9 )
" Remove breakpoint
call vimspector#ToggleBreakpoint()
@ -92,14 +94,16 @@ function! Test_Use_Mappings_HUMAN()
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 15,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" Disable the breakpoint
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 15,
\ 'vimspectorBPDisabled' )
\ 'vimspectorBPDisabled',
\ 9 )
" Delete the breakpoint
call feedkeys( "\<F9>", 'xt' )
@ -110,7 +114,8 @@ function! Test_Use_Mappings_HUMAN()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 15,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" Here we go. Start Debugging
call feedkeys( "\<F5>", 'xt' )
@ -184,7 +189,8 @@ function Test_DisableBreakpointWhileDebugging()
\ vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorCode',
\ 16,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
\ } )
" Remove the breakpoint
@ -200,7 +206,8 @@ function Test_DisableBreakpointWhileDebugging()
\ vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorCode',
\ 16,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
\ } )
" Run to breakpoint
@ -224,7 +231,8 @@ function Test_DisableBreakpointWhileDebugging()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" Disable the breakpoint
call setpos( '.', [ bufnr( 'simple.cpp' ), 16, 1 ] )
@ -232,7 +240,8 @@ function Test_DisableBreakpointWhileDebugging()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPDisabled' )
\ 'vimspectorBPDisabled',
\ 9 )
" And delete it
call feedkeys( "\<F9>", 'xt' )
@ -266,14 +275,16 @@ function! Test_Insert_Code_Above_Breakpoint()
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 25,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" Insert a line above the breakpoint
call append( 22, ' # Test' )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 26, 5 )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 26,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
" CHeck that we break at the right point
call setpos( '.', [ 0, 1, 1 ] )
@ -286,12 +297,14 @@ function! Test_Insert_Code_Above_Breakpoint()
call setpos( '.', [ 0, 26, 1 ] )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 26,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 26,
\ 'vimspectorBPDisabled' )
\ 'vimspectorBPDisabled',
\ 9 )
" Delete it
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 26 )
@ -314,14 +327,16 @@ function! Test_Conditional_Line_Breakpoint()
call feedkeys( "\\\<F9>argc==0\<CR>\<CR>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 16,
\ 'vimspectorBPCond' )
\ 'vimspectorBPCond',
\ 9 )
" Disable the breakpoint
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPDisabled' )
\ 'vimspectorBPDisabled',
\ 9 )
" Delete the breakpoint
call feedkeys( "\<F9>", 'xt' )
@ -335,20 +350,23 @@ function! Test_Conditional_Line_Breakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPCond' )
\ 'vimspectorBPCond',
\ 9 )
call setpos( '.', [ 0, 9, 1 ] )
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 9,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
call setpos( '.', [ 0, 17, 1 ] )
call vimspector#ToggleBreakpoint( { 'condition': 'argc == 1' } )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 17,
\ 'vimspectorBPCond' )
\ 'vimspectorBPCond',
\ 9 )
call setpos( '.', [ 0, 1, 1 ] )
@ -385,7 +403,8 @@ function! Test_Conditional_Line_Breakpoint_Hit()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 14,
\ 'vimspectorBPCond' )
\ 'vimspectorBPCond',
\ 9 )
call vimspector#LaunchWithSettings( { 'configuration': 'run' } )
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( fn, 14, 1 )
@ -526,3 +545,94 @@ function! Test_ListBreakpoints()
call vimspector#test#setup#Reset()
%bwipe!
endfunction
function! Test_Custom_Breakpoint_Priority()
let g:vimspector_sign_priority = {
\ 'vimspectorPC': 1,
\ 'vimspectorBP': 2,
\ 'vimspectorBPCond': 3,
\ 'vimspectorBPDisabled': 4
\ }
" While not debugging
lcd testdata/cpp/simple
edit simple.cpp
call setpos( '.', [ 0, 15, 1 ] )
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 15,
\ 'vimspectorBP',
\ 2 )
call setpos( '.', [ 0, 16, 1 ] )
call vimspector#ToggleBreakpoint()
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 16,
\ 'vimspectorBPDisabled',
\ 4 )
call vimspector#ToggleBreakpoint()
call vimspector#test#signs#AssertSignGroupEmptyAtLine( 'VimspectorBP', 15 )
call setpos( '.', [ 0, 17, 1 ] )
call vimspector#ToggleBreakpoint( { 'condition': '1' } )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorBP',
\ 17,
\ 'vimspectorBPCond',
\ 3 )
" While debugging
call vimspector#Launch()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 15, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 15 )
call vimspector#test#signs#AssertSignAtLine(
\ 'VimspectorCode',
\ 15,
\ 'vimspectorBP',
\ 2 )
call vimspector#test#signs#AssertSignAtLine(
\ 'VimspectorCode',
\ 15,
\ 'vimspectorPC',
\ 1 )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorCode',
\ 17,
\ 'vimspectorBP',
\ 2 )
call vimspector#StepOver()
" No sign as disabled
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 16, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 16 )
call vimspector#StepOver()
call vimspector#test#signs#AssertCursorIsAtLineInBuffer( 'simple.cpp', 17, 1 )
call vimspector#test#signs#AssertPCIsAtLineInBuffer( 'simple.cpp', 17 )
call vimspector#test#signs#AssertSignGroupSingletonAtLine(
\ 'VimspectorCode',
\ 15,
\ 'vimspectorBP',
\ 2 )
call vimspector#test#signs#AssertSignAtLine(
\ 'VimspectorCode',
\ 17,
\ 'vimspectorBP',
\ 2 )
call vimspector#test#signs#AssertSignAtLine(
\ 'VimspectorCode',
\ 17,
\ 'vimspectorPC',
\ 1 )
call vimspector#test#setup#Reset()
lcd -
%bwipeout!
endfunction
function! TearDown_Test_Custom_Breakpoint_Priority()
unlet! g:vimspector_sign_priority
endfunction

View file

@ -23,7 +23,8 @@ function! Test_Go_Simple()
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 4,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
call setpos( '.', [ 0, 1, 1 ] )

View file

@ -23,7 +23,8 @@ function! Test_Python_Simple()
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 6,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
call setpos( '.', [ 0, 1, 1 ] )
@ -79,7 +80,8 @@ function! Test_Python_Remote_Attach()
call feedkeys( "\<F9>", 'xt' )
call vimspector#test#signs#AssertSignGroupSingletonAtLine( 'VimspectorBP',
\ 6,
\ 'vimspectorBP' )
\ 'vimspectorBP',
\ 9 )
call setpos( '.', [ 0, 1, 1 ] )

View file

@ -46,7 +46,8 @@ endfunction
function! vimspector#test#signs#AssertSignGroupSingletonAtLine( group,
\ line,
\ sign_name )
\ sign_name,
\ priority )
\ abort
let signs = sign_getplaced( '%', {
@ -62,10 +63,46 @@ function! vimspector#test#signs#AssertSignGroupSingletonAtLine( group,
\ 'Num signs in ' . a:group . ' at ' . a:line ) ||
\ assert_equal( a:sign_name,
\ signs[ 0 ].signs[ 0 ].name,
\ 'Sign in group ' . a:group . ' at ' . a:line )
\ 'Sign in group ' . a:group . ' at ' . a:line ) ||
\ assert_equal( a:priority,
\ signs[ 0 ].signs[ 0 ].priority,
\ 'Sign priority in group ' . a:group . ' at ' . a:line )
endfunction
function! vimspector#test#signs#AssertSignAtLine( group, line, sign_name, priority ) abort
let signs = sign_getplaced( '%', {
\ 'group': a:group,
\ 'lnum': a:line,
\ } )
let errors_before = v:errors
let result = 1
let errors = [ 'No signs were found' ]
for sign in signs[ 0 ].signs
let v:errors = []
let result =
\ assert_equal( a:sign_name,
\ sign.name,
\ 'Sign in group ' . a:group . ' at ' . a:line ) ||
\ assert_equal( a:priority,
\ sign.priority,
\ 'Sign priority in group ' . a:group . ' at ' . a:line )
if result
let errors = v:errors
else
let errors = []
break
endif
endfor
let v:errors = errors_before + errors
return result
endfunction
function! vimspector#test#signs#AssertSignGroupEmptyAtLine( group, line ) abort
let signs = sign_getplaced( '%', {
\ 'group': a:group,