Pārlūkot izejas kodu

Fix issue with omnifunc mode persisting

This can happen when the user inserts a candidate string like "operator[]" which
doesn't end with an identifier char. A very obscure bug, but a bug nonetheless.
Strahinja Val Markovic 11 gadi atpakaļ
vecāks
revīzija
e0c7db4ac5
2 mainītis faili ar 21 papildinājumiem un 0 dzēšanām
  1. 7 0
      autoload/youcompleteme.vim
  2. 14 0
      python/ycm/base.py

+ 7 - 0
autoload/youcompleteme.vim

@@ -370,6 +370,13 @@ function! s:OnCursorMovedInsertMode()
   if g:ycm_auto_trigger || s:omnifunc_mode
     call s:InvokeCompletion()
   endif
+
+  " We have to make sure we correctly leave omnifunc mode even when the user
+  " inserts something like a "operator[]" candidate string which fails
+  " CurrentIdentifierFinished check.
+  if s:omnifunc_mode && !pyeval( 'base.LastEnteredCharIsIdentifierChar()')
+    let s:omnifunc_mode = 0
+  endif
 endfunction
 
 

+ 14 - 0
python/ycm/base.py

@@ -93,6 +93,20 @@ def CurrentIdentifierFinished():
     return line[ : current_column ].isspace()
 
 
+def LastEnteredCharIsIdentifierChar():
+  current_column = vimsupport.CurrentColumn()
+  previous_char_index = current_column - 1
+  if previous_char_index < 0:
+    return False
+  line = vim.current.line
+  try:
+    previous_char = line[ previous_char_index ]
+  except IndexError:
+    return False
+
+  return utils.IsIdentifierChar( previous_char )
+
+
 def AdjustCandidateInsertionText( candidates ):
   """This function adjusts the candidate insertion text to take into account the
   text that's currently in front of the cursor.