diff --git a/python/ycm/syntax_parse.py b/python/ycm/syntax_parse.py index 964361a2..2014aa72 100644 --- a/python/ycm/syntax_parse.py +++ b/python/ycm/syntax_parse.py @@ -24,7 +24,6 @@ from builtins import * # noqa from future.utils import itervalues import re -import vim from ycm import vimsupport SYNTAX_GROUP_REGEX = re.compile( @@ -70,10 +69,7 @@ class SyntaxGroup( object ): def SyntaxKeywordsForCurrentBuffer(): - vim.command( 'redir => b:ycm_syntax' ) - vim.command( 'silent! syntax list' ) - vim.command( 'redir END' ) - syntax_output = vimsupport.VimExpressionToPythonType( 'b:ycm_syntax' ) + syntax_output = vimsupport.CaptureVimCommand( 'syntax list' ) return _KeywordsFromSyntaxListOutput( syntax_output ) diff --git a/python/ycm/tests/event_notification_test.py b/python/ycm/tests/event_notification_test.py index 3041d5df..1a2d882c 100644 --- a/python/ycm/tests/event_notification_test.py +++ b/python/ycm/tests/event_notification_test.py @@ -517,8 +517,9 @@ def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test( ) -@patch( 'ycm.syntax_parse.SyntaxKeywordsForCurrentBuffer', - return_value = [ 'foo', 'bar' ] ) +@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """ +fooGroup xxx foo bar + links to Statement""" ) @YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } ) def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test( ycm, *args ): @@ -551,8 +552,9 @@ def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test( ) -@patch( 'ycm.syntax_parse.SyntaxKeywordsForCurrentBuffer', - return_value = [ 'foo', 'bar' ] ) +@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """ +fooGroup xxx foo bar + links to Statement""" ) @YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } ) def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test( ycm, *args ): diff --git a/python/ycm/tests/test_utils.py b/python/ycm/tests/test_utils.py index 6bba7907..16b78d93 100644 --- a/python/ycm/tests/test_utils.py +++ b/python/ycm/tests/test_utils.py @@ -48,7 +48,7 @@ OMNIFUNC_REGEX_FORMAT = ( '^{omnifunc_name}\((?P[01]),[\'"](?P.*)[\'"]\)$' ) FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P.+)\'\)$' ) SIGN_LIST_REGEX = re.compile( - "^silent sign place buffer=(?P\d+)$" ) + "^silent! sign place buffer=(?P\d+)$" ) SIGN_PLACE_REGEX = re.compile( '^sign place (?P\d+) name=(?P\w+) line=(?P\d+) ' 'buffer=(?P\d+)$' ) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index f27b41ec..71c7aff7 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -171,6 +171,15 @@ def GetBufferChangedTick( bufnr ): return GetIntValue( 'getbufvar({0}, "changedtick")'.format( bufnr ) ) +def CaptureVimCommand( command ): + vim.command( 'redir => b:ycm_command' ) + vim.command( 'silent! {}'.format( command ) ) + vim.command( 'redir END' ) + output = vim.eval( 'b:ycm_command' ) + vim.command( 'unlet b:ycm_command' ) + return output + + class DiagnosticSign( namedtuple( 'DiagnosticSign', [ 'id', 'line', 'name', 'buffer_number' ] ) ): # We want two signs that have different ids but the same location to compare @@ -182,11 +191,8 @@ class DiagnosticSign( namedtuple( 'DiagnosticSign', def GetSignsInBuffer( buffer_number ): - vim.command( 'redir => b:ycm_sign' ) - vim.command( 'silent sign place buffer={}'.format( buffer_number ) ) - vim.command( 'redir END' ) - sign_output = vim.eval( 'b:ycm_sign' ) - vim.command( 'unlet b:ycm_sign' ) + sign_output = CaptureVimCommand( + 'sign place buffer={}'.format( buffer_number ) ) signs = [] for line in sign_output.split( '\n' ): match = SIGN_PLACE_REGEX.search( line )