简体   繁体   English

如何结合多个类似ctags的标签工具?

[英]How to combine multiple ctags-like tags tools?

Ctags is the most famous tags tools. Ctags是最著名的标签工具。 However, there are some disadvantages of ctags, and there are some better choices vary from target languages to languages. 但是,ctags有一些缺点,并且从目标语言到语言都有一些更好的选择。

For example, for Ruby, I prefer to use ripper-tags . 例如,对于Ruby,我更喜欢使用ripper-tags And for JavaScript, people often use jsctags . 对于JavaScript,人们经常使用jsctags There is also something like CoffeeTags , too. 也有类似CoffeeTags的东西。

So, my question is, how to integrate or combine these tools? 因此,我的问题是,如何集成或组合这些工具? Is it possible to write a shell script (or something else), for example: omni-tags , so that I can use omni-tags for all kind of files. 是否可以编写一个shell脚本(或其他),例如: omni-tags ,这样我就可以对所有类型的文件使用omni-tags And it will automatically invoke different tags tools depends on file types? 并且它会自动调用不同标签工具取决于文件类型吗?

Sometimes there are more than one file types in a projects, so it will be more convenient if we can use a unified tool to generate tags. 有时一个项目中有多个文件类型,所以如果我们可以使用统一的工具来生成标签,它将更加方便。

Thanks. 谢谢。

Your hypothetical omni-tags command would be easy to implement in shell or any scripting language (Perl, Python, Ruby, whatever) assuming you were only dealing with projects with one particular kind of source code. 假设您只处理带有一种特定类型源代码的项目,那么您可以使用Shell或任何脚本语言(Perl,Python,Ruby等)轻松实现假设的omni-tags命令。 Just recursively scan a project directory, look for the predominant type of file within it (by matching file extensions, or using the Unix file program) and then run the tags-generation program associated with that particular kind of source file. 只需递归扫描项目目录,查找其中的主要文件类型(通过匹配文件扩展名或使用Unix file程序),然后运行与该特定种类的源文件关联的标签生成程序。

This would get more difficult, but not impossible, if you have a project containing code in multiple languages. 如果您的项目中包含多种语言的代码,这将变得更加困难,但并非没有可能。 One example would be a Ruby gem containing both Ruby .rb source files and some .c and .h files implementing a native C extension. 一个示例是一个Ruby gem,其中包含Ruby .rb源文件以及一些实现本机C扩展的.c.h文件。 In this case the Ruby and C files are usually fairly cleanly separated--ie, one directory tree under the root directory of the gem is all Ruby, and another is all C. So omni-tags could probably be written to recognize this case and run ctags on the .c and .h files and ripper-tags on the .rb files. 在这种情况下,通常将Ruby和C文件完全分开-即,gem根目录下的一个目录树全是Ruby,而另一个omni-tags是C。因此,可以编写omni-tags来识别这种情况,并且在.c.h文件上运行ctags ,在.rb文件上运行ripper-tags Since most editors can integrate multiple tags files per project (at least, I know Emacs can), you would then be able to navigate between a symbol defined in the C source and used in the Ruby source (for example). 由于大多数编辑器可以在每个项目中集成多个标签文件(至少,我知道Emacs可以这样做),因此您将能够在C源代码中定义的符号和Ruby源代码中使用的符号之间进行导航。

The trickiest part would be how to deal with code bases where multiple languages are intermingled that you want to tag. 最棘手的部分是如何处理您要标记的多种语言混合在一起的代码库。 For your JavaScript example, are you likely to have a directory containing both JavaScript and CoffeeScript files, for instance? 对于您的JavaScript示例,例如,您是否有可能同时包含JavaScript和CoffeeScript文件的目录? In this case omni-tags needs to run the tool appropriate to each language on each source file. 在这种情况下,需要使用omni-tags在每个源文件上运行适合每种语言的工具。 If the tags-generating tools are written to ignore any file not of the right type, you could just run each from the root directory of your project and then, again, use an editor that integrates multiple tags files. 如果编写了标签生成工具来忽略任何类型不正确的文件,则可以从项目的根目录运行每个文件,然后再次使用集成多个标签文件的编辑器。 If the tools need to be fed only the right kind of files, then omni-tags needs to build an index of the files in question and then feed the names of only the correct files to each tool. 如果仅需要向工具提供正确类型的文件,则omni-tags需要为所讨论的文件建立索引,然后仅将正确文件的名称提供给每个工具。 It's not impossible, but would require a bit more work (in contrast to the simplest case described in the first paragraph, which would probably be doable in about 10 lines of Python or Ruby). 这不是不可能的,但是需要做更多的工作(与第一段中描述的最简单的情况相反,这可能在大约10行Python或Ruby中是可行的)。

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

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