Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for ActiveSupport::Concern #491

Open
andyw8 opened this issue Oct 22, 2024 · 1 comment
Open

Improve support for ActiveSupport::Concern #491

andyw8 opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@andyw8
Copy link
Contributor

andyw8 commented Oct 22, 2024

Note

This issue is aimed at those attending the RubyConf 2024 Hack Day

Caution

This will likely be a difficult issue, please discuss approaches with the maintainers before attempting.

For ActiveRecord model, you'll notice that you can hover over some DSLs, such as has_one:, to see its documentation, but if you others, such as validates:, nothing is shown.

This is because the ActiveModel::Validations::Callbacks module is mixed into the parent’s class using an included block:

https://github.com/rails/rails/blob/d4fff28caf25546dfef68087047af34927a3d5f0/activerecord/lib/active_record/callbacks.rb#L413

As this a Rails feature, it is not supported by Ruby LSP natively.

It should be possible to support this via an Indexing Enhancement in the Rails addon so that the index knows about ActiveModel::Validations::Callbacks, and Ruby LSP will then be able to show the documentation on hover.

Also, since included can be used in application code, this will improve Ruby's LSP's ability to provide features for your app.

There is partial support for concerns in indexing_enhancement.rb but it doesn't yet know about included.

(Note that there can also be a prepended block).

These articles may help with understanding the details of concerns:

@andyw8 andyw8 added enhancement New feature or request railsconf-hackday Issues intented for working on during RailsConf 2024 Hack Day labels Oct 22, 2024
@andyw8 andyw8 removed the railsconf-hackday Issues intented for working on during RailsConf 2024 Hack Day label Oct 24, 2024
@kassemsandarusi
Copy link

kassemsandarusi commented Dec 17, 2024

Hi there!

I've been playing around with building an indexing enhancement for another package with a similar DSL, and I see a few roadblocks and was wondering what y'all were thinking around this topic.

Rails server boot

Today the rails server boots in a background thread. However, in order to contribute to indexing the Rails server likely needs to boot before indexing starts, so that it and dependent addons can register indexing enhancements that contribute to indexing and leverage the rails server during it. Otherwise (I think) you'll need to re-index after the server has loaded. The good news is that Ruby LSP likely already supports loading the server beforehand by only starting indexing after addons are loaded and so its mostly a rails LSP problem.

The obvious bad news is that this possibly increases the total time to index if the server needs to boot up.

Enhancement construction

The second issue I see is that unlike the overrides in Addon you can have for creating listeners, the enhancement registry manages initialization of enhancements so there's no clear injection point for additional dependencies.

Perhaps there's a way to reference global state that isn't passed, but it does seem a little gross.

Let me know what y'all think and if I'm on the right track for what are the major impediments here!

@andyw8 andyw8 self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants