From 3db1413cd9d3159055ee4ae64df3db5674272ff3 Mon Sep 17 00:00:00 2001 From: Andrey Pikas Date: Sat, 11 Mar 2017 12:59:21 +0300 Subject: [PATCH 1/4] Send extra_conf_vim_data in requests from :YcmCompleter and :YcmDebugInfo commands. It's needed for passing compile_commands.json directory to every call of FlagsForFile in client_data argument. --- python/ycm/client/command_request.py | 9 ++++++--- python/ycm/client/debug_info_request.py | 9 ++++++--- python/ycm/youcompleteme.py | 8 ++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/python/ycm/client/command_request.py b/python/ycm/client/command_request.py index 5f728c92..51916c9d 100644 --- a/python/ycm/client/command_request.py +++ b/python/ycm/client/command_request.py @@ -36,16 +36,19 @@ def _EnsureBackwardsCompatibility( arguments ): class CommandRequest( BaseRequest ): - def __init__( self, arguments, completer_target = None ): + def __init__( self, arguments, completer_target = None, extra_data = None ): super( CommandRequest, self ).__init__() self._arguments = _EnsureBackwardsCompatibility( arguments ) self._completer_target = ( completer_target if completer_target else 'filetype_default' ) + self._extra_data = extra_data self._response = None def Start( self ): request_data = BuildRequestData() + if self._extra_data: + request_data.update( self._extra_data ) request_data.update( { 'completer_target': self._completer_target, 'command_arguments': self._arguments @@ -129,8 +132,8 @@ class CommandRequest( BaseRequest ): vimsupport.WriteToPreviewWindow( self._response[ 'detailed_info' ] ) -def SendCommandRequest( arguments, completer ): - request = CommandRequest( arguments, completer ) +def SendCommandRequest( arguments, completer, extra_data = None ): + request = CommandRequest( arguments, completer, extra_data ) # This is a blocking call. request.Start() request.RunPostCommandActionsIfNeeded() diff --git a/python/ycm/client/debug_info_request.py b/python/ycm/client/debug_info_request.py index d7a5822b..8e856a75 100644 --- a/python/ycm/client/debug_info_request.py +++ b/python/ycm/client/debug_info_request.py @@ -28,13 +28,16 @@ from ycm.client.base_request import ( BaseRequest, BuildRequestData, class DebugInfoRequest( BaseRequest ): - def __init__( self ): + def __init__( self, extra_data = None ): super( DebugInfoRequest, self ).__init__() + self._extra_data = extra_data self._response = None def Start( self ): request_data = BuildRequestData() + if self._extra_data: + request_data.update( self._extra_data ) with HandleServerException( display = False ): self._response = self.PostDataToHandler( request_data, 'debug_info' ) @@ -111,8 +114,8 @@ def _FormatCompleterDebugInfo( completer ): return message -def SendDebugInfoRequest(): - request = DebugInfoRequest() +def SendDebugInfoRequest( extra_data = None ): + request = DebugInfoRequest( extra_data ) # This is a blocking call. request.Start() return request.Response() diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 3fa33846..a5454789 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -302,7 +302,9 @@ class YouCompleteMe( object ): def SendCommandRequest( self, arguments, completer ): - return SendCommandRequest( arguments, completer ) + extra_data = {} + self._AddExtraConfDataIfNeeded( extra_data ) + return SendCommandRequest( arguments, completer, extra_data ) def GetDefinedSubcommands( self ): @@ -636,7 +638,9 @@ class YouCompleteMe( object ): debug_info = '' if self._client_logfile: debug_info += 'Client logfile: {0}\n'.format( self._client_logfile ) - debug_info += FormatDebugInfoResponse( SendDebugInfoRequest() ) + extra_data = {} + self._AddExtraConfDataIfNeeded( extra_data ) + debug_info += FormatDebugInfoResponse( SendDebugInfoRequest( extra_data ) ) debug_info += ( 'Server running at: {0}\n' 'Server process ID: {1}\n'.format( BaseRequest.server_location, From 592b85516bbd700f74cdc1b4e2da2436799cc9df Mon Sep 17 00:00:00 2001 From: Andrey Pikas Date: Sun, 12 Mar 2017 19:03:07 +0300 Subject: [PATCH 2/4] Tests for checking that extra_conf_data sended to server from :DebugInfo and :YcmCompleter commands. --- python/ycm/tests/command_test.py | 10 ++++++++-- python/ycm/tests/testdata/.ycm_extra_conf.py | 7 +++++++ python/ycm/tests/youcompleteme_test.py | 20 ++++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 python/ycm/tests/testdata/.ycm_extra_conf.py diff --git a/python/ycm/tests/command_test.py b/python/ycm/tests/command_test.py index e894647b..d18506c0 100644 --- a/python/ycm/tests/command_test.py +++ b/python/ycm/tests/command_test.py @@ -32,13 +32,19 @@ from mock import patch from ycm.tests import YouCompleteMeInstance -@YouCompleteMeInstance() +@YouCompleteMeInstance( { 'extra_conf_vim_data': [ 'tempname()' ] } ) def SendCommandRequest_test( ycm ): current_buffer = VimBuffer( 'buffer' ) with MockVimBuffers( [ current_buffer ], current_buffer ): + with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request: + ycm.SendCommandRequest( [ 'GoTo' ], 'python' ) + send_request.assert_called_once_with( + [ 'GoTo' ], 'python', { 'extra_conf_data': { + 'tempname()': '_TEMP_FILE_' } } + ) with patch( 'ycm.client.base_request.JsonFromFuture', return_value = 'Some response' ): assert_that( - ycm.SendCommandRequest( 'GoTo', 'python' ), + ycm.SendCommandRequest( [ 'GoTo' ], 'python' ), equal_to( 'Some response' ) ) diff --git a/python/ycm/tests/testdata/.ycm_extra_conf.py b/python/ycm/tests/testdata/.ycm_extra_conf.py new file mode 100644 index 00000000..2f0aef50 --- /dev/null +++ b/python/ycm/tests/testdata/.ycm_extra_conf.py @@ -0,0 +1,7 @@ +def FlagsForFile( filename, **kwargs ): + temp_dir = kwargs[ 'client_data' ][ 'tempname()' ] + + return { + 'flags': [ temp_dir ], + 'do_cache': False + } diff --git a/python/ycm/tests/youcompleteme_test.py b/python/ycm/tests/youcompleteme_test.py index 27990bc5..e057f46f 100644 --- a/python/ycm/tests/youcompleteme_test.py +++ b/python/ycm/tests/youcompleteme_test.py @@ -140,9 +140,16 @@ def YouCompleteMe_NotifyUserIfServerCrashed_UnexpectedExitCode_test(): } ) -@YouCompleteMeInstance() +@YouCompleteMeInstance( { 'extra_conf_vim_data': [ 'tempname()' ] } ) def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ): - current_buffer = VimBuffer( 'current_buffer' ) + dir_of_script = os.path.dirname( os.path.abspath( __file__ ) ) + buf_name = os.path.join( dir_of_script, 'testdata', 'test.cpp' ) + extra_conf = os.path.join( dir_of_script, 'testdata', '.ycm_extra_conf.py' ) + + from ycm.client.base_request import _LoadExtraConfFile + _LoadExtraConfFile( extra_conf ) + + current_buffer = VimBuffer( buf_name, filetype='cpp' ) with MockVimBuffers( [ current_buffer ], current_buffer ): assert_that( ycm.DebugInfo(), @@ -150,9 +157,14 @@ def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ): 'Client logfile: .+\n' 'Server Python interpreter: .+\n' 'Server Python version: .+\n' - 'Server has Clang support compiled in: (True|False)\n' + 'Server has Clang support compiled in: ' + '(?PTrue)?(?(CLANG)|False)\n' 'Clang version: .+\n' - 'No extra configuration file found\n' + 'Extra configuration file found and loaded\n' + 'Extra configuration path: .*/testdata/\\.ycm_extra_conf\\.py\n' + '(?(CLANG)C-family completer debug information:\n' + ' Compilation database path: None\n' + ' Flags: \\[\'_TEMP_FILE_\'.*\\]\n)' 'Server running at: .+\n' 'Server process ID: \d+\n' 'Server logfiles:\n' From 822010fe4c87703eb468662e9fe1cf35e8aa19c9 Mon Sep 17 00:00:00 2001 From: Andrey Pikas Date: Sun, 12 Mar 2017 20:16:51 +0300 Subject: [PATCH 3/4] Move import to the top of file. --- python/ycm/tests/youcompleteme_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/ycm/tests/youcompleteme_test.py b/python/ycm/tests/youcompleteme_test.py index e057f46f..f869199f 100644 --- a/python/ycm/tests/youcompleteme_test.py +++ b/python/ycm/tests/youcompleteme_test.py @@ -34,6 +34,7 @@ from hamcrest import ( assert_that, contains, empty, is_in, is_not, has_length, from mock import call, MagicMock, patch from ycm.tests import StopServer, YouCompleteMeInstance +from ycm.client.base_request import _LoadExtraConfFile from ycmd.responses import ServerError @@ -145,8 +146,6 @@ def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ): dir_of_script = os.path.dirname( os.path.abspath( __file__ ) ) buf_name = os.path.join( dir_of_script, 'testdata', 'test.cpp' ) extra_conf = os.path.join( dir_of_script, 'testdata', '.ycm_extra_conf.py' ) - - from ycm.client.base_request import _LoadExtraConfFile _LoadExtraConfFile( extra_conf ) current_buffer = VimBuffer( buf_name, filetype='cpp' ) From 2495dffa59eb7e94fa1412825e21124ef1484daa Mon Sep 17 00:00:00 2001 From: Andrey Pikas Date: Sun, 12 Mar 2017 23:06:05 +0300 Subject: [PATCH 4/4] Fix tests under Windows. --- python/ycm/tests/youcompleteme_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ycm/tests/youcompleteme_test.py b/python/ycm/tests/youcompleteme_test.py index f869199f..15cce008 100644 --- a/python/ycm/tests/youcompleteme_test.py +++ b/python/ycm/tests/youcompleteme_test.py @@ -160,7 +160,7 @@ def YouCompleteMe_DebugInfo_ServerRunning_test( ycm ): '(?PTrue)?(?(CLANG)|False)\n' 'Clang version: .+\n' 'Extra configuration file found and loaded\n' - 'Extra configuration path: .*/testdata/\\.ycm_extra_conf\\.py\n' + 'Extra configuration path: .*testdata[/\\\\]\\.ycm_extra_conf\\.py\n' '(?(CLANG)C-family completer debug information:\n' ' Compilation database path: None\n' ' Flags: \\[\'_TEMP_FILE_\'.*\\]\n)'