tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.11k stars 384 forks source link

Deep directories in projections #491

Closed samstickland closed 7 years ago

samstickland commented 7 years ago

Hi, great gem! It's already saving me a lot of time :)

I'm wondering if it's possible to use arbitrary levels of nesting in a projection. For example:

let g:rails_projections = {
      \ "app/concepts/**/cell/*.rb": {
      \   "command": "cell",
      \   "affinity": "cell",
      \   "alternative": "spec/concepts/**/cell/{}_spec",
      \   "related": "app/concepts/**/view/{}.slim"
      \ }
      \ }

This isn't working. The alternative and related commands continue to open the matching spec, which I believe is the default?

If there's a way to do this I'll write up the example in the wiki.

tpope commented 7 years ago

Use {dirname} and {basename}.

samstickland commented 7 years ago

Hi,

Thanks the reply.. however I think I'm misunderstanding something here :/

This config doesn't work:

let g:rails_projections = {
      \ "app/concepts/**/cell/*.rb": {
      \   "command": "cell",
      \   "affinity": "cell",
      \   "alternative": "spec/concepts/{dirname}/cell/{basename}_spec.rb",
      \   "related": "app/concepts/{dirname}/view/{basename}.slim"
      \ }
      \ }

However, if I try it with a specific directory name from my project, like below, then it does work:

let g:rails_projections = {
      \ "app/concepts/open_role/cell/*.rb": {
      \   "command": "cell",
      \   "affinity": "cell",
      \   "alternative": "spec/concepts/open_role/cell/{basename}_spec.rb",
      \   "related": "app/concepts/open_role/view/{basename}.slim"
      \ }
      \ }
tpope commented 7 years ago

So looks like **/.../* support is actually a projectionist.vim feature I never got around to porting over to rails.vim. Someone looking into that would be wonderful, though I'm guessing that won't be the most approachable of tasks to the uninitiated.

A good starting place would be s:readable_projected_with_raw() in rails.vim and projectionist#query_raw() in projectionist.vim.

akarzim commented 3 years ago

@tpope Oh! I'm looking for that exact feature! Is anyone working on porting this useful projectionist.vim feature to rails.vim?

Subsidiary question: Why does rails.vim mimic the projectionist.vim features rather than calling projectionist.vim if the plugin is present?

tpope commented 3 years ago

Rails.vim's projections are older than Projectionist. The latter was inspired by the former.

akarzim commented 3 years ago

Rails.vim's projections are older than Projectionist. The latter was inspired by the former.

It makes sense! Thanks for the quick response and this useful plugin