From fa32819d4f273f50f872ed2d525bc842e6798155 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Wed, 26 Aug 2015 23:41:40 +0100 Subject: [PATCH 1/9] Pass cwd to completer for filename completions --- python/ycm/youcompleteme.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 895296dd..102683bd 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -188,6 +188,8 @@ class YouCompleteMe( object ): self._omnicomp, wrapped_request_data ) return self._latest_completion_request + request_data[ 'working_dir' ] = os.getcwd() + self._AddExtraConfDataIfNeeded( request_data ) if force_semantic: request_data[ 'force_semantic' ] = True From dab5ab1d728029b84e122bf833d6e05d304b7810 Mon Sep 17 00:00:00 2001 From: micbou Date: Fri, 28 Aug 2015 00:44:51 +0200 Subject: [PATCH 2/9] Use SVG Travis badge --- README.md | 2 +- doc/youcompleteme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4619698..90b32ffd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ YouCompleteMe: a code-completion engine for Vim =============================================== -[![Build Status](https://travis-ci.org/Valloric/YouCompleteMe.png?branch=master)](https://travis-ci.org/Valloric/YouCompleteMe) +[![Build Status](https://travis-ci.org/Valloric/YouCompleteMe.svg?branch=master)](https://travis-ci.org/Valloric/YouCompleteMe) - [Intro](#intro) - [Installation](#installation) diff --git a/doc/youcompleteme.txt b/doc/youcompleteme.txt index f47138ae..0e55f635 100644 --- a/doc/youcompleteme.txt +++ b/doc/youcompleteme.txt @@ -2303,7 +2303,7 @@ contributors References ~ [1] https://travis-ci.org/Valloric/YouCompleteMe -[2] https://travis-ci.org/Valloric/YouCompleteMe.png?branch=master +[2] https://travis-ci.org/Valloric/YouCompleteMe.svg?branch=master [3] http://clang.llvm.org/ [4] https://github.com/davidhalter/jedi [5] https://github.com/nosami/OmniSharpServer From 9fc26130efe2117327ffb880f1ed23c94bbdf973 Mon Sep 17 00:00:00 2001 From: micbou Date: Wed, 2 Sep 2015 01:50:32 +0200 Subject: [PATCH 3/9] Update table of contents in README Remove Project Management entry. --- README.md | 1 - doc/youcompleteme.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index 90b32ffd..d6a69750 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ YouCompleteMe: a code-completion engine for Vim - [Options](#options) - [FAQ](#faq) - [Contact](#contact) -- [Project Management](#project-management) - [License](#license) Intro diff --git a/doc/youcompleteme.txt b/doc/youcompleteme.txt index 0e55f635..a4ad60e6 100644 --- a/doc/youcompleteme.txt +++ b/doc/youcompleteme.txt @@ -158,7 +158,6 @@ Introduction ~ - Options - FAQ - Contact -- Project Management - License =============================================================================== From a2808ee3ff7e8f4e90f6157f062c2aac6057c087 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 1 Sep 2015 19:51:04 -0700 Subject: [PATCH 4/9] Updating to latest ycmd --- third_party/ycmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/ycmd b/third_party/ycmd index 01d5f2df..b46b8f09 160000 --- a/third_party/ycmd +++ b/third_party/ycmd @@ -1 +1 @@ -Subproject commit 01d5f2df8da4a4d960ddc8ab0349d62813147f59 +Subproject commit b46b8f09e33ccb6c70dfd02bba879c0b77fff4d5 From 33316d8bf8108d71c40dc1b35a2b3842ccc42527 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 12 Sep 2015 16:30:21 +0200 Subject: [PATCH 5/9] Refactor _HandleFixitResponse function --- python/ycm/client/command_request.py | 52 +++++++--------------------- python/ycm/vimsupport.py | 40 ++++++++++++++++++--- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/python/ycm/client/command_request.py b/python/ycm/client/command_request.py index 6e766e99..6311d308 100644 --- a/python/ycm/client/command_request.py +++ b/python/ycm/client/command_request.py @@ -22,6 +22,7 @@ from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError from ycm import vimsupport from ycmd.utils import ToUtf8IfNeeded + def _EnsureBackwardsCompatibility( arguments ): if arguments and arguments[ 0 ] == 'GoToDefinitionElseDeclaration': arguments[ 0 ] = 'GoTo' @@ -49,7 +50,7 @@ class CommandRequest( BaseRequest ): } ) try: self._response = self.PostDataToHandler( request_data, - 'run_completer_command' ) + 'run_completer_command' ) except ServerError as e: vimsupport.PostMultiLineNotice( e ) @@ -57,6 +58,7 @@ class CommandRequest( BaseRequest ): def Response( self ): return self._response + def RunPostCommandActionsIfNeeded( self ): if not self.Done() or not self._response: return @@ -68,6 +70,7 @@ class CommandRequest( BaseRequest ): elif 'message' in self._response: self._HandleMessageResponse() + def _HandleGotoResponse( self ): if isinstance( self._response, list ): defs = [ _BuildQfListItem( x ) for x in self._response ] @@ -75,56 +78,27 @@ class CommandRequest( BaseRequest ): vim.eval( 'youcompleteme#OpenGoToList()' ) else: vimsupport.JumpToLocation( self._response[ 'filepath' ], - self._response[ 'line_num' ], - self._response[ 'column_num' ] ) + self._response[ 'line_num' ], + self._response[ 'column_num' ] ) + def _HandleFixitResponse( self ): if not len( self._response[ 'fixits' ] ): vimsupport.EchoText( "No fixits found for current line" ) else: - fixit = self._response[ 'fixits' ][ 0 ] + chunks = self._response[ 'fixits' ][ 0 ][ 'chunks' ] - # We need to track the difference in length, but ensuring we apply fixes - # in ascending order of insertion point. - fixit[ 'chunks' ].sort( key = lambda chunk: ( - str(chunk[ 'range' ][ 'start' ][ 'line_num' ]) - + ',' - + str(chunk[ 'range' ][ 'start' ][ 'column_num' ]) - )) + vimsupport.ReplaceChunksList( chunks ) - # Remember the line number we're processing. Negative line number means we - # haven't processed any lines yet (by nature of being not equal to any - # real line number). - last_line = -1 + vimsupport.EchoTextVimWidth( "FixIt applied " + + str( len( chunks ) ) + + " changes" ) - # Counter of changes applied, so the user has a mental picture of the - # undo history this change is creating. - num_fixed = 0 - line_delta = 0 - for chunk in fixit[ 'chunks' ]: - if chunk[ 'range' ][ 'start' ][ 'line_num' ] != last_line: - # If this chunk is on a different line than the previous chunk, - # then ignore previous deltas (as offsets won't have changed). - last_line = chunk[ 'range' ][ 'end' ][ 'line_num' ] - char_delta = 0 - - (new_line_delta, new_char_delta) = vimsupport.ReplaceChunk( - chunk[ 'range' ][ 'start' ], - chunk[ 'range' ][ 'end' ], - chunk[ 'replacement_text' ], - line_delta, char_delta ) - line_delta += new_line_delta - char_delta += new_char_delta - - num_fixed = num_fixed + 1 - - vimsupport.EchoTextVimWidth("FixIt applied " - + str(num_fixed) - + " changes") def _HandleMessageResponse( self ): vimsupport.EchoText( self._response[ 'message' ] ) + def SendCommandRequest( arguments, completer ): request = CommandRequest( arguments, completer ) # This is a blocking call. diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index 62200003..a0baa75f 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -459,6 +459,41 @@ def GetIntValue( variable ): return int( vim.eval( variable ) ) +def ReplaceChunksList( chunks, vim_buffer = None ): + if vim_buffer is None: + vim_buffer = vim.current.buffer + + # We need to track the difference in length, but ensuring we apply fixes + # in ascending order of insertion point. + chunks.sort( key = lambda chunk: ( + str( chunk[ 'range' ][ 'start' ][ 'line_num' ] ) + + ',' + + str( chunk[ 'range' ][ 'start' ][ 'column_num' ] ) + ) ) + + # Remember the line number we're processing. Negative line number means we + # haven't processed any lines yet (by nature of being not equal to any + # real line number). + last_line = -1 + + line_delta = 0 + for chunk in chunks: + if chunk[ 'range' ][ 'start' ][ 'line_num' ] != last_line: + # If this chunk is on a different line than the previous chunk, + # then ignore previous deltas (as offsets won't have changed). + last_line = chunk[ 'range' ][ 'end' ][ 'line_num' ] + char_delta = 0 + + ( new_line_delta, new_char_delta ) = ReplaceChunk( + chunk[ 'range' ][ 'start' ], + chunk[ 'range' ][ 'end' ], + chunk[ 'replacement_text' ], + line_delta, char_delta, + vim_buffer ) + line_delta += new_line_delta + char_delta += new_char_delta + + # Replace the chunk of text specified by a contiguous range with the supplied # text. # * start and end are objects with line_num and column_num properties @@ -469,10 +504,7 @@ def GetIntValue( variable ): # returns the delta (in lines and characters) that any position after the end # needs to be adjusted by. def ReplaceChunk( start, end, replacement_text, line_delta, char_delta, - vim_buffer = None ): - if vim_buffer is None: - vim_buffer = vim.current.buffer - + vim_buffer ): # ycmd's results are all 1-based, but vim's/python's are all 0-based # (so we do -1 on all of the values) start_line = start[ 'line_num' ] - 1 + line_delta From 2c72a3c5984cd1394e2b01294079e291af062923 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 12 Sep 2015 16:34:47 +0200 Subject: [PATCH 6/9] Clean code in vimsupport tests --- python/ycm/tests/vimsupport_test.py | 96 ++++++++++++++++------------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index c0c4d5eb..d2b2ddc8 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -20,6 +20,7 @@ from ycm import vimsupport from nose.tools import eq_ + def ReplaceChunk_SingleLine_Repl_1_test(): # Replace with longer range # 12345678901234567 @@ -38,7 +39,7 @@ def ReplaceChunk_SingleLine_Repl_1_test(): # and replace again, using delta start, end = _BuildLocations( 1, 10, 1, 11 ) - ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( + ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( start, end, ' piece of ', @@ -58,7 +59,7 @@ def ReplaceChunk_SingleLine_Repl_1_test(): # and once more, for luck start, end = _BuildLocations( 1, 11, 1, 17 ) - ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( + ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( start, end, 'pie', @@ -75,6 +76,7 @@ def ReplaceChunk_SingleLine_Repl_1_test(): eq_( line_offset, 0 ) eq_( char_offset, 10 ) + def ReplaceChunk_SingleLine_Repl_2_test(): # Replace with shorter range # 12345678901234567 @@ -91,6 +93,7 @@ def ReplaceChunk_SingleLine_Repl_2_test(): eq_( line_offset, 0 ) eq_( char_offset, -2 ) + def ReplaceChunk_SingleLine_Repl_3_test(): # Replace with equal range # 12345678901234567 @@ -107,6 +110,7 @@ def ReplaceChunk_SingleLine_Repl_3_test(): eq_( line_offset, 0 ) eq_( char_offset, 0 ) + def ReplaceChunk_SingleLine_Add_1_test(): # Insert at start result_buffer = [ "is a string" ] @@ -122,6 +126,7 @@ def ReplaceChunk_SingleLine_Add_1_test(): eq_( line_offset, 0 ) eq_( char_offset, 5 ) + def ReplaceChunk_SingleLine_Add_2_test(): # Insert at end result_buffer = [ "This is a " ] @@ -137,6 +142,7 @@ def ReplaceChunk_SingleLine_Add_2_test(): eq_( line_offset, 0 ) eq_( char_offset, 6 ) + def ReplaceChunk_SingleLine_Add_3_test(): # Insert in the middle result_buffer = [ "This is a string" ] @@ -152,6 +158,7 @@ def ReplaceChunk_SingleLine_Add_3_test(): eq_( line_offset, 0 ) eq_( char_offset, 4 ) + def ReplaceChunk_SingleLine_Del_1_test(): # Delete from start result_buffer = [ "This is a string" ] @@ -167,6 +174,7 @@ def ReplaceChunk_SingleLine_Del_1_test(): eq_( line_offset, 0 ) eq_( char_offset, -5 ) + def ReplaceChunk_SingleLine_Del_2_test(): # Delete from end result_buffer = [ "This is a string" ] @@ -182,6 +190,7 @@ def ReplaceChunk_SingleLine_Del_2_test(): eq_( line_offset, 0 ) eq_( char_offset, -8 ) + def ReplaceChunk_SingleLine_Del_3_test(): # Delete from middle result_buffer = [ "This is not a string" ] @@ -197,6 +206,7 @@ def ReplaceChunk_SingleLine_Del_3_test(): eq_( line_offset, 0 ) eq_( char_offset, -4 ) + def ReplaceChunk_RemoveSingleLine_test(): result_buffer = [ "aAa", "aBa", "aCa" ] start, end = _BuildLocations( 2, 1, 3, 1 ) @@ -209,13 +219,13 @@ def ReplaceChunk_RemoveSingleLine_test(): def ReplaceChunk_SingleToMultipleLines_test(): - result_buffer = [ "aAa", - "aBa", + result_buffer = [ "aAa", + "aBa", "aCa" ] start, end = _BuildLocations( 2, 2, 2, 2 ) ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF', 0, 0, result_buffer ) - expected_buffer = [ "aAa", + expected_buffer = [ "aAa", "aEb", "bFBa", "aCa" ] @@ -245,12 +255,12 @@ def ReplaceChunk_SingleToMultipleLines2_test(): result_buffer = [ "aAa", "aBa", "aCa" ] start, end = _BuildLocations( 2, 2, 2, 2 ) ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + end, 'Eb\nbFb\nG', - 0, - 0, + 0, + 0, result_buffer ) - expected_buffer = [ "aAa", "aEb" ,"bFb", "GBa", "aCa" ] + expected_buffer = [ "aAa", "aEb", "bFb", "GBa", "aCa" ] eq_( expected_buffer, result_buffer ) eq_( line_offset, 2 ) eq_( char_offset, 0 ) @@ -259,45 +269,47 @@ def ReplaceChunk_SingleToMultipleLines2_test(): def ReplaceChunk_SingleToMultipleLines3_test(): result_buffer = [ "aAa", "aBa", "aCa" ] start, end = _BuildLocations( 2, 2, 2, 2 ) - ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, + end, 'Eb\nbFb\nbGb', - 0, - 0, + 0, + 0, result_buffer ) - expected_buffer = [ "aAa", "aEb" ,"bFb", "bGbBa", "aCa" ] + expected_buffer = [ "aAa", "aEb", "bFb", "bGbBa", "aCa" ] eq_( expected_buffer, result_buffer ) eq_( line_offset, 2 ) eq_( char_offset, 2 ) + def ReplaceChunk_SingleToMultipleLinesReplace_test(): result_buffer = [ "aAa", "aBa", "aCa" ] start, end = _BuildLocations( 1, 2, 1, 4 ) - ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, + end, 'Eb\nbFb\nbGb', - 0, - 0, + 0, + 0, result_buffer ) expected_buffer = [ "aEb", "bFb", "bGb", "aBa", "aCa" ] eq_( expected_buffer, result_buffer ) eq_( line_offset, 2 ) eq_( char_offset, 0 ) + def ReplaceChunk_SingleToMultipleLinesReplace_2_test(): - result_buffer = [ "aAa", - "aBa", + result_buffer = [ "aAa", + "aBa", "aCa" ] start, end = _BuildLocations( 1, 2, 1, 4 ) - ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, + end, 'Eb\nbFb\nbGb', - 0, - 0, + 0, + 0, result_buffer ) - expected_buffer = [ "aEb", - "bFb", - "bGb", + expected_buffer = [ "aEb", + "bFb", + "bGb", "aBa", "aCa" ] eq_( expected_buffer, result_buffer ) @@ -306,7 +318,7 @@ def ReplaceChunk_SingleToMultipleLinesReplace_2_test(): # now do a subsequent change (insert at end of line "1") start, end = _BuildLocations( 1, 4, 1, 4 ) - ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( + ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( start, end, 'cccc', @@ -340,7 +352,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test(): # make another modification applying offsets start, end = _BuildLocations( 3, 3, 3, 4 ) - ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( + ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( start, end, 'cccc', @@ -357,7 +369,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test(): # and another, for luck start, end = _BuildLocations( 3, 4, 3, 5 ) - ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( + ( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk( start, end, 'dd\ndd', @@ -367,7 +379,7 @@ def ReplaceChunk_MultipleLinesToSingleLine_test(): line_offset += new_line_offset char_offset += new_char_offset - + eq_( [ "aAa", "aECccccdd", "ddaa" ], result_buffer ) eq_( line_offset, 0 ) eq_( char_offset, -2 ) @@ -387,11 +399,11 @@ def ReplaceChunk_MultipleLinesToSameMultipleLines_test(): def ReplaceChunk_MultipleLinesToMoreMultipleLines_test(): result_buffer = [ "aAa", "aBa", "aCa", "aDe" ] start, end = _BuildLocations( 2, 2, 3, 2 ) - ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, + end, 'Eb\nbFb\nbG', - 0, - 0, + 0, + 0, result_buffer ) expected_buffer = [ "aAa", "aEb", "bFb", "bGCa", "aDe" ] eq_( expected_buffer, result_buffer ) @@ -501,11 +513,11 @@ def ReplaceChunk_MultipleLinesToSingleLineOffsetWorks_test(): def ReplaceChunk_MultipleLineOffsetWorks_test(): result_buffer = [ "aAa", "aBa", "aCa" ] start, end = _BuildLocations( 3, 1, 4, 3 ) - ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, - end, + ( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, + end, 'bDb\nbEb\nbFb', - -1, - 1, + -1, + 1, result_buffer ) expected_buffer = [ "aAa", "abDb", "bEb", "bFba" ] eq_( expected_buffer, result_buffer ) @@ -514,10 +526,10 @@ def ReplaceChunk_MultipleLineOffsetWorks_test(): def _BuildLocations( start_line, start_column, end_line, end_column ): - return { - 'line_num' : start_line, + return { + 'line_num' : start_line, 'column_num': start_column, }, { - 'line_num' : end_line, + 'line_num' : end_line, 'column_num': end_column, } From 17f5f20cd64d2adcc0e38dff61004b40bdfddb62 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 12 Sep 2015 17:06:17 +0200 Subject: [PATCH 7/9] Add chunks sorting tests --- python/ycm/tests/vimsupport_test.py | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index d2b2ddc8..ff4e8e1c 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -533,3 +533,46 @@ def _BuildLocations( start_line, start_column, end_line, end_column ): 'line_num' : end_line, 'column_num': end_column, } + + +def ReplaceChunksList_SortedChunks_test(): + chunks = [ + _BuildChunk( 1, 4, 1, 4, '('), + _BuildChunk( 1, 11, 1, 11, ')' ) + ] + + result_buffer = [ "CT<10 >> 2> ct" ] + vimsupport.ReplaceChunksList( chunks, result_buffer ) + + expected_buffer = [ "CT<(10 >> 2)> ct" ] + eq_( expected_buffer, result_buffer ) + + +def ReplaceChunksList_UnsortedChunks_test(): + chunks = [ + _BuildChunk( 1, 11, 1, 11, ')'), + _BuildChunk( 1, 4, 1, 4, '(' ) + ] + + result_buffer = [ "CT<10 >> 2> ct" ] + vimsupport.ReplaceChunksList( chunks, result_buffer ) + + expected_buffer = [ "CT<(10 >> 2)> ct" ] + eq_( expected_buffer, result_buffer ) + + +def _BuildChunk( start_line, start_column, end_line, end_column, + replacement_text ): + return { + 'range': { + 'start': { + 'line_num': start_line, + 'column_num': start_column, + }, + 'end': { + 'line_num': end_line, + 'column_num': end_column, + }, + }, + 'replacement_text': replacement_text + } From 8c17995bee385389bdc0c4c52577d60e32b749e3 Mon Sep 17 00:00:00 2001 From: micbou Date: Sat, 12 Sep 2015 17:08:58 +0200 Subject: [PATCH 8/9] Correct FixIt chunks sorting --- python/ycm/vimsupport.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index a0baa75f..d53eae21 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -466,9 +466,8 @@ def ReplaceChunksList( chunks, vim_buffer = None ): # We need to track the difference in length, but ensuring we apply fixes # in ascending order of insertion point. chunks.sort( key = lambda chunk: ( - str( chunk[ 'range' ][ 'start' ][ 'line_num' ] ) - + ',' - + str( chunk[ 'range' ][ 'start' ][ 'column_num' ] ) + chunk[ 'range' ][ 'start' ][ 'line_num' ], + chunk[ 'range' ][ 'start' ][ 'column_num' ] ) ) # Remember the line number we're processing. Negative line number means we From 5cfd6376c6381b943b2fbebc88f9316a2998ca40 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Sun, 16 Aug 2015 15:17:12 +0100 Subject: [PATCH 9/9] Show docs from clang completer in preview window We add the detailed_info (which is the function definiton) followed by the brief comment --- python/ycm/client/completion_request.py | 12 ++ python/ycm/client/tests/__init__.py | 0 .../client/tests/completion_request_test.py | 134 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 python/ycm/client/tests/__init__.py create mode 100644 python/ycm/client/tests/completion_request_test.py diff --git a/python/ycm/client/completion_request.py b/python/ycm/client/completion_request.py index c630fb22..12ed0269 100644 --- a/python/ycm/client/completion_request.py +++ b/python/ycm/client/completion_request.py @@ -21,6 +21,7 @@ from ycmd.utils import ToUtf8IfNeeded from ycm.client.base_request import ( BaseRequest, JsonFromFuture, HandleServerException, MakeServerException ) +import os TIMEOUT_SECONDS = 0.5 @@ -64,6 +65,13 @@ def _ConvertCompletionDataToVimData( completion_data ): 'dup' : 1, } + if ( 'extra_data' in completion_data and + 'doc_string' in completion_data[ 'extra_data' ] ): + doc_string = ToUtf8IfNeeded( + completion_data[ 'extra_data' ][ 'doc_string' ] ) + else: + doc_string = "" + if 'menu_text' in completion_data: vim_data[ 'abbr' ] = ToUtf8IfNeeded( completion_data[ 'menu_text' ] ) if 'extra_menu_info' in completion_data: @@ -73,6 +81,10 @@ def _ConvertCompletionDataToVimData( completion_data ): completion_data[ 'kind' ] )[ 0 ].lower() if 'detailed_info' in completion_data: vim_data[ 'info' ] = ToUtf8IfNeeded( completion_data[ 'detailed_info' ] ) + if doc_string: + vim_data[ 'info' ] += os.linesep + doc_string + elif doc_string: + vim_data[ 'info' ] = doc_string return vim_data diff --git a/python/ycm/client/tests/__init__.py b/python/ycm/client/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/ycm/client/tests/completion_request_test.py b/python/ycm/client/tests/completion_request_test.py new file mode 100644 index 00000000..89e536f6 --- /dev/null +++ b/python/ycm/client/tests/completion_request_test.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# +# Copyright (C) 2015 YouCompleteMe Contributors +# +# This file is part of YouCompleteMe. +# +# YouCompleteMe is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# YouCompleteMe is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with YouCompleteMe. If not, see . + +from nose.tools import eq_ +from ycm.test_utils import MockVimModule +vim_mock = MockVimModule() +import os + +from .. import completion_request + +class ConvertCompletionResponseToVimDatas_test: + """ This class tests the + completion_request._ConvertCompletionResponseToVimDatas method """ + + def _Check( self, completion_data, expected_vim_data ): + vim_data = completion_request._ConvertCompletionDataToVimData( + completion_data ) + + try: + eq_( expected_vim_data, vim_data ) + except: + print "Expected:\n'{0}'\nwhen parsing:\n'{1}'\nBut found:\n'{2}'".format( + expected_vim_data, + completion_data, + vim_data ) + raise + + + def All_Fields_test( self ): + self._Check( { + 'insertion_text': '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': 'INSERTION TEXT', + 'abbr': 'MENU TEXT', + 'menu': 'EXTRA MENU INFO', + 'kind': 'k', + 'info': 'DETAILED INFO' + os.linesep + 'DOC STRING', + 'dup' : 1, + } ) + + + def Just_Detailed_Info_test( self ): + self._Check( { + 'insertion_text': 'INSERTION TEXT', + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'detailed_info': 'DETAILED INFO', + }, { + 'word': 'INSERTION TEXT', + 'abbr': 'MENU TEXT', + 'menu': 'EXTRA MENU INFO', + 'kind': 'k', + 'info': 'DETAILED INFO', + 'dup' : 1, + } ) + + + def Just_Doc_String_test( self ): + self._Check( { + 'insertion_text': 'INSERTION TEXT', + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'extra_data': { + 'doc_string': 'DOC STRING', + }, + }, { + 'word': 'INSERTION TEXT', + 'abbr': 'MENU TEXT', + 'menu': 'EXTRA MENU INFO', + 'kind': 'k', + 'info': 'DOC STRING', + 'dup' : 1, + } ) + + + def Extra_Info_No_Doc_String_test( self ): + self._Check( { + 'insertion_text': 'INSERTION TEXT', + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'extra_data': { + }, + }, { + 'word': 'INSERTION TEXT', + 'abbr': 'MENU TEXT', + 'menu': 'EXTRA MENU INFO', + 'kind': 'k', + 'dup' : 1, + } ) + + + def Extra_Info_No_Doc_String_With_Detailed_Info_test( self ): + self._Check( { + 'insertion_text': 'INSERTION TEXT', + 'menu_text': 'MENU TEXT', + 'extra_menu_info': 'EXTRA MENU INFO', + 'kind': 'K', + 'detailed_info': 'DETAILED INFO', + 'extra_data': { + }, + }, { + 'word': 'INSERTION TEXT', + 'abbr': 'MENU TEXT', + 'menu': 'EXTRA MENU INFO', + 'kind': 'k', + 'info': 'DETAILED INFO', + 'dup' : 1, + } )