thoughtbot / factory_bot_rails

Factory Bot ♥ Rails
https://thoughtbot.com/services/ruby-on-rails
MIT License
3.07k stars 369 forks source link

Add projections.json for Dispatch.vim support #405

Closed calebhearth closed 1 year ago

calebhearth commented 2 years ago

Rails.vim allows gems to provide their own projections compatible with Dispatch.vim by placing them at lib/rails/projections.json. This configuration allows:

To use this, you'll need Rails.vim, Bundler.vim, and Dispatch.vim plugins.

See :help rails-projections or the file on GitHub for more clarity on what specifically each config key is doing.

Inspired and updated from @henrik's Gist

tpope commented 2 years ago

Found this via https://twitter.com/caleb_hearth/status/1567269197545340928, wherein the recent removal of this rails.vim feature, and the possibility of bringing it back, are discussed. I've tentatively done so.

Note that rails.vim has partial support for FactoryBot built-in by way of :Efixtures. I did this because :Efixtures is a special case command that isn't possible to extend, and because conceptually it's a pretty clean fit, filling the same use case. This also covers other navigational uses like :A. Until today it also forced the default task to be db:fixtures:load; I just fixed that. What I didn't take responsibility for is syntax highlighting and the template, as there are official interfaces for doing that externally.

That said, I think any attempt at an external implementation should attempt to do as much as possible, even if it's redundant, for future-proofing. I bring it up because it might explain some of the oversights below.

Issues with this PR:

That last one raises a question: Is there any way the list of highlighted keywords can be kept up-to-date automatically? If this list is going to fall out of date, it's probably better not to ship it at all. Nothing worse than syntax highlighting that lies to you. (If the API is fully matured and no longer gaining new methods, that would also render this moot.)

calebhearth commented 2 years ago

Thanks @tpope for the input here! Lots of good stuff, some sounds like easy fixes and some like discussions. I have a tough schedule this week but I'm happy to circle back on this as soon as my schedule frees up, hopefully next week (kiddo is sick and home from day care, so I'm parenting a lot more than usual)

calebhearth commented 2 years ago
  • The list of highlighted keywords barely scratches the surface. A quick check of GETTING_STARTED reveals that add_attribute, association, after, before, callback, initialize_with, traits_for_enum, to_create, and skip_create are omitted, and I have no reason to believe that list is exhaustive.

That last one raises a question: Is there any way the list of highlighted keywords can be kept up-to-date automatically? If this list is going to fall out of date, it's probably better not to ship it at all. Nothing worse than syntax highlighting that lies to you. (If the API is fully matured and no longer gaining new methods, that would also render this moot.)

Anyone at thoughtbot have an opinion on this one? If not, I'm inclined to agree that it's better to omit. I think all it will do is add some highlights to certain methods, which doesn't add value commensurate with the maintenance burden.

calebhearth commented 2 years ago

I guess I had some time.

mike-burns commented 1 year ago

The thing I'm looking at here is that only the vim-projectionist project loads these files -- other implementations such as vscode-alternate-file and the command-line projectionist project only look for .projectionist.json files in the current or parent directories.

So this would be something for only the (Neo)Vim users. That said, I'm one of those.

How much work will this be to maintain? It looks like something I can set and forget -- is that actually true?

mike-burns commented 1 year ago

Alright, merged. Thank you for this @calebhearth , and thanks to @tpope for the suggested improvements (and for writing projectionist in the first place).