2016-10-11 18:05:24 -04:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
2018-01-06 07:16:30 -05:00
|
|
|
# Copyright (C) 2015-2018 YouCompleteMe contributors
|
2015-12-22 18:28:36 -05:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
2017-03-09 09:57:27 -05:00
|
|
|
# Not installing aliases from python-future; it's unreliable and slow.
|
2016-02-27 19:12:24 -05:00
|
|
|
from builtins import * # noqa
|
|
|
|
|
2016-10-11 18:05:24 -04:00
|
|
|
from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock,
|
2018-02-13 17:21:12 -05:00
|
|
|
MockVimBuffers, MockVimModule, VimBuffer,
|
|
|
|
VimSign )
|
2015-12-22 18:28:36 -05:00
|
|
|
MockVimModule()
|
|
|
|
|
2016-01-20 14:09:11 -05:00
|
|
|
import contextlib
|
|
|
|
import os
|
2015-12-22 18:28:36 -05:00
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
from ycm.tests import ( PathToTestFile, test_utils, YouCompleteMeInstance,
|
|
|
|
WaitUntilReady )
|
|
|
|
from ycm.vimsupport import SIGN_BUFFER_ID_INITIAL_VALUE
|
2016-01-11 14:16:49 -05:00
|
|
|
from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
|
2016-02-28 19:01:59 -05:00
|
|
|
UnknownExtraConf, ServerError )
|
2015-12-22 18:28:36 -05:00
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
from hamcrest import ( assert_that, contains, empty, has_entries, has_entry,
|
|
|
|
has_item, has_items, has_key, is_not )
|
2015-12-22 18:28:36 -05:00
|
|
|
from mock import call, MagicMock, patch
|
2016-01-11 14:16:49 -05:00
|
|
|
from nose.tools import eq_, ok_
|
2015-12-22 18:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
def PresentDialog_Confirm_Call( message ):
|
|
|
|
"""Return a mock.call object for a call to vimsupport.PresentDialog, as called
|
|
|
|
why vimsupport.Confirm with the supplied confirmation message"""
|
|
|
|
return call( message, [ 'Ok', 'Cancel' ] )
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
2017-06-11 13:46:09 -04:00
|
|
|
def MockArbitraryBuffer( filetype ):
|
2016-10-11 18:05:24 -04:00
|
|
|
"""Used via the with statement, set up a single buffer with an arbitrary name
|
|
|
|
and no contents. Its filetype is set to the supplied filetype."""
|
2015-12-22 18:28:36 -05:00
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
# Arbitrary, but valid, single buffer open.
|
|
|
|
current_buffer = VimBuffer( os.path.realpath( 'TEST_BUFFER' ),
|
|
|
|
window = 1,
|
|
|
|
filetype = filetype )
|
|
|
|
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
2016-10-11 18:05:24 -04:00
|
|
|
yield
|
2015-12-22 18:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def MockEventNotification( response_method, native_filetype_completer = True ):
|
|
|
|
"""Mock out the EventNotification client request object, replacing the
|
|
|
|
Response handler's JsonFromFuture with the supplied |response_method|.
|
|
|
|
Additionally mock out YouCompleteMe's FiletypeCompleterExistsForFiletype
|
|
|
|
method to return the supplied |native_filetype_completer| parameter, rather
|
|
|
|
than querying the server"""
|
|
|
|
|
|
|
|
# We don't want the event to actually be sent to the server, just have it
|
|
|
|
# return success
|
2017-05-15 06:41:45 -04:00
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
|
|
|
'PostDataToHandlerAsync',
|
2015-12-22 18:28:36 -05:00
|
|
|
return_value = MagicMock( return_value=True ) ):
|
|
|
|
|
2017-05-17 05:12:00 -04:00
|
|
|
# We set up a fake a Response (as called by EventNotification.Response)
|
|
|
|
# which calls the supplied callback method. Generally this callback just
|
|
|
|
# raises an apropriate exception, otherwise it would have to return a mock
|
|
|
|
# future object.
|
|
|
|
with patch( 'ycm.client.base_request._JsonFromFuture',
|
2015-12-22 18:28:36 -05:00
|
|
|
side_effect = response_method ):
|
|
|
|
|
|
|
|
# Filetype available information comes from the server, so rather than
|
|
|
|
# relying on that request, we mock out the check. The caller decides if
|
|
|
|
# filetype completion is available
|
|
|
|
with patch(
|
|
|
|
'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
|
|
|
|
return_value = native_filetype_completer ):
|
|
|
|
|
2017-07-03 12:06:01 -04:00
|
|
|
yield
|
2015-12-22 18:28:36 -05:00
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
|
|
|
|
ycm, post_vim_message ):
|
|
|
|
|
|
|
|
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
|
|
|
|
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
|
|
|
|
# raises an exception handling FileReadyToParse event notification
|
|
|
|
ERROR_TEXT = 'Some completer response text'
|
|
|
|
|
|
|
|
def ErrorResponse( *args ):
|
|
|
|
raise ServerError( ERROR_TEXT )
|
|
|
|
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockArbitraryBuffer( 'javascript' ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with MockEventNotification( ErrorResponse ):
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
# The first call raises a warning
|
|
|
|
post_vim_message.assert_has_exact_calls( [
|
2016-11-05 09:57:02 -04:00
|
|
|
call( ERROR_TEXT, truncate = True )
|
2016-10-11 16:54:00 -04:00
|
|
|
] )
|
|
|
|
|
|
|
|
# Subsequent calls don't re-raise the warning
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
post_vim_message.assert_has_exact_calls( [
|
2016-11-05 09:57:02 -04:00
|
|
|
call( ERROR_TEXT, truncate = True )
|
2016-10-11 16:54:00 -04:00
|
|
|
] )
|
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
# But it does if a subsequent event raises again
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
post_vim_message.assert_has_exact_calls( [
|
2016-11-05 09:57:02 -04:00
|
|
|
call( ERROR_TEXT, truncate = True ),
|
|
|
|
call( ERROR_TEXT, truncate = True )
|
2016-10-11 16:54:00 -04:00
|
|
|
] )
|
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_FileReadyToParse_NonDiagnostic_Error_NonNative_test(
|
2018-02-13 17:21:12 -05:00
|
|
|
ycm ):
|
|
|
|
|
|
|
|
test_utils.VIM_MATCHES = []
|
|
|
|
test_utils.VIM_SIGNS = []
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockArbitraryBuffer( 'javascript' ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with MockEventNotification( None, False ):
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_MATCHES,
|
|
|
|
contains()
|
|
|
|
)
|
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains()
|
|
|
|
)
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
|
2018-04-05 11:53:54 -04:00
|
|
|
ycm ):
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
# This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
|
|
|
|
# in combination with YouCompleteMe.OnFileReadyToParse when the completer
|
|
|
|
# raises the (special) UnknownExtraConf exception
|
|
|
|
FILE_NAME = 'a_file'
|
|
|
|
MESSAGE = ( 'Found ' + FILE_NAME + '. Load? \n\n(Question can be '
|
|
|
|
'turned off with options, see YCM docs)' )
|
|
|
|
|
|
|
|
def UnknownExtraConfResponse( *args ):
|
|
|
|
raise UnknownExtraConf( FILE_NAME )
|
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
with patch( 'ycm.client.base_request.BaseRequest.PostDataToHandler',
|
|
|
|
new_callable = ExtendedMock ) as post_data_to_handler:
|
|
|
|
with MockArbitraryBuffer( 'javascript' ):
|
|
|
|
with MockEventNotification( UnknownExtraConfResponse ):
|
|
|
|
|
|
|
|
# When the user accepts the extra conf, we load it
|
|
|
|
with patch( 'ycm.vimsupport.PresentDialog',
|
|
|
|
return_value = 0,
|
|
|
|
new_callable = ExtendedMock ) as present_dialog:
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Subsequent calls don't re-raise the warning
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE )
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
ok_( ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
|
|
|
# But it does if a subsequent event raises again
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' ),
|
|
|
|
call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
ok_( ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
|
|
|
post_data_to_handler.reset_mock()
|
|
|
|
|
|
|
|
# When the user rejects the extra conf, we reject it
|
|
|
|
with patch( 'ycm.vimsupport.PresentDialog',
|
|
|
|
return_value = 1,
|
|
|
|
new_callable = ExtendedMock ) as present_dialog:
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Subsequent calls don't re-raise the warning
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE )
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
ok_( ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
|
|
|
# But it does if a subsequent event raises again
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
|
|
|
|
present_dialog.assert_has_exact_calls( [
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
PresentDialog_Confirm_Call( MESSAGE ),
|
|
|
|
] )
|
|
|
|
post_data_to_handler.assert_has_exact_calls( [
|
|
|
|
call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' ),
|
|
|
|
call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
ok_( ycm.ShouldResendFileParseRequest() )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_FileReadyToParse_Diagnostic_Error_Native_test( ycm ):
|
2018-02-13 17:21:12 -05:00
|
|
|
test_utils.VIM_SIGNS = []
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
_Check_FileReadyToParse_Diagnostic_Error( ycm )
|
|
|
|
_Check_FileReadyToParse_Diagnostic_Warning( ycm )
|
|
|
|
_Check_FileReadyToParse_Diagnostic_Clean( ycm )
|
|
|
|
|
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
def _Check_FileReadyToParse_Diagnostic_Error( ycm ):
|
2016-10-11 16:54:00 -04:00
|
|
|
# Tests Vim sign placement and error/warning count python API
|
|
|
|
# when one error is returned.
|
|
|
|
def DiagnosticResponse( *args ):
|
|
|
|
start = Location( 1, 2, 'TEST_BUFFER' )
|
|
|
|
end = Location( 1, 4, 'TEST_BUFFER' )
|
|
|
|
extent = Range( start, end )
|
|
|
|
diagnostic = Diagnostic( [], start, extent, 'expected ;', 'ERROR' )
|
|
|
|
return [ BuildDiagnosticData( diagnostic ) ]
|
|
|
|
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockArbitraryBuffer( 'cpp' ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with MockEventNotification( DiagnosticResponse ):
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains(
|
|
|
|
VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
|
|
|
|
)
|
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( ycm.GetErrorCount(), 1 )
|
|
|
|
eq_( ycm.GetWarningCount(), 0 )
|
|
|
|
|
|
|
|
# Consequent calls to HandleFileParseRequest shouldn't mess with
|
|
|
|
# existing diagnostics, when there is no new parse request.
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains(
|
|
|
|
VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
|
|
|
|
)
|
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( ycm.GetErrorCount(), 1 )
|
|
|
|
eq_( ycm.GetWarningCount(), 0 )
|
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
# New identical requests should result in the same diagnostics.
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains(
|
|
|
|
VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
|
|
|
|
)
|
|
|
|
)
|
|
|
|
eq_( ycm.GetErrorCount(), 1 )
|
|
|
|
eq_( ycm.GetWarningCount(), 0 )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
|
|
|
|
def _Check_FileReadyToParse_Diagnostic_Warning( ycm ):
|
2016-10-11 16:54:00 -04:00
|
|
|
# Tests Vim sign placement/unplacement and error/warning count python API
|
|
|
|
# when one warning is returned.
|
|
|
|
# Should be called after _Check_FileReadyToParse_Diagnostic_Error
|
|
|
|
def DiagnosticResponse( *args ):
|
|
|
|
start = Location( 2, 2, 'TEST_BUFFER' )
|
|
|
|
end = Location( 2, 4, 'TEST_BUFFER' )
|
|
|
|
extent = Range( start, end )
|
|
|
|
diagnostic = Diagnostic( [], start, extent, 'cast', 'WARNING' )
|
|
|
|
return [ BuildDiagnosticData( diagnostic ) ]
|
|
|
|
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockArbitraryBuffer( 'cpp' ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with MockEventNotification( DiagnosticResponse ):
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ok_( ycm.FileParseRequestReady() )
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains(
|
2018-05-14 08:18:18 -04:00
|
|
|
VimSign( SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1 )
|
2018-02-13 17:21:12 -05:00
|
|
|
)
|
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( ycm.GetErrorCount(), 0 )
|
|
|
|
eq_( ycm.GetWarningCount(), 1 )
|
|
|
|
|
|
|
|
# Consequent calls to HandleFileParseRequest shouldn't mess with
|
|
|
|
# existing diagnostics, when there is no new parse request.
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
contains(
|
2018-05-14 08:18:18 -04:00
|
|
|
VimSign( SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1 )
|
2018-02-13 17:21:12 -05:00
|
|
|
)
|
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( ycm.GetErrorCount(), 0 )
|
|
|
|
eq_( ycm.GetWarningCount(), 1 )
|
|
|
|
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
|
2018-02-13 17:21:12 -05:00
|
|
|
def _Check_FileReadyToParse_Diagnostic_Clean( ycm ):
|
2016-10-11 16:54:00 -04:00
|
|
|
# Tests Vim sign unplacement and error/warning count python API
|
|
|
|
# when there are no errors/warnings left.
|
|
|
|
# Should be called after _Check_FileReadyToParse_Diagnostic_Warning
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockArbitraryBuffer( 'cpp' ):
|
2016-10-11 16:54:00 -04:00
|
|
|
with MockEventNotification( MagicMock( return_value = [] ) ):
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
ycm.HandleFileParseRequest()
|
2018-02-13 17:21:12 -05:00
|
|
|
assert_that(
|
|
|
|
test_utils.VIM_SIGNS,
|
|
|
|
empty()
|
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
eq_( ycm.GetErrorCount(), 0 )
|
|
|
|
eq_( ycm.GetWarningCount(), 0 )
|
2018-04-05 11:53:54 -04:00
|
|
|
ok_( not ycm.ShouldResendFileParseRequest() )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
|
2016-10-11 18:05:24 -04:00
|
|
|
@patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
|
2018-05-14 08:18:18 -04:00
|
|
|
@YouCompleteMeInstance( { 'g:ycm_collect_identifiers_from_tags_files': 1 } )
|
2016-10-11 18:05:24 -04:00
|
|
|
def EventNotification_FileReadyToParse_TagFiles_UnicodeWorkingDirectory_test(
|
|
|
|
ycm, *args ):
|
|
|
|
unicode_dir = PathToTestFile( 'uni¢𐍈d€' )
|
|
|
|
current_buffer_file = PathToTestFile( 'uni¢𐍈d€', 'current_buffer' )
|
|
|
|
current_buffer = VimBuffer( name = current_buffer_file,
|
|
|
|
contents = [ 'current_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype' )
|
|
|
|
|
2017-05-15 06:41:45 -04:00
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
2016-10-11 18:05:24 -04:00
|
|
|
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
|
|
|
with CurrentWorkingDirectory( unicode_dir ):
|
2017-07-03 11:59:20 -04:00
|
|
|
with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 5 ) ):
|
2016-10-11 18:05:24 -04:00
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entries( {
|
|
|
|
'filepath': current_buffer_file,
|
2017-07-03 11:59:20 -04:00
|
|
|
'line_num': 1,
|
2016-10-11 18:05:24 -04:00
|
|
|
'column_num': 6,
|
|
|
|
'file_data': has_entries( {
|
|
|
|
current_buffer_file: has_entries( {
|
|
|
|
'contents': 'current_buffer_contents\n',
|
|
|
|
'filetypes': [ 'some_filetype' ]
|
|
|
|
} )
|
|
|
|
} ),
|
|
|
|
'event_name': 'FileReadyToParse',
|
|
|
|
'tag_files': has_item( PathToTestFile( 'uni¢𐍈d€', 'tags' ) )
|
|
|
|
} ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
|
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
|
|
|
|
ycm, *args ):
|
|
|
|
|
|
|
|
current_buffer_file = os.path.realpath( 'current_buffer' )
|
|
|
|
current_buffer = VimBuffer( name = current_buffer_file,
|
|
|
|
number = 1,
|
|
|
|
contents = [ 'current_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype',
|
|
|
|
modified = False )
|
|
|
|
modified_buffer_file = os.path.realpath( 'modified_buffer' )
|
|
|
|
modified_buffer = VimBuffer( name = modified_buffer_file,
|
|
|
|
number = 2,
|
|
|
|
contents = [ 'modified_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype',
|
|
|
|
modified = True )
|
|
|
|
|
|
|
|
unmodified_buffer_file = os.path.realpath( 'unmodified_buffer' )
|
|
|
|
unmodified_buffer = VimBuffer( name = unmodified_buffer_file,
|
|
|
|
number = 3,
|
|
|
|
contents = [ 'unmodified_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype',
|
|
|
|
modified = False )
|
2016-10-08 04:53:17 -04:00
|
|
|
|
2017-05-15 06:41:45 -04:00
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
2016-10-11 16:54:00 -04:00
|
|
|
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
2016-10-11 18:05:24 -04:00
|
|
|
with MockVimBuffers( [ current_buffer, modified_buffer, unmodified_buffer ],
|
|
|
|
current_buffer,
|
2017-07-03 11:59:20 -04:00
|
|
|
( 1, 5 ) ):
|
2016-10-11 18:05:24 -04:00
|
|
|
ycm.OnBufferVisit()
|
2016-10-08 04:53:17 -04:00
|
|
|
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entries( {
|
|
|
|
'filepath': current_buffer_file,
|
2017-07-03 11:59:20 -04:00
|
|
|
'line_num': 1,
|
2016-10-08 04:53:17 -04:00
|
|
|
'column_num': 6,
|
|
|
|
'file_data': has_entries( {
|
|
|
|
current_buffer_file: has_entries( {
|
2016-10-11 16:54:00 -04:00
|
|
|
'contents': 'current_buffer_contents\n',
|
2016-10-08 04:53:17 -04:00
|
|
|
'filetypes': [ 'some_filetype' ]
|
|
|
|
} ),
|
|
|
|
modified_buffer_file: has_entries( {
|
2016-10-11 16:54:00 -04:00
|
|
|
'contents': 'modified_buffer_contents\n',
|
2016-10-08 04:53:17 -04:00
|
|
|
'filetypes': [ 'some_filetype' ]
|
|
|
|
} )
|
|
|
|
} ),
|
|
|
|
'event_name': 'BufferVisit'
|
|
|
|
} ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-10-11 16:54:00 -04:00
|
|
|
@YouCompleteMeInstance()
|
|
|
|
def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
|
|
|
|
ycm ):
|
2017-07-06 13:43:34 -04:00
|
|
|
current_buffer_file = os.path.realpath( 'current_βuffer' )
|
2016-10-11 16:54:00 -04:00
|
|
|
current_buffer = VimBuffer( name = current_buffer_file,
|
|
|
|
number = 1,
|
|
|
|
contents = [ 'current_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype',
|
|
|
|
modified = True )
|
|
|
|
|
2017-07-06 13:43:34 -04:00
|
|
|
deleted_buffer_file = os.path.realpath( 'deleted_βuffer' )
|
2016-10-11 16:54:00 -04:00
|
|
|
deleted_buffer = VimBuffer( name = deleted_buffer_file,
|
|
|
|
number = 2,
|
|
|
|
contents = [ 'deleted_buffer_contents' ],
|
|
|
|
filetype = 'some_filetype',
|
|
|
|
modified = False )
|
|
|
|
|
2017-05-15 06:41:45 -04:00
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
2016-10-11 16:54:00 -04:00
|
|
|
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
2016-10-11 18:05:24 -04:00
|
|
|
with MockVimBuffers( [ current_buffer, deleted_buffer ], current_buffer ):
|
2018-01-06 07:16:30 -05:00
|
|
|
ycm.OnBufferUnload( deleted_buffer.number )
|
2016-10-11 16:54:00 -04:00
|
|
|
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entries( {
|
|
|
|
'filepath': deleted_buffer_file,
|
|
|
|
'line_num': 1,
|
|
|
|
'column_num': 1,
|
|
|
|
'file_data': has_entries( {
|
|
|
|
current_buffer_file: has_entries( {
|
|
|
|
'contents': 'current_buffer_contents\n',
|
|
|
|
'filetypes': [ 'some_filetype' ]
|
2016-10-08 04:53:17 -04:00
|
|
|
} ),
|
2016-10-11 16:54:00 -04:00
|
|
|
deleted_buffer_file: has_entries( {
|
|
|
|
'contents': 'deleted_buffer_contents\n',
|
|
|
|
'filetypes': [ 'some_filetype' ]
|
|
|
|
} )
|
2016-10-08 04:53:17 -04:00
|
|
|
} ),
|
2016-10-11 16:54:00 -04:00
|
|
|
'event_name': 'BufferUnload'
|
|
|
|
} ),
|
|
|
|
'event_notification'
|
2016-10-08 04:53:17 -04:00
|
|
|
)
|
2016-10-11 16:54:00 -04:00
|
|
|
)
|
2017-05-15 06:41:45 -04:00
|
|
|
|
|
|
|
|
2018-02-18 07:40:35 -05:00
|
|
|
@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
|
|
|
|
fooGroup xxx foo bar
|
|
|
|
links to Statement""" )
|
2018-05-14 08:18:18 -04:00
|
|
|
@YouCompleteMeInstance( { 'g:ycm_seed_identifiers_with_syntax': 1 } )
|
2017-05-15 06:41:45 -04:00
|
|
|
def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
|
|
|
|
ycm, *args ):
|
|
|
|
|
|
|
|
current_buffer = VimBuffer( name = 'current_buffer',
|
|
|
|
filetype = 'some_filetype' )
|
|
|
|
|
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
|
|
|
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
2017-05-15 06:41:45 -04:00
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Do not send again syntax keywords in subsequent requests.
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
is_not( has_key( 'syntax_keywords' ) ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-02-18 07:40:35 -05:00
|
|
|
@patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
|
|
|
|
fooGroup xxx foo bar
|
|
|
|
links to Statement""" )
|
2018-05-14 08:18:18 -04:00
|
|
|
@YouCompleteMeInstance( { 'g:ycm_seed_identifiers_with_syntax': 1 } )
|
2017-05-15 06:41:45 -04:00
|
|
|
def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test(
|
|
|
|
ycm, *args ):
|
|
|
|
|
|
|
|
current_buffer = VimBuffer( name = 'current_buffer',
|
|
|
|
filetype = 'some_filetype' )
|
|
|
|
|
|
|
|
with patch( 'ycm.client.event_notification.EventNotification.'
|
|
|
|
'PostDataToHandlerAsync' ) as post_data_to_handler_async:
|
2017-06-11 13:46:09 -04:00
|
|
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
2017-05-15 06:41:45 -04:00
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Send again the syntax keywords after restarting the server.
|
|
|
|
ycm.RestartServer()
|
|
|
|
WaitUntilReady()
|
|
|
|
ycm.OnFileReadyToParse()
|
|
|
|
assert_that(
|
|
|
|
# Positional arguments passed to PostDataToHandlerAsync.
|
|
|
|
post_data_to_handler_async.call_args[ 0 ],
|
|
|
|
contains(
|
|
|
|
has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
|
|
|
|
'event_notification'
|
|
|
|
)
|
|
|
|
)
|