@@ -67,10 +67,16 @@ let s:subcmd_map = { 'Symbol' : 1,
67
67
\ ' DefinitionGroup' : 20 }
68
68
69
69
70
+ let s: c_family_filetype_list =
71
+ \ [' c' , ' h' , ' cpp' , ' cxx' , ' cc' , ' hpp' , ' hxx' , ' hh' ]
72
+
73
+
74
+ let s: supported_filetypes = s: c_family_filetype_list +
75
+ \ [' python' , ' javascript' , ' go' , ' ruby' , ' java' , ' c' , ' cpp' ]
76
+
77
+
70
78
function ! s: check_filetype (filetype )
71
- let supported_filetypes =
72
- \ [' python' , ' javascript' , ' go' , ' ruby' , ' java' , ' c' , ' cpp' ]
73
- if index (supported_filetypes, a: filetype ) == -1
79
+ if index (s: supported_filetypes , a: filetype ) == -1
74
80
return 0
75
81
endif
76
82
return 1
@@ -79,7 +85,12 @@ endfunction
79
85
80
86
" `lcd` brings side effect !!
81
87
function ! s: find_db_path (filetype )
82
- let db_name = a: filetype . ' .db'
88
+ if index (s: c_family_filetype_list , a: filetype ) != -1
89
+ let db_name = ' c_family.db'
90
+ else
91
+ let db_name = a: filetype . ' .db'
92
+ endif
93
+
83
94
let lookup_path = findfile (expand (' %:p:h' ) . ' /' . db_name, ' .' )
84
95
85
96
if ! empty (lookup_path)
@@ -209,6 +220,32 @@ function! s:construct_java_db_build_cmd(db_path)
209
220
endfunction
210
221
211
222
223
+ function ! s: construct_c_db_build_cmd (db_path)
224
+ let find_cmd = ' find . -iname "*.c" > c_cscope.files && ' .
225
+ \ ' find . -iname "*.h" >> c_cscope.files && ' .
226
+ \ ' find . -iname "*.cpp" >> c_cscope.files && ' .
227
+ \ ' find . -iname "*.cxx" >> c_cscope.files && ' .
228
+ \ ' find . -iname "*.cc" >> c_cscope.files && ' .
229
+ \ ' find . -iname "*.hpp" >> c_cscope.files && ' .
230
+ \ ' find . -iname "*.hxx" >> c_cscope.files && ' .
231
+ \ ' find . -iname "*.hh" >> c_cscope.files'
232
+ let cscope_cmd = ' cscope -cbk -i c_cscope.files -f c_cscope.out'
233
+ let ctags_cmd = ' ctags --fields=+i -n -R -f "c_tags" -L c_cscope.files'
234
+ let cqmakedb_cmd = ' cqmakedb -s "' . a: db_path . ' " -c c_cscope.out' .
235
+ \ ' -t c_tags -p'
236
+ let shell_cmd = find_cmd . ' && ' .
237
+ \ cscope_cmd . ' && ' .
238
+ \ ctags_cmd . ' && ' .
239
+ \ cqmakedb_cmd
240
+
241
+ if exists (' g:codequery_enable_auto_clean_languages' ) &&
242
+ \ index (g: codequery_enable_auto_clean_languages , ' c' ) != -1
243
+ let shell_cmd .= ' && rm c_cscope.files c_cscope.out c_tags'
244
+ endif
245
+
246
+ return exists (' g:codequery_build_c_db_cmd' ) ? g: codequery_build_c_db_cmd : shell_cmd
247
+ endfunction
248
+
212
249
function ! s: is_valid_word (word)
213
250
return strlen (matchstr (a: word , ' \v^[a-z|A-Z|0-9|_|*|?]+$' )) > 0
214
251
endfunction
@@ -544,7 +581,11 @@ function! s:make_codequery_db(args)
544
581
545
582
let db_path = s: find_db_path (ft )
546
583
if empty (db_path)
547
- let db_path = ft . ' .db'
584
+ if index (s: c_family_filetype_list , ft ) != -1
585
+ let db_path = ' c_family.db'
586
+ else
587
+ let db_path = ft . ' .db'
588
+ endif
548
589
endif
549
590
550
591
if ft == ? ' python'
@@ -557,8 +598,10 @@ function! s:make_codequery_db(args)
557
598
let shell_cmd = s: construct_go_db_build_cmd (db_path)
558
599
elseif ft == ? ' java'
559
600
let shell_cmd = s: construct_java_db_build_cmd (db_path)
601
+ elseif index (s: c_family_filetype_list , ft ) != -1
602
+ let shell_cmd = s: construct_c_db_build_cmd (db_path)
560
603
else
561
- echom ' No Command For Building ' . ft . ' DB '
604
+ echom ' No Command For Building . ' . ft . ' file '
562
605
continue
563
606
endif
564
607
@@ -591,7 +634,11 @@ function! s:view_codequery_db(args)
591
634
592
635
let db_path = s: find_db_path (ft )
593
636
if empty (db_path)
594
- execute ' !echo "\n(' . ft . ' ) DB Not Found"'
637
+ if index (s: c_family_filetype_list , ft ) != -1
638
+ execute ' !echo "\n(c family) DB Not Found"'
639
+ else
640
+ execute ' !echo "\n(' . ft . ' ) DB Not Found"'
641
+ endif
595
642
continue
596
643
endif
597
644
@@ -607,17 +654,21 @@ function! s:move_codequery_db_to_git_hidden_dir(args)
607
654
endif
608
655
609
656
for ft in args
610
- let db_name = ft . ' .db'
657
+ if index (s: c_family_filetype_list , ft ) != -1
658
+ let db_name = ' c_family.db'
659
+ else
660
+ let db_name = ft . ' .db'
661
+ endif
611
662
let git_root_dir = systemlist (' git rev-parse --show-toplevel' )[0 ]
612
663
let db_path = s: find_db_path (ft )
613
664
614
665
if ! v: shell_error && ! empty (db_path)
615
666
let new_db_path = git_root_dir . ' /.git/codequery/' . db_name
616
667
call system (' mkdir -p ' . git_root_dir . ' /.git/codequery/' )
617
668
call system (' mv ' . db_path . ' ' . new_db_path)
618
- echom ' Done (' . ft . ' )'
669
+ echom ' Done (' . db_name . ' )'
619
670
else
620
- echom ' Git Dir Not Found or (' . ft . ' ) DB Not Found'
671
+ echom ' Git Dir Not Found or (' . db_name . ' ) Not Found'
621
672
endif
622
673
endfor
623
674
endfunction
0 commit comments