event_notification_test.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. # coding: utf-8
  2. #
  3. # Copyright (C) 2015-2018 YouCompleteMe contributors
  4. #
  5. # This file is part of YouCompleteMe.
  6. #
  7. # YouCompleteMe is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # YouCompleteMe is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  19. from __future__ import unicode_literals
  20. from __future__ import print_function
  21. from __future__ import division
  22. from __future__ import absolute_import
  23. # Not installing aliases from python-future; it's unreliable and slow.
  24. from builtins import * # noqa
  25. from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock,
  26. MockVimBuffers, MockVimModule, VimBuffer,
  27. VimSign )
  28. MockVimModule()
  29. import contextlib
  30. import os
  31. from ycm.tests import ( PathToTestFile, test_utils, YouCompleteMeInstance,
  32. WaitUntilReady )
  33. from ycm.vimsupport import SIGN_BUFFER_ID_INITIAL_VALUE
  34. from ycmd.responses import ( BuildDiagnosticData, Diagnostic, Location, Range,
  35. UnknownExtraConf, ServerError )
  36. from hamcrest import ( assert_that, contains, empty, has_entries, has_entry,
  37. has_item, has_items, has_key, is_not )
  38. from mock import call, MagicMock, patch
  39. from nose.tools import eq_, ok_
  40. def PresentDialog_Confirm_Call( message ):
  41. """Return a mock.call object for a call to vimsupport.PresentDialog, as called
  42. why vimsupport.Confirm with the supplied confirmation message"""
  43. return call( message, [ 'Ok', 'Cancel' ] )
  44. @contextlib.contextmanager
  45. def MockArbitraryBuffer( filetype ):
  46. """Used via the with statement, set up a single buffer with an arbitrary name
  47. and no contents. Its filetype is set to the supplied filetype."""
  48. # Arbitrary, but valid, single buffer open.
  49. current_buffer = VimBuffer( os.path.realpath( 'TEST_BUFFER' ),
  50. window = 1,
  51. filetype = filetype )
  52. with MockVimBuffers( [ current_buffer ], current_buffer ):
  53. yield
  54. @contextlib.contextmanager
  55. def MockEventNotification( response_method, native_filetype_completer = True ):
  56. """Mock out the EventNotification client request object, replacing the
  57. Response handler's JsonFromFuture with the supplied |response_method|.
  58. Additionally mock out YouCompleteMe's FiletypeCompleterExistsForFiletype
  59. method to return the supplied |native_filetype_completer| parameter, rather
  60. than querying the server"""
  61. # We don't want the event to actually be sent to the server, just have it
  62. # return success
  63. with patch( 'ycm.client.event_notification.EventNotification.'
  64. 'PostDataToHandlerAsync',
  65. return_value = MagicMock( return_value=True ) ):
  66. # We set up a fake a Response (as called by EventNotification.Response)
  67. # which calls the supplied callback method. Generally this callback just
  68. # raises an apropriate exception, otherwise it would have to return a mock
  69. # future object.
  70. with patch( 'ycm.client.base_request._JsonFromFuture',
  71. side_effect = response_method ):
  72. # Filetype available information comes from the server, so rather than
  73. # relying on that request, we mock out the check. The caller decides if
  74. # filetype completion is available
  75. with patch(
  76. 'ycm.youcompleteme.YouCompleteMe.FiletypeCompleterExistsForFiletype',
  77. return_value = native_filetype_completer ):
  78. yield
  79. @patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
  80. @YouCompleteMeInstance()
  81. def EventNotification_FileReadyToParse_NonDiagnostic_Error_test(
  82. ycm, post_vim_message ):
  83. # This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
  84. # in combination with YouCompleteMe.OnFileReadyToParse when the completer
  85. # raises an exception handling FileReadyToParse event notification
  86. ERROR_TEXT = 'Some completer response text'
  87. def ErrorResponse( *args ):
  88. raise ServerError( ERROR_TEXT )
  89. with MockArbitraryBuffer( 'javascript' ):
  90. with MockEventNotification( ErrorResponse ):
  91. ycm.OnFileReadyToParse()
  92. ok_( ycm.FileParseRequestReady() )
  93. ycm.HandleFileParseRequest()
  94. # The first call raises a warning
  95. post_vim_message.assert_has_exact_calls( [
  96. call( ERROR_TEXT, truncate = True )
  97. ] )
  98. # Subsequent calls don't re-raise the warning
  99. ycm.HandleFileParseRequest()
  100. post_vim_message.assert_has_exact_calls( [
  101. call( ERROR_TEXT, truncate = True )
  102. ] )
  103. ok_( not ycm.ShouldResendFileParseRequest() )
  104. # But it does if a subsequent event raises again
  105. ycm.OnFileReadyToParse()
  106. ok_( ycm.FileParseRequestReady() )
  107. ycm.HandleFileParseRequest()
  108. post_vim_message.assert_has_exact_calls( [
  109. call( ERROR_TEXT, truncate = True ),
  110. call( ERROR_TEXT, truncate = True )
  111. ] )
  112. ok_( not ycm.ShouldResendFileParseRequest() )
  113. @YouCompleteMeInstance()
  114. def EventNotification_FileReadyToParse_NonDiagnostic_Error_NonNative_test(
  115. ycm ):
  116. test_utils.VIM_MATCHES = []
  117. test_utils.VIM_SIGNS = []
  118. with MockArbitraryBuffer( 'javascript' ):
  119. with MockEventNotification( None, False ):
  120. ycm.OnFileReadyToParse()
  121. ycm.HandleFileParseRequest()
  122. assert_that(
  123. test_utils.VIM_MATCHES,
  124. contains()
  125. )
  126. assert_that(
  127. test_utils.VIM_SIGNS,
  128. contains()
  129. )
  130. ok_( not ycm.ShouldResendFileParseRequest() )
  131. @YouCompleteMeInstance()
  132. def EventNotification_FileReadyToParse_NonDiagnostic_ConfirmExtraConf_test(
  133. ycm ):
  134. # This test validates the behaviour of YouCompleteMe.HandleFileParseRequest
  135. # in combination with YouCompleteMe.OnFileReadyToParse when the completer
  136. # raises the (special) UnknownExtraConf exception
  137. FILE_NAME = 'a_file'
  138. MESSAGE = ( 'Found ' + FILE_NAME + '. Load? \n\n(Question can be '
  139. 'turned off with options, see YCM docs)' )
  140. def UnknownExtraConfResponse( *args ):
  141. raise UnknownExtraConf( FILE_NAME )
  142. with patch( 'ycm.client.base_request.BaseRequest.PostDataToHandler',
  143. new_callable = ExtendedMock ) as post_data_to_handler:
  144. with MockArbitraryBuffer( 'javascript' ):
  145. with MockEventNotification( UnknownExtraConfResponse ):
  146. # When the user accepts the extra conf, we load it
  147. with patch( 'ycm.vimsupport.PresentDialog',
  148. return_value = 0,
  149. new_callable = ExtendedMock ) as present_dialog:
  150. ycm.OnFileReadyToParse()
  151. ok_( ycm.FileParseRequestReady() )
  152. ycm.HandleFileParseRequest()
  153. present_dialog.assert_has_exact_calls( [
  154. PresentDialog_Confirm_Call( MESSAGE ),
  155. ] )
  156. post_data_to_handler.assert_has_exact_calls( [
  157. call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
  158. ] )
  159. # Subsequent calls don't re-raise the warning
  160. ycm.HandleFileParseRequest()
  161. present_dialog.assert_has_exact_calls( [
  162. PresentDialog_Confirm_Call( MESSAGE )
  163. ] )
  164. post_data_to_handler.assert_has_exact_calls( [
  165. call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
  166. ] )
  167. ok_( ycm.ShouldResendFileParseRequest() )
  168. # But it does if a subsequent event raises again
  169. ycm.OnFileReadyToParse()
  170. ok_( ycm.FileParseRequestReady() )
  171. ycm.HandleFileParseRequest()
  172. present_dialog.assert_has_exact_calls( [
  173. PresentDialog_Confirm_Call( MESSAGE ),
  174. PresentDialog_Confirm_Call( MESSAGE ),
  175. ] )
  176. post_data_to_handler.assert_has_exact_calls( [
  177. call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' ),
  178. call( { 'filepath': FILE_NAME }, 'load_extra_conf_file' )
  179. ] )
  180. ok_( ycm.ShouldResendFileParseRequest() )
  181. post_data_to_handler.reset_mock()
  182. # When the user rejects the extra conf, we reject it
  183. with patch( 'ycm.vimsupport.PresentDialog',
  184. return_value = 1,
  185. new_callable = ExtendedMock ) as present_dialog:
  186. ycm.OnFileReadyToParse()
  187. ok_( ycm.FileParseRequestReady() )
  188. ycm.HandleFileParseRequest()
  189. present_dialog.assert_has_exact_calls( [
  190. PresentDialog_Confirm_Call( MESSAGE ),
  191. ] )
  192. post_data_to_handler.assert_has_exact_calls( [
  193. call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
  194. ] )
  195. # Subsequent calls don't re-raise the warning
  196. ycm.HandleFileParseRequest()
  197. present_dialog.assert_has_exact_calls( [
  198. PresentDialog_Confirm_Call( MESSAGE )
  199. ] )
  200. post_data_to_handler.assert_has_exact_calls( [
  201. call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
  202. ] )
  203. ok_( ycm.ShouldResendFileParseRequest() )
  204. # But it does if a subsequent event raises again
  205. ycm.OnFileReadyToParse()
  206. ok_( ycm.FileParseRequestReady() )
  207. ycm.HandleFileParseRequest()
  208. present_dialog.assert_has_exact_calls( [
  209. PresentDialog_Confirm_Call( MESSAGE ),
  210. PresentDialog_Confirm_Call( MESSAGE ),
  211. ] )
  212. post_data_to_handler.assert_has_exact_calls( [
  213. call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' ),
  214. call( { 'filepath': FILE_NAME }, 'ignore_extra_conf_file' )
  215. ] )
  216. ok_( ycm.ShouldResendFileParseRequest() )
  217. @YouCompleteMeInstance()
  218. def EventNotification_FileReadyToParse_Diagnostic_Error_Native_test( ycm ):
  219. test_utils.VIM_SIGNS = []
  220. _Check_FileReadyToParse_Diagnostic_Error( ycm )
  221. _Check_FileReadyToParse_Diagnostic_Warning( ycm )
  222. _Check_FileReadyToParse_Diagnostic_Clean( ycm )
  223. def _Check_FileReadyToParse_Diagnostic_Error( ycm ):
  224. # Tests Vim sign placement and error/warning count python API
  225. # when one error is returned.
  226. def DiagnosticResponse( *args ):
  227. start = Location( 1, 2, 'TEST_BUFFER' )
  228. end = Location( 1, 4, 'TEST_BUFFER' )
  229. extent = Range( start, end )
  230. diagnostic = Diagnostic( [], start, extent, 'expected ;', 'ERROR' )
  231. return [ BuildDiagnosticData( diagnostic ) ]
  232. with MockArbitraryBuffer( 'cpp' ):
  233. with MockEventNotification( DiagnosticResponse ):
  234. ycm.OnFileReadyToParse()
  235. ok_( ycm.FileParseRequestReady() )
  236. ycm.HandleFileParseRequest()
  237. assert_that(
  238. test_utils.VIM_SIGNS,
  239. contains(
  240. VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
  241. )
  242. )
  243. eq_( ycm.GetErrorCount(), 1 )
  244. eq_( ycm.GetWarningCount(), 0 )
  245. # Consequent calls to HandleFileParseRequest shouldn't mess with
  246. # existing diagnostics, when there is no new parse request.
  247. ycm.HandleFileParseRequest()
  248. assert_that(
  249. test_utils.VIM_SIGNS,
  250. contains(
  251. VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
  252. )
  253. )
  254. eq_( ycm.GetErrorCount(), 1 )
  255. eq_( ycm.GetWarningCount(), 0 )
  256. ok_( not ycm.ShouldResendFileParseRequest() )
  257. # New identical requests should result in the same diagnostics.
  258. ycm.OnFileReadyToParse()
  259. ok_( ycm.FileParseRequestReady() )
  260. ycm.HandleFileParseRequest()
  261. assert_that(
  262. test_utils.VIM_SIGNS,
  263. contains(
  264. VimSign( SIGN_BUFFER_ID_INITIAL_VALUE, 1, 'YcmError', 1 )
  265. )
  266. )
  267. eq_( ycm.GetErrorCount(), 1 )
  268. eq_( ycm.GetWarningCount(), 0 )
  269. ok_( not ycm.ShouldResendFileParseRequest() )
  270. def _Check_FileReadyToParse_Diagnostic_Warning( ycm ):
  271. # Tests Vim sign placement/unplacement and error/warning count python API
  272. # when one warning is returned.
  273. # Should be called after _Check_FileReadyToParse_Diagnostic_Error
  274. def DiagnosticResponse( *args ):
  275. start = Location( 2, 2, 'TEST_BUFFER' )
  276. end = Location( 2, 4, 'TEST_BUFFER' )
  277. extent = Range( start, end )
  278. diagnostic = Diagnostic( [], start, extent, 'cast', 'WARNING' )
  279. return [ BuildDiagnosticData( diagnostic ) ]
  280. with MockArbitraryBuffer( 'cpp' ):
  281. with MockEventNotification( DiagnosticResponse ):
  282. ycm.OnFileReadyToParse()
  283. ok_( ycm.FileParseRequestReady() )
  284. ycm.HandleFileParseRequest()
  285. assert_that(
  286. test_utils.VIM_SIGNS,
  287. contains(
  288. VimSign( SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1 )
  289. )
  290. )
  291. eq_( ycm.GetErrorCount(), 0 )
  292. eq_( ycm.GetWarningCount(), 1 )
  293. # Consequent calls to HandleFileParseRequest shouldn't mess with
  294. # existing diagnostics, when there is no new parse request.
  295. ycm.HandleFileParseRequest()
  296. assert_that(
  297. test_utils.VIM_SIGNS,
  298. contains(
  299. VimSign( SIGN_BUFFER_ID_INITIAL_VALUE + 2, 2, 'YcmWarning', 1 )
  300. )
  301. )
  302. eq_( ycm.GetErrorCount(), 0 )
  303. eq_( ycm.GetWarningCount(), 1 )
  304. ok_( not ycm.ShouldResendFileParseRequest() )
  305. def _Check_FileReadyToParse_Diagnostic_Clean( ycm ):
  306. # Tests Vim sign unplacement and error/warning count python API
  307. # when there are no errors/warnings left.
  308. # Should be called after _Check_FileReadyToParse_Diagnostic_Warning
  309. with MockArbitraryBuffer( 'cpp' ):
  310. with MockEventNotification( MagicMock( return_value = [] ) ):
  311. ycm.OnFileReadyToParse()
  312. ycm.HandleFileParseRequest()
  313. assert_that(
  314. test_utils.VIM_SIGNS,
  315. empty()
  316. )
  317. eq_( ycm.GetErrorCount(), 0 )
  318. eq_( ycm.GetWarningCount(), 0 )
  319. ok_( not ycm.ShouldResendFileParseRequest() )
  320. @patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
  321. @YouCompleteMeInstance( { 'g:ycm_collect_identifiers_from_tags_files': 1 } )
  322. def EventNotification_FileReadyToParse_TagFiles_UnicodeWorkingDirectory_test(
  323. ycm, *args ):
  324. unicode_dir = PathToTestFile( 'uni¢𐍈d€' )
  325. current_buffer_file = PathToTestFile( 'uni¢𐍈d€', 'current_buffer' )
  326. current_buffer = VimBuffer( name = current_buffer_file,
  327. contents = [ 'current_buffer_contents' ],
  328. filetype = 'some_filetype' )
  329. with patch( 'ycm.client.event_notification.EventNotification.'
  330. 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
  331. with CurrentWorkingDirectory( unicode_dir ):
  332. with MockVimBuffers( [ current_buffer ], current_buffer, ( 1, 5 ) ):
  333. ycm.OnFileReadyToParse()
  334. assert_that(
  335. # Positional arguments passed to PostDataToHandlerAsync.
  336. post_data_to_handler_async.call_args[ 0 ],
  337. contains(
  338. has_entries( {
  339. 'filepath': current_buffer_file,
  340. 'line_num': 1,
  341. 'column_num': 6,
  342. 'file_data': has_entries( {
  343. current_buffer_file: has_entries( {
  344. 'contents': 'current_buffer_contents\n',
  345. 'filetypes': [ 'some_filetype' ]
  346. } )
  347. } ),
  348. 'event_name': 'FileReadyToParse',
  349. 'tag_files': has_item( PathToTestFile( 'uni¢𐍈d€', 'tags' ) )
  350. } ),
  351. 'event_notification'
  352. )
  353. )
  354. @patch( 'ycm.youcompleteme.YouCompleteMe._AddUltiSnipsDataIfNeeded' )
  355. @YouCompleteMeInstance()
  356. def EventNotification_BufferVisit_BuildRequestForCurrentAndUnsavedBuffers_test(
  357. ycm, *args ):
  358. current_buffer_file = os.path.realpath( 'current_buffer' )
  359. current_buffer = VimBuffer( name = current_buffer_file,
  360. number = 1,
  361. contents = [ 'current_buffer_contents' ],
  362. filetype = 'some_filetype',
  363. modified = False )
  364. modified_buffer_file = os.path.realpath( 'modified_buffer' )
  365. modified_buffer = VimBuffer( name = modified_buffer_file,
  366. number = 2,
  367. contents = [ 'modified_buffer_contents' ],
  368. filetype = 'some_filetype',
  369. modified = True )
  370. unmodified_buffer_file = os.path.realpath( 'unmodified_buffer' )
  371. unmodified_buffer = VimBuffer( name = unmodified_buffer_file,
  372. number = 3,
  373. contents = [ 'unmodified_buffer_contents' ],
  374. filetype = 'some_filetype',
  375. modified = False )
  376. with patch( 'ycm.client.event_notification.EventNotification.'
  377. 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
  378. with MockVimBuffers( [ current_buffer, modified_buffer, unmodified_buffer ],
  379. current_buffer,
  380. ( 1, 5 ) ):
  381. ycm.OnBufferVisit()
  382. assert_that(
  383. # Positional arguments passed to PostDataToHandlerAsync.
  384. post_data_to_handler_async.call_args[ 0 ],
  385. contains(
  386. has_entries( {
  387. 'filepath': current_buffer_file,
  388. 'line_num': 1,
  389. 'column_num': 6,
  390. 'file_data': has_entries( {
  391. current_buffer_file: has_entries( {
  392. 'contents': 'current_buffer_contents\n',
  393. 'filetypes': [ 'some_filetype' ]
  394. } ),
  395. modified_buffer_file: has_entries( {
  396. 'contents': 'modified_buffer_contents\n',
  397. 'filetypes': [ 'some_filetype' ]
  398. } )
  399. } ),
  400. 'event_name': 'BufferVisit'
  401. } ),
  402. 'event_notification'
  403. )
  404. )
  405. @YouCompleteMeInstance()
  406. def EventNotification_BufferUnload_BuildRequestForDeletedAndUnsavedBuffers_test(
  407. ycm ):
  408. current_buffer_file = os.path.realpath( 'current_βuffer' )
  409. current_buffer = VimBuffer( name = current_buffer_file,
  410. number = 1,
  411. contents = [ 'current_buffer_contents' ],
  412. filetype = 'some_filetype',
  413. modified = True )
  414. deleted_buffer_file = os.path.realpath( 'deleted_βuffer' )
  415. deleted_buffer = VimBuffer( name = deleted_buffer_file,
  416. number = 2,
  417. contents = [ 'deleted_buffer_contents' ],
  418. filetype = 'some_filetype',
  419. modified = False )
  420. with patch( 'ycm.client.event_notification.EventNotification.'
  421. 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
  422. with MockVimBuffers( [ current_buffer, deleted_buffer ], current_buffer ):
  423. ycm.OnBufferUnload( deleted_buffer.number )
  424. assert_that(
  425. # Positional arguments passed to PostDataToHandlerAsync.
  426. post_data_to_handler_async.call_args[ 0 ],
  427. contains(
  428. has_entries( {
  429. 'filepath': deleted_buffer_file,
  430. 'line_num': 1,
  431. 'column_num': 1,
  432. 'file_data': has_entries( {
  433. current_buffer_file: has_entries( {
  434. 'contents': 'current_buffer_contents\n',
  435. 'filetypes': [ 'some_filetype' ]
  436. } ),
  437. deleted_buffer_file: has_entries( {
  438. 'contents': 'deleted_buffer_contents\n',
  439. 'filetypes': [ 'some_filetype' ]
  440. } )
  441. } ),
  442. 'event_name': 'BufferUnload'
  443. } ),
  444. 'event_notification'
  445. )
  446. )
  447. @patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
  448. fooGroup xxx foo bar
  449. links to Statement""" )
  450. @YouCompleteMeInstance( { 'g:ycm_seed_identifiers_with_syntax': 1 } )
  451. def EventNotification_FileReadyToParse_SyntaxKeywords_SeedWithCache_test(
  452. ycm, *args ):
  453. current_buffer = VimBuffer( name = 'current_buffer',
  454. filetype = 'some_filetype' )
  455. with patch( 'ycm.client.event_notification.EventNotification.'
  456. 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
  457. with MockVimBuffers( [ current_buffer ], current_buffer ):
  458. ycm.OnFileReadyToParse()
  459. assert_that(
  460. # Positional arguments passed to PostDataToHandlerAsync.
  461. post_data_to_handler_async.call_args[ 0 ],
  462. contains(
  463. has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
  464. 'event_notification'
  465. )
  466. )
  467. # Do not send again syntax keywords in subsequent requests.
  468. ycm.OnFileReadyToParse()
  469. assert_that(
  470. # Positional arguments passed to PostDataToHandlerAsync.
  471. post_data_to_handler_async.call_args[ 0 ],
  472. contains(
  473. is_not( has_key( 'syntax_keywords' ) ),
  474. 'event_notification'
  475. )
  476. )
  477. @patch( 'ycm.vimsupport.CaptureVimCommand', return_value = """
  478. fooGroup xxx foo bar
  479. links to Statement""" )
  480. @YouCompleteMeInstance( { 'g:ycm_seed_identifiers_with_syntax': 1 } )
  481. def EventNotification_FileReadyToParse_SyntaxKeywords_ClearCacheIfRestart_test(
  482. ycm, *args ):
  483. current_buffer = VimBuffer( name = 'current_buffer',
  484. filetype = 'some_filetype' )
  485. with patch( 'ycm.client.event_notification.EventNotification.'
  486. 'PostDataToHandlerAsync' ) as post_data_to_handler_async:
  487. with MockVimBuffers( [ current_buffer ], current_buffer ):
  488. ycm.OnFileReadyToParse()
  489. assert_that(
  490. # Positional arguments passed to PostDataToHandlerAsync.
  491. post_data_to_handler_async.call_args[ 0 ],
  492. contains(
  493. has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
  494. 'event_notification'
  495. )
  496. )
  497. # Send again the syntax keywords after restarting the server.
  498. ycm.RestartServer()
  499. WaitUntilReady()
  500. ycm.OnFileReadyToParse()
  501. assert_that(
  502. # Positional arguments passed to PostDataToHandlerAsync.
  503. post_data_to_handler_async.call_args[ 0 ],
  504. contains(
  505. has_entry( 'syntax_keywords', has_items( 'foo', 'bar' ) ),
  506. 'event_notification'
  507. )
  508. )