comparison autoload/gutentags.vim @ 89:8bf96f9f649c

Add support for project types.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 01 Dec 2015 22:04:45 -0800
parents 073e63cc0456
children b9965d1288c3
comparison
equal deleted inserted replaced
88:073e63cc0456 89:8bf96f9f649c
54 " }}} 54 " }}}
55 55
56 " Gutentags Setup {{{ 56 " Gutentags Setup {{{
57 57
58 let s:known_files = [] 58 let s:known_files = []
59 let s:known_projects = {}
60
61 function! s:cache_project_root(path) abort
62 let l:result = {}
63
64 for proj_info in g:gutentags_project_info
65 let l:filematch = get(proj_info, 'file', '')
66 if l:filematch != '' && filereadable(a:path . '/'. l:filematch)
67 let l:result = copy(proj_info)
68 break
69 endif
70
71 let l:globmatch = get(proj_info, 'glob', '')
72 if l:globmatch != '' && glob(a:path . '/' . l:globmatch) != ''
73 let l:result = copy(proj_info)
74 break
75 endif
76 endfor
77
78 let s:known_projects[a:path] = l:result
79 endfunction
59 80
60 " Finds the first directory with a project marker by walking up from the given 81 " Finds the first directory with a project marker by walking up from the given
61 " file path. 82 " file path.
62 function! gutentags#get_project_root(path) abort 83 function! gutentags#get_project_root(path) abort
63 let l:path = gutentags#stripslash(a:path) 84 let l:path = gutentags#stripslash(a:path)
77 let l:path = fnamemodify(l:path, ':h') 98 let l:path = fnamemodify(l:path, ':h')
78 endwhile 99 endwhile
79 call gutentags#throw("Can't figure out what tag file to use for: " . a:path) 100 call gutentags#throw("Can't figure out what tag file to use for: " . a:path)
80 endfunction 101 endfunction
81 102
103 " Get info on the project we're inside of.
104 function! gutentags#get_project_info(path) abort
105 return get(s:known_projects, a:path, {})
106 endfunction
107
82 " Generate a path for a given filename in the cache directory. 108 " Generate a path for a given filename in the cache directory.
83 function! gutentags#get_cachefile(root_dir, filename) abort 109 function! gutentags#get_cachefile(root_dir, filename) abort
84 let l:tag_path = gutentags#stripslash(a:root_dir) . '/' . a:filename 110 let l:tag_path = gutentags#stripslash(a:root_dir) . '/' . a:filename
85 if g:gutentags_cache_dir != "" 111 if g:gutentags_cache_dir != ""
86 " Put the tag file in the cache dir instead of inside the 112 " Put the tag file in the cache dir instead of inside the
124 endif 150 endif
125 let b:gutentags_root = gutentags#get_project_root(l:buf_dir) 151 let b:gutentags_root = gutentags#get_project_root(l:buf_dir)
126 if filereadable(b:gutentags_root . '/.notags') 152 if filereadable(b:gutentags_root . '/.notags')
127 call gutentags#trace("'notags' file found... no gutentags support.") 153 call gutentags#trace("'notags' file found... no gutentags support.")
128 return 154 return
155 endif
156
157 if !has_key(s:known_projects, b:gutentags_root)
158 call s:cache_project_root(b:gutentags_root)
159 endif
160 if g:gutentags_trace
161 let l:projnfo = gutentags#get_project_info(b:gutentags_root)
162 if l:projnfo != {}
163 call gutentags#trace("Setting project type to ".l:projnfo['type'])
164 else
165 call gutentags#trace("No specific project type.")
166 endif
129 endif 167 endif
130 168
131 let b:gutentags_files = {} 169 let b:gutentags_files = {}
132 for module in g:gutentags_modules 170 for module in g:gutentags_modules
133 call call("gutentags#".module."#init", [b:gutentags_root]) 171 call call("gutentags#".module."#init", [b:gutentags_root])