tpope / vim-rails

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

ViewComponent related file #604

Open natematykiewicz opened 4 months ago

natematykiewicz commented 4 months ago

When using ViewComponent, you'll have a .rb file in app/components, and a corresponding Rails view whose path is the same except for the file extension.

For example: app/components/foo_component.rb app/components/foo_component.html.erb

Is there a good way to go to the Ruby file when I'm in the view, and go to the view when I'm in the Ruby file? :A and :R both bring me to spec/components/foo_component_spec.rb when in the Ruby file and do nothing ("No alternate file defined") when in the view.

Given how controllers and views work with :R, I think :R would be a good fit for this.

jbigler commented 4 days ago

Create a .projections.json file in your project directory with the following content:

{
  "app/components/*_component.rb": {
    "type": "component",
    "related": "app/components/{}_component.html.erb"
  },
  "app/components/*_component.html.erb": {
    "type": "template",
    "related": "app/components/{}_component.rb"
  }
}

That will make :R work for moving between file and template. since we are already able to open the test with :A.