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
|
from future.utils import itervalues
|
||||||
import re
|
import re
|
||||||
import vim
|
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
|
|
||||||
SYNTAX_GROUP_REGEX = re.compile(
|
SYNTAX_GROUP_REGEX = re.compile(
|
||||||
@ -70,10 +69,7 @@ class SyntaxGroup( object ):
|
|||||||
|
|
||||||
|
|
||||||
def SyntaxKeywordsForCurrentBuffer():
|
def SyntaxKeywordsForCurrentBuffer():
|
||||||
vim.command( 'redir => b:ycm_syntax' )
|
syntax_output = vimsupport.CaptureVimCommand( 'syntax list' )
|
||||||
vim.command( 'silent! syntax list' )
|
|
||||||
vim.command( 'redir END' )
|
|
||||||
syntax_output = vimsupport.VimExpressionToPythonType( 'b:ycm_syntax' )
|
|
||||||
return _KeywordsFromSyntaxListOutput( syntax_output )
|
return _KeywordsFromSyntaxListOutput( syntax_output )
|
||||||
|
|
||||||
|
|
||||||
|
@ -517,8 +517,9 @@ def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.syntax_parse.SyntaxKeywordsForCurrentBuffer',
|
@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
|
||||||
return_value = [ 'foo', 'bar' ] )
|
fooGroup xxx foo bar
|
||||||
|
links to Statement""" )
|
||||||
@YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } )
|
@YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } )
|
||||||
def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
|
def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
|
||||||
ycm, *args ):
|
ycm, *args ):
|
||||||
@ -551,8 +552,9 @@ def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch( 'ycm.syntax_parse.SyntaxKeywordsForCurrentBuffer',
|
@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
|
||||||
return_value = [ 'foo', 'bar' ] )
|
fooGroup xxx foo bar
|
||||||
|
links to Statement""" )
|
||||||
@YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } )
|
@YouCompleteMeInstance( { 'seed_identifiers_with_syntax': 1 } )
|
||||||
def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test(
|
def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test(
|
||||||
ycm, *args ):
|
ycm, *args ):
|
||||||
|
@ -48,7 +48,7 @@ OMNIFUNC_REGEX_FORMAT = (
|
|||||||
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' )
|
'^{omnifunc_name}\((?P<findstart>[01]),[\'"](?P<base>.*)[\'"]\)$' )
|
||||||
FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P<filepath>.+)\'\)$' )
|
FNAMEESCAPE_REGEX = re.compile( '^fnameescape\(\'(?P<filepath>.+)\'\)$' )
|
||||||
SIGN_LIST_REGEX = re.compile(
|
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_REGEX = re.compile(
|
||||||
'^sign place (?P<id>\d+) name=(?P<name>\w+) line=(?P<line>\d+) '
|
'^sign place (?P<id>\d+) name=(?P<name>\w+) line=(?P<line>\d+) '
|
||||||
'buffer=(?P<bufnr>\d+)$' )
|
'buffer=(?P<bufnr>\d+)$' )
|
||||||
|
@ -171,6 +171,15 @@ def GetBufferChangedTick( bufnr ):
|
|||||||
return GetIntValue( 'getbufvar({0}, "changedtick")'.format( 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',
|
class DiagnosticSign( namedtuple( 'DiagnosticSign',
|
||||||
[ 'id', 'line', 'name', 'buffer_number' ] ) ):
|
[ 'id', 'line', 'name', 'buffer_number' ] ) ):
|
||||||
# We want two signs that have different ids but the same location to compare
|
# 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 ):
|
def GetSignsInBuffer( buffer_number ):
|
||||||
vim.command( 'redir => b:ycm_sign' )
|
sign_output = CaptureVimCommand(
|
||||||
vim.command( 'silent sign place buffer={}'.format( buffer_number ) )
|
'sign place buffer={}'.format( buffer_number ) )
|
||||||
vim.command( 'redir END' )
|
|
||||||
sign_output = vim.eval( 'b:ycm_sign' )
|
|
||||||
vim.command( 'unlet b:ycm_sign' )
|
|
||||||
signs = []
|
signs = []
|
||||||
for line in sign_output.split( '\n' ):
|
for line in sign_output.split( '\n' ):
|
||||||
match = SIGN_PLACE_REGEX.search( line )
|
match = SIGN_PLACE_REGEX.search( line )
|
||||||
|
Loading…
Reference in New Issue
Block a user