Skip to content

Lazy Index Entries #3545

@joeldrapper

Description

@joeldrapper

I have checked that this feature is not already implemented

  • This feature does not exist

Use case

For every Ruby DSL I can think of, false positives could be avoided by querying the index to understand the context of the call. For example, the belongs_to DSL method in Rails is only available on descendants of ActiveRecord::Base.

Unfortunately, it is not possible to query the index to check if the current context inherits from ActiveRecord::Base while still building the index.

Description

I think this problem could be solved by allowing you to store lazy “potential” entries in the index. Let’s say you pick up the method call belongs_to :user. You want to define the method user as a result of this, but only if the class inherits from ActiveRecord::Base.

What if you could add an entry like this?

@listener.add_lazy_method("user") do |index|
  if index.linearized_ancestors_of(owner).include?("ActiveRecord::Base")
    RubyIndex::Entry::Method.new(
      # ...
    )
  end
end

The index could store that there is potentially a method called user and its signature is in this Proc.

At lookup time, once the indexing is completed, the proc could be executed and if it returns nil, the entry is ignored. Otherwise, the returned Method entry is used.

Implementation

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpinnedThis issue or pull request is pinned and won't be marked as stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions