From dffd65f241ea727399248fedb80bee6b84ffa424 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 1 Sep 2020 16:30:16 +0100 Subject: [PATCH] Use CursorLine highlihgt to highlight current PC line --- README.md | 4 +- python3/vimspector/code.py | 3 +- python3/vimspector/settings.py | 2 +- python3/vimspector/signs.py | 8 +++- tests/breakpoints.test.vim | 86 ++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d354108..674bb0b 100644 --- a/README.md +++ b/README.md @@ -1370,7 +1370,7 @@ define them in your `vimrc`. | `vimspectorBP` | Line breakpoint | 9 | | `vimspectorBPCond` | Conditional line breakpiont | 9 | | `vimspectorBPDisabled` | Disabled breakpoint | 9 | -| `vimspectorPC` | Program counter (i.e. current line) | 20 | +| `vimspectorPC` | Program counter (i.e. current line) | 200 | The default symbols are the equivalent of something like the following: @@ -1378,7 +1378,7 @@ The default symbols are the equivalent of something like the following: sign define vimspectorBP text=\ ● texthl=WarningMsg sign define vimspectorBPCond text=\ ◆ texthl=WarningMsg sign define vimspectorBPDisabled text=\ ● texthl=LineNr -sign define vimspectorPC text=\ ▶ texthl=MatchParen +sign define vimspectorPC text=\ ▶ texthl=MatchParen linehl=CursorLine ``` If the signs don't display properly, your font probably doesn't contain these diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index bab847c..cb55af7 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -53,7 +53,8 @@ class CodeView( object ): if not signs.SignDefined( 'vimspectorPC' ): signs.DefineSign( 'vimspectorPC', text = '▶', - texthl = 'MatchParen' ) + texthl = 'MatchParen', + linehl = 'CursorLine' ) def SetCurrentFrame( self, frame ): diff --git a/python3/vimspector/settings.py b/python3/vimspector/settings.py index c80f682..04d9834 100644 --- a/python3/vimspector/settings.py +++ b/python3/vimspector/settings.py @@ -28,7 +28,7 @@ DEFAULTS = { # Signs 'sign_priority': { - 'vimspectorPC': 20, + 'vimspectorPC': 200, 'vimspectorBP': 9, 'vimspectorBPCond': 9, 'vimspectorBPDisabled': 9, diff --git a/python3/vimspector/signs.py b/python3/vimspector/signs.py index a1faa92..0c5e704 100644 --- a/python3/vimspector/signs.py +++ b/python3/vimspector/signs.py @@ -12,14 +12,18 @@ def SignDefined( name ): return False -def DefineSign( name, text, texthl, col = 'right' ): +def DefineSign( name, text, texthl, col = 'right', **kwargs ): if col == 'right': if int( utils.Call( 'strdisplaywidth', text ) ) < 2: text = ' ' + text text = text.replace( ' ', r'\ ' ) - vim.command( f'sign define { name } text={ text } texthl={ texthl }' ) + cmd = f'sign define { name } text={ text } texthl={ texthl }' + for key, value in kwargs.items(): + cmd += f' { key }={ value }' + + vim.command( cmd ) def PlaceSign( sign_id, group, name, file, line ): diff --git a/tests/breakpoints.test.vim b/tests/breakpoints.test.vim index ca57157..fed7f2a 100644 --- a/tests/breakpoints.test.vim +++ b/tests/breakpoints.test.vim @@ -633,6 +633,92 @@ function! Test_Custom_Breakpoint_Priority() %bwipeout! endfunction +function! Test_Custom_Breakpoint_Priority_Partial() + let g:vimspector_sign_priority = { + \ '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', + \ 200 ) + 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', + \ 200 ) + + + call vimspector#test#setup#Reset() + lcd - + %bwipeout! +endfunction + function! TearDown_Test_Custom_Breakpoint_Priority() unlet! g:vimspector_sign_priority endfunction