Skip to content

Index instance variable references#757

Open
vinistock wants to merge 2 commits intomainfrom
04-13-index_instance_variable_references
Open

Index instance variable references#757
vinistock wants to merge 2 commits intomainfrom
04-13-index_instance_variable_references

Conversation

@vinistock
Copy link
Copy Markdown
Member

@vinistock vinistock commented Apr 20, 2026

Closes #517

This PR starts indexing and handling instance variable references, which is required to match the Ruby LSP's find references for ivars.

The approach is mostly the same as any other reference. We have a new reference struct that gets collected during indexing and then merged into the main graph.

Resolution is running as a separate step at the end, which reuses the same logic as instance variable definitions.

Copy link
Copy Markdown
Member Author

vinistock commented Apr 20, 2026

@vinistock vinistock changed the title WIP WIP: index instance variable references Apr 20, 2026
Base automatically changed from 04-13-ensure_singleton_class_ancestors_are_linearized_when_created_out_of_resolution_loop to main April 20, 2026 17:55
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from 3454bd4 to 9fa22d6 Compare April 22, 2026 13:20
@vinistock vinistock self-assigned this Apr 22, 2026
@vinistock vinistock added the enhancement New feature or request label Apr 22, 2026
@vinistock vinistock changed the title WIP: index instance variable references Index instance variable references Apr 22, 2026
@vinistock vinistock marked this pull request as ready for review April 22, 2026 13:23
@vinistock vinistock requested a review from a team as a code owner April 22, 2026 13:23
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from 9fa22d6 to 3351ec6 Compare April 24, 2026 15:15
Copy link
Copy Markdown
Contributor

@Morriar Morriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the lint errors related?

Comment thread rust/rubydex/src/model/graph.rs
Comment thread rust/rubydex/src/indexing/ruby_indexer_tests.rs
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from 3351ec6 to a104e54 Compare April 30, 2026 21:29
@vinistock vinistock requested a review from Morriar April 30, 2026 21:30
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from a104e54 to ea66bbb Compare April 30, 2026 21:31
Comment thread rust/rubydex/src/resolution.rs
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from ea66bbb to 55e1349 Compare May 4, 2026 23:21
@vinistock vinistock force-pushed the 04-13-index_instance_variable_references branch from 55e1349 to ddac659 Compare May 4, 2026 23:26
/// Re-queueing is essential during incremental delete-then-readd of a receiver: without it,
/// ivars whose owner depends on a freshly-deleted receiver would be permanently dropped or
/// attached to `Object` (regression of #775).
fn resolve_ivar_owner(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work with weird cases like:

class Foo::Bar # Foo should be a TODO
  def Foo.baz
    @baz = 1
  end
end

}
}

#[test]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 additional cases we can cover:

  • ivar reference in a singleton class body: class Foo; class << self; @bar; end; end
  • ivar reference that can't be resolved from a parent: class Bar < Foo; def bar; @bar; end; end but Foo doesn't define @bar

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

Successfully merging this pull request may close these issues.

Index instance variable references

3 participants