comparison runtime/autoload/ccomplete.vim @ 22958:e7c125224b1a

Update runtime files Commit: https://github.com/vim/vim/commit/4466ad6baa22485abb1147aca3340cced4778a66 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 21 13:16:30 2020 +0100 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Sat, 21 Nov 2020 13:30:04 +0100
parents 1908e92b02fd
children edb7d53fc7e3
comparison
equal deleted inserted replaced
22957:80212aa40750 22958:e7c125224b1a
1 " Vim completion script 1 " Vim completion script
2 " Language: C 2 " Language: C
3 " Maintainer: Bram Moolenaar <Bram@vim.org> 3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2020 Apr 08 4 " Last Change: 2020 Nov 14
5 5
6 let s:cpo_save = &cpo 6 let s:cpo_save = &cpo
7 set cpo&vim 7 set cpo&vim
8 8
9 " This function is used for the 'omnifunc' option. 9 " This function is used for the 'omnifunc' option.
10 function! ccomplete#Complete(findstart, base) 10 func ccomplete#Complete(findstart, base)
11 if a:findstart 11 if a:findstart
12 " Locate the start of the item, including ".", "->" and "[...]". 12 " Locate the start of the item, including ".", "->" and "[...]".
13 let line = getline('.') 13 let line = getline('.')
14 let start = col('.') - 1 14 let start = col('.') - 1
15 let lastword = -1 15 let lastword = -1
242 endwhile 242 endwhile
243 243
244 return map(res, 's:Tagline2item(v:val, brackets)') 244 return map(res, 's:Tagline2item(v:val, brackets)')
245 endfunc 245 endfunc
246 246
247 function! s:GetAddition(line, match, memarg, bracket) 247 func s:GetAddition(line, match, memarg, bracket)
248 " Guess if the item is an array. 248 " Guess if the item is an array.
249 if a:bracket && match(a:line, a:match . '\s*\[') > 0 249 if a:bracket && match(a:line, a:match . '\s*\[') > 0
250 return '[' 250 return '['
251 endif 251 endif
252 252
258 else 258 else
259 return '.' 259 return '.'
260 endif 260 endif
261 endif 261 endif
262 return '' 262 return ''
263 endfunction 263 endfunc
264 264
265 " Turn the tag info "val" into an item for completion. 265 " Turn the tag info "val" into an item for completion.
266 " "val" is is an item in the list returned by taglist(). 266 " "val" is is an item in the list returned by taglist().
267 " If it is a variable we may add "." or "->". Don't do it for other types, 267 " If it is a variable we may add "." or "->". Don't do it for other types,
268 " such as a typedef, by not including the info that s:GetAddition() uses. 268 " such as a typedef, by not including the info that s:GetAddition() uses.
269 function! s:Tag2item(val) 269 func s:Tag2item(val)
270 let res = {'match': a:val['name']} 270 let res = {'match': a:val['name']}
271 271
272 let res['extra'] = s:Tagcmd2extra(a:val['cmd'], a:val['name'], a:val['filename']) 272 let res['extra'] = s:Tagcmd2extra(a:val['cmd'], a:val['name'], a:val['filename'])
273 273
274 let s = s:Dict2info(a:val) 274 let s = s:Dict2info(a:val)
287 let res['match'] = a:val['name'] . '(' 287 let res['match'] = a:val['name'] . '('
288 endif 288 endif
289 endif 289 endif
290 290
291 return res 291 return res
292 endfunction 292 endfunc
293 293
294 " Use all the items in dictionary for the "info" entry. 294 " Use all the items in dictionary for the "info" entry.
295 function! s:Dict2info(dict) 295 func s:Dict2info(dict)
296 let info = '' 296 let info = ''
297 for k in sort(keys(a:dict)) 297 for k in sort(keys(a:dict))
298 let info .= k . repeat(' ', 10 - len(k)) 298 let info .= k . repeat(' ', 10 - len(k))
299 if k == 'cmd' 299 if k == 'cmd'
300 let info .= substitute(matchstr(a:dict['cmd'], '/^\s*\zs.*\ze$/'), '\\\(.\)', '\1', 'g') 300 let info .= substitute(matchstr(a:dict['cmd'], '/^\s*\zs.*\ze$/'), '\\\(.\)', '\1', 'g')
305 endfor 305 endfor
306 return info 306 return info
307 endfunc 307 endfunc
308 308
309 " Parse a tag line and return a dictionary with items like taglist() 309 " Parse a tag line and return a dictionary with items like taglist()
310 function! s:ParseTagline(line) 310 func s:ParseTagline(line)
311 let l = split(a:line, "\t") 311 let l = split(a:line, "\t")
312 let d = {} 312 let d = {}
313 if len(l) >= 3 313 if len(l) >= 3
314 let d['name'] = l[0] 314 let d['name'] = l[0]
315 let d['filename'] = l[1] 315 let d['filename'] = l[1]
332 endif 332 endif
333 endfor 333 endfor
334 endif 334 endif
335 335
336 return d 336 return d
337 endfunction 337 endfunc
338 338
339 " Turn a match item "val" into an item for completion. 339 " Turn a match item "val" into an item for completion.
340 " "val['match']" is the matching item. 340 " "val['match']" is the matching item.
341 " "val['tagline']" is the tagline in which the last part was found. 341 " "val['tagline']" is the tagline in which the last part was found.
342 function! s:Tagline2item(val, brackets) 342 func s:Tagline2item(val, brackets)
343 let line = a:val['tagline'] 343 let line = a:val['tagline']
344 let add = s:GetAddition(line, a:val['match'], [a:val], a:brackets == '') 344 let add = s:GetAddition(line, a:val['match'], [a:val], a:brackets == '')
345 let res = {'word': a:val['match'] . a:brackets . add } 345 let res = {'word': a:val['match'] . a:brackets . add }
346 346
347 if has_key(a:val, 'info') 347 if has_key(a:val, 'info')
375 let s = matchstr(line, '[^\t]*\t[^\t]*\t\zs\(/^.*$/\|[^\t]*\)\ze\(;"\t\|\t\|$\)') 375 let s = matchstr(line, '[^\t]*\t[^\t]*\t\zs\(/^.*$/\|[^\t]*\)\ze\(;"\t\|\t\|$\)')
376 if s != '' 376 if s != ''
377 let res['menu'] = s:Tagcmd2extra(s, a:val['match'], matchstr(line, '[^\t]*\t\zs[^\t]*\ze\t')) 377 let res['menu'] = s:Tagcmd2extra(s, a:val['match'], matchstr(line, '[^\t]*\t\zs[^\t]*\ze\t'))
378 endif 378 endif
379 return res 379 return res
380 endfunction 380 endfunc
381 381
382 " Turn a command from a tag line to something that is useful in the menu 382 " Turn a command from a tag line to something that is useful in the menu
383 function! s:Tagcmd2extra(cmd, name, fname) 383 func s:Tagcmd2extra(cmd, name, fname)
384 if a:cmd =~ '^/^' 384 if a:cmd =~ '^/^'
385 " The command is a search command, useful to see what it is. 385 " The command is a search command, useful to see what it is.
386 let x = matchstr(a:cmd, '^/^\s*\zs.*\ze$/') 386 let x = matchstr(a:cmd, '^/^\s*\zs.*\ze$/')
387 let x = substitute(x, '\<' . a:name . '\>', '@@', '') 387 let x = substitute(x, '\<' . a:name . '\>', '@@', '')
388 let x = substitute(x, '\\\(.\)', '\1', 'g') 388 let x = substitute(x, '\\\(.\)', '\1', 'g')
393 else 393 else
394 " Not recognized, use command and file name. 394 " Not recognized, use command and file name.
395 let x = a:cmd . ' - ' . a:fname 395 let x = a:cmd . ' - ' . a:fname
396 endif 396 endif
397 return x 397 return x
398 endfunction 398 endfunc
399 399
400 " Find composing type in "lead" and match items[0] with it. 400 " Find composing type in "lead" and match items[0] with it.
401 " Repeat this recursively for items[1], if it's there. 401 " Repeat this recursively for items[1], if it's there.
402 " When resolving typedefs "depth" is used to avoid infinite recursion. 402 " When resolving typedefs "depth" is used to avoid infinite recursion.
403 " Return the list of matches. 403 " Return the list of matches.
404 function! s:Nextitem(lead, items, depth, all) 404 func s:Nextitem(lead, items, depth, all)
405 405
406 " Use the text up to the variable name and split it in tokens. 406 " Use the text up to the variable name and split it in tokens.
407 let tokens = split(a:lead, '\s\+\|\<') 407 let tokens = split(a:lead, '\s\+\|\<')
408 408
409 " Try to recognize the type of the variable. This is rough guessing... 409 " Try to recognize the type of the variable. This is rough guessing...
483 break 483 break
484 endif 484 endif
485 endfor 485 endfor
486 486
487 return res 487 return res
488 endfunction 488 endfunc
489 489
490 490
491 " Search for members of structure "typename" in tags files. 491 " Search for members of structure "typename" in tags files.
492 " Return a list with resulting matches. 492 " Return a list with resulting matches.
493 " Each match is a dictionary with "match" and "tagline" entries. 493 " Each match is a dictionary with "match" and "tagline" entries.
494 " When "all" is non-zero find all, otherwise just return 1 if there is any 494 " When "all" is non-zero find all, otherwise just return 1 if there is any
495 " member. 495 " member.
496 function! s:StructMembers(typename, items, all) 496 func s:StructMembers(typename, items, all)
497 " Todo: What about local structures? 497 " Todo: What about local structures?
498 let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) 498 let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")'))
499 if fnames == '' 499 if fnames == ''
500 return [] 500 return []
501 endif 501 endif
584 return s:SearchMembers(matches, a:items[idx :], a:all) 584 return s:SearchMembers(matches, a:items[idx :], a:all)
585 endif 585 endif
586 586
587 " Failed to find anything. 587 " Failed to find anything.
588 return [] 588 return []
589 endfunction 589 endfunc
590 590
591 " For matching members, find matches for following items. 591 " For matching members, find matches for following items.
592 " When "all" is non-zero find all, otherwise just return 1 if there is any 592 " When "all" is non-zero find all, otherwise just return 1 if there is any
593 " member. 593 " member.
594 function! s:SearchMembers(matches, items, all) 594 func s:SearchMembers(matches, items, all)
595 let res = [] 595 let res = []
596 for i in range(len(a:matches)) 596 for i in range(len(a:matches))
597 let typename = '' 597 let typename = ''
598 if has_key(a:matches[i], 'dict') 598 if has_key(a:matches[i], 'dict')
599 if has_key(a:matches[i].dict, 'typename') 599 if has_key(a:matches[i].dict, 'typename')