annotate runtime/autoload/ccomplete.vim @ 2079:5abd3e3c0085 v7.2.363

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