⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complete.vim

📁 vim的自动配置文件
💻 VIM
📖 第 1 页 / 共 2 页
字号:
        let s:CACHE_TAG_FILES = {}        return 1    endif    let result = 0    for tagFile in tagfiles()        if has_key(s:CACHE_TAG_FILES, tagFile)            let currentFiletime = getftime(tagFile)            if currentFiletime > s:CACHE_TAG_FILES[tagFile]                " The file has changed, updating the cache                let s:CACHE_TAG_FILES[tagFile] = currentFiletime                let result = 1            endif        else            " We store the time of the file            let s:CACHE_TAG_FILES[tagFile] = getftime(tagFile)            let result = 1        endif    endfor    return resultendfunc" Initializationcall s:HasATagFileOrTagEnvChanged()" Filter same function signatures of base classesfunction! s:FilterOverloadedFunctions(tagPopupList)    let result = []    for tagPopupItem in a:tagPopupList        if has_key(tagPopupItem, 'kind') && index(['f', 'p'], tagPopupItem.kind[0])>=0 && has_key(tagPopupItem, 'signature')            if !has_key(s:CACHE_OVERLOADED_FUNCTIONS, tagPopupItem.word . tagPopupItem.signature)                let s:CACHE_OVERLOADED_FUNCTIONS[tagPopupItem.word . tagPopupItem.signature] = 1                call extend(result, [tagPopupItem])            endif        else            call extend(result, [tagPopupItem])        endif    endfor    return resultendfunc" Access filterfunction! s:GetAccessFilter(szFilter, szAccessFilter)    let szFilter = a:szFilter    if g:OmniCpp_DisplayMode == 0        if a:szAccessFilter == 'public'            " We only get public members            let szFilter .= "&& v:val.access == 'public'"        elseif a:szAccessFilter == 'protected'            " We get public and protected members            let szFilter .= "&& v:val.access != 'private'"        endif    endif    return szFilterendfunc" Filter class members in the popup menu after a completion with -> or .function! s:FilterClassMembers(tagPopupList, szAccessFilter)    let szFilter = "(!has_key(v:val, 'friendfunc') && !has_key(v:val, 'ctor') && has_key(v:val, 'kind') && index(['m', 'p', 'f'], v:val.kind[0])>=0 && has_key(v:val, 'access'))"    call filter(a:tagPopupList, s:GetAccessFilter(szFilter, a:szAccessFilter))    call extend(s:popupItemResultList, s:FilterOverloadedFunctions(a:tagPopupList))endfunc" Filter class scope members in the popup menu after a completion with ::" We only display attribute and functions members that" have an access information. We also display nested" class, struct, union, and enums, typedefsfunction! s:FilterClassScopeMembers(tagPopupList, szAccessFilter)    let szFilter = "!has_key(v:val, 'friendfunc') && has_key(v:val, 'kind') && (index(['m', 'p', 'f'], v:val.kind[0])>=0 && has_key(v:val, 'access'))"    let szFilter = s:GetAccessFilter(szFilter, a:szAccessFilter)    let szFilter .= "|| index(['c','e','g','s','t','u'], v:val.kind[0])>=0"    call filter(a:tagPopupList, szFilter)    call extend(s:popupItemResultList, s:FilterOverloadedFunctions(a:tagPopupList))endfunc" Filter static class members in the popup menufunction! s:FilterStaticClassMembers(tagPopupList, szAccessFilter)    let szFilter = "!has_key(v:val, 'friendfunc') && has_key(v:val, 'kind') && (index(['m', 'p', 'f'], v:val.kind[0])>=0 && has_key(v:val, 'access') && match(v:val.cmd, '\\Cstatic')!=-1)"    let szFilter = s:GetAccessFilter(szFilter, a:szAccessFilter)    let szFilter = szFilter . "|| index(['c','e','g','n','s','t','u','v'], v:val.kind[0])>=0"    call filter(a:tagPopupList, szFilter)    call extend(s:popupItemResultList, s:FilterOverloadedFunctions(a:tagPopupList))endfunc" Filter scope members in the popup menufunction! s:FilterNamespaceScopeMembers(tagPopupList)    call extend(s:popupItemResultList, a:tagPopupList)endfunc" Init data at the start of completionfunction! s:InitComplete()    " Reset the popup item list    let s:popupItemResultList = []    let s:CACHE_OVERLOADED_FUNCTIONS = {}    " Reset includes cache when the current working directory has changed    let szCurrentWorkingDir = getcwd()    if s:szCurrentWorkingDir != szCurrentWorkingDir        let s:szCurrentWorkingDir = szCurrentWorkingDir        let g:omni#cpp#includes#CACHE_INCLUDES = {}        let g:omni#cpp#includes#CACHE_FILE_TIME = {}    endif    " Has preview window ?    let s:hasPreviewWindow = match(&completeopt, 'preview')>=0    let bResetCache = 0    " Reset tag env or tag files dependent caches    if s:HasATagFileOrTagEnvChanged()        let bResetCache = 1    endif    if  (s:OmniCpp_ShowScopeInAbbr !=  g:OmniCpp_ShowScopeInAbbr)        \|| (s:OmniCpp_ShowPrototypeInAbbr != g:OmniCpp_ShowPrototypeInAbbr)        \|| (s:OmniCpp_ShowAccess != g:OmniCpp_ShowAccess)        let s:OmniCpp_ShowScopeInAbbr = g:OmniCpp_ShowScopeInAbbr        let s:OmniCpp_ShowPrototypeInAbbr = g:OmniCpp_ShowPrototypeInAbbr        let s:OmniCpp_ShowAccess = g:OmniCpp_ShowAccess        let bResetCache = 1    endif    if s:hasPreviewWindow != s:hasPreviewWindowOld        let s:hasPreviewWindowOld = s:hasPreviewWindow        let bResetCache = 1    endif    if bResetCache        let g:omni#cpp#namespaces#CacheResolve = {}        let s:CACHE_TAG_POPUP_ITEMS = {}        let g:omni#cpp#utils#CACHE_TAG_INHERITS = {}        call garbagecollect()    endif    " Check for updates    for szIncludeName in keys(g:omni#cpp#includes#CACHE_INCLUDES)        let fTime = getftime(szIncludeName)        let bNeedUpdate = 0        if has_key(g:omni#cpp#includes#CACHE_FILE_TIME, szIncludeName)            if fTime != g:omni#cpp#includes#CACHE_FILE_TIME[szIncludeName]                let bNeedUpdate = 1            endif        else            let g:omni#cpp#includes#CACHE_FILE_TIME[szIncludeName] = fTime            let bNeedUpdate = 1        endif                if bNeedUpdate            " We have to update include list and namespace map of this file            call omni#cpp#includes#GetList(szIncludeName, 1)            call omni#cpp#namespaces#GetMapFromBuffer(szIncludeName, 1)        endif    endfor    let s:bDoNotComplete = 0endfunc" This function is used for the 'omnifunc' option.function! omni#cpp#complete#Main(findstart, base)    if a:findstart        "call omni#common#debug#Start()        call s:InitComplete()        " Note: if s:bMayComplete==1 g:omni#cpp#items#data is build by MayComplete functions        if !s:bMayComplete            " If the cursor is in a comment we go out            if omni#cpp#utils#IsCursorInCommentOrString()                " Returning -1 is not enough we have to set a variable to let                " the second call of omni#cpp#complete knows that the                " cursor was in a comment                " Why is there a second call when the first call returns -1 ?                let s:bDoNotComplete = 1                return -1            endif            " We get items here (whend a:findstart==1) because GetItemsToComplete()            " depends on the cursor position.            " When a:findstart==0 the cursor position is modified            let g:omni#cpp#items#data = omni#cpp#items#Get(omni#cpp#utils#TokenizeCurrentInstruction())        endif        " Get contexts stack        let s:contextStack = omni#cpp#namespaces#GetContexts()        " Reinit of may complete indicator        let s:bMayComplete = 0        return s:FindStartPositionOfCompletion()    endif    " If the cursor is in a comment we return an empty result    if s:bDoNotComplete        let s:bDoNotComplete = 0        return []    endif    if len(g:omni#cpp#items#data)==0        " A) CURRENT_SCOPE_COMPLETION_MODE        " 1) Displaying data of each context        let szAccessFilter = 'all'        for szCurrentContext in s:contextStack            if szCurrentContext == '::'                continue            endif            let resolvedTagItem = omni#cpp#utils#GetResolvedTagItem(s:contextStack, omni#cpp#utils#CreateTypeInfo(szCurrentContext))            if resolvedTagItem != {}                " We don't search base classes because bases classes are                " already in the context stack                let tagPopupList = s:SearchMembers(resolvedTagItem, a:base)                if index(['c','s'], resolvedTagItem.kind[0])>=0                    " It's a class or struct                    call s:FilterClassScopeMembers(tagPopupList, szAccessFilter)                    let szAccessFilter = 'protected'                else                    " It's a namespace or union, we display all members                    call s:FilterNamespaceScopeMembers(tagPopupList)                endif            endif        endfor        " 2) Displaying global scope members        if g:OmniCpp_GlobalScopeSearch            call s:SearchGlobalMembers(a:base)        endif    else        let typeInfo = omni#cpp#items#ResolveItemsTypeInfo(s:contextStack, g:omni#cpp#items#data)        if typeInfo != {}            if g:omni#cpp#items#data[-1].kind == 'itemScope'                " B) SCOPE_COMPLETION_MODE                if omni#cpp#utils#GetTypeInfoString(typeInfo)==''                    call s:SearchGlobalMembers(a:base)                else                    for resolvedTagItem in omni#cpp#utils#GetResolvedTags(s:contextStack, typeInfo)                        let tagPopupList = s:SearchMembers(resolvedTagItem, a:base)                        if index(['c','s'], resolvedTagItem.kind[0])>=0                            let szTypeInfo = omni#cpp#utils#ExtractTypeInfoFromTag(resolvedTagItem)                            if g:OmniCpp_DisplayMode==0                                " We want to complete a class or struct                                " If this class is a base class so we display all class members                                if index(s:contextStack, szTypeInfo)<0                                    let szAccessFilter = 'public'                                    call s:FilterStaticClassMembers(tagPopupList, szAccessFilter)                                else                                    let szAccessFilter = (s:contextStack[0] == szTypeInfo)? 'all' : 'protected'                                    call s:FilterClassScopeMembers(tagPopupList, szAccessFilter)                                endif                            else                                if index(s:contextStack, szTypeInfo)<0                                    let szAccessFilter = 'public'                                else                                    let szAccessFilter = (s:contextStack[0] == szTypeInfo)? 'all' : 'protected'                                endif                                call s:FilterClassScopeMembers(tagPopupList, szAccessFilter)                            endif                        else                            " We want to complete a namespace                            call s:FilterNamespaceScopeMembers(tagPopupList)                        endif                    endfor                endif            else                " C) CLASS_MEMBERS_COMPLETION_MODE                for resolvedTagItem in omni#cpp#utils#GetResolvedTags(s:contextStack, typeInfo)                    let szTypeInfo = omni#cpp#utils#ExtractTypeInfoFromTag(resolvedTagItem)                    if index(s:contextStack, szTypeInfo)<0                        let szAccessFilter = 'public'                    else                        let szAccessFilter = (s:contextStack[0] == szTypeInfo)? 'all' : 'protected'                    endif                    call s:FilterClassMembers(s:SearchMembers(resolvedTagItem, a:base), szAccessFilter)                endfor            endif        endif    endif    "call omni#common#debug#End()    return s:popupItemResultListendfunc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -