Browse Source

Improve interaction of text properties - use SpellBad/SpellCap without adornment for warnings/errors

Ben Jackson 2 years ago
parent
commit
c14286b697
3 changed files with 76 additions and 36 deletions
  1. 51 5
      autoload/youcompleteme.vim
  2. 24 30
      python/ycm/diagnostic_interface.py
  3. 1 1
      python/ycm/vimsupport.py

+ 51 - 5
autoload/youcompleteme.vim

@@ -435,7 +435,9 @@ function! s:SetUpSyntaxHighlighting()
   if s:PropertyTypeNotDefined( 'YcmErrorProperty' )
     call prop_type_add( 'YcmErrorProperty', {
           \ 'highlight': 'YcmErrorSection',
-          \ 'priority': 30 } )
+          \ 'priority': 30,
+          \ 'combine': 0,
+          \ 'override': 1 } )
   endif
 
   " Used for virtual text
@@ -445,10 +447,52 @@ function! s:SetUpSyntaxHighlighting()
   if !hlexists( 'YcmInlayHint' )
     highlight default link YcmInlayHint NonText
   endif
+  if !hlexists( 'YcmErrorText' )
+    if exists( '*hlget' )
+      let YcmErrorText = hlget( 'SpellBad', v:true )[ 0 ]
+      let YcmErrorText.name = 'YcmErrorText'
+      let YcmErrorText.cterm = {}
+      let YcmErrorText.gui = {}
+      let YcmErrorText.term = {}
+      call hlset( [ YcmErrorText ] )
+    else
+      " approximation
+      hi default link YcmErrorText WarningMsg
+    endif
+  endif
+  if !hlexists( 'YcmWarningText' )
+    if exists( '*hlget' )
+      let YcmWarningText = hlget( 'SpellCap', v:true )[ 0 ]
+      let YcmWarningText.name = 'YcmWarningText'
+      let YcmWarningText.cterm = {}
+      let YcmWarningText.gui = {}
+      let YcmWarningText.term = {}
+      call hlset( [ YcmWarningText] )
+    else
+      " Lame approximation
+      hi default link YcmWarningText Conceal
+    endif
+  endif
+
+  if s:PropertyTypeNotDefined( 'YcmVirtError' )
+    call prop_type_add( 'YcmVirtError', {
+          \ 'highlight': 'YcmErrorText',
+          \ 'priority': 20,
+          \ 'combine': 0 } )
+  endif
+  if s:PropertyTypeNotDefined( 'YcmVirtWarning' )
+    call prop_type_add( 'YcmVirtWarning', {
+          \ 'highlight': 'YcmWarningText',
+          \ 'priority': 19,
+          \ 'combine': 0 } )
+  endif
+
+
   if s:PropertyTypeNotDefined( 'YcmPadding' )
-    call prop_type_add( 'YcmPadding',
-          \ { 'highlight': 'YcmInvisible',
-          \   'priority': 100 } )
+    call prop_type_add( 'YcmPadding', {
+          \ 'highlight': 'YcmInvisible',
+          \ 'priority': 100,
+          \ 'combine': 1 } )
   endif
 
   if !hlexists( 'YcmWarningSection' )
@@ -461,7 +505,9 @@ function! s:SetUpSyntaxHighlighting()
   if s:PropertyTypeNotDefined( 'YcmWarningProperty' )
     call prop_type_add( 'YcmWarningProperty', {
           \ 'highlight': 'YcmWarningSection',
-          \ 'priority': 30 } )
+          \ 'priority': 29,
+          \ 'combine': 0,
+          \ 'override': 1 } )
   endif
 endfunction
 

+ 24 - 30
python/ycm/diagnostic_interface.py

@@ -18,6 +18,7 @@
 from collections import defaultdict
 from ycm import vimsupport
 from ycm.diagnostic_filter import DiagnosticFilter, CompileLevel
+from ycm import text_properties as tp
 import vim
 YCM_VIM_PROPERTY_ID = 0
 
@@ -32,7 +33,6 @@ class DiagnosticInterface:
     self._line_to_diags = defaultdict( list )
     self._previous_diag_line_number = -1
     self._diag_message_needs_clearing = False
-    self._diag_message_prop_ids = []
 
 
   def OnCursorMoved( self ):
@@ -109,40 +109,33 @@ class DiagnosticInterface:
         text += ' (FixIt)'
 
     if self._user_options[ 'echo_current_diagnostic' ] == 'virtual-text':
-      if self._diag_message_prop_ids:
+      if self._diag_message_needs_clearing:
         # Clear any previous diag echo
-        for prop in self._diag_message_prop_ids:
-          vimsupport.RemoveTextProperty( **prop )
-        self._diag_message_prop_ids.clear()
+        tp.ClearTextProperties( self._bufnr, type = 'YcmVirtError' )
+        tp.ClearTextProperties( self._bufnr, type = 'YcmVirtWarning' )
+        self._diag_message_needs_clearing = False
 
       if not text:
         return
 
       def MakeVritualTextProperty( prop_type, text, position='after' ):
-        return {
-          'buffer_number': self._bufnr,
-          'prop_id': vimsupport.AddTextProperty(
-            self._bufnr,
-            line_num,
-            0,
-            prop_type,
-            {
-              'text': text,
-              'text_align': position,
-              'text_wrap': 'wrap'
-            } ),
-          'line_num': line_num,
-          'prop_type': prop_type
-        }
-
-      self._diag_message_prop_ids = [
-        MakeVritualTextProperty(
-          'YcmPadding',
-          ' ' * vim.buffers[ self._bufnr ].options[ 'shiftwidth' ] ),
-        MakeVritualTextProperty(
-          'YcmErrorProperty',
-          [ line for line in text.splitlines() if line ][ 0 ] )
-      ]
+        vimsupport.AddTextProperty( self._bufnr,
+                                    line_num,
+                                    0,
+                                    prop_type,
+                                    {
+                                      'text': text,
+                                      'text_align': position,
+                                      'text_wrap': 'wrap'
+                                    } )
+
+      MakeVritualTextProperty(
+        'YcmPadding',
+        ' ' * vim.buffers[ self._bufnr ].options[ 'shiftwidth' ] ),
+      MakeVritualTextProperty(
+        'YcmVirtError' if _DiagnosticIsError( first_diag )
+                       else 'YcmVirtWarning',
+        [ line for line in text.splitlines() if line ][ 0 ] )
     else:
       if not text:
         if self._diag_message_needs_clearing:
@@ -152,7 +145,8 @@ class DiagnosticInterface:
         return
 
       vimsupport.PostVimMessage( text, warning = False, truncate = True )
-      self._diag_message_needs_clearing = True
+
+    self._diag_message_needs_clearing = True
 
 
   def _DiagnosticsCount( self, predicate ):

+ 1 - 1
python/ycm/vimsupport.py

@@ -62,7 +62,7 @@ YCM_NEOVIM_NS_ID = vim.eval( 'g:ycm_neovim_ns_id' )
 
 # Virtual text is not a feature in itself and early patches don't work well, so
 # we need to keep changing this at the moment
-VIM_VIRTUAL_TEXT_VERSION_REQ = '9.0.193'
+VIM_VIRTUAL_TEXT_VERSION_REQ = '9.0.199'
 
 
 def CurrentLineAndColumn():