Auto merge of #3117 - micbou:omnifunc-restore-cursor-position, r=micbou
[READY] Restore cursor position after omnifunc calls
An omnifunc may move the cursor position even on the first call, e.g. [`completeR` from the `Nvim-R` plugin](0db20893d3/R/common_global.vim (L3383)
). The cursor position is not restored between the two calls because it's unnecessary with the changes from PR #3112.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/3117)
<!-- Reviewable:end -->
This commit is contained in:
commit
e018777b38
@ -78,6 +78,14 @@ class OmniCompleter( Completer ):
|
||||
if not self._omnifunc:
|
||||
return []
|
||||
|
||||
# Calling directly the omnifunc may move the cursor position. This is the
|
||||
# case with the default Vim omnifunc for C-family languages
|
||||
# (ccomplete#Complete) which calls searchdecl to find a declaration. This
|
||||
# function is supposed to move the cursor to the found declaration but it
|
||||
# doesn't when called through the omni completion mapping (CTRL-X CTRL-O).
|
||||
# So, we restore the cursor position after the omnifunc calls.
|
||||
line, column = vimsupport.CurrentLineAndColumn()
|
||||
|
||||
try:
|
||||
start_column = vimsupport.GetIntValue( self._omnifunc + '(1,"")' )
|
||||
if start_column < 0:
|
||||
@ -92,14 +100,6 @@ class OmniCompleter( Completer ):
|
||||
# because it affects the value returned by 'query'.
|
||||
request_data[ 'start_column' ] = start_column + 1
|
||||
|
||||
# Calling directly the omnifunc may move the cursor position. This is the
|
||||
# case with the default Vim omnifunc for C-family languages
|
||||
# (ccomplete#Complete) which calls searchdecl to find a declaration. This
|
||||
# function is supposed to move the cursor to the found declaration but it
|
||||
# doesn't when called through the omni completion mapping (CTRL-X CTRL-O).
|
||||
# So, we restore the cursor position after calling the omnifunc.
|
||||
line, column = vimsupport.CurrentLineAndColumn()
|
||||
|
||||
# Vim internally moves the cursor to the start column before calling again
|
||||
# the omnifunc. Some omnifuncs like the one defined by the
|
||||
# LanguageClient-neovim plugin depend on this behavior to compute the list
|
||||
@ -112,8 +112,6 @@ class OmniCompleter( Completer ):
|
||||
"')" ]
|
||||
items = vim.eval( ''.join( omnifunc_call ) )
|
||||
|
||||
vimsupport.SetCurrentLineAndColumn( line, column )
|
||||
|
||||
if isinstance( items, dict ) and 'words' in items:
|
||||
items = items[ 'words' ]
|
||||
|
||||
@ -127,6 +125,9 @@ class OmniCompleter( Completer ):
|
||||
OMNIFUNC_RETURNED_BAD_VALUE + ' ' + str( error ) )
|
||||
return []
|
||||
|
||||
finally:
|
||||
vimsupport.SetCurrentLineAndColumn( line, column )
|
||||
|
||||
|
||||
def FilterAndSortCandidatesInner( self, candidates, sort_property, query ):
|
||||
request_data = {
|
||||
|
@ -622,9 +622,9 @@ def OmniCompleter_GetCompletions_RestoreCursorPositionAfterOmnifuncCall_test(
|
||||
# This omnifunc moves the cursor to the test definition like
|
||||
# ccomplete#Complete would.
|
||||
def Omnifunc( findstart, base ):
|
||||
vimsupport.SetCurrentLineAndColumn( 0, 0 )
|
||||
if findstart:
|
||||
return 5
|
||||
vimsupport.SetCurrentLineAndColumn( 0, 0 )
|
||||
return [ 'length' ]
|
||||
|
||||
current_buffer = VimBuffer( 'buffer',
|
||||
|
Loading…
Reference in New Issue
Block a user