From 9fdd465c260121ce5a4631b8660dc96431280037 Mon Sep 17 00:00:00 2001 From: Francisco Lopes Date: Sat, 2 Jan 2016 20:55:49 -0200 Subject: [PATCH] Allows empty insertion text. This is useful for hints for example, whose purpose is information display solely. --- python/ycm/client/completion_request.py | 7 +- .../client/tests/completion_request_test.py | 104 +++++++++++++----- 2 files changed, 80 insertions(+), 31 deletions(-) diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index 584a9bd0..93375a03 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -64,8 +64,9 @@ class CompletionRequest( BaseRequest ): def ConvertCompletionDataToVimData( completion_data ): # see :h complete-items for a description of the dictionary fields vim_data = { - 'word' : ToUtf8IfNeeded( completion_data[ 'insertion_text' ] ), - 'dup' : 1, + 'word' : '', + 'dup' : 1, + 'empty' : 1, } if ( 'extra_data' in completion_data and @@ -75,6 +76,8 @@ def ConvertCompletionDataToVimData( completion_data ): else: doc_string = "" + if 'insertion_text' in completion_data: + vim_data[ 'word' ] = ToUtf8IfNeeded( completion_data[ 'insertion_text' ] ) if 'menu_text' in completion_data: vim_data[ 'abbr' ] = ToUtf8IfNeeded( completion_data[ 'menu_text' ] ) if 'extra_menu_info' in completion_data: diff --git a/python/ycm/client/tests/completion_request_test.py b/python/ycm/client/tests/completion_request_test.py index b23514ea..15243ab7 100644 --- a/python/ycm/client/tests/completion_request_test.py +++ b/python/ycm/client/tests/completion_request_test.py @@ -52,12 +52,13 @@ class ConvertCompletionResponseToVimDatas_test: 'doc_string': 'DOC STRING', }, }, { - 'word': 'INSERTION TEXT', - 'abbr': 'MENU TEXT', - 'menu': 'EXTRA MENU INFO', - 'kind': 'k', - 'info': 'DETAILED INFO\nDOC STRING', - 'dup' : 1, + 'word' : 'INSERTION TEXT', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DETAILED INFO\nDOC STRING', + 'dup' : 1, + 'empty': 1, } ) @@ -69,12 +70,13 @@ class ConvertCompletionResponseToVimDatas_test: 'kind': 'K', 'detailed_info': 'DETAILED INFO', }, { - 'word': 'INSERTION TEXT', - 'abbr': 'MENU TEXT', - 'menu': 'EXTRA MENU INFO', - 'kind': 'k', - 'info': 'DETAILED INFO', - 'dup' : 1, + 'word' : 'INSERTION TEXT', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DETAILED INFO', + 'dup' : 1, + 'empty': 1, } ) @@ -88,12 +90,13 @@ class ConvertCompletionResponseToVimDatas_test: 'doc_string': 'DOC STRING', }, }, { - 'word': 'INSERTION TEXT', - 'abbr': 'MENU TEXT', - 'menu': 'EXTRA MENU INFO', - 'kind': 'k', - 'info': 'DOC STRING', - 'dup' : 1, + 'word' : 'INSERTION TEXT', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DOC STRING', + 'dup' : 1, + 'empty': 1, } ) @@ -106,11 +109,12 @@ class ConvertCompletionResponseToVimDatas_test: 'extra_data': { }, }, { - 'word': 'INSERTION TEXT', - 'abbr': 'MENU TEXT', - 'menu': 'EXTRA MENU INFO', - 'kind': 'k', - 'dup' : 1, + 'word' : 'INSERTION TEXT', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'dup' : 1, + 'empty': 1, } ) @@ -124,10 +128,52 @@ class ConvertCompletionResponseToVimDatas_test: 'extra_data': { }, }, { - 'word': 'INSERTION TEXT', - 'abbr': 'MENU TEXT', - 'menu': 'EXTRA MENU INFO', - 'kind': 'k', - 'info': 'DETAILED INFO', - 'dup' : 1, + 'word' : 'INSERTION TEXT', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DETAILED INFO', + 'dup' : 1, + 'empty': 1, + } ) + + + def Empty_Insertion_Text_test( self ): + self._Check( { + 'insertion_text': '', + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'detailed_info': 'DETAILED INFO', + 'extra_data': { + 'doc_string': 'DOC STRING', + }, + }, { + 'word' : '', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DETAILED INFO\nDOC STRING', + 'dup' : 1, + 'empty': 1, + } ) + + + def No_Insertion_Text_test( self ): + self._Check( { + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'detailed_info': 'DETAILED INFO', + 'extra_data': { + 'doc_string': 'DOC STRING', + }, + }, { + 'word' : '', + 'abbr' : 'MENU TEXT', + 'menu' : 'EXTRA MENU INFO', + 'kind' : 'k', + 'info' : 'DETAILED INFO\nDOC STRING', + 'dup' : 1, + 'empty': 1, } )