1
0

signature_help.test.vim 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. let s:timer_interval = 2000
  2. function! s:WaitForSigHelpAvailable( filetype )
  3. let tries = 0
  4. call WaitFor( {-> s:_CheckSignatureHelpAvailable( a:filetype ) } )
  5. while py3eval(
  6. \ 'ycm_state._signature_help_available_requests[ '
  7. \ . 'vim.eval( "a:filetype" ) ].Response() == "PENDING"' ) &&
  8. \ tries < 10
  9. " Force sending another request
  10. py3 ycm_state._signature_help_available_requests[
  11. \ vim.eval( 'a:filetype' ) ].Start( vim.eval( 'a:filetype' ) )
  12. call WaitFor( {-> s:_CheckSignatureHelpAvailable( a:filetype ) } )
  13. let tries += 1
  14. endwhile
  15. call ch_log( "Signature help is avaialble now for " . a:filetype )
  16. endfunction
  17. function! s:_ClearSigHelp()
  18. pythonx _sh_state = sh.UpdateSignatureHelp( _sh_state, {} )
  19. call assert_true( pyxeval( '_sh_state.popup_win_id is None' ),
  20. \ 'win id none with emtpy' )
  21. unlet! s:popup_win_id
  22. endfunction
  23. function! s:_CheckSignatureHelpAvailable( filetype )
  24. return pyxeval(
  25. \ 'ycm_state.SignatureHelpAvailableRequestComplete('
  26. \ . ' vim.eval( "a:filetype" ), False )' )
  27. endfunction
  28. function s:_GetSigHelpWinID()
  29. call WaitForAssert( {->
  30. \ assert_true(
  31. \ pyxeval(
  32. \ 'ycm_state.SignatureHelpRequestReady()'
  33. \ ),
  34. \ 'sig help request reqdy'
  35. \ )
  36. \ } )
  37. call WaitForAssert( {->
  38. \ assert_true(
  39. \ pyxeval(
  40. \ 'ycm_state._signature_help_state.popup_win_id is not None'
  41. \ ),
  42. \ 'popup_win_id'
  43. \ )
  44. \ } )
  45. let s:popup_win_id = pyxeval( 'ycm_state._signature_help_state.popup_win_id' )
  46. return s:popup_win_id
  47. endfunction
  48. function! s:_CheckSigHelpAtPos( sh, cursor, pos )
  49. call setpos( '.', [ 0 ] + a:cursor )
  50. redraw
  51. pythonx _sh_state = sh.UpdateSignatureHelp( _sh_state,
  52. \ vim.eval( 'a:sh' ) )
  53. redraw
  54. let winid = pyxeval( '_sh_state.popup_win_id' )
  55. call youcompleteme#test#popup#CheckPopupPosition( winid, a:pos )
  56. endfunction
  57. function! SetUp()
  58. let g:ycm_use_clangd = 1
  59. let g:ycm_confirm_extra_conf = 0
  60. let g:ycm_auto_trigger = 1
  61. let g:ycm_keep_logfiles = 1
  62. let g:ycm_log_level = 'DEBUG'
  63. call youcompleteme#test#setup#SetUp()
  64. pythonx from ycm import signature_help as sh
  65. pythonx _sh_state = sh.SignatureHelpState()
  66. endfunction
  67. function! TearDown()
  68. call s:_ClearSigHelp()
  69. call youcompleteme#test#setup#CleanUp()
  70. endfunction
  71. " This is how we might do screen dump tests
  72. " function! Test_Compl()
  73. " let setup =<< trim END
  74. " edit ../third_party/ycmd/ycmd/tests/clangd/testdata/general_fallback/make_drink.cc
  75. " call setpos( '.', [ 0, 7, 27 ] )
  76. " END
  77. " call writefile( setup, 'Xtest_Compl' )
  78. " let vim = RunVimInTerminal( '-Nu vimrc -S Xtest_Compl', {} )
  79. "
  80. " function! Test() closure
  81. " " Wait for Vim to be ready
  82. " call term_sendkeys( vim, "cl:" )
  83. " call term_wait( vim )
  84. " call VerifyScreenDump( vim, "signature_help_Test_Compl_01", {} )
  85. " endfunction
  86. "
  87. " call WaitForAssert( {-> Test()} )
  88. "
  89. " " clean up
  90. " call StopVimInTerminal(vim)
  91. " call delete('XtestPopup')
  92. " endfunction
  93. function! Test_Enough_Screen_Space()
  94. call assert_true( &lines >= 25,
  95. \ &lines . " is not enough rows. need 25." )
  96. call assert_true( &columns >= 80,
  97. \ &columns . " is not enough columns. need 80." )
  98. endfunction
  99. function! Test_Signatures_After_Trigger()
  100. call youcompleteme#test#setup#OpenFile(
  101. \ '/test/testdata/vim/mixed_filetype.vim',
  102. \ { 'native_ft': 0, 'force_delay': v:true } )
  103. call WaitFor( {-> s:_CheckSignatureHelpAvailable( 'vim' ) } )
  104. call s:WaitForSigHelpAvailable( 'python' )
  105. call setpos( '.', [ 0, 3, 17 ] )
  106. " Required to trigger TextChangedI
  107. " https://github.com/vim/vim/issues/4665#event-2480928194
  108. call test_override( 'char_avail', 1 )
  109. " Must do the checks in a timer callback because we need to stay in insert
  110. " mode until done. Use a func because it's big enough (a lambda is a little
  111. " neater in many contexts).
  112. function! Check( id ) closure
  113. call WaitForAssert( {->
  114. \ assert_true(
  115. \ pyxeval(
  116. \ 'ycm_state.SignatureHelpRequestReady()'
  117. \ ),
  118. \ 'sig help request ready'
  119. \ )
  120. \ } )
  121. call WaitForAssert( {->
  122. \ assert_true(
  123. \ pyxeval(
  124. \ "bool( ycm_state.GetSignatureHelpResponse()[ 'signatures' ] )"
  125. \ ),
  126. \ 'sig help request has signatures'
  127. \ )
  128. \ } )
  129. call WaitForAssert( {->
  130. \ assert_true(
  131. \ pyxeval(
  132. \ 'ycm_state._signature_help_state.popup_win_id is not None'
  133. \ ),
  134. \ 'popup_win_id'
  135. \ )
  136. \ } )
  137. let popup_win_id = pyxeval( 'ycm_state._signature_help_state.popup_win_id' )
  138. let pos = win_screenpos( popup_win_id )
  139. call assert_false( pos == [ 0, 0 ] )
  140. " Exit insert mode to ensure the test continues
  141. call test_override( 'ALL', 0 )
  142. call feedkeys( "\<ESC>" )
  143. endfunction
  144. call assert_false( pyxeval( 'ycm_state.SignatureHelpRequestReady()' ) )
  145. call timer_start( s:timer_interval, funcref( 'Check' ) )
  146. call feedkeys( 'cl(', 'ntx!' )
  147. call assert_false( pumvisible(), 'pumvisible()' )
  148. call WaitForAssert( {->
  149. \ assert_true(
  150. \ pyxeval(
  151. \ 'ycm_state._signature_help_state.popup_win_id is None'
  152. \ ),
  153. \ 'popup_win_id'
  154. \ )
  155. \ } )
  156. call test_override( 'ALL', 0 )
  157. delfunc! Check
  158. endfunction
  159. function! Test_Signatures_With_PUM_NoSigns()
  160. call youcompleteme#test#setup#OpenFile(
  161. \ '/third_party/ycmd/ycmd/tests/clangd/testdata/general_fallback'
  162. \ . '/make_drink.cc', {} )
  163. call s:WaitForSigHelpAvailable( 'cpp' )
  164. " Make sure that error signs don't shift the window
  165. setlocal signcolumn=no
  166. call setpos( '.', [ 0, 7, 13 ] )
  167. " Required to trigger TextChangedI
  168. " https://github.com/vim/vim/issues/4665#event-2480928194
  169. call test_override( 'char_avail', 1 )
  170. function! Check2( id ) closure
  171. call WaitForAssert( {-> assert_true( pumvisible() ) } )
  172. call WaitForAssert( {-> assert_notequal( [], complete_info().items ) } )
  173. call assert_equal( 7, pum_getpos().row )
  174. redraw
  175. " NOTE: anchor is 0-based
  176. call assert_equal( 6,
  177. \ pyxeval( 'ycm_state._signature_help_state.anchor[0]' ) )
  178. call assert_equal( 13,
  179. \ pyxeval( 'ycm_state._signature_help_state.anchor[1]' ) )
  180. " Popup is shifted due to 80 column screen
  181. call youcompleteme#test#popup#CheckPopupPosition(
  182. \ s:_GetSigHelpWinID(),
  183. \ { 'line': 5, 'col': 5 } )
  184. call test_override( 'ALL', 0 )
  185. call feedkeys( "\<ESC>", 't' )
  186. endfunction
  187. " Must do the checks in a timer callback because we need to stay in insert
  188. " mode until done.
  189. function! Check( id ) closure
  190. call WaitForAssert( {->
  191. \ assert_true(
  192. \ pyxeval(
  193. \ 'ycm_state._signature_help_state.popup_win_id is not None'
  194. \ ),
  195. \ 'popup_win_id'
  196. \ )
  197. \ } )
  198. " Popup is shifted left due to 80 char screen
  199. call youcompleteme#test#popup#CheckPopupPosition(
  200. \ s:_GetSigHelpWinID(),
  201. \ { 'line': 5, 'col': 5 } )
  202. call timer_start( s:timer_interval, funcref( 'Check2' ) )
  203. call feedkeys( ' TypeOfD', 't' )
  204. endfunction
  205. call assert_false( pyxeval( 'ycm_state.SignatureHelpRequestReady()' ) )
  206. call timer_start( s:timer_interval, funcref( 'Check' ) )
  207. call feedkeys( 'C(', 'ntx!' )
  208. call WaitForAssert( {->
  209. \ assert_true(
  210. \ pyxeval(
  211. \ 'ycm_state._signature_help_state.popup_win_id is None'
  212. \ ),
  213. \ 'popup_win_id'
  214. \ )
  215. \ } )
  216. call test_override( 'ALL', 0 )
  217. delfunc! Check
  218. delfunc! Check2
  219. endfunction
  220. function! Test_Signatures_With_PUM_Signs()
  221. call youcompleteme#test#setup#OpenFile(
  222. \ '/third_party/ycmd/ycmd/tests/clangd/testdata/general_fallback'
  223. \ . '/make_drink.cc', {} )
  224. call s:WaitForSigHelpAvailable( 'cpp' )
  225. " Make sure that sign causes the popup to shift
  226. setlocal signcolumn=auto
  227. call setpos( '.', [ 0, 7, 13 ] )
  228. " Required to trigger TextChangedI
  229. " https://github.com/vim/vim/issues/4665#event-2480928194
  230. call test_override( 'char_avail', 1 )
  231. function Check2( id ) closure
  232. call WaitForAssert( {-> assert_true( pumvisible() ) } )
  233. call WaitForAssert( {-> assert_notequal( [], complete_info().items ) } )
  234. call assert_equal( 7, pum_getpos().row )
  235. redraw
  236. " NOTE: anchor is 0-based
  237. call assert_equal( 6,
  238. \ pyxeval( 'ycm_state._signature_help_state.anchor[0]' ) )
  239. call assert_equal( 13,
  240. \ pyxeval( 'ycm_state._signature_help_state.anchor[1]' ) )
  241. " Sign column is shown, popup shifts to the right 2 screen columns
  242. " Then shifts back due to 80 character screen width
  243. " FIXME: This test was supposed to show the shifting right. Write another
  244. " one which uses a much smaller popup to do that.
  245. call youcompleteme#test#popup#CheckPopupPosition(
  246. \ s:_GetSigHelpWinID(),
  247. \ { 'line': 5, 'col': 5 } )
  248. call test_override( 'ALL', 0 )
  249. call feedkeys( "\<ESC>", 't' )
  250. endfunction
  251. " Must do the checks in a timer callback because we need to stay in insert
  252. " mode until done.
  253. function! Check( id ) closure
  254. call WaitForAssert( {->
  255. \ assert_true(
  256. \ pyxeval(
  257. \ 'ycm_state._signature_help_state.popup_win_id is not None'
  258. \ ),
  259. \ 'popup_win_id'
  260. \ )
  261. \ } )
  262. " Popup is shifted left due to 80 char screen
  263. call youcompleteme#test#popup#CheckPopupPosition(
  264. \ s:_GetSigHelpWinID(),
  265. \ { 'line': 5, 'col': 5 } )
  266. call timer_start( s:timer_interval, funcref( 'Check2' ) )
  267. call feedkeys( ' TypeOfD', 't' )
  268. endfunction
  269. call assert_false( pyxeval( 'ycm_state.SignatureHelpRequestReady()' ) )
  270. call timer_start( s:timer_interval, funcref( 'Check' ) )
  271. call feedkeys( 'C(', 'ntx!' )
  272. call WaitForAssert( {->
  273. \ assert_true(
  274. \ pyxeval(
  275. \ 'ycm_state._signature_help_state.popup_win_id is None'
  276. \ ),
  277. \ 'popup_win_id'
  278. \ )
  279. \ } )
  280. call test_override( 'ALL', 0 )
  281. delfunc! Check
  282. delfunc! Check2
  283. endfunction
  284. function! Test_Placement_Simple()
  285. call assert_true( &lines >= 25, "Enough rows" )
  286. call assert_true( &columns >= 25, "Enough columns" )
  287. let X = join( map( range( 0, &columns - 1 ), {->'X'} ), '' )
  288. for i in range( 0, &lines )
  289. call append( line('$'), X )
  290. endfor
  291. " Delete the blank line that is always added to a buffer
  292. 0delete
  293. call s:_ClearSigHelp()
  294. let v_sh = {
  295. \ 'activeSignature': 0,
  296. \ 'activeParameter': 0,
  297. \ 'signatures': [
  298. \ { 'label': 'test function', 'parameters': [] }
  299. \ ]
  300. \ }
  301. " When displayed in the middle with plenty of space
  302. call s:_CheckSigHelpAtPos( v_sh, [ 10, 3 ], {
  303. \ 'line': 9,
  304. \ 'col': 1
  305. \ } )
  306. " Confirm that anchoring works (i.e. it doesn't move!)
  307. call s:_CheckSigHelpAtPos( v_sh, [ 20, 10 ], {
  308. \ 'line': 9,
  309. \ 'col': 1
  310. \ } )
  311. call s:_ClearSigHelp()
  312. " Window slides from left of screen
  313. call s:_CheckSigHelpAtPos( v_sh, [ 10, 2 ], {
  314. \ 'line': 9,
  315. \ 'col': 1,
  316. \ } )
  317. call s:_ClearSigHelp()
  318. " Window slides from left of screen
  319. call s:_CheckSigHelpAtPos( v_sh, [ 10, 1 ], {
  320. \ 'line': 9,
  321. \ 'col': 1,
  322. \ } )
  323. call s:_ClearSigHelp()
  324. " Cursor at top-left of window
  325. call s:_CheckSigHelpAtPos( v_sh, [ 1, 1 ], {
  326. \ 'line': 2,
  327. \ 'col': 1,
  328. \ } )
  329. call s:_ClearSigHelp()
  330. " Cursor at top-right of window
  331. call s:_CheckSigHelpAtPos( v_sh, [ 1, &columns ], {
  332. \ 'line': 2,
  333. \ 'col': &columns - len( "test function" ) - 1,
  334. \ } )
  335. call s:_ClearSigHelp()
  336. " Bottom-left of window
  337. call s:_CheckSigHelpAtPos( v_sh, [ &lines + 1, 1 ], {
  338. \ 'line': &lines - 2,
  339. \ 'col': 1,
  340. \ } )
  341. call s:_ClearSigHelp()
  342. " Bottom-right of window
  343. call s:_CheckSigHelpAtPos( v_sh, [ &lines + 1, &columns ], {
  344. \ 'line': &lines - 2,
  345. \ 'col': &columns - len( "test function" ) - 1,
  346. \ } )
  347. call s:_ClearSigHelp()
  348. call popup_clear()
  349. endfunction
  350. function! Test_Placement_MultiLine()
  351. call assert_true( &lines >= 25, "Enough rows" )
  352. call assert_true( &columns >= 25, "Enough columns" )
  353. let X = join( map( range( 0, &columns - 1 ), {->'X'} ), '' )
  354. for i in range( 0, &lines )
  355. call append( line('$'), X )
  356. endfor
  357. " Delete the blank line that is always added to a buffer
  358. 0delete
  359. call s:_ClearSigHelp()
  360. let v_sh = {
  361. \ 'activeSignature': 0,
  362. \ 'activeParameter': 0,
  363. \ 'signatures': [
  364. \ { 'label': 'test function', 'parameters': [] },
  365. \ { 'label': 'toast function', 'parameters': [
  366. \ { 'label': [ 0, 5 ] }
  367. \ ] },
  368. \ ]
  369. \ }
  370. " When displayed in the middle with plenty of space
  371. call s:_CheckSigHelpAtPos( v_sh, [ 10, 3 ], {
  372. \ 'line': 8,
  373. \ 'col': 1
  374. \ } )
  375. " Confirm that anchoring works (i.e. it doesn't move!)
  376. call s:_CheckSigHelpAtPos( v_sh, [ 20, 10 ], {
  377. \ 'line': 8,
  378. \ 'col': 1
  379. \ } )
  380. call s:_ClearSigHelp()
  381. " Window slides from left of screen
  382. call s:_CheckSigHelpAtPos( v_sh, [ 10, 2 ], {
  383. \ 'line': 8,
  384. \ 'col': 1,
  385. \ } )
  386. call s:_ClearSigHelp()
  387. " Window slides from left of screen
  388. call s:_CheckSigHelpAtPos( v_sh, [ 10, 1 ], {
  389. \ 'line': 8,
  390. \ 'col': 1,
  391. \ } )
  392. call s:_ClearSigHelp()
  393. " Cursor at top-left of window
  394. call s:_CheckSigHelpAtPos( v_sh, [ 1, 1 ], {
  395. \ 'line': 2,
  396. \ 'col': 1,
  397. \ } )
  398. call s:_ClearSigHelp()
  399. " Cursor at top-right of window
  400. call s:_CheckSigHelpAtPos( v_sh, [ 1, &columns ], {
  401. \ 'line': 2,
  402. \ 'col': &columns - len( "toast function" ) - 1,
  403. \ } )
  404. call s:_ClearSigHelp()
  405. " Bottom-left of window
  406. call s:_CheckSigHelpAtPos( v_sh, [ &lines + 1, 1 ], {
  407. \ 'line': &lines - 3,
  408. \ 'col': 1,
  409. \ } )
  410. call s:_ClearSigHelp()
  411. " Bottom-right of window
  412. call s:_CheckSigHelpAtPos( v_sh, [ &lines + 1, &columns ], {
  413. \ 'line': &lines - 3,
  414. \ 'col': &columns - len( "toast function" ) - 1,
  415. \ } )
  416. call s:_ClearSigHelp()
  417. call popup_clear()
  418. endfunction
  419. function! Test_Signatures_TopLine()
  420. call youcompleteme#test#setup#OpenFile( 'test/testdata/python/test.py', {} )
  421. call s:WaitForSigHelpAvailable( 'python' )
  422. call setpos( '.', [ 0, 1, 24 ] )
  423. call test_override( 'char_avail', 1 )
  424. function! Check( id ) closure
  425. call youcompleteme#test#popup#CheckPopupPosition(
  426. \ s:_GetSigHelpWinID(),
  427. \ { 'line': 2, 'col': 23 } )
  428. call test_override( 'ALL', 0 )
  429. call feedkeys( "\<ESC>" )
  430. endfunction
  431. call timer_start( s:timer_interval, funcref( 'Check' ) )
  432. call feedkeys( 'cl(', 'ntx!' )
  433. call test_override( 'ALL', 0 )
  434. delfun! Check
  435. endfunction
  436. function! Test_Signatures_TopLineWithPUM()
  437. call youcompleteme#test#setup#OpenFile( 'test/testdata/python/test.py', {} )
  438. call s:WaitForSigHelpAvailable( 'python' )
  439. call setpos( '.', [ 0, 1, 24 ] )
  440. call test_override( 'char_avail', 1 )
  441. function! CheckSigHelpAndTriggerCompletion( id ) closure
  442. " Popup placed below the cursor
  443. call youcompleteme#test#popup#CheckPopupPosition(
  444. \ s:_GetSigHelpWinID(),
  445. \ { 'line': 2, 'col': 23 } )
  446. " Push more characters into the typeahead buffer to trigger insert mode
  447. " completion.
  448. "
  449. " Nte for some reason the first semantic response can take quite some time,
  450. " and if our timer fires before then, the test just fails. so we take 2
  451. " seconds here.
  452. call timer_start( s:timer_interval,
  453. \ funcref( 'CheckCompletionVisibleAndSigHelpHidden' ) )
  454. call feedkeys( " os.", 't' )
  455. endfunction
  456. function! CheckCompletionVisibleAndSigHelpHidden( id ) closure
  457. " Completion popup now visible, overlapping where the sig help popup was
  458. redraw
  459. call WaitForAssert( {-> assert_true( pumvisible() ) } )
  460. call assert_equal( 1, get( pum_getpos(), 'row', -1 ) )
  461. call assert_equal( 28, get( pum_getpos(), 'col', -1 ) )
  462. " so we hide the sig help popup.
  463. call WaitForAssert( {->
  464. \ assert_true(
  465. \ pyxeval(
  466. \ 'ycm_state._signature_help_state.popup_win_id is None'
  467. \ ),
  468. \ 'popup_win_id'
  469. \ )
  470. \ } )
  471. call youcompleteme#test#popup#CheckPopupPosition( s:popup_win_id, {} )
  472. " We're done in insert mode now.
  473. call test_override( 'ALL', 0 )
  474. call feedkeys( "\<ESC>", 't' )
  475. endfunction
  476. " Edit the line and trigger signature help
  477. call timer_start( s:timer_interval,
  478. \ funcref( 'CheckSigHelpAndTriggerCompletion' ) )
  479. call feedkeys( 'C(', 'ntx!' )
  480. call test_override( 'ALL', 0 )
  481. delfunc! CheckSigHelpAndTriggerCompletion
  482. delfunc! CheckCompletionVisibleAndSigHelpHidden
  483. endfunction
  484. function! SetUp_Test_Semantic_Completion_Popup_With_Sig_Help()
  485. set signcolumn=no
  486. call youcompleteme#test#setup#PushGlobal( 'ycm_add_preview_to_completeopt',
  487. \ 'popup' )
  488. endfunction
  489. function! Test_Semantic_Completion_Popup_With_Sig_Help()
  490. call youcompleteme#test#setup#OpenFile(
  491. \ 'test/testdata/cpp/complete_with_sig_help.cc', {} )
  492. call s:WaitForSigHelpAvailable( 'cpp' )
  493. call setpos( '.', [ 0, 10, 1 ] )
  494. " Required to trigger TextChangedI
  495. " https://github.com/vim/vim/issues/4665#event-2480928194
  496. call test_override( 'char_avail', 1 )
  497. function! Check( ... )
  498. call youcompleteme#test#popup#CheckPopupPosition(
  499. \ s:_GetSigHelpWinID(),
  500. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  501. call FeedAndCheckAgain( '"", t.', funcref( 'Check2' ) )
  502. endfunction
  503. function! Check2( ... )
  504. call WaitForCompletion()
  505. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  506. \ 'this_is_a_thing' ] )
  507. call youcompleteme#test#popup#CheckPopupPosition(
  508. \ s:_GetSigHelpWinID(),
  509. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  510. call CheckCurrentLine( 'printf("", t.' )
  511. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check3' ) )
  512. endfunction
  513. function! Check3( ... )
  514. " Ensure that we didn't make an error?
  515. call WaitForCompletion()
  516. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  517. \ 'this_is_a_thing' ] )
  518. call youcompleteme#test#popup#CheckPopupPosition(
  519. \ s:_GetSigHelpWinID(),
  520. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  521. let compl = complete_info()
  522. let selected = compl.items[ compl.selected ]
  523. call assert_equal( 'that_is_a_thing', selected.word )
  524. call WaitFor( {->
  525. \ popup_findinfo() > 0 &&
  526. \ has_key( popup_getpos( popup_findinfo() ), 'visible' ) } )
  527. let info_popup_id = popup_findinfo()
  528. call assert_true( popup_getpos( info_popup_id )[ 'visible' ] )
  529. call CheckCurrentLine( 'printf("", t.that_is_a_thing' )
  530. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check4' ) )
  531. endfunction
  532. function! Check4( ... )
  533. " Ensure that we didn't make an error?
  534. call WaitForCompletion()
  535. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  536. \ 'this_is_a_thing' ] )
  537. call youcompleteme#test#popup#CheckPopupPosition(
  538. \ s:_GetSigHelpWinID(),
  539. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  540. let info_popup_id = popup_findinfo()
  541. let compl = complete_info()
  542. let selected = compl.items[ compl.selected ]
  543. call assert_equal( 'this_is_a_thing', selected.word )
  544. call assert_true( popup_getpos( info_popup_id )[ 'visible' ] )
  545. call CheckCurrentLine( 'printf("", t.this_is_a_thing' )
  546. call feedkeys( "\<Esc>" )
  547. endfunction
  548. call FeedAndCheckMain( 'iprintf(', funcref( 'Check' ) )
  549. call test_override( 'ALL', 0 )
  550. delfunc! Check
  551. delfunc! Check2
  552. delfunc! Check3
  553. delfunc! Check4
  554. endfunction
  555. function! TearDown_Test_Semantic_Completion_Popup_With_Sig_Help()
  556. set signcolumn&
  557. call youcompleteme#test#setup#PopGlobal( 'ycm_add_preview_to_completeopt' )
  558. endfunction
  559. function! SetUp_Test_Semantic_Completion_Popup_With_Sig_Help_EmptyBuf()
  560. set signcolumn=no
  561. call youcompleteme#test#setup#PushGlobal( 'ycm_filetype_whitelist', {
  562. \ '*': 1,
  563. \ 'ycm_nofiletype': 1
  564. \ } )
  565. call youcompleteme#test#setup#PushGlobal( 'ycm_filetype_blacklist', {} )
  566. call youcompleteme#test#setup#PushGlobal( 'ycm_add_preview_to_completeopt',
  567. \ 'popup' )
  568. endfunction
  569. function! Test_Semantic_Completion_Popup_With_Sig_Help_EmptyBuf()
  570. call youcompleteme#test#setup#OpenFile(
  571. \ 'test/testdata/cpp/complete_with_sig_help.cc', {} )
  572. call s:WaitForSigHelpAvailable( 'cpp' )
  573. call setpos( '.', [ 0, 10, 1 ] )
  574. " Required to trigger TextChangedI
  575. " https://github.com/vim/vim/issues/4665#event-2480928194
  576. call test_override( 'char_avail', 1 )
  577. function! Check( ... )
  578. call youcompleteme#test#popup#CheckPopupPosition(
  579. \ s:_GetSigHelpWinID(),
  580. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  581. call FeedAndCheckAgain( '"", t.', funcref( 'Check2' ) )
  582. endfunction
  583. function! Check2( ... )
  584. call WaitForCompletion()
  585. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  586. \ 'this_is_a_thing' ] )
  587. call youcompleteme#test#popup#CheckPopupPosition(
  588. \ s:_GetSigHelpWinID(),
  589. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  590. call CheckCurrentLine( 'printf("", t.' )
  591. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check3' ) )
  592. endfunction
  593. function! Check3( ... )
  594. " Ensure that we didn't make an error?
  595. call WaitForCompletion()
  596. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  597. \ 'this_is_a_thing' ] )
  598. " XFAIL: Currently the test fails here because the signature help popup
  599. " disappears when the info_popup is displayed. This seems to be because we
  600. " end up triggering a FileReadyToParse event inside the info popup (or the
  601. " signature popup) due to what appears to be a vim bug - the `buftype` of
  602. " the buffer inside the popup starts off as `popup` but shimers to `""` at
  603. " some point, making us think it's ok to parse it with ycm_nofiletype is
  604. " whitelisted.
  605. call youcompleteme#test#popup#CheckPopupPosition(
  606. \ s:_GetSigHelpWinID(),
  607. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  608. let compl = complete_info()
  609. let selected = compl.items[ compl.selected ]
  610. call assert_equal( 'that_is_a_thing', selected.word )
  611. call WaitFor( {->
  612. \ popup_findinfo() > 0 &&
  613. \ has_key( popup_getpos( popup_findinfo() ), 'visible' ) } )
  614. let info_popup_id = popup_findinfo()
  615. call assert_true( popup_getpos( info_popup_id )[ 'visible' ] )
  616. call CheckCurrentLine( 'printf("", t.that_is_a_thing' )
  617. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check4' ) )
  618. endfunction
  619. function! Check4( ... )
  620. " Ensure that we didn't make an error?
  621. call WaitForCompletion()
  622. call CheckCompletionItemsContainsExactly( [ 'that_is_a_thing',
  623. \ 'this_is_a_thing' ] )
  624. call youcompleteme#test#popup#CheckPopupPosition(
  625. \ s:_GetSigHelpWinID(),
  626. \ { 'line': 9, 'col': 6, 'visible': 1 } )
  627. let info_popup_id = popup_findinfo()
  628. let compl = complete_info()
  629. let selected = compl.items[ compl.selected ]
  630. call assert_equal( 'this_is_a_thing', selected.word )
  631. call assert_true( popup_getpos( info_popup_id )[ 'visible' ] )
  632. call CheckCurrentLine( 'printf("", t.this_is_a_thing' )
  633. call feedkeys( "\<Esc>" )
  634. endfunction
  635. call FeedAndCheckMain( 'iprintf(', funcref( 'Check' ) )
  636. call test_override( 'ALL', 0 )
  637. delfunc! Check
  638. delfunc! Check2
  639. delfunc! Check3
  640. delfunc! Check4
  641. throw 'SKIPPED: XFAIL: This test is expected to fail due to '
  642. \ .. 'https://github.com/ycm-core/YouCompleteMe/issues/3781'
  643. endfunction
  644. function! TearDown_Test_Semantic_Completion_Popup_With_Sig_Help_EmptyBuf()
  645. set signcolumn&
  646. call youcompleteme#test#setup#PopGlobal( 'ycm_filetype_whitelist' )
  647. call youcompleteme#test#setup#PopGlobal( 'ycm_filetype_blacklist' )
  648. call youcompleteme#test#setup#PopGlobal( 'ycm_add_preview_to_completeopt' )
  649. endfunction
  650. function! SetUp_Test_Signature_Help_Manual_HideShow()
  651. imap <silent> kjkj <Plug>(YCMToggleSignatureHelp)
  652. endfunction
  653. function! Test_Signature_Help_Manual_HideShow()
  654. call youcompleteme#test#setup#OpenFile(
  655. \ 'test/testdata/cpp/complete_with_sig_help.cc', {} )
  656. call s:WaitForSigHelpAvailable( 'cpp' )
  657. call setpos( '.', [ 0, 10, 1 ] )
  658. call test_override( 'char_avail', 1 )
  659. function! Check( ... )
  660. call youcompleteme#test#popup#CheckPopupPosition(
  661. \ s:_GetSigHelpWinID(),
  662. \ { 'line': 9, 'col': 8, 'visible': 1 } )
  663. call FeedAndCheckAgain( 'kjkj', funcref( 'Check2' ) )
  664. endfunction
  665. function! Check2( ... )
  666. call youcompleteme#test#popup#CheckPopupPosition(
  667. \ s:_GetSigHelpWinID(),
  668. \ { 'line': 9, 'col': 8, 'visible': 0 } )
  669. call FeedAndCheckAgain( 'kjkj', funcref( 'Check3' ) )
  670. endfunction
  671. function! Check3( ... )
  672. call youcompleteme#test#popup#CheckPopupPosition(
  673. \ s:_GetSigHelpWinID(),
  674. \ { 'line': 9, 'col': 8, 'visible': 1 } )
  675. call feedkeys( "\<Esc>" )
  676. endfunction
  677. call FeedAndCheckMain( 'iprintf(', funcref( 'Check' ) )
  678. call test_override( 'ALL', 0 )
  679. delfunc! Check
  680. delfunc! Check2
  681. delfunc! Check3
  682. endfunction
  683. function! TearDown_Test_Signature_Help_Manual_HideShow()
  684. silent! iunmap kjkj
  685. endfunction
  686. function! SetUp_Test_Signature_Help_Manual_NoSigs()
  687. imap <silent> kjkj <Plug>(YCMToggleSignatureHelp)
  688. endfunction
  689. function! Test_Signature_Help_Manual_NoSigs()
  690. call youcompleteme#test#setup#OpenFile(
  691. \ 'test/testdata/cpp/complete_with_sig_help.cc', {} )
  692. call s:WaitForSigHelpAvailable( 'cpp' )
  693. call setpos( '.', [ 0, 10, 1 ] )
  694. call test_override( 'char_avail', 1 )
  695. let popup_id = 0
  696. function! CheckSigs( ... ) closure
  697. let popup_id = s:_GetSigHelpWinID()
  698. call youcompleteme#test#popup#CheckPopupPosition(
  699. \ s:_GetSigHelpWinID(),
  700. \ { 'line': 9, 'col': 8, 'visible': 1 } )
  701. call FeedAndCheckAgain( ')', funcref( 'CheckSigsClosed' ) )
  702. endfunction
  703. function! CheckSigsClosed( ... ) closure
  704. call youcompleteme#test#popup#CheckPopupPosition(
  705. \ popup_id,
  706. \ {} )
  707. call FeedAndCheckAgain( 'kjkj', funcref( 'CheckStillOK' ) )
  708. endfunction
  709. function! CheckStillOK( ... ) closure
  710. call youcompleteme#test#popup#CheckPopupPosition(
  711. \ popup_id,
  712. \ {} )
  713. call feedkeys( "\<Esc>" )
  714. endfunction
  715. call FeedAndCheckMain( 'iprintf(', funcref( 'CheckSigs' ) )
  716. call test_override( 'ALL', 0 )
  717. delfunc! CheckSigs
  718. delfunc! CheckSigsClosed
  719. delfunc! CheckStillOK
  720. endfunction
  721. function! TearDown_Test_Signature_Help_Manual_NoSigs()
  722. silent! iunmap kjkj
  723. endfunction