如何为 Rails 项目生成良好的 ctags 文件?一个包含所有宝石、红宝石库并按正确顺序对它们进行排序的库(例如,当您搜索“Rails”时,它不会搜索到空气制动宝石或其他任何东西)
我现在正在使用这个,但由于上述原因我不喜欢它:
ctags --tag-relative -Rf.git/tags.$$ --exclude=.git --exclude=*.html --exclude=tmp --exclude=public --exclude=app/assets --languages=-javascript,js,sql,html `bundle show --paths` $MY_RUBY_HOME .
Vim 和 ctags 都无法理解或无法被教导理解您的代码和/或您的想法。如果您想跳转到与
tags
文件中第一个匹配的标签不同的标签,请使用正确的命令:
:tselect foo " list all tags 'foo'
:tselect /foo " list all tags containing 'foo'
g] " list all tags matching the word under your cursor
另请注意,您可以通过将文件类型列入白名单来使“您的”ctags 命令稍微短一些:
ctags --tag-relative -Rf.git/tags.$$ --exclude=.git --exclude=tmp --exclude=public --exclude=app/assets --languages=ruby `bundle show --paths` $MY_RUBY_HOME .
所以事实证明,更好的选择(比 ctags 更好)是 Emacs 的 Robe 或
vim + tmux + vmux + pry
的组合(获得 show-source
和 edit
)。
irb-config 是一个有趣的 vim 设置示例。
这就是我正在做的事情,效果很好:
#!/bin/bash
project_dir="~/<project>"
# Delete existing tags to start fresh
rm -f tags gemtags evrthngelse
# Generate tags for Ruby gems
ripper-tags -R -f gemtags <path to project gemfile>/gems
# Generate tags for the project, excluding certain directories and files
ctags -R -f evrthngelse --exclude=vendor --exclude=.git --exclude=log --exclude=tmp --exclude='*.rb' --exclude='*.erb' .
ripper-tags -R --exclude=vendor --exclude=.git --exclude=log --exclude=tmp .
# Concatenate temporary tag files into the main 'tags' file
cat evrthngelse >> tags
cat gemtags >> tags
# Remove temporary tag files
rm -f gemtags evrthngelse
# De-duplicate the tags file, preserving order
awk '!seen[$0]++' tags > temp_tags && mv temp_tags tags
我知道根本问题是 Ruby 松散的动态类/模块/方法定义,但仍然感觉它应该工作得更好。我对 Ripper-tags 充满希望,但在预测您想要访问哪些标签定义方面,它比 IDE 差很多。