Skip to content

Commit

Permalink
Merge pull request #4187 from bstaletic/diag-fixes-pt1
Browse files Browse the repository at this point in the history
Diagnostics fixes - hopefully only the non-controversial parts
  • Loading branch information
mergify[bot] committed Oct 6, 2023
2 parents 88ed5a7 + 456b469 commit cc9a3ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
3 changes: 1 addition & 2 deletions python/ycm/diagnostic_interface.py
Expand Up @@ -44,8 +44,7 @@ def OnCursorMoved( self ):
if self._user_options[ 'echo_current_diagnostic' ]:
line, _ = vimsupport.CurrentLineAndColumn()
line += 1 # Convert to 1-based
if ( not self.ShouldUpdateDiagnosticsUINow() and
self._diag_message_needs_clearing ):
if not self.ShouldUpdateDiagnosticsUINow():
# Clear any previously echo'd diagnostic in insert mode
self._EchoDiagnosticText( line, None, None )
elif line != self._previous_diag_line_number:
Expand Down
4 changes: 3 additions & 1 deletion python/ycm/youcompleteme.py
Expand Up @@ -614,8 +614,10 @@ def OnInsertEnter( self ):


def OnInsertLeave( self ):
async_diags = any( self._message_poll_requests.get( filetype )
for filetype in vimsupport.CurrentFiletypes() )
if ( not self._user_options[ 'update_diagnostics_in_insert_mode' ] and
not self.CurrentBuffer().ParseRequestPending() ):
( async_diags or not self.CurrentBuffer().ParseRequestPending() ) ):
self.CurrentBuffer().RefreshDiagnosticsUI()
SendEventNotificationAsync( 'InsertLeave' )

Expand Down
37 changes: 33 additions & 4 deletions test/diagnostics.test.vim
Expand Up @@ -52,7 +52,7 @@ function! Test_Disable_Diagnostics_Update_In_insert_Mode()

" Must do the checks in a timer callback because we need to stay in insert
" mode until done.
function! Check( id ) closure
function! CheckNoDiagUIAfterOpenParenthesis( id ) closure
call WaitForAssert( {->
\ assert_true(
\ py3eval(
Expand All @@ -62,10 +62,11 @@ function! Test_Disable_Diagnostics_Update_In_insert_Mode()
\ '%',
\ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )

call FeedAndCheckAgain( " \<BS>\<BS>\<BS>", funcref( 'CheckAgain' ) )
call FeedAndCheckAgain( " \<BS>\<BS>\<BS>)",
\ funcref( 'CheckNoDiagUIAfterClosingPatenthesis' ) )
endfunction

function! CheckAgain( id ) closure
function! CheckNoDiagUIAfterClosingPatenthesis( id ) closure
call WaitForAssert( {->
\ assert_true(
\ py3eval(
Expand All @@ -76,9 +77,37 @@ function! Test_Disable_Diagnostics_Update_In_insert_Mode()
\ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )

call feedkeys( "\<ESC>" )
call FeedAndCheckAgain( "\<ESC>",
\ funcref( 'CheckDiagUIRefreshedAfterLeavingInsertMode' ) )
endfunction

call FeedAndCheckMain( 'imain(', funcref( 'Check' ) )
function! CheckDiagUIRefreshedAfterLeavingInsertMode( id ) closure
call WaitForAssert( {->
\ assert_true(
\ py3eval(
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
\ ) ) } )
call WaitForAssert( {-> assert_true( len( sign_getplaced(
\ '%',
\ { 'group': 'ycm_signs' } )[ 0 ][ 'signs' ] ) ) } )
call FeedAndCheckAgain( "A\<CR>", funcref( 'CheckNoPropsAfterNewLine' )
endfunction

function! CheckNoPropsAfterNewLine( id ) closure
call WaitForAssert( {->
\ assert_true(
\ py3eval(
\ 'len( ycm_state.CurrentBuffer()._diag_interface._diagnostics )'
\ ) ) } )
call WaitForAssert( {-> assert_false( len( prop_list(
\ 1, { 'end_lnum': -1,
\ 'types': [ 'YcmVirtDiagWarning',
\ 'YcmVirtDiagError',
\ 'YcmVirtDiagPadding' ] } ) ) ) )
endfunction

call FeedAndCheckMain( 'imain(',
\ funcref( 'CheckNoDiagUIAfterOpenParenthesis' ) )
call test_override( 'ALL', 0 )
endfunction

Expand Down

0 comments on commit cc9a3ae

Please sign in to comment.