Mercurial > vim
comparison runtime/autoload/ccomplete.vim @ 27492:4789f29c9595
Update runtime files
Commit: https://github.com/vim/vim/commit/c4573eb12dba6a062af28ee0b8938d1521934ce4
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 31 15:40:56 2022 +0000
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 31 Jan 2022 16:45:03 +0100 |
parents | edb7d53fc7e3 |
children | 4027cefc2aab |
comparison
equal
deleted
inserted
replaced
27491:1836c6b25222 | 27492:4789f29c9595 |
---|---|
2 | 2 |
3 # Vim completion script | 3 # Vim completion script |
4 # Language: C | 4 # Language: C |
5 # Maintainer: Bram Moolenaar <Bram@vim.org> | 5 # Maintainer: Bram Moolenaar <Bram@vim.org> |
6 # Rewritten in Vim9 script by github user lacygoill | 6 # Rewritten in Vim9 script by github user lacygoill |
7 # Last Change: 2021 Dec 27 | 7 # Last Change: 2022 Jan 31 |
8 | 8 |
9 var prepended: string | 9 var prepended: string |
10 var grepCache: dict<list<dict<any>>> | 10 var grepCache: dict<list<dict<any>>> |
11 | 11 |
12 # This function is used for the 'omnifunc' option. | 12 # This function is used for the 'omnifunc' option. |
13 def ccomplete#Complete(findstart: bool, abase: string): any # {{{1 | 13 export def Complete(findstart: bool, abase: string): any # {{{1 |
14 if findstart | 14 if findstart |
15 # Locate the start of the item, including ".", "->" and "[...]". | 15 # Locate the start of the item, including ".", "->" and "[...]". |
16 var line: string = getline('.') | 16 var line: string = getline('.') |
17 var start: number = charcol('.') - 1 | 17 var start: number = charcol('.') - 1 |
18 var lastword: number = -1 | 18 var lastword: number = -1 |
200 ->filter((_, v: dict<any>): bool => | 200 ->filter((_, v: dict<any>): bool => |
201 !v->has_key('static') | 201 !v->has_key('static') |
202 || !v['static'] | 202 || !v['static'] |
203 || bufnr('%') == bufnr(v['filename'])) | 203 || bufnr('%') == bufnr(v['filename'])) |
204 | 204 |
205 res = extendnew(res, tags->map((_, v: dict<any>) => Tag2item(v))) | 205 res = res->extend(tags->map((_, v: dict<any>) => Tag2item(v))) |
206 endif | 206 endif |
207 | 207 |
208 if len(res) == 0 | 208 if len(res) == 0 |
209 # Find the variable in the tags file(s) | 209 # Find the variable in the tags file(s) |
210 var diclist: list<dict<any>> = taglist('^' .. items[0] .. '$') | 210 var diclist: list<dict<any>> = taglist('^' .. items[0] .. '$') |
214 | 214 |
215 res = [] | 215 res = [] |
216 for i: number in len(diclist)->range() | 216 for i: number in len(diclist)->range() |
217 # New ctags has the "typeref" field. Patched version has "typename". | 217 # New ctags has the "typeref" field. Patched version has "typename". |
218 if diclist[i]->has_key('typename') | 218 if diclist[i]->has_key('typename') |
219 res = extendnew(res, diclist[i]['typename']->StructMembers(items[1 :], true)) | 219 res = res->extend(diclist[i]['typename']->StructMembers(items[1 :], true)) |
220 elseif diclist[i]->has_key('typeref') | 220 elseif diclist[i]->has_key('typeref') |
221 res = extendnew(res, diclist[i]['typeref']->StructMembers(items[1 :], true)) | 221 res = res->extend(diclist[i]['typeref']->StructMembers(items[1 :], true)) |
222 endif | 222 endif |
223 | 223 |
224 # For a variable use the command, which must be a search pattern that | 224 # For a variable use the command, which must be a search pattern that |
225 # shows the declaration of the variable. | 225 # shows the declaration of the variable. |
226 if diclist[i]['kind'] == 'v' | 226 if diclist[i]['kind'] == 'v' |
227 var line: string = diclist[i]['cmd'] | 227 var line: string = diclist[i]['cmd'] |
228 if line[: 1] == '/^' | 228 if line[: 1] == '/^' |
229 var col: number = line->charidx(match(line, '\<' .. items[0] .. '\>')) | 229 var col: number = line->charidx(match(line, '\<' .. items[0] .. '\>')) |
230 res = extendnew(res, line[2 : col - 1]->Nextitem(items[1 :], 0, true)) | 230 res = res->extend(line[2 : col - 1]->Nextitem(items[1 :], 0, true)) |
231 endif | 231 endif |
232 endif | 232 endif |
233 endfor | 233 endfor |
234 endif | 234 endif |
235 | 235 |
254 | 254 |
255 return res->map((_, v: dict<any>): dict<string> => Tagline2item(v, brackets)) | 255 return res->map((_, v: dict<any>): dict<string> => Tagline2item(v, brackets)) |
256 enddef | 256 enddef |
257 | 257 |
258 def GetAddition( # {{{1 | 258 def GetAddition( # {{{1 |
259 line: string, | 259 line: string, |
260 match: string, | 260 match: string, |
261 memarg: list<dict<any>>, | 261 memarg: list<dict<any>>, |
262 bracket: bool | 262 bracket: bool): string |
263 ): string | |
264 # Guess if the item is an array. | 263 # Guess if the item is an array. |
265 if bracket && match(line, match .. '\s*\[') > 0 | 264 if bracket && match(line, match .. '\s*\[') > 0 |
266 return '[' | 265 return '[' |
267 endif | 266 endif |
268 | 267 |
401 endif | 400 endif |
402 return res | 401 return res |
403 enddef | 402 enddef |
404 | 403 |
405 def Tagcmd2extra( # {{{1 | 404 def Tagcmd2extra( # {{{1 |
406 cmd: string, | 405 cmd: string, |
407 name: string, | 406 name: string, |
408 fname: string | 407 fname: string): string |
409 ): string | |
410 # Turn a command from a tag line to something that is useful in the menu | 408 # Turn a command from a tag line to something that is useful in the menu |
411 var x: string | 409 var x: string |
412 if cmd =~ '^/^' | 410 if cmd =~ '^/^' |
413 # The command is a search command, useful to see what it is. | 411 # The command is a search command, useful to see what it is. |
414 x = cmd | 412 x = cmd |
425 endif | 423 endif |
426 return x | 424 return x |
427 enddef | 425 enddef |
428 | 426 |
429 def Nextitem( # {{{1 | 427 def Nextitem( # {{{1 |
430 lead: string, | 428 lead: string, |
431 items: list<string>, | 429 items: list<string>, |
432 depth: number, | 430 depth: number, |
433 all: bool | 431 all: bool): list<dict<string>> |
434 ): list<dict<string>> | |
435 # Find composing type in "lead" and match items[0] with it. | 432 # Find composing type in "lead" and match items[0] with it. |
436 # Repeat this recursively for items[1], if it's there. | 433 # Repeat this recursively for items[1], if it's there. |
437 # When resolving typedefs "depth" is used to avoid infinite recursion. | 434 # When resolving typedefs "depth" is used to avoid infinite recursion. |
438 # Return the list of matches. | 435 # Return the list of matches. |
439 | 436 |
471 for tagidx: number in len(diclist)->range() | 468 for tagidx: number in len(diclist)->range() |
472 var item: dict<any> = diclist[tagidx] | 469 var item: dict<any> = diclist[tagidx] |
473 | 470 |
474 # New ctags has the "typeref" field. Patched version has "typename". | 471 # New ctags has the "typeref" field. Patched version has "typename". |
475 if item->has_key('typeref') | 472 if item->has_key('typeref') |
476 res = extendnew(res, item['typeref']->StructMembers(items, all)) | 473 res = res->extend(item['typeref']->StructMembers(items, all)) |
477 continue | 474 continue |
478 endif | 475 endif |
479 if item->has_key('typename') | 476 if item->has_key('typename') |
480 res = extendnew(res, item['typename']->StructMembers(items, all)) | 477 res = res->extend(item['typename']->StructMembers(items, all)) |
481 continue | 478 continue |
482 endif | 479 endif |
483 | 480 |
484 # Only handle typedefs here. | 481 # Only handle typedefs here. |
485 if item['kind'] != 't' | 482 if item['kind'] != 't' |
509 name = cmdtokens[ti] | 506 name = cmdtokens[ti] |
510 break | 507 break |
511 endif | 508 endif |
512 endfor | 509 endfor |
513 if name != '' | 510 if name != '' |
514 res = extendnew(res, StructMembers(cmdtokens[0] .. ':' .. name, items, all)) | 511 res = res->extend(StructMembers(cmdtokens[0] .. ':' .. name, items, all)) |
515 endif | 512 endif |
516 elseif depth < 10 | 513 elseif depth < 10 |
517 # Could be "typedef other_T some_T". | 514 # Could be "typedef other_T some_T". |
518 res = extendnew(res, cmdtokens[0]->Nextitem(items, depth + 1, all)) | 515 res = res->extend(cmdtokens[0]->Nextitem(items, depth + 1, all)) |
519 endif | 516 endif |
520 endif | 517 endif |
521 endif | 518 endif |
522 endfor | 519 endfor |
523 if len(res) > 0 | 520 if len(res) > 0 |
527 | 524 |
528 return res | 525 return res |
529 enddef | 526 enddef |
530 | 527 |
531 def StructMembers( # {{{1 | 528 def StructMembers( # {{{1 |
532 atypename: string, | 529 atypename: string, |
533 items: list<string>, | 530 items: list<string>, |
534 all: bool | 531 all: bool): list<dict<string>> |
535 ): list<dict<string>> | |
536 | 532 |
537 # Search for members of structure "typename" in tags files. | 533 # Search for members of structure "typename" in tags files. |
538 # Return a list with resulting matches. | 534 # Return a list with resulting matches. |
539 # Each match is a dictionary with "match" and "tagline" entries. | 535 # Each match is a dictionary with "match" and "tagline" entries. |
540 # When "all" is true find all, otherwise just return 1 if there is any member. | 536 # When "all" is true find all, otherwise just return 1 if there is any member. |
639 # Failed to find anything. | 635 # Failed to find anything. |
640 return [] | 636 return [] |
641 enddef | 637 enddef |
642 | 638 |
643 def SearchMembers( # {{{1 | 639 def SearchMembers( # {{{1 |
644 matches: list<dict<any>>, | 640 matches: list<dict<any>>, |
645 items: list<string>, | 641 items: list<string>, |
646 all: bool | 642 all: bool): list<dict<string>> |
647 ): list<dict<string>> | |
648 | 643 |
649 # For matching members, find matches for following items. | 644 # For matching members, find matches for following items. |
650 # When "all" is true find all, otherwise just return 1 if there is any member. | 645 # When "all" is true find all, otherwise just return 1 if there is any member. |
651 var res: list<dict<string>> | 646 var res: list<dict<string>> |
652 for i: number in len(matches)->range() | 647 for i: number in len(matches)->range() |
672 typename = line->matchstr('[^\t]*', eb) | 667 typename = line->matchstr('[^\t]*', eb) |
673 endif | 668 endif |
674 endif | 669 endif |
675 | 670 |
676 if typename != '' | 671 if typename != '' |
677 res = extendnew(res, StructMembers(typename, items, all)) | 672 res = res->extend(StructMembers(typename, items, all)) |
678 else | 673 else |
679 # Use the search command (the declaration itself). | 674 # Use the search command (the declaration itself). |
680 var sb: number = line->match('\t\zs/^') | 675 var sb: number = line->match('\t\zs/^') |
681 var s: number = charidx(line, sb) | 676 var s: number = charidx(line, sb) |
682 if s > 0 | 677 if s > 0 |
683 var e: number = line | 678 var e: number = line |
684 ->charidx(match(line, '\<' .. matches[i]['match'] .. '\>', sb)) | 679 ->charidx(match(line, '\<' .. matches[i]['match'] .. '\>', sb)) |
685 if e > 0 | 680 if e > 0 |
686 res = extendnew(res, line[s : e - 1]->Nextitem(items, 0, all)) | 681 res = res->extend(line[s : e - 1]->Nextitem(items, 0, all)) |
687 endif | 682 endif |
688 endif | 683 endif |
689 endif | 684 endif |
690 if !all && len(res) > 0 | 685 if !all && len(res) > 0 |
691 break | 686 break |