Update sign place regex pattern for newer versions

This commit is contained in:
micbou 2018-12-24 13:13:41 +01:00
parent a53ccefca9
commit b0f18804f3
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
3 changed files with 52 additions and 20 deletions

View File

@ -84,14 +84,17 @@ VIM_OPTIONS = {
'&expandtab': 1 '&expandtab': 1
} }
# This variable must be patched with a Version object for tests depending on the Version = namedtuple( 'Version', [ 'major', 'minor', 'patch' ] )
# Vim version. Example:
# This variable must be patched with a Version object for tests depending on a
# recent Vim version. Example:
# #
# @patch( 'ycm.tests.test_utils.VIM_VERSION', Version( 7, 4, 1578 ) ) # @patch( 'ycm.tests.test_utils.VIM_VERSION', Version( 8, 1, 614 ) )
# def ThisTestDependsOnTheVimVersion_test(): # def ThisTestDependsOnTheVimVersion_test():
# ... # ...
# #
VIM_VERSION = None # Default is the oldest supported version.
VIM_VERSION = Version( 7, 4, 1578 )
REDIR = { REDIR = {
'status': False, 'status': False,
@ -100,9 +103,6 @@ REDIR = {
} }
Version = namedtuple( 'Version', [ 'major', 'minor', 'patch' ] )
@contextlib.contextmanager @contextlib.contextmanager
def CurrentWorkingDirectory( path ): def CurrentWorkingDirectory( path ):
old_cwd = GetCurrentDirectory() old_cwd = GetCurrentDirectory()
@ -312,10 +312,12 @@ def _MockSignCommand( command ):
'Signs for foo:\n' ) 'Signs for foo:\n' )
for sign in VIM_SIGNS: for sign in VIM_SIGNS:
if sign.bufnr == bufnr: if sign.bufnr == bufnr:
REDIR[ 'output' ] += ( if VIM_VERSION >= Version( 8, 1, 614 ):
' line={0} id={1} name={2}'.format( sign.line, # 10 is the default priority.
sign.id, line_output = ' line={} id={} name={} priority=10'
sign.name ) ) else:
line_output = ' line={} id={} name={}'
REDIR[ 'output' ] += line_output.format( sign.line, sign.id, sign.name )
return True return True
match = SIGN_PLACE_REGEX.search( command ) match = SIGN_PLACE_REGEX.search( command )

View File

