diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index aacbf6e95c..b43df82a39 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -1196,6 +1196,7 @@ function! s:RequestSemanticCompletion() abort if get( b:, 'ycm_completing' ) let s:force_semantic = 1 + let s:current_cursor_position = getpos( '.' ) call s:StopPoller( s:pollers.completion ) py3 ycm_state.SendCompletionRequest( True ) diff --git a/test/completion_info.test.vim b/test/completion_info.test.vim index 75d5635814..6ace93f1f9 100644 --- a/test/completion_info.test.vim +++ b/test/completion_info.test.vim @@ -203,3 +203,47 @@ function! Test_DontResolveCompletion_AlreadyResolved() call test_override( 'ALL', 0 ) endfunction + +function! Test_SwitchingToSemanticCompletionAfterSelectingIdentifierCandidate() + call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/identifier_semantic_switch.cpp', {} ) + call setpos( '.', [ 0, 3, 0 ] ) + call test_override( 'char_avail', 1 ) + + function! Check1( id ) + call WaitForCompletion() + call CheckCompletionItemsContainsExactly( [ 'ZbCdE' ], 'word' ) + let compl = complete_info() + call assert_equal( -1, compl.selected ) + call assert_equal( 1, len( compl.items ) ) + let ZbCdE = compl.items[ 0 ] + call assert_equal( 'ZbCdE', ZbCdE.word ) + call assert_equal( '[ID]', ZbCdE.menu ) + call assert_equal( '', ZbCdE.kind ) + call FeedAndCheckAgain( "\", funcref( 'Check2' ) ) + endfunction + + function! Check2( id ) + call WaitForCompletion() + call assert_match( 'ZbCdE', getline( '.' ) ) + call FeedAndCheckAgain( "\", funcref( 'Check3' ) ) + endfunction + + function! Check3( id ) + call WaitForCompletion() + call CheckCompletionItemsContainsExactly( [ 'ZbCdE' ], 'word' ) + let compl = complete_info() + call assert_equal( -1, compl.selected ) + call assert_match( 'ZbCdE', getline( '.' ) ) + call assert_equal( 1, len( compl.items ) ) + let ZbCdE = compl.items[ 0 ] + call assert_equal( 'ZbCdE', ZbCdE.word ) + call assert_equal( 'void', ZbCdE.menu ) + call assert_equal( 'f', ZbCdE.kind ) + call feedkeys( "\" ) + endfunction + + + call FeedAndCheckMain( 'ZCE', funcref( 'Check1' ) ) + call assert_false( pumvisible(), 'pumvisible()' ) + call test_override( 'ALL', 0 ) +endfunction