Skip to content

Commit 2fac015

Browse files
FromtonRougevim-scripts
authored andcommitted
Version 0.41
- It's recommended to update ctags to version 5.7 or higher - The plugin is now activated for C files - New value for OmniCpp_SelectFirstItem when the option is equal to 2 the first item is selected without inserting it to the text (patch from Marek Olszewski) - Bug when completing union members fixed with ctags 5.7 (reported by Willem-Jan de Hoog) - New option OmniCpp_LocalSearchDecl (patch from Roland Kuck) - Bug when tags=something,,somethingelse (reported by Tobias Pflug) - Bug with nested structure (reported by Mikhail Daen) - Bug where the script fails to detect the type of a variable when the ignorecase option is on (reported by Alexey Vakhov) - Error message when trying to use completion on a not yet saved Vim buffer (reported by Neil Bird) - Error message when trying to use completion on an file opened from a tselect command (reported by Henrique Andrade)
1 parent 7e0a2fb commit 2fac015

File tree

12 files changed

+279
-70
lines changed

12 files changed

+279
-70
lines changed

after/ftplugin/c.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
" OmniCppComplete initialization
2+
call omni#cpp#complete#Init()

autoload/omni/common/debug.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion debug functions
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
let s:CACHE_DEBUG_TRACE = []
66

autoload/omni/common/utils.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion utils
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
" For sort numbers in list
66
function! omni#common#utils#CompareNumber(i1, i2)

autoload/omni/cpp/complete.vim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 juin 2006
3+
" Last Change: 27 sept. 2007
44

55
if v:version < 700
66
echohl WarningMsg
@@ -20,7 +20,6 @@ let s:CACHE_TAG_POPUP_ITEMS = {}
2020
let s:CACHE_TAG_FILES = {}
2121
let s:CACHE_TAG_ENV = ''
2222
let s:CACHE_OVERLOADED_FUNCTIONS = {}
23-
call garbagecollect()
2423

2524
" Has preview window?
2625
let s:hasPreviewWindow = match(&completeopt, 'preview')>=0
@@ -287,6 +286,10 @@ function! s:HasATagFileOrTagEnvChanged()
287286

288287
let result = 0
289288
for tagFile in tagfiles()
289+
if tagFile == ""
290+
continue
291+
endif
292+
290293
if has_key(s:CACHE_TAG_FILES, tagFile)
291294
let currentFiletime = getftime(tagFile)
292295
if currentFiletime > s:CACHE_TAG_FILES[tagFile]
@@ -510,6 +513,7 @@ function! omni#cpp#complete#Main(findstart, base)
510513
endif
511514
else
512515
let typeInfo = omni#cpp#items#ResolveItemsTypeInfo(s:contextStack, g:omni#cpp#items#data)
516+
513517
if typeInfo != {}
514518
if g:omni#cpp#items#data[-1].kind == 'itemScope'
515519
" B) SCOPE_COMPLETION_MODE

autoload/omni/cpp/includes.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
let g:omni#cpp#includes#CACHE_INCLUDES = {}
66
let g:omni#cpp#includes#CACHE_FILE_TIME = {}

autoload/omni/cpp/items.vim

