diff 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
line wrap: on
line diff
--- a/autoload/gutentags.vim	Tue Nov 24 21:47:26 2015 -0800
+++ b/autoload/gutentags.vim	Tue Dec 01 22:04:45 2015 -0800
@@ -56,6 +56,27 @@
 " Gutentags Setup {{{
 
 let s:known_files = []
+let s:known_projects = {}
+
+function! s:cache_project_root(path) abort
+    let l:result = {}
+
+    for proj_info in g:gutentags_project_info
+        let l:filematch = get(proj_info, 'file', '')
+        if l:filematch != '' && filereadable(a:path . '/'. l:filematch)
+            let l:result = copy(proj_info)
+            break
+        endif
+
+        let l:globmatch = get(proj_info, 'glob', '')
+        if l:globmatch != '' && glob(a:path . '/' . l:globmatch) != ''
+            let l:result = copy(proj_info)
+            break
+        endif
+    endfor
+
+    let s:known_projects[a:path] = l:result
+endfunction
 
 " Finds the first directory with a project marker by walking up from the given
 " file path.
@@ -79,6 +100,11 @@
     call gutentags#throw("Can't figure out what tag file to use for: " . a:path)
 endfunction
 
+" Get info on the project we're inside of.
+function! gutentags#get_project_info(path) abort
+    return get(s:known_projects, a:path, {})
+endfunction
+
 " Generate a path for a given filename in the cache directory.
 function! gutentags#get_cachefile(root_dir, filename) abort
     let l:tag_path = gutentags#stripslash(a:root_dir) . '/' . a:filename
@@ -128,6 +154,18 @@
             return
         endif
 
+        if !has_key(s:known_projects, b:gutentags_root)
+            call s:cache_project_root(b:gutentags_root)
+        endif
+        if g:gutentags_trace
+            let l:projnfo = gutentags#get_project_info(b:gutentags_root)
+            if l:projnfo != {}
+                call gutentags#trace("Setting project type to ".l:projnfo['type'])
+            else
+                call gutentags#trace("No specific project type.")
+            endif
+        endif
+
         let b:gutentags_files = {}
         for module in g:gutentags_modules
             call call("gutentags#".module."#init", [b:gutentags_root])