From 6b8349ba8e3df37bfa2fa19b80c86558bc1244d0 Mon Sep 17 00:00:00 2001 From: micbou Date: Tue, 11 Dec 2018 02:15:24 +0100 Subject: [PATCH] Fix insertion adjustment for omnifunc candidates The abbr field may not be present for candidates returned by Vim's omnifunc. --- python/ycm/base.py | 2 +- python/ycm/tests/base_test.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/ycm/base.py b/python/ycm/base.py index 8135ee06..7013dfed 100644 --- a/python/ycm/base.py +++ b/python/ycm/base.py @@ -103,7 +103,7 @@ def AdjustCandidateInsertionText( candidates ): for candidate in candidates: new_candidate = candidate.copy() - if not new_candidate[ 'abbr' ]: + if not new_candidate.get( 'abbr' ): new_candidate[ 'abbr' ] = new_candidate[ 'word' ] new_candidate[ 'word' ] = NewCandidateInsertionText( diff --git a/python/ycm/tests/base_test.py b/python/ycm/tests/base_test.py index ff972ceb..15e51b2c 100644 --- a/python/ycm/tests/base_test.py +++ b/python/ycm/tests/base_test.py @@ -130,6 +130,13 @@ def AdjustCandidateInsertionText_DontTouchAbbr_test(): { 'word': 'foobar', 'abbr': '1234' } ] ) ) +def AdjustCandidateInsertionText_NoAbbr_test(): + with MockTextAfterCursor( 'bar' ): + eq_( [ { 'word': 'foo', 'abbr': 'foobar' } ], + base.AdjustCandidateInsertionText( [ + { 'word': 'foobar' } ] ) ) + + def OverlapLength_Basic_test(): eq_( 3, base.OverlapLength( 'foo bar', 'bar zoo' ) ) eq_( 3, base.OverlapLength( 'foobar', 'barzoo' ) )