简体   繁体   English

.ycm_extra_conf.py和旺盛的Ctags有什么关系

[英]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. 我目前正在将基于C ++的IDE从XCode切换到Vim。 I have been reading about the Vim plugin "YCM" and it requires the presence of .ycm_extra_conf.py in the source dir. 我一直在阅读有关Vim插件“ YCM”的信息,它要求源目录中存在.ycm_extra_conf.py。 I am using YCM Generator to generate the .ycm_extra_conf.py and Ctags for generating Tags. 我正在使用YCM Generator生成.ycm_extra_conf.py和Ctags以生成标签。 My questions is what uses Tags ? 我的问题是什么使用标签? Does YCM have any use for Ctags (Which collects all the definitions and important information about the code) ? YCM对Ctags有什么用(哪个收集了有关代码的所有定义和重要信息)? Does YCM using tags generated by CTags in any way ? YCM是否以任何方式使用CTags生成的标签? Does the generation of .ycm_extra_conf.py require the presence of Tags ? .ycm_extra_conf.py的生成是否需要存在标签?

I'd say that YCM doesn't require a tags database. 我会说YCM不需要标签数据库。 If you have compiled it to rely on clang parser, well, you'll get very smart completion. 如果您已经编译它依赖于clang解析器,那么您将获得非常聪明的完成。 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. lh-cppvim-refactor中,我在最后一刻建立了一个标记库,以便推断出父母,孩子,成员,跳转/生成函数定义等。

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. 您必须知道,使用标签无法实现像使用基于clang的插件所能实现的那样聪明。 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)). 生成标签的速度实际上要快得多(但是YCM在后台运行,以及标签生成的插件,例如easytags(IIRC),Gutentag和lh-tags v2(我维护))。 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. 特别是当我们使用不太活跃的丰富的ctags时,我强烈建议使用通用ctags来解析C ++代码,它甚至可以理解C ++ 11的构造。

if your .ycm_extra_conf.py set correctly, you don't need ctags. 如果您的.ycm_extra_conf.py设置正确,则不需要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. 如果let g:ycm_collect_identifiers_from_tags_files = 1并使用选项--fields=+l生成ctags,则YCM会识别出这些ctags并将所有标签作为标识符完成,这在语义上是不准确的。 and big ctags file use a lot of memory. 大的ctags文件会占用大量内存。 So ctags is not recommended. 因此,不建议使用ctags。

Edit: 编辑:

YCM use clang as semantic backend. YCM使用clang作为语义后端。 and the .ycm_extra_conf.py sets the flags clang needed. .ycm_extra_conf.py设置所需的clang标志。 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. 注意.ycm_extra_conf.py是一个python文件,因此您也可以动态生成标志。 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. 因此,我使用全局.ycm_extra_conf.py生成用于在项目中包括所有.h文件的标志。 this way normally I don't need to create .ycm_extra_conf.py , and all the completion and goto function works. 这样,通常我不需要创建.ycm_extra_conf.py ,所有完成和goto函数都可以正常工作。

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. 您可以下载我的全局.ycm_extra_conf.py ,并更改一些固定标志作为您的喜好,然后将其放置到项目根目录或将其设置为全局,这样您就可以完成工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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