rusty-tags
Oct 07, 2014 Download Exuberant Ctags for free. Exuberant Ctags is a multilanguage reimplementation of the Unix ctags utility. Ctags generates an index of source code definitions which is used by numerous editors and utilities to instantly locate the definitions. How to install GNU Global with universall ctags support on mac OS - Readme.md.
A command line tool that creates tags - for source code navigation by using ctags - for a cargo project, all of its direct and indirect dependencies and the rust standard library.
Prerequisites
- ctags installed, needs a version with the
--recurse
flag
On a linux system the package is most likely called
exuberant-ctags
.Otherwise you can get the sources directly from here or use the newer and alternative universal-ctags.
![Ctags For Mac Ctags For Mac](https://programmer.group/images/article/099f9b4c15f00292df1f33a0aa318e31.jpg)
Only
universal-ctags
will add tags for struct fields and enum variants.Installation
The build binary will be located at
~/.cargo/bin/rusty-tags
.Usage
Just calling
rusty-tags vi
or rusty-tags emacs
anywhere inside of the cargo project should just work.After its run a
rusty-tags.vi / rusty-tags.emacs
file should be beside of the Cargo.toml
file.Additionally every dependency gets a tags file at its source directory, so jumping further to its dependencies is possible.
Rust Standard Library Support
Tags for the standard library are created if the rust source is supplied by defining the environment variable
RUST_SRC_PATH
.These tags aren't automatically added to the tags of the cargo project and have to be added manually with the path
$RUST_SRC_PATH/rusty-tags.vi
or $RUST_SRC_PATH/rusty-tags.emacs
.If you're using rustup you can get the rust source of the currently used compiler version by calling:
And then setting
RUST_SRC_PATH
inside of e.g. ~/.bashrc
:Or without
rustup
by getting the rust source by yourself:Using
rustup
is the recommended way, because then you will automatically get the correct standard library tags for the currently used compiler version.Configuration
The current supported configuration at
~/.rusty-tags/config.toml
(defaults displayed):Vim Configuration
Put this into your
~/.vimrc
file:Or if you've supplied the rust source code by defining
RUST_SRC_PATH
:And:
Emacs Configuration
Install counsel-etags.
Create file
.dir-locals.el
in rust project root (please note the line to set counsel-etags-extra-tags-files
is optional):Use
M-x counsel-etags-find-tag-at-point
for code navigation.counsel-etags
will automatically detect and update tags file in project root. So no extra setup is required.Sublime Configuration
The plugin CTags uses vi style tags, so calling
rusty-tags vi
should work.By default it expects tag files with the name
.tags
, which can be set in ~/.rusty-tags/config.toml
:Or by calling
rusty-tags vi --output='.tags'
.MacOS Issues
Mac OS users may encounter problems with the execution of
ctags
because the shipped version of this program does not support the recursive flag. See this posting for how to install a working version with homebrew.Cygwin/Msys Issues
If you're running Cygwin or Msys under Windows, you might have to set the environment variable
$CARGO_HOME
explicitly. Otherwise you might get errors when the tags files are moved.Exuberant ctags is a cool, language-agnostic tool for creating tag files for your source code. Nice editors such as Vim, could use these tag files to implement the much needed 'jump to definition' feature.
Ctags is awesome, it supports Python, and is supported by Vim. It seems that the world is perfect and there's no reason to write a post about configuring it. Well... almost.
ctags has a little downside when using Python: it recognizes import lines as a definition, at least as of ctags v5.8. No need to explain why it's annoying in most cases. After 2 years of suffering, I've found it's possible to overcome this simply by adding the --python-kinds=-i option to the command line, or better: to ~/.ctags.
And just to make it complete, a quick cookbook style for setting everything up and using:
Ctags For Macbook
- Install ctags
e.g. aptitude install exuberant-ctags - Configurectags.
Add to ~/.ctags the following, one option per line:- --python-kinds=-i
- optional: --exclude=<partial names of bad files/directories>. e.g. --exclude=*/build/* to exclude all files inside 'build/' directories
- Add a cron to rebuild tags, for instance:
1 * * * * ctags -R -o ~/mytags ~/src - Configure vim:
add to ~/.vimrc: :set tags=~/mytags - Use Vim:
- vim -t <tag name> to open vim straight on the tag
- Ctrl+] to jump to tag when over a word
- Ctrl+T to pop back
- :tselect or :stselect to open
- :tnext, :tprev to go to next/prev tag finding
- :help tags for more ?