Selaa lähdekoodia

Hide diagnostics UI when entering Insert Mode

Ben Jackson 2 vuotta sitten
vanhempi
commit
854232047d

+ 1 - 0
autoload/youcompleteme.vim

@@ -1035,6 +1035,7 @@ endfunction
 
 function! s:OnInsertEnter() abort
   let s:current_cursor_position = getpos( '.' )
+  py3 ycm_state.OnInsertEnter()
   if s:ShouldUseInlayHintsNow( bufnr() ) &&
         \ get(g:, 'ycm_clear_inlay_hints_in_insert_mode' )
     py3 ycm_state.CurrentBuffer().inlay_hints.Clear()

+ 10 - 2
python/ycm/buffer.py

@@ -43,8 +43,8 @@ class Buffer:
 
 
   def FileParseRequestReady( self, block = False ):
-    return bool( self._parse_request and
-                 ( block or self._parse_request.Done() ) )
+    return ( bool( self._parse_request ) and
+             ( block or self._parse_request.Done() ) )
 
 
   def SendParseRequest( self, extra_data ):
@@ -64,6 +64,10 @@ class Buffer:
     self._parse_tick = self._ChangedTick()
 
 
+  def ParseRequestPending( self ):
+    return bool( self._parse_request ) and not self._parse_request.Done()
+
+
   def NeedsReparse( self ):
     return self._parse_tick != self._ChangedTick()
 
@@ -127,6 +131,10 @@ class Buffer:
     return self._diag_interface.RefreshDiagnosticsUI()
 
 
+  def ClearDiagnosticsUI( self ):
+    return self._diag_interface.ClearDiagnosticsUI()
+
+
   def DiagnosticsForLine( self, line_number ):
     return self._diag_interface.DiagnosticsForLine( line_number )
 

+ 41 - 12
python/ycm/diagnostic_interface.py

@@ -89,6 +89,16 @@ class DiagnosticInterface:
       self._UpdateLocationLists( open_on_edit )
 
 
+  def ClearDiagnosticsUI( self ):
+    if self._user_options[ 'echo_current_diagnostic' ]:
+      self._ClearCurrentDiagnostic()
+
+    if self._user_options[ 'enable_diagnostic_signs' ]:
+      self._ClearSigns()
+
+    self._ClearMatches()
+
+
   def DiagnosticsForLine( self, line_number ):
     return self._line_to_diags[ line_number ]
 
@@ -120,17 +130,28 @@ class DiagnosticInterface:
     self._EchoDiagnosticText( line_num, first_diag, text )
 
 
-  def _EchoDiagnosticText( self, line_num, first_diag, text ):
+  def _ClearCurrentDiagnostic( self, will_be_replaced=False ):
+    if not self._diag_message_needs_clearing:
+      return
+
     if ( vimsupport.VimSupportsVirtualText() and
          self._user_options[ 'echo_current_diagnostic' ] == 'virtual-text' ):
-      if self._diag_message_needs_clearing:
-        # Clear any previous diag echo
-        tp.ClearTextProperties( self._bufnr,
-                                prop_types = [ 'YcmVirtDiagPadding',
-                                               'YcmVirtDiagError',
-                                               'YcmVirtDiagWarning' ] )
-        self._diag_message_needs_clearing = False
+      tp.ClearTextProperties( self._bufnr,
+                              prop_types = [ 'YcmVirtDiagPadding',
+                                             'YcmVirtDiagError',
+                                             'YcmVirtDiagWarning' ] )
+    else:
+      if not will_be_replaced:
+        vimsupport.PostVimMessage( '', warning = False )
+
+    self._diag_message_needs_clearing = False
+
 
+  def _EchoDiagnosticText( self, line_num, first_diag, text ):
+    self._ClearCurrentDiagnostic( bool( text ) )
+
+    if ( vimsupport.VimSupportsVirtualText() and
+         self._user_options[ 'echo_current_diagnostic' ] == 'virtual-text' ):
       if not text:
         return
 
@@ -159,10 +180,7 @@ class DiagnosticInterface:
         marker + ' ' + [ line for line in text.splitlines() if line ][ 0 ] )
     else:
       if not text:
-        if self._diag_message_needs_clearing:
-          # Clear any previous diag echo
-          vimsupport.PostVimMessage( '', warning = False )
-          self._diag_message_needs_clearing = False
+        # We already cleared it
         return
 
       vimsupport.PostVimMessage( text, warning = False, truncate = True )
@@ -184,6 +202,12 @@ class DiagnosticInterface:
       open_on_edit )
 
 
+  def _ClearMatches( self ):
+    props_to_remove = vimsupport.GetTextProperties( self._bufnr )
+    for prop in props_to_remove:
+      vimsupport.RemoveDiagnosticProperty( self._bufnr, prop )
+
+
   def UpdateMatches( self ):
     if not self._user_options[ 'enable_diagnostic_highlighting' ]:
       return
@@ -221,6 +245,11 @@ class DiagnosticInterface:
       vimsupport.RemoveDiagnosticProperty( self._bufnr, prop )
 
 
+  def _ClearSigns( self ):
+    signs_to_unplace = vimsupport.GetSignsInBuffer( self._bufnr )
+    vim.eval( f'sign_unplacelist( { signs_to_unplace } )' )
+
+
   def _UpdateSigns( self ):
     signs_to_unplace = vimsupport.GetSignsInBuffer( self._bufnr )
     signs_to_place = []

+ 6 - 1
python/ycm/youcompleteme.py

@@ -608,9 +608,14 @@ class YouCompleteMe:
     return self._buffers[ bufnr ]
 
 
+  def OnInsertEnter( self ):
+    if not self._user_options[ 'update_diagnostics_in_insert_mode' ]:
+      self.CurrentBuffer().ClearDiagnosticsUI()
+
+
   def OnInsertLeave( self ):
     if ( not self._user_options[ 'update_diagnostics_in_insert_mode' ] and
-         not self.NeedsReparse() ):
+         not self.CurrentBuffer().ParseRequestPending() ):
       self.CurrentBuffer().RefreshDiagnosticsUI()
     SendEventNotificationAsync( 'InsertLeave' )