tpope / vim-bundler

bundler.vim: Lightweight support for Ruby's Bundler
https://www.vim.org/scripts/script.php?script_id=4280
404 stars 29 forks source link

The path doesn't contain the bundled gems anymore when we go away #27

Closed janko closed 11 years ago

janko commented 11 years ago

TL;DR: Is it possible for vim-bundler to look in for the Gemfile in :pwd, rather than relative to the currently opened project?

I open my project in Vim. Then I :find rails. And then I try to gf under active_support, but I can't. When I look at Vim's path, I see that my gems aren't there anymore. I assume that's because vim-bundler looks for the Gemfile relative to the currently opened project (Railties, in this case). And the railties gem, like most others, doesn't include their Gemfile in the installed gem, so I can't :find ActiveSupport.

Could vim-bundler look for the Gemfile in :pwd, which is always equal to the working directory?

tpope commented 11 years ago

This is an unacceptable trade-off in my book. Shit gets mad confusing when you accidentally forget to cd.

janko commented 11 years ago

Aha, I see what you mean. It's impossible for me to forget to cd into my project, because I'm using Terminal Vim (so I execute all commands from it). It's a shame, it would be really perfect browsing. This is an awesome feature what vim-bundler does, it just doesn't feel complete this way.

For example, vim-ruby does the same thing; it doesn't look for .ruby-version in :pwd, and then after 2 jumps you suddenly switched ruby versions :)

What about a fallback to :pwd (if there's no Gemfile in the currently opened project)?

nikhgupta commented 9 years ago

I wanted exactly the same behaviour, i.e. when I navigate away to Gem directories from my Rails project, I should be able to dig deeper into the tags. Here is what I am doing (o'course this is hackish):

let $GEMPATH__LOCAL = system("gem env home")[:-2] . "/gems"
augroup gem_ctags
  au!
  au BufEnter $GEMPATH__LOCAL/**/*.rb setl tags+=$GEMPATH__LOCAL/*/tags
  au BufLeave $GEMPATH__LOCAL/**/*.rb setl tags-=$GEMPATH__LOCAL/*/tags
augroup END

This may/should help others looking for this.

tpope commented 9 years ago

A slightly cleaner version of that might use something like let &l:tags = getbufvar('#', 'tags'), which steals the tags list from the previous buffer. You could do the same for 'path' too. A really clean solution (and one that I would consider merging) would check the Bundler project of the previous buffer to see if the current file belongs to one of its gems.

tpope commented 9 years ago

I took a slightly closer look at this and accidentally ended up implementing a solution. Very lightly tested so let me know how it works.

JohnMorales commented 9 years ago

:laughing: "accidentally ended up implementing a solution"

thanks Tim!

janko commented 9 years ago

Works for me, thank you!