Browse Source

Inlay Hints: Only enable when supported by vim

Ben Jackson 2 years ago
parent
commit
6b4e5c712f
2 changed files with 15 additions and 8 deletions
  1. 12 6
      autoload/youcompleteme.vim
  2. 3 2
      python/ycm/inlay_hints.py

+ 12 - 6
autoload/youcompleteme.vim

@@ -81,6 +81,7 @@ let s:buftype_blacklist = {
 let s:last_char_inserted_by_user = v:true
 let s:enable_hover = 0
 let s:cursorhold_popup = -1
+let s:enable_inlay_hints = 0
 
 let s:force_preview_popup = 0
 
@@ -301,7 +302,8 @@ try:
 
   ycm_state = youcompleteme.YouCompleteMe( default_options )
   ycm_semantic_highlighting.Initialise()
-  ycm_inlay_hints.Initialise()
+  vim.command( 'let s:enable_inlay_hints = ' +
+    '1' if ycm_inlay_hints.Initialise() else '0' )
 except Exception as error:
   # We don't use PostVimMessage or EchoText from the vimsupport module because
   # importing this module may fail.
@@ -793,7 +795,7 @@ endfunction
 
 function! s:UpdateInlayHints( bufnr )
   call s:StopPoller( s:pollers.inlay_hints )
-  if !s:is_neovim &&
+  if s:enable_inlay_hints &&
         \ get( b:, 'ycm_enable_inlay_hints',
         \   get( g:, 'ycm_enable_inlay_hints', 0 ) )
 
@@ -984,7 +986,9 @@ endfunction
 
 function! s:OnInsertEnter() abort
   let s:current_cursor_position = getpos( '.' )
-  py3 ycm_state.CurrentBuffer().inlay_hints.Clear()
+  if s:enable_inlay_hints
+    py3 ycm_state.CurrentBuffer().inlay_hints.Clear()
+  endif
 endfunction
 
 function! s:OnInsertLeave()
@@ -1006,9 +1010,11 @@ function! s:OnInsertLeave()
   endif
 
   call s:ClearSignatureHelp()
-  " We cleared inlay hints on insert enter
-  " TODO: Probalby should use ModeChange
-  py3 ycm_state.CurrentBuffer().inlay_hints.Refresh()
+  if s:enable_inlay_hints
+    " We cleared inlay hints on insert enter
+    " TODO: Probalby should use ModeChange
+    py3 ycm_state.CurrentBuffer().inlay_hints.Refresh()
+  endif
 endfunction
 
 

+ 3 - 2
python/ycm/inlay_hints.py

@@ -34,8 +34,8 @@ REPORTED_MISSING_TYPES = set()
 
 
 def Initialise():
-  if vimsupport.VimIsNeovim():
-    return
+  if not vimsupport.VimSupportsVirtualText():
+    return False
 
   props = tp.GetTextPropertyTypes()
   if 'YCM_INLAY_UNKNOWN' not in props:
@@ -47,6 +47,7 @@ def Initialise():
         f"hlexists( '{ vimsupport.EscapeForVim( group ) }' )" ):
       tp.AddTextPropertyType( prop, highlight = group )
 
+  return True
 
 class InlayHints:
   """Stores the inlay hints state for a Vim buffer"""