annotate runtime/autoload/ccomplete.vim @ 14324:b4ea70c0eb82

Added tag v8.1.0177 for changeset 9df95cf9ea7e09a29ef408dda88ddc40a6559994
author Christian Brabandt <cb@256bit.org>
date Tue, 10 Jul 2018 19:45:06 +0200
parents 11d40fc82f11
children 34fd018452ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
1 " Vim completion script
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
2 " Language: C
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
3682
11d40fc82f11 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
4 " Last Change: 2012 Jun 20
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
5
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2152
diff changeset
6 let s:cpo_save = &cpo
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2152
diff changeset
7 set cpo&vim
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
8
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
9 " This function is used for the 'omnifunc' option.
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
10 function! ccomplete#Complete(findstart, base)
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
11 if a:findstart
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
12 " Locate the start of the item, including ".", "->" and "[...]".
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
13 let line = getline('.')
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
14 let start = col('.') - 1
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
15 let lastword = -1
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
16 while start > 0
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
17 if line[start - 1] =~ '\w'
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
18 let start -= 1
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
19 elseif line[start - 1] =~ '\.'
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
20 if lastword == -1
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
21 let lastword = start
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
22 endif
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
23 let start -= 1
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
24 elseif start > 1 && line[start - 2] == '-' && line[start - 1] == '>'
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
25 if lastword == -1
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
26 let lastword = start
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
27 endif
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
28 let start -= 2
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
29 elseif line[start - 1] == ']'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
30 " Skip over [...].
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
31 let n = 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
32 let start -= 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
33 while start > 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
34 let start -= 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
35 if line[start] == '['
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
36 if n == 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
37 break
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
38 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
39 let n -= 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
40 elseif line[start] == ']' " nested []
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
41 let n += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
42 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
43 endwhile
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
44 else
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
45 break
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
46 endif
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
47 endwhile
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
48
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
49 " Return the column of the last word, which is going to be changed.
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
50 " Remember the text that comes before it in s:prepended.
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
51 if lastword == -1
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
52 let s:prepended = ''
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
53 return start
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
54 endif
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
55 let s:prepended = strpart(line, start, lastword - start)
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
56 return lastword
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
57 endif
52e76e2b5b65 updated for version 7.0140
vimboss
parents:
diff changeset
58
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
59 " Return list of matches.
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
60
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
61 let base = s:prepended . a:base
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
62
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
63 " Don't do anything for an empty base, would result in all the tags in the
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
64 " tags file.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
65 if base == ''
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
66 return []
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
67 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
68
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
69 " init cache for vimgrep to empty
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
70 let s:grepCache = {}
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
71
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
72 " Split item in words, keep empty word after "." or "->".
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
73 " "aa" -> ['aa'], "aa." -> ['aa', ''], "aa.bb" -> ['aa', 'bb'], etc.
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
74 " We can't use split, because we need to skip nested [...].
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
75 let items = []
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
76 let s = 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
77 while 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
78 let e = match(base, '\.\|->\|\[', s)
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
79 if e < 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
80 if s == 0 || base[s - 1] != ']'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
81 call add(items, strpart(base, s))
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
82 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
83 break
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
84 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
85 if s == 0 || base[s - 1] != ']'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
86 call add(items, strpart(base, s, e - s))
548
f43150a669dc updated for version 7.0155
vimboss
parents: 523
diff changeset
87 endif
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
88 if base[e] == '.'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
89 let s = e + 1 " skip over '.'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
90 elseif base[e] == '-'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
91 let s = e + 2 " skip over '->'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
92 else
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
93 " Skip over [...].
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
94 let n = 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
95 let s = e
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
96 let e += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
97 while e < len(base)
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
98 if base[e] == ']'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
99 if n == 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
100 break
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
101 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
102 let n -= 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
103 elseif base[e] == '[' " nested [...]
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
104 let n += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
105 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
106 let e += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
107 endwhile
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
108 let e += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
109 call add(items, strpart(base, s, e - s))
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
110 let s = e
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
111 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
112 endwhile
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
113
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
114 " Find the variable items[0].
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
115 " 1. in current function (like with "gd")
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
116 " 2. in tags file(s) (like with ":tag")
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
117 " 3. in current file (like with "gD")
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
118 let res = []
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
119 if searchdecl(items[0], 0, 1) == 0
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
120 " Found, now figure out the type.
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
121 " TODO: join previous line if it makes sense
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
122 let line = getline('.')
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
123 let col = col('.')
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
124 if stridx(strpart(line, 0, col), ';') != -1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
125 " Handle multiple declarations on the same line.
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
126 let col2 = col - 1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
127 while line[col2] != ';'
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
128 let col2 -= 1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
129 endwhile
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
130 let line = strpart(line, col2 + 1)
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
131 let col -= col2
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
132 endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
133 if stridx(strpart(line, 0, col), ',') != -1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
134 " Handle multiple declarations on the same line in a function
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
135 " declaration.
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
136 let col2 = col - 1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
137 while line[col2] != ','
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
138 let col2 -= 1
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
139 endwhile
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
140 if strpart(line, col2 + 1, col - col2 - 1) =~ ' *[^ ][^ ]* *[^ ]'
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
141 let line = strpart(line, col2 + 1)
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
142 let col -= col2
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
143 endif
18ee39301b82 updated for version 7.2a
vimboss
parents: 876
diff changeset
144 endif
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
145 if len(items) == 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
146 " Completing one word and it's a local variable: May add '[', '.' or
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
147 " '->'.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
148 let match = items[0]
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
149 let kind = 'v'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
150 if match(line, '\<' . match . '\s*\[') > 0
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
151 let match .= '['
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
152 else
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
153 let res = s:Nextitem(strpart(line, 0, col), [''], 0, 1)
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
154 if len(res) > 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
155 " There are members, thus add "." or "->".
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
156 if match(line, '\*[ \t(]*' . match . '\>') > 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
157 let match .= '->'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
158 else
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
159 let match .= '.'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
160 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
161 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
162 endif
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
163 let res = [{'match': match, 'tagline' : '', 'kind' : kind, 'info' : line}]
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
164 else
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
165 " Completing "var.", "var.something", etc.
2152
b9e314fe473f Updated runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1624
diff changeset
166 let res = s:Nextitem(strpart(line, 0, col), items[1:], 0, 1)
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
167 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
168 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
169
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
170 if len(items) == 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
171 " Only one part, no "." or "->": complete from tags file.
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
172 let tags = taglist('^' . base)
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
173
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
174 " Remove members, these can't appear without something in front.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
175 call filter(tags, 'has_key(v:val, "kind") ? v:val["kind"] != "m" : 1')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
176
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
177 " Remove static matches in other files.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
178 call filter(tags, '!has_key(v:val, "static") || !v:val["static"] || bufnr("%") == bufnr(v:val["filename"])')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
179
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
180 call extend(res, map(tags, 's:Tag2item(v:val)'))
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
181 endif
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
182
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
183 if len(res) == 0
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
184 " Find the variable in the tags file(s)
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
185 let diclist = taglist('^' . items[0] . '$')
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
186
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
187 " Remove members, these can't appear without something in front.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
188 call filter(diclist, 'has_key(v:val, "kind") ? v:val["kind"] != "m" : 1')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
189
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
190 let res = []
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
191 for i in range(len(diclist))
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
192 " New ctags has the "typeref" field. Patched version has "typename".
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
193 if has_key(diclist[i], 'typename')
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
194 call extend(res, s:StructMembers(diclist[i]['typename'], items[1:], 1))
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
195 elseif has_key(diclist[i], 'typeref')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
196 call extend(res, s:StructMembers(diclist[i]['typeref'], items[1:], 1))
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
197 endif
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
198
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
199 " For a variable use the command, which must be a search pattern that
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
200 " shows the declaration of the variable.
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
201 if diclist[i]['kind'] == 'v'
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
202 let line = diclist[i]['cmd']
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
203 if line[0] == '/' && line[1] == '^'
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 548
diff changeset
204 let col = match(line, '\<' . items[0] . '\>')
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
205 call extend(res, s:Nextitem(strpart(line, 2, col - 2), items[1:], 0, 1))
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
206 endif
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
207 endif
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
208 endfor
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
209 endif
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
210
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
211 if len(res) == 0 && searchdecl(items[0], 1) == 0
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
212 " Found, now figure out the type.
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
213 " TODO: join previous line if it makes sense
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
214 let line = getline('.')
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
215 let col = col('.')
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
216 let res = s:Nextitem(strpart(line, 0, col), items[1:], 0, 1)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
217 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
218
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
219 " If the last item(s) are [...] they need to be added to the matches.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
220 let last = len(items) - 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
221 let brackets = ''
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
222 while last >= 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
223 if items[last][0] != '['
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
224 break
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
225 endif
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
226 let brackets = items[last] . brackets
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
227 let last -= 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
228 endwhile
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
229
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
230 return map(res, 's:Tagline2item(v:val, brackets)')
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
231 endfunc
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
232
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
233 function! s:GetAddition(line, match, memarg, bracket)
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
234 " Guess if the item is an array.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
235 if a:bracket && match(a:line, a:match . '\s*\[') > 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
236 return '['
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
237 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
238
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
239 " Check if the item has members.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
240 if len(s:SearchMembers(a:memarg, [''], 0)) > 0
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
241 " If there is a '*' before the name use "->".
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
242 if match(a:line, '\*[ \t(]*' . a:match . '\>') > 0
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
243 return '->'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
244 else
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
245 return '.'
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
246 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
247 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
248 return ''
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
249 endfunction
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
250
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
251 " Turn the tag info "val" into an item for completion.
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
252 " "val" is is an item in the list returned by taglist().
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
253 " If it is a variable we may add "." or "->". Don't do it for other types,
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
254 " such as a typedef, by not including the info that s:GetAddition() uses.
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
255 function! s:Tag2item(val)
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
256 let res = {'match': a:val['name']}
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
257
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
258 let res['extra'] = s:Tagcmd2extra(a:val['cmd'], a:val['name'], a:val['filename'])
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
259
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
260 let s = s:Dict2info(a:val)
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
261 if s != ''
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
262 let res['info'] = s
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
263 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
264
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
265 let res['tagline'] = ''
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
266 if has_key(a:val, "kind")
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
267 let kind = a:val['kind']
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
268 let res['kind'] = kind
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
269 if kind == 'v'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
270 let res['tagline'] = "\t" . a:val['cmd']
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
271 let res['dict'] = a:val
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
272 elseif kind == 'f'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
273 let res['match'] = a:val['name'] . '('
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
274 endif
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
275 endif
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
276
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
277 return res
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
278 endfunction
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
279
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
280 " Use all the items in dictionary for the "info" entry.
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
281 function! s:Dict2info(dict)
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
282 let info = ''
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
283 for k in sort(keys(a:dict))
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
284 let info .= k . repeat(' ', 10 - len(k))
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
285 if k == 'cmd'
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
286 let info .= substitute(matchstr(a:dict['cmd'], '/^\s*\zs.*\ze$/'), '\\\(.\)', '\1', 'g')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
287 else
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
288 let info .= a:dict[k]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
289 endif
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
290 let info .= "\n"
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
291 endfor
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
292 return info
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
293 endfunc
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
294
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
295 " Parse a tag line and return a dictionary with items like taglist()
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
296 function! s:ParseTagline(line)
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
297 let l = split(a:line, "\t")
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
298 let d = {}
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
299 if len(l) >= 3
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
300 let d['name'] = l[0]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
301 let d['filename'] = l[1]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
302 let d['cmd'] = l[2]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
303 let n = 2
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
304 if l[2] =~ '^/'
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
305 " Find end of cmd, it may contain Tabs.
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
306 while n < len(l) && l[n] !~ '/;"$'
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
307 let n += 1
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
308 let d['cmd'] .= " " . l[n]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
309 endwhile
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
310 endif
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
311 for i in range(n + 1, len(l) - 1)
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
312 if l[i] == 'file:'
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
313 let d['static'] = 1
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
314 elseif l[i] !~ ':'
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
315 let d['kind'] = l[i]
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
316 else
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
317 let d[matchstr(l[i], '[^:]*')] = matchstr(l[i], ':\zs.*')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
318 endif
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
319 endfor
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
320 endif
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
321
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
322 return d
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
323 endfunction
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
324
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
325 " Turn a match item "val" into an item for completion.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
326 " "val['match']" is the matching item.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
327 " "val['tagline']" is the tagline in which the last part was found.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
328 function! s:Tagline2item(val, brackets)
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
329 let line = a:val['tagline']
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
330 let add = s:GetAddition(line, a:val['match'], [a:val], a:brackets == '')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
331 let res = {'word': a:val['match'] . a:brackets . add }
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
332
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
333 if has_key(a:val, 'info')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
334 " Use info from Tag2item().
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
335 let res['info'] = a:val['info']
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
336 else
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
337 " Parse the tag line and add each part to the "info" entry.
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
338 let s = s:Dict2info(s:ParseTagline(line))
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
339 if s != ''
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
340 let res['info'] = s
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
341 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
342 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
343
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
344 if has_key(a:val, 'kind')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
345 let res['kind'] = a:val['kind']
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
346 elseif add == '('
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
347 let res['kind'] = 'f'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
348 else
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
349 let s = matchstr(line, '\t\(kind:\)\=\zs\S\ze\(\t\|$\)')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
350 if s != ''
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
351 let res['kind'] = s
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
352 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
353 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
354
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 654
diff changeset
355 if has_key(a:val, 'extra')
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
356 let res['menu'] = a:val['extra']
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
357 return res
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 654
diff changeset
358 endif
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
359
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
360 " Isolate the command after the tag and filename.
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
361 let s = matchstr(line, '[^\t]*\t[^\t]*\t\zs\(/^.*$/\|[^\t]*\)\ze\(;"\t\|\t\|$\)')
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
362 if s != ''
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
363 let res['menu'] = s:Tagcmd2extra(s, a:val['match'], matchstr(line, '[^\t]*\t\zs[^\t]*\ze\t'))
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
364 endif
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
365 return res
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
366 endfunction
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
367
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
368 " Turn a command from a tag line to something that is useful in the menu
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
369 function! s:Tagcmd2extra(cmd, name, fname)
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
370 if a:cmd =~ '^/^'
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
371 " The command is a search command, useful to see what it is.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
372 let x = matchstr(a:cmd, '^/^\s*\zs.*\ze$/')
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
373 let x = substitute(x, '\<' . a:name . '\>', '@@', '')
666
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
374 let x = substitute(x, '\\\(.\)', '\1', 'g')
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
375 let x = x . ' - ' . a:fname
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
376 elseif a:cmd =~ '^\d*$'
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
377 " The command is a line number, the file name is more useful.
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
378 let x = a:fname . ' - ' . a:cmd
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
379 else
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
380 " Not recognized, use command and file name.
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
381 let x = a:cmd . ' - ' . a:fname
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
382 endif
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
383 return x
0137e7c3d31b updated for version 7.0196
vimboss
parents: 659
diff changeset
384 endfunction
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
385
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
386 " Find composing type in "lead" and match items[0] with it.
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
387 " Repeat this recursively for items[1], if it's there.
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
388 " When resolving typedefs "depth" is used to avoid infinite recursion.
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
389 " Return the list of matches.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
390 function! s:Nextitem(lead, items, depth, all)
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
391
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
392 " Use the text up to the variable name and split it in tokens.
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
393 let tokens = split(a:lead, '\s\+\|\<')
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
394
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
395 " Try to recognize the type of the variable. This is rough guessing...
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
396 let res = []
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
397 for tidx in range(len(tokens))
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
398
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
399 " Skip tokens starting with a non-ID character.
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
400 if tokens[tidx] !~ '^\h'
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
401 continue
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
402 endif
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
403
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
404 " Recognize "struct foobar" and "union foobar".
860
2fe516aa3710 updated for version 7.0g02
vimboss
parents: 800
diff changeset
405 " Also do "class foobar" when it's C++ after all (doesn't work very well
2fe516aa3710 updated for version 7.0g02
vimboss
parents: 800
diff changeset
406 " though).
2fe516aa3710 updated for version 7.0g02
vimboss
parents: 800
diff changeset
407 if (tokens[tidx] == 'struct' || tokens[tidx] == 'union' || tokens[tidx] == 'class') && tidx + 1 < len(tokens)
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
408 let res = s:StructMembers(tokens[tidx] . ':' . tokens[tidx + 1], a:items, a:all)
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
409 break
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
410 endif
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
411
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
412 " TODO: add more reserved words
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
413 if index(['int', 'short', 'char', 'float', 'double', 'static', 'unsigned', 'extern'], tokens[tidx]) >= 0
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
414 continue
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
415 endif
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
416
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
417 " Use the tags file to find out if this is a typedef.
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
418 let diclist = taglist('^' . tokens[tidx] . '$')
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
419 for tagidx in range(len(diclist))
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
420 let item = diclist[tagidx]
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
421
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
422 " New ctags has the "typeref" field. Patched version has "typename".
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
423 if has_key(item, 'typeref')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
424 call extend(res, s:StructMembers(item['typeref'], a:items, a:all))
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
425 continue
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
426 endif
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
427 if has_key(item, 'typename')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
428 call extend(res, s:StructMembers(item['typename'], a:items, a:all))
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
429 continue
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
430 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
431
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
432 " Only handle typedefs here.
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
433 if item['kind'] != 't'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
434 continue
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
435 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
436
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
437 " Skip matches local to another file.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
438 if has_key(item, 'static') && item['static'] && bufnr('%') != bufnr(item['filename'])
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
439 continue
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
440 endif
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
441
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
442 " For old ctags we recognize "typedef struct aaa" and
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
443 " "typedef union bbb" in the tags file command.
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
444 let cmd = item['cmd']
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
445 let ei = matchend(cmd, 'typedef\s\+')
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
446 if ei > 1
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
447 let cmdtokens = split(strpart(cmd, ei), '\s\+\|\<')
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
448 if len(cmdtokens) > 1
860
2fe516aa3710 updated for version 7.0g02
vimboss
parents: 800
diff changeset
449 if cmdtokens[0] == 'struct' || cmdtokens[0] == 'union' || cmdtokens[0] == 'class'
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
450 let name = ''
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
451 " Use the first identifier after the "struct" or "union"
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
452 for ti in range(len(cmdtokens) - 1)
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
453 if cmdtokens[ti] =~ '^\w'
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
454 let name = cmdtokens[ti]
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
455 break
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
456 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
457 endfor
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
458 if name != ''
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
459 call extend(res, s:StructMembers(cmdtokens[0] . ':' . name, a:items, a:all))
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
460 endif
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
461 elseif a:depth < 10
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
462 " Could be "typedef other_T some_T".
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
463 call extend(res, s:Nextitem(cmdtokens[0], a:items, a:depth + 1, a:all))
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
464 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
465 endif
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
466 endif
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
467 endfor
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
468 if len(res) > 0
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
469 break
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
470 endif
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
471 endfor
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
472
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
473 return res
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
474 endfunction
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
475
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
476
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
477 " Search for members of structure "typename" in tags files.
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
478 " Return a list with resulting matches.
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
479 " Each match is a dictionary with "match" and "tagline" entries.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
480 " When "all" is non-zero find all, otherwise just return 1 if there is any
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
481 " member.
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
482 function! s:StructMembers(typename, items, all)
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
483 " Todo: What about local structures?
876
1d0ef79659af updated for version 7.0-002
vimboss
parents: 860
diff changeset
484 let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")'))
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
485 if fnames == ''
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
486 return []
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
487 endif
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
488
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
489 let typename = a:typename
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
490 let qflist = []
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
491 let cached = 0
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
492 if a:all == 0
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
493 let n = '1' " stop at first found match
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
494 if has_key(s:grepCache, a:typename)
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
495 let qflist = s:grepCache[a:typename]
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
496 let cached = 1
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
497 endif
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
498 else
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
499 let n = ''
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
500 endif
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
501 if !cached
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
502 while 1
3682
11d40fc82f11 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3237
diff changeset
503 exe 'silent! keepj noautocmd ' . n . 'vimgrep /\t' . typename . '\(\t\|$\)/j ' . fnames
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
504
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
505 let qflist = getqflist()
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
506 if len(qflist) > 0 || match(typename, "::") < 0
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
507 break
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
508 endif
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
509 " No match for "struct:context::name", remove "context::" and try again.
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
510 let typename = substitute(typename, ':[^:]*::', ':', '')
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
511 endwhile
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
512
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
513 if a:all == 0
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
514 " Store the result to be able to use it again later.
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
515 let s:grepCache[a:typename] = qflist
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
516 endif
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
517 endif
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
518
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
519 " Put matching members in matches[].
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
520 let matches = []
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
521 for l in qflist
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
522 let memb = matchstr(l['text'], '[^\t]*')
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
523 if memb =~ '^' . a:items[0]
734
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
524 " Skip matches local to another file.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
525 if match(l['text'], "\tfile:") < 0 || bufnr('%') == bufnr(matchstr(l['text'], '\t\zs[^\t]*'))
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
526 let item = {'match': memb, 'tagline': l['text']}
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
527
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
528 " Add the kind of item.
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
529 let s = matchstr(l['text'], '\t\(kind:\)\=\zs\S\ze\(\t\|$\)')
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
530 if s != ''
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
531 let item['kind'] = s
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
532 if s == 'f'
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
533 let item['match'] = memb . '('
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
534 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
535 endif
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
536
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
537 call add(matches, item)
5220ea46cb9a updated for version 7.0221
vimboss
parents: 720
diff changeset
538 endif
516
b7abd41f91da updated for version 7.0144
vimboss
parents: 511
diff changeset
539 endif
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
540 endfor
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
541
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
542 if len(matches) > 0
654
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
543 " Skip over [...] items
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
544 let idx = 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
545 while 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
546 if idx >= len(a:items)
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
547 return matches " No further items, return the result.
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
548 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
549 if a:items[idx][0] != '['
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
550 break
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
551 endif
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
552 let idx += 1
441f938ea9e9 updated for version 7.0192
vimboss
parents: 651
diff changeset
553 endwhile
505
7e6d264ec0a2 updated for version 7.0141
vimboss
parents: 502
diff changeset
554
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
555 " More items following. For each of the possible members find the
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
556 " matching following members.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
557 return s:SearchMembers(matches, a:items[idx :], a:all)
511
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
558 endif
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
559
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
560 " Failed to find anything.
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
561 return []
32cf0d2e14b4 updated for version 7.0143
vimboss
parents: 505
diff changeset
562 endfunction
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
563
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
564 " For matching members, find matches for following items.
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
565 " When "all" is non-zero find all, otherwise just return 1 if there is any
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
566 " member.
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
567 function! s:SearchMembers(matches, items, all)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
568 let res = []
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
569 for i in range(len(a:matches))
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
570 let typename = ''
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
571 if has_key(a:matches[i], 'dict')
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
572 if has_key(a:matches[i].dict, 'typename')
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
573 let typename = a:matches[i].dict['typename']
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
574 elseif has_key(a:matches[i].dict, 'typeref')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
575 let typename = a:matches[i].dict['typeref']
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
576 endif
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
577 let line = "\t" . a:matches[i].dict['cmd']
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
578 else
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
579 let line = a:matches[i]['tagline']
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
580 let e = matchend(line, '\ttypename:')
800
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
581 if e < 0
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
582 let e = matchend(line, '\ttyperef:')
d8f905020502 updated for version 7.0b
vimboss
parents: 787
diff changeset
583 endif
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
584 if e > 0
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
585 " Use typename field
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
586 let typename = matchstr(line, '[^\t]*', e)
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
587 endif
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
588 endif
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
589
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
590 if typename != ''
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
591 call extend(res, s:StructMembers(typename, a:items, a:all))
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
592 else
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
593 " Use the search command (the declaration itself).
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
594 let s = match(line, '\t\zs/^')
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
595 if s > 0
648
9032e4668296 updated for version 7.0189
vimboss
parents: 610
diff changeset
596 let e = match(line, '\<' . a:matches[i]['match'] . '\>', s)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
597 if e > 0
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
598 call extend(res, s:Nextitem(strpart(line, s, e - s), a:items, 0, a:all))
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
599 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
600 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
601 endif
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
602 if a:all == 0 && len(res) > 0
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
603 break
8ae24f338cab updated for version 7.0217
vimboss
parents: 666
diff changeset
604 endif
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
605 endfor
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
606 return res
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 520
diff changeset
607 endfunc
3237
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2152
diff changeset
608
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2152
diff changeset
609 let &cpo = s:cpo_save
91e53bcb7946 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2152
diff changeset
610 unlet s:cpo_save