completion_info.test.vim 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. function! s:AssertInfoPopupNotVisible()
  2. call WaitForAssert( {-> assert_true(
  3. \ popup_findinfo() == 0 ||
  4. \ !popup_getpos( popup_findinfo() ).visible ) } )
  5. endfunction
  6. function! s:AssertInfoPopupVisible()
  7. call WaitForAssert( {-> assert_true(
  8. \ popup_findinfo() != 0 &&
  9. \ !empty( popup_getpos( popup_findinfo() ) ) &&
  10. \ popup_getpos( popup_findinfo() ).visible ) } )
  11. endfunction
  12. function! SetUp()
  13. let g:ycm_use_clangd = 1
  14. let g:ycm_confirm_extra_conf = 0
  15. let g:ycm_auto_trigger = 1
  16. let g:ycm_keep_logfiles = 1
  17. let g:ycm_log_level = 'DEBUG'
  18. let g:ycm_add_preview_to_completeopt = 'popup'
  19. call youcompleteme#test#setup#SetUp()
  20. endfunction
  21. function! TearDown()
  22. call youcompleteme#test#setup#CleanUp()
  23. endfunction
  24. exe 'source' expand( "<sfile>:p:h" ) .. '/completion.common.vim'
  25. function! Test_Using_Ondemand_Resolve()
  26. let debug_info = split( execute( 'YcmDebugInfo' ), "\n" )
  27. enew
  28. setf cpp
  29. call assert_equal( '', &completefunc )
  30. for line in debug_info
  31. if line =~# "^-- Resolve completions: "
  32. let ver = substitute( line, "^-- Resolve completions: ", "", "" )
  33. call assert_equal( 'On demand', ver, 'API version' )
  34. return
  35. endif
  36. endfor
  37. call assert_report( "Didn't find the resolve type in the YcmDebugInfo" )
  38. endfunction
  39. function! Test_ResolveCompletion_OnChange()
  40. call SkipIf( !exists( '*popup_findinfo' ), 'no popup_findinfo' )
  41. " Only the java completer actually uses the completion resolve
  42. call youcompleteme#test#setup#OpenFile(
  43. \ '/third_party/ycmd/ycmd/tests/java/testdata/simple_eclipse_project' .
  44. \ '/src/com/test/TestWithDocumentation.java', { 'delay': 15 } )
  45. call setpos( '.', [ 0, 6, 21 ] )
  46. " Required to trigger TextChangedI
  47. " https://github.com/vim/vim/issues/4665#event-2480928194
  48. call test_override( 'char_avail', 1 )
  49. function! Check1( id )
  50. call WaitForCompletion()
  51. call s:AssertInfoPopupNotVisible()
  52. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check2', [ 0 ] ) )
  53. endfunction
  54. let found_getAString = 0
  55. function! Check2( counter, id ) closure
  56. call WaitForCompletion()
  57. call s:AssertInfoPopupVisible()
  58. let info_popup_id = popup_findinfo()
  59. let compl = complete_info()
  60. let selected = compl.items[ compl.selected ]
  61. " All items should be resolved
  62. " NOTE: Even after resolving the item still has this as there's no way to
  63. " update the user data of the item at this point (need a vim change to do
  64. " that)
  65. call assert_true( has_key( json_decode( selected.user_data ),
  66. \ 'resolve' ) )
  67. if selected.word ==# 'getAString'
  68. " It's line 5 because we truncated the signature to fit it in
  69. call WaitForAssert( { ->
  70. \ assert_equal( [ 'MethodsWithDocumentation.getAString() : String',
  71. \ '',
  72. \ 'getAString() : String',
  73. \ '',
  74. \ 'Single line description.',
  75. \ ],
  76. \ getbufline( winbufnr( info_popup_id ), '1', '5' ) )
  77. \ } )
  78. let found_getAString += 1
  79. endif
  80. if a:counter < 10
  81. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check2', [ a:counter + 1 ] ) )
  82. else
  83. call feedkeys( "\<Esc>" )
  84. endif
  85. endfunction
  86. call FeedAndCheckMain( 'cw', funcref( 'Check1' ) )
  87. call assert_false( pumvisible(), 'pumvisible()' )
  88. call assert_equal( 1, found_getAString )
  89. call test_override( 'ALL', 0 )
  90. endfunction
  91. function! Test_DontResolveCompletion_AlreadyResolved()
  92. call SkipIf( !exists( '*popup_findinfo' ), 'no popup_findinfo' )
  93. " Only the java completer actually uses the completion resolve
  94. call youcompleteme#test#setup#OpenFile(
  95. \ '/third_party/ycmd/ycmd/tests/java/testdata/simple_eclipse_project' .
  96. \ '/src/com/test/TestWithDocumentation.java', { 'delay': 15 } )
  97. call setpos( '.', [ 0, 7, 12 ] )
  98. " Required to trigger TextChangedI
  99. " https://github.com/vim/vim/issues/4665#event-2480928194
  100. call test_override( 'char_avail', 1 )
  101. function! Check1( id )
  102. call WaitForCompletion()
  103. call CheckCompletionItems( [ 'hashCode' ], 'word' )
  104. call s:AssertInfoPopupNotVisible()
  105. call assert_equal( -1, complete_info().selected )
  106. let compl = complete_info()
  107. let hashCode = compl.items[ 0 ]
  108. call assert_equal( 1, len( compl.items ) )
  109. call assert_equal( 'hashCode', hashCode.word )
  110. call assert_false( has_key( json_decode( hashCode.user_data ),
  111. \ 'resolve' ) )
  112. call FeedAndCheckAgain( "\<Tab>", funcref( 'Check2' ) )
  113. endfunction
  114. function! Check2( id )
  115. call WaitForCompletion()
  116. call s:AssertInfoPopupVisible()
  117. let compl = complete_info()
  118. let selected = compl.items[ 0 ]
  119. call assert_equal( 1, len( compl.items ) )
  120. call assert_equal( 'hashCode', selected.word )
  121. call assert_false( has_key( json_decode( selected.user_data ),
  122. \ 'resolve' ) )
  123. call feedkeys( "\<Esc>" )
  124. endfunction
  125. call FeedAndCheckMain( 'C', funcref( 'Check1' ) )
  126. call assert_false( pumvisible(), 'pumvisible()' )
  127. call test_override( 'ALL', 0 )
  128. endfunction