dan-t / rusty-tags

Create ctags/etags for a cargo project
Other
405 stars 32 forks source link

Vim can't find recursive tag files #86

Open thenorili opened 2 years ago

thenorili commented 2 years ago

setup:

I can follow the tag "bevy::sprite" which leads to crates/bevy_internal/src/lib.rs. I can follow tags to other prototypes inside of crates/bevy_internal/src/lib.rs. I can find things inside the standard library with no problem. My autocmds are exactly like the "if you have a $RUST_SRC_PATH".

My uneducated guess is that Vim's not finding the recursively-created tag files and adding them to the tags variable. My tags variable is below.

tags=./rusty-tags.vi;/,~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rusty-tags.vi

dan-t commented 2 years ago

You're telling what works, but not what doesn't work.

I never tested it with neovim. The whole "magic" of recursive tags files is the tags setting './rusty-tags.vi;/', which searches for a opened file for a tags file, starting at the directory of the file going upwards the directory tree. I don't know if neovim supports this setting.

thenorili commented 2 years ago

ah, I'm sorry! That pattern definitely works with neovim, no change. What doesn't work is "every other tag". Nothing actually goes to its definition.

Like, consider:

$ROOT/examples/games/breakout.rs is going up, but not down. When I build the tags each individual crate at $ROOT/crates/* gets its own tags file, but there's no reference from the root file to those dependencies even when they're formally declared, all that it finds is the prototypes in $ROOT/src/lib.rs and the standard library stuff.

dan-t commented 2 years ago

I think I know what your problem is.

All these separate crates in the bevy engine are independent of each other, they aren‘t dependencies of each other. Therefore the tag files of each crate don‘t contain/know anything about the other crates and you can‘t jump to them.

It‘s like having several rust cargo projects. If they don‘t depend on each other you can‘t jump between them.

But if you e.g. create your own game, which depends on several bevy crates, you‘ll get tags for them and can jump to them.

thenorili commented 2 years ago

The example program does have dependencies on several bevy crates which it declares explicitly. However, the tags can't find those dependencies. They can find the lib.rs with prototypes for some stuff, but they can't find the actual source.

dan-t commented 2 years ago

The problem is how bevy defines the sprite module:

pub mod sprite {
    //! Items for sprites, rects, texture atlases, etc.
    pub use bevy_sprite::*;
}

The ctags program doesn't understand this definition, which includes all the definitions from bevy_sprite and therefore also can't create tags for them.

dmlary commented 1 year ago

I encountered a similar problem with vim, bevy, and vim-fzf. vim-fzf uses the tags file in your current working directory, which for my workflow is the top-level directory of my project.

I was able to build the tags file with rusty-tags -O tags vi, but it was missing all of the deeper bevy_* dependencies, such as Assets from bevy_assets. I figured out this was because I only listed bevy as a dependency in Cargo.toml.

My workaround was to construct the tags file manually from the generated tags file and the cache files:

rusty-tags -v -O tags.partial vi
cat ~/.rusty-tags/cache/bevy* tags.partial | sort -u > tags

Question

Is there any way rusty-tags could add something like a --monolithic or --all-tags flag to rusty-tags to write every tag found to the output file? That would add support for stable current working directory workflows.