Add function to capture Vim command output

This commit is contained in:
micbou 2018-02-18 13:40:35 +01:00
parent 3f287967f3
commit b182556804
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
4 changed files with 19 additions and 15 deletions

View File

@ -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 )

View File

@ -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 ):

View File

@ -48,7 +48,7 @@ OMNIFUNC_REGEX_FORMAT = (
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' )
FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P<filepath>.+)\'\)$' )
SIGN_LIST_REGEX = re.compile(
"^silent sign place buffer=(?P<bufnr>\d+)$" )
"^silent! sign place buffer=(?P<bufnr>\d+)$" )
SIGN_PLACE_REGEX = re.compile(
'^sign place (?P<id>\d+) name=(?P<name>\w+) line=(?P<line>\d+) '
'buffer=(?P<bufnr>\d+)$' )

View File

@ -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 )