annotate runtime/autoload/ccomplete.vim @ 1463:e6a8d55a1626 v7.1.178

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