File: completion.vim

package info (click to toggle)
vim-youcompleteme 0%2B20230109%2Bgit7620d87%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,404 kB
  • sloc: python: 10,569; sh: 203; cpp: 121; makefile: 24; f90: 5; xml: 1
file content (98 lines) | stat: -rw-r--r-- 2,475 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function! CheckCompletionItemsContainsExactly( expected_props, ... )
  let prop = 'abbr'
  if a:0 > 0
    let prop = a:1
  endif

  let items = complete_info( [ 'items' ] )[ 'items' ]
  let abbrs = []
  for item in items
    call add( abbrs, get( item, prop ) )
  endfor

  return assert_equal( a:expected_props,
                     \ abbrs,
                     \ 'not matched: '
                     \ .. string( a:expected_props )
                     \ .. ' against '
                     \ .. prop
                     \ .. ' in '
                     \ .. string( items )
                     \ .. ' matching '
                     \ .. string( abbrs ) )
endfunction

function! CheckCompletionItemsHasItems( expected_props, ... )
  let prop = 'abbr'
  if a:0 > 0
    let prop = a:1
  endif

  let items = complete_info( [ 'items' ] )[ 'items' ]
  let abbrs = []
  for item in items
    call add( abbrs, get( item, prop ) )
  endfor

  let result = 0
  for expected in a:expected_props
    if index( abbrs, expected ) < 0
      call assert_report( "Didn't find item with "
                        \ .. prop
                        \ .. '="'
                        \ .. expected
                        \ .. '" in completion list: '
                        \ .. string( abbrs ) )
      let result += 1
    endif
  endfor

  return result
endfunction

function! IndexOfCompletionItemInList( item, ... )
  let prop = 'abbr'
  if a:0 > 0
    let prop = a:1
  endif

  let items = complete_info( [ 'items' ] )[ 'items' ]
  let abbrs = []
  let idx = 0
  while idx < len( items )
    if get( items[ idx ], prop ) == a:item
      return idx
    endif
    let idx += 1
  endwhile

  call assert_report( 'Did not find item '
                    \ . string( a:item )
                    \ . ' in completion info list' )
  return -1
endfunction


function! FeedAndCheckMain( keys, func )
  call timer_start( 500, a:func )
  call feedkeys( a:keys, 'tx!' )
endfunction

function! FeedAndCheckAgain( keys, func )
  call timer_start( 500, a:func )
  call feedkeys( a:keys )
endfunction

function! WaitForCompletion()
  call WaitForAssert( {->
        \ assert_true( pyxeval( 'ycm_state.GetCurrentCompletionRequest() is not None' ) )
        \ } )
  call WaitForAssert( {->
        \ assert_true( pyxeval( 'ycm_state.CompletionRequestReady()' ) )
        \ } )
  redraw
  call WaitForAssert( {->
        \ assert_true( pumvisible(), 'pumvisible()' )
        \ }, 10000 )
endfunction