From e0c7db4ac5c8bbac5e4dc121a428df87c7320d7a Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 3 Dec 2013 14:38:23 -0800 Subject: [PATCH] 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. --- autoload/youcompleteme.vim | 7 +++++++ python/ycm/base.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 3002e885..404b493a 100644 --- a/autoload/youcompleteme.vim +++ b/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 diff --git a/python/ycm/base.py b/python/ycm/base.py index e578fa3b..2d0c2f7d 100644 --- a/python/ycm/base.py +++ b/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.