Auto merge of #2921 - micbou:capture-command-output, r=bstaletic
[READY] Add function to capture Vim command output Since there are now two places where we need to capture the output of a Vim command (for diagnostic signs and for syntax keywords), we should add a function for that. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2921) <!-- Reviewable:end -->
This commit is contained in:
commit
92405cb011
@ -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 )
|
||||
|
||||
|
||||
|
@ -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 ):
|
||||
|
@ -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+)$' )
|
||||
|
@ -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 )
|
||||
|
Loading…
Reference in New Issue
Block a user