Lines changed: 122 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
" Build the item list of an instruction
66
" An item is an instruction between a -> or . or ->* or .*
@@ -296,35 +296,47 @@ function! s:GetTypeInfoOfVariable(contextStack, szVariable, bSearchDecl)
296296
if tagItem=={}
297297
return result
298298
endif
299-
if has_key(tagItem, 'typeref')
300-
" Maybe the variable is a global var of an
301-
" unnamed class, struct or union.
302-
" eg:
303-
" 1)
299+
300+
let szCmdWithoutVariable = substitute(omni#cpp#utils#ExtractCmdFromTagItem(tagItem), '\C\<'.a:szVariable.'\>.*', '', 'g')
301+
let tokens = omni#cpp#tokenizer#Tokenize(omni#cpp#utils#GetCodeFromLine(szCmdWithoutVariable))
302+
let result = omni#cpp#utils#CreateTypeInfo(omni#cpp#utils#ExtractTypeInfoFromTokens(tokens))
303+
" TODO: Namespace resolution for result
304+
305+
if result != {} && result.value==''
306+
" result.value==''
307+
" eg:
304308
" struct
305309
" {
306310
" }gVariable;
307-
" In this case we need the tags (the patched version)
308-
" Note: We can have a named type like this:
309-
" 2)
310-
" class A
311-
" {
312-
" }gVariable;
313-
if s:IsUnnamedType(tagItem)
314-
" It's an unnamed type we are in the case 1)
315-
let result = omni#cpp#utils#CreateTypeInfo(tagItem)
316-
else
317-
" It's not an unnamed type we are in the case 2)
318-
let result = omni#cpp#utils#CreateTypeInfo(substitute(tagItem.typeref, '\w\+:', '', 'g'))
311+
if has_key(tagItem, 'typeref')
312+
" Maybe the variable is a global var of an
313+
" unnamed class, struct or union.
314+
" eg:
315+
" 1)
316+
" struct
317+
" {
318+
" }gVariable;
319+
" In this case we need the tags (the patched version)
320+
" Note: We can have a named type like this:
321+
" 2)
322+
" class A
323+
" {
324+
" }gVariable;
325+
if s:IsUnnamedType(tagItem)
326+
" It's an unnamed type we are in the case 1)
327+
let result = omni#cpp#utils#CreateTypeInfo(tagItem)
328+
else
329+
" It's not an unnamed type we are in the case 2)
330+
331+
" eg: tagItem.typeref = 'struct:MY_STRUCT::MY_SUBSTRUCT'
332+
let szTypeRef = substitute(tagItem.typeref, '^\w\+:', '', '')
333+
334+
" eg: szTypeRef = 'MY_STRUCT::MY_SUBSTRUCT'
335+
let result = omni#cpp#utils#CreateTypeInfo(szTypeRef)
336+
endif
319337
endif
320-
else
321-
let szCmdWithoutVariable = substitute(omni#cpp#utils#ExtractCmdFromTagItem(tagItem), '\C\<'.a:szVariable.'\>.*', '', 'g')
322-
let tokens = omni#cpp#tokenizer#Tokenize(omni#cpp#utils#GetCodeFromLine(szCmdWithoutVariable))
323-
let result = omni#cpp#utils#CreateTypeInfo(omni#cpp#utils#ExtractTypeInfoFromTokens(tokens))
324-
" TODO: Namespace resolution for result
325338
endif
326339
endif
327-
328340
return result
329341
endfunc
330342

@@ -439,7 +451,7 @@ function! s:SearchTypeInfoOfDecl(szVariable)
439451
endwhile
440452

441453
let result = {}
442-
if searchdecl(a:szVariable, 0, 1)==0 && !omni#cpp#utils#IsCursorInCommentOrString()
454+
if s:LocalSearchDecl(a:szVariable)==0 && !omni#cpp#utils#IsCursorInCommentOrString()
443455
let tokens = omni#cpp#utils#TokenizeCurrentInstruction()
444456
let szTypeInfo = s:ExtractTypeInfoFromDecl(tokens)
445457
if szTypeInfo != ''
@@ -459,12 +471,13 @@ endfunc
459471
function! s:SearchDecl(szVariable)
460472
let result = {}
461473
let originalPos = getpos('.')
462-
let searchResult = searchdecl(a:szVariable, 0, 1)
474+
let searchResult = s:LocalSearchDecl(a:szVariable)
463475
if searchResult==0
464476
" searchdecl() may detect a decl if the variable is in a conditional
465477
" instruction (if, elseif, while etc...)
466478
" We have to check if the detected decl is really a decl instruction
467479
let tokens = omni#cpp#utils#TokenizeCurrentInstruction()
480+
468481
for token in tokens
469482
" Simple test
470483
if index(['if', 'elseif', 'while', 'for', 'switch'], token.value)>=0
@@ -562,3 +575,86 @@ function! s:ResolveCast(tokens, startChar, endChar)
562575

563576
return tokens[startIndex+1 : endIndex-1]
564577
endfunc
578+
579+
" Replacement for build-in function 'searchdecl'
580+
" It does not require that the upper-level bracket is in the first column.
581+
" Otherwise it should be equal to 'searchdecl(name, 0, 1)'
582+
" @param name: name of variable to find declaration for
583+
function! s:LocalSearchDecl(name)
584+
585+
if g:OmniCpp_LocalSearchDecl == 0
586+
let bUserIgnoreCase = &ignorecase
587+
588+
" Forcing the noignorecase option
589+
" avoid bug when, for example, if we have a declaration like this : "A a;"
590+
set noignorecase
591+
592+
let result = searchdecl(a:name, 0, 1)
593+
594+
" Restoring user's setting
595+
let &ignorecase = bUserIgnoreCase
596+
597+
return result
598+
endif
599+
600+
let lastpos = getpos('.')
601+
let winview = winsaveview()
602+
let lastfoldenable = &foldenable
603+
let &foldenable = 0
604+
605+
" We add \C (noignorecase) to
606+
" avoid bug when, for example, if we have a declaration like this : "A a;"
607+
let varname = "\\C\\<" . a:name . "\\>"
608+
609+
" Go to first blank line before begin of highest scope
610+
normal 99[{
611+
let scopepos = getpos('.')
612+
while (line('.') > 1) && (len(split(getline('.'))) > 0)
613+
call cursor(line('.')-1, 0)
614+
endwhile
615+
616+
let declpos = [ 0, 0, 0, 0 ]
617+
while search(varname, '', scopepos[1]) > 0
618+
" Check if we are a string or a comment
619+
if omni#cpp#utils#IsCursorInCommentOrString()
620+
continue
621+
endif
622+
623+
" Remember match
624+
let declpos = getpos('.')
625+
endwhile
626+
if declpos[1] != 0
627+
" We found a match
628+
call winrestview(winview)
629+
call setpos('.', declpos)
630+
let &foldenable = lastfoldenable
631+
return 0
632+
endif
633+
634+
while search(varname, '', lastpos[1]) > 0
635+
" Check if current scope is ending before variable
636+
let old_cur = getpos('.')
637+
normal ]}
638+
let new_cur = getpos('.')
639+
call setpos('.', old_cur)
640+
if (new_cur[1] < lastpos[1]) || ((new_cur[1] == lastpos[1]) && (new_cur[2] < lastpos[2]))
641+
continue
642+
endif
643+
644+
" Check if we are a string or a comment
645+
if omni#cpp#utils#IsCursorInCommentOrString()
646+
continue
647+
endif
648+
649+
" We found match
650+
call winrestview(winview)
651+
call setpos('.', old_cur)
652+
let &foldenable = lastfoldenable
653+
return 0
654+
endwhile
655+
656+
" No match found.
657+
call winrestview(winview)
658+
let &foldenable = lastfoldenable
659+
return 1
660+
endfunc

autoload/omni/cpp/maycomplete.vim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
" Check if we can use omni completion in the current buffer
66
function! s:CanUseOmnicompletion()
@@ -11,12 +11,23 @@ endfunc
1111
" Return the mapping of omni completion
1212
function! omni#cpp#maycomplete#Complete()
1313
let szOmniMapping = "\<C-X>\<C-O>"
14-
if !g:OmniCpp_SelectFirstItem
14+
15+
" 0 = don't select first item
16+
" 1 = select first item (inserting it to the text, default vim behaviour)
17+
" 2 = select first item (without inserting it to the text)
18+
if g:OmniCpp_SelectFirstItem == 0
19+
" We have to force the menuone option to avoid confusion when there is
20+
" only one popup item
21+
set completeopt-=menu
22+
set completeopt+=menuone
23+
let szOmniMapping .= "\<C-P>"
24+
elseif g:OmniCpp_SelectFirstItem == 2
1525
" We have to force the menuone option to avoid confusion when there is
1626
" only one popup item
1727
set completeopt-=menu
1828
set completeopt+=menuone
1929
let szOmniMapping .= "\<C-P>"
30+
let szOmniMapping .= "\<C-R>=pumvisible() ? \"\\<down>\" : \"\"\<cr>"
2031
endif
2132
return szOmniMapping
2233
endfunc

autoload/omni/cpp/namespaces.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
let g:omni#cpp#namespaces#CacheResolve = {}
66
let g:omni#cpp#namespaces#CacheUsing = {}
@@ -181,7 +181,11 @@ endfunc
181181
" Get global using namespace map from the current buffer and include files recursively
182182
function! s:GetAllUsingNamespaceMapFromCurrentBuffer(...)
183183
let includeGuard = (a:0>0)? a:1 : {}
184-
let szFilePath = omni#cpp#utils#ResolveFilePath(getreg('%'))
184+
185+
let szBufferName = getreg("%")
186+
let szFilePath = omni#cpp#utils#ResolveFilePath(szBufferName)
187+
let szFilePath = (szFilePath=='')? szBufferName : szFilePath
188+
185189
let namespaceMap = {}
186190
if has_key(includeGuard, szFilePath)
187191
return namespaceMap
@@ -217,7 +221,9 @@ function! s:GetAllUsingNamespaceMapFromFile(szFilePath, ...)
217221
if a:0 >0
218222
let includeGuard = a:1
219223
endif
224+
220225
let szFilePath = omni#cpp#utils#ResolveFilePath(a:szFilePath)
226+
let szFilePath = (szFilePath=='')? a:szFilePath : szFilePath
221227

222228
let namespaceMap = {}
223229
if has_key(includeGuard, szFilePath)
@@ -282,6 +288,8 @@ function! omni#cpp#namespaces#GetMapFromBuffer(szFilePath, ...)
282288
endif
283289

284290
let szFilePath = omni#cpp#utils#ResolveFilePath(a:szFilePath)
291+
let szFilePath = (szFilePath=='')? a:szFilePath : szFilePath
292+
285293
if !bUpdate && has_key(g:omni#cpp#namespaces#CacheUsing, szFilePath)
286294
return copy(g:omni#cpp#namespaces#CacheUsing[szFilePath])
287295
endif
@@ -640,7 +648,7 @@ function! s:BuildContextStack(namespaces, szCurrentScope)
640648
if has_key(tagItem, 'inherits')
641649
let listBaseClass = omni#cpp#utils#GetClassInheritanceList(a:namespaces, omni#cpp#utils#CreateTypeInfo(a:szCurrentScope))
642650
let result = listBaseClass + result
643-
elseif has_key(tagItem, 'kind') && index(['c', 's', 'u'], tagItem.kind[0])>=0
651+
elseif has_key(tagItem, 'kind') && index(['c', 's', 'u', 'n'], tagItem.kind[0])>=0
644652
call insert(result, omni#cpp#utils#ExtractTypeInfoFromTag(tagItem))
645653
endif
646654
endif

autoload/omni/cpp/settings.vim

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion script for cpp files
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44

55
function! omni#cpp#settings#Init()
66
" Global scope search on/off
@@ -76,12 +76,21 @@ function! omni#cpp#settings#Init()
7676
let g:OmniCpp_MayCompleteScope = 0
7777
endif
7878

79-
" When completeopt does not contain longest option, this setting allow to not
80-
" select the first item
79+
" When completeopt does not contain longest option, this setting
80+
" controls the behaviour of the popup menu selection when starting the completion
8181
" 0 = don't select first item
82-
" 1 = select first item
82+
" 1 = select first item (inserting it to the text)
83+
" 2 = select first item (without inserting it to the text)
8384
" default = 0
8485
if !exists('g:OmniCpp_SelectFirstItem')
8586
let g:OmniCpp_SelectFirstItem= 0
8687
endif
88+
89+
" Use local search function for variable definitions
90+
" 0 = use standard vim search function
91+
" 1 = use local search function
92+
" default = 0
93+
if !exists('g:OmniCpp_LocalSearchDecl')
94+
let g:OmniCpp_LocalSearchDecl= 0
95+
endif
8796
endfunc

autoload/omni/cpp/tokenizer.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Description: Omni completion tokenizer
22
" Maintainer: Vissale NEANG
3-
" Last Change: 25 jun 2006
3+
" Last Change: 26 sept. 2007
44
" TODO: Generic behaviour for Tokenize()
55

66
" From the C++ BNF

0 commit comments

Comments
 (0)