From 06d653c60ddfb4c8c9584e565db093eb662a2a52 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 31 Jul 2012 19:01:22 -0700 Subject: [PATCH] Adding the cursor identifier on InsertLeave This should help catch cases where the user jumps to an identifier and then edits it in place; we want to add that new ident to the db ASAP because the user may want to have it completed soon. Still, we're not perfect. If the user just deletes chars with 'x' or 'd' in Vim and therefore never even enters insert mode we are obviously not going to pick up that identifier until the next full file sweep. --- autoload/youcompleteme.vim | 4 +--- python/ycm.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 20ff57f4..cc776654 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -140,11 +140,9 @@ endfunction function! s:OnInsertLeave() - " TODO: Also, look at the current identifier under the cursor on InsertLeave - " and add it to the identifier database; this should catch the cases where the - " user slightly changes a variable name in-place let s:omnifunc_mode = 0 call s:UpdateDiagnosticNotifications() + py identcomp.AddIdentifierUnderCursor() endfunction diff --git a/python/ycm.py b/python/ycm.py index 3327e5fd..1b8300e6 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -82,6 +82,20 @@ class IdentifierCompleter( Completer ): self.AddIdentifier( PreviousIdentifier() ) + def AddIdentifierUnderCursor( self ): + cursor_identifier = vim.eval( 'expand("")' ) + if not cursor_identifier: + return + + stripped_cursor_identifier = ''.join( ( x for x in + cursor_identifier if + IsIdentifierChar( x ) ) ) + if not stripped_cursor_identifier: + return + + self.AddIdentifier( stripped_cursor_identifier ) + + def AddBufferIdentifiers( self ): filetype = vim.eval( "&filetype" ) filepath = vim.eval( "expand('%:p')" )