简体   繁体   中英

What is the relation between .ycm_extra_conf.py and Exuberant Ctags

I am currently in the middle of switching my C++ based IDE from XCode to Vim. I have been reading about the Vim plugin "YCM" and it requires the presence of .ycm_extra_conf.py in the source dir. I am using YCM Generator to generate the .ycm_extra_conf.py and Ctags for generating Tags. My questions is what uses Tags ? Does YCM have any use for Ctags (Which collects all the definitions and important information about the code) ? Does YCM using tags generated by CTags in any way ? Does the generation of .ycm_extra_conf.py require the presence of Tags ?

I'd say that YCM doesn't require a tags database. If you have compiled it to rely on clang parser, well, you'll get very smart completion. Without that, thanks to tags you'll get something that's better than nothing.

Otherwise, most other plugins rely on a tags database to accomplish various things. For instance tagbar will display a structured outline of the tags in your system. In lh-cpp and vim-refactor I build a tags base at the last moment in order to deduce parents, children, members, jump/generate function definitions, etc.

You have to know that we cannot achieve things as smart with tags as what we'll be able to achieve with clang based plugins. Generating tags is actually much faster (but YCM works in background, as well as tags generating plugins like easytags (IIRC), Gutentag and lh-tags v2 (which I maintain)). Unfortunately they miss may informations. In particular when we use the not-very active exhuberant ctags -- I highly recommend universal ctags instead to parse C++ code, it'll even understand C++11 constructs.

if your .ycm_extra_conf.py set correctly, you don't need ctags.

if you let g:ycm_collect_identifiers_from_tags_files = 1 , and generate ctags with option --fields=+l , then YCM recognized the ctags and complete all tags as identifier, it's not accurate as semantic completion. and big ctags file use a lot of memory. So ctags is not recommended.

Edit:

YCM use clang as semantic backend. and the .ycm_extra_conf.py sets the flags clang needed. You could generate the compilation database, but when you add new file, you need to recreate compilation database.

Notice .ycm_extra_conf.py is a python file, so you can also generate flags dynamically. In my development, most flags is same, but the include flags changes. so I use a global .ycm_extra_conf.py to generate flags for including all .h file in my project. this way normally I don't need to create .ycm_extra_conf.py , and all the completion and goto function works.

You can download my global .ycm_extra_conf.py , and change some fixed flags as your favor, and put it to your project root or set it as globally, then you completion should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM