Skip to content

Conversation

@joshuay03
Copy link
Contributor

@joshuay03 joshuay03 commented Jul 3, 2025

Currently, cmd + clicking on the through association name goes to the same file as the association name. I've added definition support to navigate to the correct through association model file.

I've also added hover support as a follow-up to #616.

@joshuay03 joshuay03 requested a review from a team as a code owner July 3, 2025 14:09
@joshuay03 joshuay03 force-pushed the through-association-support branch from de3a801 to 62c54e5 Compare July 3, 2025 14:10
@joshuay03 joshuay03 changed the title Add support for :through associations Add support for :through associations Jul 3, 2025
@joshuay03 joshuay03 moved this to In Progress / Pending Review in Open Source Jul 3, 2025
has_one :profile
scope :adult, -> { where(age: 18..) }
has_one :location, class_name: "Country"
belongs_to :location, class_name: "Country"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going off of the schema I'm pretty sure this was incorrectly set up, as I don't see any tests that expect this to be invalid.

@joshuay03 joshuay03 force-pushed the through-association-support branch from 62c54e5 to 631ee7e Compare July 3, 2025 14:13
end
RUBY

assert_equal(2, response.size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without patch:
Screenshot 2025-07-03 at 11 52 27 pm

end
RUBY

assert_equal(2, response.size)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without patch:
Screenshot 2025-07-03 at 11 53 04 pm

@vinistock vinistock added the enhancement New feature or request label Jul 16, 2025
Copy link
Member

@vinistock vinistock left a comment

Choose a reason for hiding this comment

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

The Windows failures are unrelated. This makes sense, just added a question about the experience and the structure of the code

Comment on lines 113 to 119
through_association_name = node.arguments.arguments
.filter_map { |arg| arg.elements if arg.is_a?(Prism::KeywordHashNode) }
.flatten
.find { |elem| elem.key.value == "through" }
&.value
&.unescaped
handle_association_name(through_association_name) if through_association_name
Copy link
Member

Choose a reason for hiding this comment

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

Just to understand the intended experience, when going to definition you'd see both the association and the through association as options, correct?

Also, the node.arguments return is nilable for when there are no arguments. I think we can restructure this a bit.

  1. At the top of the handle_association method, we can get the arguments and return early if it's nil.
arguments = node.arguments&.arguments
return unless arguments
  1. Then you can reuse the same arguments array for checking the first argument and the through

Copy link
Contributor Author

@joshuay03 joshuay03 Aug 23, 2025

Choose a reason for hiding this comment

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

Just to understand the intended experience, when going to definition you'd see both the association and the through association as options, correct?

Yeah, that's what I initially implemented, but it's not what I actually wanted. I was showing both definitions regardless of which symbol was clicked. What I actually wanted was for each symbol to show only its specific definition.

I've updated both the implementation and tests to fix this.

Also, the node.arguments return is nilable for when there are no arguments. I think we can restructure this a bit.

  1. At the top of the handle_association method, we can get the arguments and return early if it's nil.
arguments = node.arguments&.arguments
return unless arguments
  1. Then you can reuse the same arguments array for checking the first argument and the through

Good idea. I've implemented this.

I've also added hover support here as a follow-up to #616.

@joshuay03 joshuay03 force-pushed the through-association-support branch 3 times, most recently from 93b5518 to a09ac2d Compare August 23, 2025 00:39
@joshuay03 joshuay03 changed the title Add support for :through associations Add definition and hover support for :through associations Aug 23, 2025
@joshuay03 joshuay03 force-pushed the through-association-support branch 13 times, most recently from 50f1527 to 098529a Compare August 23, 2025 02:16
@joshuay03 joshuay03 force-pushed the through-association-support branch from 098529a to 1f9206b Compare August 23, 2025 02:18
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.

2 participants