有没有比 ctags 效果更好的替代方案?

发布于 2024-12-09 17:17:32 字数 1539 浏览 0 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧情勿念 2024-12-16 17:17:32

我自己也花了相当长的时间来解决这个问题。

我得到的最接近的是gccsense。不幸的是,该项目似乎已被放弃,而且由于英语不是作者的母语,因此很难建立它。

我最终从另一个角度解决了这个问题。我决定智能感知/自动完成对我的编码来说比拥有 vim 的所有可用功能更重要,所以我选择了像 Eclipse 这样的 IDE,然后找到了一个模拟 Vim 的 Eclipse 插件。到目前为止,我发现的最好的类似插件是 Viable

以下是我尝试过但发现不满意的选项的完整列表:

  • clang - 要求您从 gcc 切换到不同的“更好”编译器。问题是 gcc 更加成熟 [编辑 显然你不需要切换编译器,请参阅下面的评论,我可能会在将来再次尝试。]
  • gccsense - 好主意(使用 gcc 给出你完成了代码)但是该项目的工作被放弃了:(并且发布的版本是测试版质量
  • xref - xref 是一个很棒的独立工具,非常适合解析 C。它可以通过 vxref,但是根据我的经验,xref 缺乏解析当前的 C++ 代码,并且它的开发已经停止(以及 vxref 的开发。)
  • eclim - 似乎有效非常适合使用 eclipse 进行 Java 支持,在解析 C++ 或 C 代码时速度极慢且完全不可靠,通常会发生很长一段时间一切正常,但突然间,解析器停止解析您编写的任何新代码,并且完全无法加载。启动 Eclipse 本身并强制 Eclipse 重新解析项目似乎有帮助。另外,不那么重要的事实,但更令人烦恼的是 eclim 接管了错误处理,因此它搞砸了 vim 通常解析 gcc 错误的方式,这意味着你无法访问快速修复列表,这很烦人。
  • netbeans + jvi - 很多人都对此深信不疑,但我在使用 jvi 时遇到了各种各样的问题。我遇到的一个主要问题是 jvi 会说我处于正常模式,但实际上处于插入模式,除了重新启动之外没有什么帮助。
  • eclipse + viplugin/vrapper - 这开始看起来像是最好的选择;每个都有自己的一组错误+缺乏功能,但仍然是最有吸引力的,直到我发现可行的似乎是最稳定的并且具有最多的功能。

如果您确实找到了满意的解决方案,请在评论中分享,因为我会对它感兴趣。

I've spent quite some time struggling with this myself.

The closest I ever got was something called gccsense. Unfortunately, the project seems abandoned and moreover it was difficult setting it up because English was not the author's first language.

I ended up approaching the problem from another angle. I made the decision that intellisense/autocomplete was more important to my coding than having all the available features of vim, so I chose an IDE like Eclipse, and then found a plugin for Eclipse that emulates Vim. So far the best kind of plugin like that that I found was Viable.

Here is the full list of options that I have tried and found unsatisfactory:

  • clang - requires you switch from gcc to a different and "better" compiler. The problem is gcc is much more mature [edit apparently you don't need to switch compilers see comments below, I may give this another try in the future.]
  • gccsense - great idea (using gcc to give you the code completion) however work on the project is abandoned :( and the version that is up is beta quality
  • xref in vim - xref is a great standalone tool and works great for parsing C. It can be made to work in vim with vxref, however from my experience xref lacks in parsing current C++ code and development on it has stopped (as well as development on vxref.)
  • eclim - seems to work great for Java support using eclipse, extremely slow and completely unreliable when parsing C++ or C code. What usually happens is everything works for a long while, but then suddenly, the parser stops parsing any new code that you write, and nothing short of loading up eclipse itself and forcing eclipse to reparse the project seems to help. Also, less of an important fact, but more of an annoyance is that eclim takes over handling errors, so it screws up the way vim usually parses errors from gcc meaning you have no access to the quickfix list which is annoying.
  • netbeans + jvi - alot of people swear by this, but I had all sorts of problems with jvi. One major problem I had was jvi would say I'm in normal mode, but really was in insert mode, nothing short of a restart would help.
  • eclipse + viplugin/vrapper - this was beginning to look like the best option; each had its own set of bugs + lacking features, but still was most attractive, until I found viable which seemed to be the most stable and have the most features.

If you do find a solution you are happy with please share it in a comment, because I would be interested in it.

怀中猫帐中妖 2024-12-16 17:17:32

我自己还没有尝试过,但是 clang_indexer 似乎非常接近您正在寻找的内容(来源)。它仍然使用外部数据库(即本身不动态索引),但它似乎提供了通常只能在 cscope 中找到的功能(它不太支持 C++)。

对于自动完成,我使用 clang_complete。它不需要生成索引并且在大多数情况下工作得很好。它还可以在 vim 中进行自动语法检查,以便对可能出现的问题发出警告。 但它不会自动完成您提供

#define blah(x) blah__ ## x
void blah_<TAB>

bla__x 宏示例(仅作为 blah(x))。如果它能更容易配置就好了,但我也不认为它有问题。

I haven't tried this myself yet, but clang_indexer seems very close to what you are looking for (sources). It still uses an external database (i.e. doesn't index on the fly per se), but it seems to offer functionality one usually only finds in cscope (which doesn't support C++ too well).

For autocomplete I use clang_complete. It doesn't require generating an index and works most of the time pretty well. It also can do automatic syntax checking in vim so one is warned of possible issues. It doesn't autocomplete the macro example you gave

#define blah(x) blah__ ## x
void blah_<TAB>

as bla__x though (only as blah(x)). It would be nice for this to be more configurable, but I wouldn't consider this broken either.

∞觅青森が 2024-12-16 17:17:32

CScout 2.8 版提供了一个命令行选项 (-C),可以创建与 vim 兼容的标签文件对于它将处理的 C 源代码。 CScout 是一个用于 C 程序集合的源代码分析器和重构浏览器。它可以处理多个项目的工作空间,将 C 预处理器引入的复杂性映射回原始 C 源代码文件。因此,生成的标签文件包含通过预处理器宏创建的实体(如函数、变量和结构)的正确信息。 CScout 将使用代码的项目配置文件(相当于 Makefile)中指定的包含文件路径来处理包含文件。要尝试一下,请下载与您的设置匹配的软件包,进入包含 awk 源代码的示例目录并运行。

../bin/cscout -Cc awk.cs

您可以看到 CScout 可以处理的一些类型的预处理器构造在此页面中。例如,如果您处理以下代码,

#define typefun(name, type, op) \
type type ## _ ## name(type a, type b) { return a op b; }

typefun(add, int, +)
typefun(sub, int, -)
typefun(mul, int, *)
typefun(div, int, /)
typefun(add, double, +)
typefun(sub, double, -)
typefun(mul, double, *)
typefun(div, double, /)

main()
{
        printf("%d\n", int_add(5, 4));
        printf("%g\n", double_mul(3.14, 2.0));
}

CScout 将生成一个包含以下条目的标签文件。

double_add  test.c  8       ;"  f
double_div  test.c  11      ;"  f
double_mul  test.c  10      ;"  f
double_sub  test.c  9       ;"  f
int_add test.c  4       ;"  f
int_div test.c  7       ;"  f
int_mul test.c  6       ;"  f
int_sub test.c  5       ;"  f
main    test.c  13      ;"  f
typefun test.c  1       ;"  d

您可以通过在示例源代码中添加一些代码生成宏来亲自尝试一下,以查看 CScout 将创建的标签。

CScout version 2.8 offers a command-line option (-C) that will create a vim-compatible tags file for the C source code it will process. CScout is a source code analyzer and refactoring browser for collections of C programs. It can process workspaces of multiple projects mapping the complexity introduced by the C preprocessor back into the original C source code files. Consequently, the generated tags file contains correct information for entities, like functions, variables, and structures, that are created through preprocessor macros. CScout will process include files, using the include file paths specified in the code's project configuration file (the equivalent of a Makefile). To try it out, download the package matching your setup, go into the example directory containing the awk source code and run

../bin/cscout -Cc awk.cs

You can see some types of preprocessor constructs that CScout can handle in this page. For example, if you process the following code

#define typefun(name, type, op) \
type type ## _ ## name(type a, type b) { return a op b; }

typefun(add, int, +)
typefun(sub, int, -)
typefun(mul, int, *)
typefun(div, int, /)
typefun(add, double, +)
typefun(sub, double, -)
typefun(mul, double, *)
typefun(div, double, /)

main()
{
        printf("%d\n", int_add(5, 4));
        printf("%g\n", double_mul(3.14, 2.0));
}

CScout will generate a tags file with the following entries.

double_add  test.c  8       ;"  f
double_div  test.c  11      ;"  f
double_mul  test.c  10      ;"  f
double_sub  test.c  9       ;"  f
int_add test.c  4       ;"  f
int_div test.c  7       ;"  f
int_mul test.c  6       ;"  f
int_sub test.c  5       ;"  f
main    test.c  13      ;"  f
typefun test.c  1       ;"  d

You can try it out yourself by adding a few code-generating macros in the example source code to see the tags CScout will create.

神仙妹妹 2024-12-16 17:17:32

一种可能是使用 Eclim。它是一个强大的工具,可以通过多种方式使用;在你的情况下,你必须启动一个无头 Eclipse 服务器并基本上使用 Eclipse 的索引器等。我认为你需要将你的项目注册为 Eclipse 项目。

One possibility is to use Eclim. It is a powerful tool that can be used in many ways; in your case you would have to start a headless Eclipse server and basically use Eclipse's indexer etc. I think you need to have your project registered as an Eclipse project though.

看轻我的陪伴 2024-12-16 17:17:32

我使用“global”系统。安装后,您可以使用“global”命令来搜索代码,并使用“gtags”来建立索引。

我使用 Linux 内核,它帮了我很大的忙:它的定义更加智能(但仍然不如我想要的那么好),并且它了解函数原型、函数实现以及代码中对函数的所有引用。

还可以将“全局”与 VIM 集成,有一个插件:

祝你好运。

I use 'global' system. After you install it you have 'global' command to search your code and 'gtags' for indexing.

I work with Linux kernel and it helps a lot: it works with defines more intelligent (but still not as good as I want it) and it knows about function prototype, function implementation and all references to the function from the code.

It's also possible to integrate 'global' with VIM, there is a plugin for it:

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文