summaryrefslogtreecommitdiffstats
path: root/runtime/autoload/ccomplete.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2005-09-05 22:14:46 +0000
committerBram Moolenaar <Bram@vim.org>2005-09-05 22:14:46 +0000
commitdd2436f352e51b5ee214b28cd61641c59239251a (patch)
tree268dedc3984037e37599e6446efb88753218bf38 /runtime/autoload/ccomplete.vim
parent92d640fad1808085ca609aecac8b854a6945d7a6 (diff)
updated for version 7.0141v7.0141
Diffstat (limited to 'runtime/autoload/ccomplete.vim')
-rw-r--r--runtime/autoload/ccomplete.vim79
1 files changed, 74 insertions, 5 deletions
diff --git a/runtime/autoload/ccomplete.vim b/runtime/autoload/ccomplete.vim
index f699ca7582..faad718a55 100644
--- a/runtime/autoload/ccomplete.vim
+++ b/runtime/autoload/ccomplete.vim
@@ -1,7 +1,7 @@
" Vim completion script
" Language: C
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2005 Sep 01
+" Last Change: 2005 Sep 05
function! ccomplete#Complete(findstart, base)
if a:findstart
@@ -21,12 +21,81 @@ function! ccomplete#Complete(findstart, base)
endif
" return list of matches
- let items = split(a:base, '\.\|->')
- if len(items) == 1
+ if a:base !~ '\.\|->'
" Only one part, no "." or "->": complete from tags file.
- let diclist = taglist(items[0])
+ let diclist = taglist(a:base)
return map(diclist, 'v:val["name"]')
endif
- return items
+
+ " Find variable locally in function or file.
+ let items = split(a:base, '\.\|->')
+
+ " At the moment we only do "aa.bb", not "aa.bb.cc"
+ if len(items) > 2
+ return []
+ endif
+
+ let line = ''
+ if searchdecl(items[0]) == 0 || searchdecl(items[0], 1) == 0
+ " Found, now figure out the type.
+ " TODO: join previous line if it makes sense
+ let line = getline('.')
+ let col = col('.')
+ else
+ " Find the variable in the tags file
+ let diclist = taglist(items[0])
+ for i in range(len(diclist))
+ " For now we only recognize a variable.
+ if diclist[i]['kind'] == 'v'
+ let line = diclist[i]['cmd']
+ if line[0] == '/' && line[1] == '^'
+ " the command is a search pattern, remove the leading /^
+ let line = strpart(line, 2)
+ endif
+ let col = match(line, items[0])
+ break
+ endif
+ endfor
+ endif
+
+ if line == ''
+ return []
+ endif
+
+ " Is there a * before the variable name?
+ let col -= 1
+ let star = 0
+ while col > 0
+ let col -= 1
+ if line[col] == '*'
+ let star = 1
+ elseif line[col] !~ '\s'
+ break
+ endif
+ endwhile
+
+ " Use the line up to the variable name and split it in tokens.
+ let lead = strpart(line, 0, col + 1)
+ let tokens = split(lead, '\s\+\|\<')
+
+ let basetext = matchstr(a:base, '.*\.\|->')
+
+ for i in range(len(tokens) - 1)
+ if tokens[i] == 'struct'
+ let name = tokens[i + 1]
+ " Todo: Use all tags files; What about local structures?
+ exe 'vimgrep /\<struct:' . name . '\>/j tags'
+ let res = []
+ for l in getqflist()
+ let memb = matchstr(l['text'], '[^\t]*')
+ if len(items) == 1 || memb =~ '^' . items[1]
+ call add(res, basetext . memb)
+ endif
+ endfor
+ return res
+ endif
+ endfor
+
+ return tokens
endfunction