@ -22,8 +22,13 @@ from __future__ import absolute_import
# Not installing aliases from python-future; it's unreliable and slow. # Not installing aliases from python-future; it's unreliable and slow.
from builtins import * # noqa from builtins import * # noqa
from ycm.tests.test_utils import ( ExtendedMock, MockVimBuffers, MockVimModule, from ycm.tests.test_utils import ( ExtendedMock,
VimBuffer, VimMatch, VimSign ) MockVimBuffers,
MockVimModule,
Version,
VimBuffer,
VimMatch,
VimSign )
MockVimModule() MockVimModule()
import os import os
@ -32,9 +37,14 @@ from hamcrest import ( assert_that, contains, empty, equal_to, has_entries,
is_in, is_not, matches_regexp ) is_in, is_not, matches_regexp )
from mock import call, MagicMock, patch from mock import call, MagicMock, patch
from ycm import vimsupport
from ycm.paths import _PathToPythonUsedDuringBuild from ycm.paths import _PathToPythonUsedDuringBuild
from ycm.vimsupport import SetVariableValue, SIGN_BUFFER_ID_INITIAL_VALUE from ycm.vimsupport import ( SetVariableValue,
from ycm.tests import ( StopServer, test_utils, UserOptions, WaitUntilReady, SIGN_BUFFER_ID_INITIAL_VALUE )
from ycm.tests import ( StopServer,
test_utils,
UserOptions,
WaitUntilReady,
YouCompleteMeInstance ) YouCompleteMeInstance )
from ycm.client.base_request import _LoadExtraConfFile from ycm.client.base_request import _LoadExtraConfFile
from ycm.youcompleteme import YouCompleteMe from ycm.youcompleteme import YouCompleteMe
@ -537,7 +547,7 @@ def YouCompleteMe_ShowDiagnostics_DiagnosticsFound_OpenLocationList_test(
@patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype', @patch( 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
return_value = True ) return_value = True )
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock ) @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test( def YouCompleteMe_UpdateDiagnosticInterface(
ycm, post_vim_message, *args ): ycm, post_vim_message, *args ):
contents = """int main() { contents = """int main() {
@ -611,6 +621,7 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test(
test_utils.VIM_MATCHES_FOR_WINDOW.clear() test_utils.VIM_MATCHES_FOR_WINDOW.clear()
test_utils.VIM_SIGNS = [] test_utils.VIM_SIGNS = []
vimsupport.SIGN_ID_FOR_BUFFER.clear()
with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 3, 1 ) ): with MockVimBuffers( [ current_buffer ], [ current_buffer ], ( 3, 1 ) ):
with patch( 'ycm.client.event_notification.EventNotification.Response', with patch( 'ycm.client.event_notification.EventNotification.Response',
@ -686,6 +697,15 @@ def YouCompleteMe_UpdateDiagnosticInterface_PrioritizeErrorsOverWarnings_test(
) )
def YouCompleteMe_UpdateDiagnosticInterface_OldVim_test():
YouCompleteMe_UpdateDiagnosticInterface()
@patch( 'ycm.tests.test_utils.VIM_VERSION', Version( 8, 1, 614 ) )
def YouCompleteMe_UpdateDiagnosticInterface_NewVim_test():
YouCompleteMe_UpdateDiagnosticInterface()
@YouCompleteMeInstance( { 'g:ycm_enable_diagnostic_highlighting': 1 } ) @YouCompleteMeInstance( { 'g:ycm_enable_diagnostic_highlighting': 1 } )
def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ): def YouCompleteMe_UpdateMatches_ClearDiagnosticMatchesInNewBuffer_test( ycm ):
current_buffer = VimBuffer( 'buffer', current_buffer = VimBuffer( 'buffer',

View File

@ -54,8 +54,18 @@ SIGN_BUFFER_ID_INITIAL_VALUE = 100000000
# This holds the next sign's id to assign for each buffer. # This holds the next sign's id to assign for each buffer.
SIGN_ID_FOR_BUFFER = defaultdict( lambda: SIGN_BUFFER_ID_INITIAL_VALUE ) SIGN_ID_FOR_BUFFER = defaultdict( lambda: SIGN_BUFFER_ID_INITIAL_VALUE )
# The ":sign place" command ouputs each sign on one line in the format
#
# line=<line> id=<id> name=<name> priority=<priority>
#
# where the words "line", "id", "name", and "priority" are localized. On
# versions older than Vim 8.1.0614, the "priority" property doesn't exist and
# the output is
#
# line=<line> id=<id> name=<name>
#
SIGN_PLACE_REGEX = re.compile( SIGN_PLACE_REGEX = re.compile(
r"^.*=(?P<line>\d+).*=(?P<id>\d+).*=(?P<name>Ycm\w+)$" ) r"^.*=(?P<line>\d+).*=(?P<id>\d+).*=(?P<name>Ycm\w+)" )
NO_COMPLETIONS = { NO_COMPLETIONS = {
'line': -1, 'line': -1,
@ -222,12 +232,12 @@ def CreateSign( line, name, buffer_number ):
def UnplaceSign( sign ): def UnplaceSign( sign ):
vim.command( 'sign unplace {0} buffer={1}'.format( sign.id, vim.command( 'sign unplace {} buffer={}'.format( sign.id,
sign.buffer_number ) ) sign.buffer_number ) )
def PlaceSign( sign ): def PlaceSign( sign ):
vim.command( 'sign place {0} name={1} line={2} buffer={3}'.format( vim.command( 'sign place {} name={} line={} buffer={}'.format(
sign.id, sign.name, sign.line, sign.buffer_number ) ) sign.id, sign.name, sign.line, sign.buffer_number ) )