Skip to content

Implement document symbols for validations #283

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

Merged
merged 3 commits into from
Mar 11, 2024

Conversation

aryan-soni
Copy link
Contributor

Implements document symbol for the various types of Rails validations.

The remaining dsl feature is relationships. Based on my experience in this PR, it looks like the manner in which we handle each type of dsl feature doesn't generalize particularly cleanly. Consequently, after all the features are implemented, we can then reflect on the appropriate abstraction. Abstracting before comprehensive feature completion might cause us to create abstractions that we have to later rectify.

For now, these changes are scoped to focus on implementing validations exclusively.

@aryan-soni aryan-soni added the enhancement New feature or request label Mar 8, 2024
@aryan-soni aryan-soni requested a review from a team as a code owner March 8, 2024 01:30
receiver = node.receiver
return if receiver && !receiver.is_a?(Prism::SelfNode)

message_value = node.message
message = node.message
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message = node.message
message = T.must(node.message)

then we can remove the T.musts below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this one.

node.message is nilable. Once we enter the switch-case, we know for sure that it's not nil, but I don't think we can guarantee that before entering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged it without this, but we can fix this in the next PR based on your thoughts.

@andyw8
Copy link
Contributor

andyw8 commented Mar 11, 2024

Although it began with #280, I'm now thinking more that we should have a visual distinction between macros and plain methods:
Screenshot 2024-03-11 at 3 43 49 PM

@andyw8
Copy link
Contributor

andyw8 commented Mar 11, 2024

(we could perhaps push for a Macro type, as suggested here).

@andyw8
Copy link
Contributor

andyw8 commented Mar 11, 2024

One slight oddity: if you have multiple validations for one field, such as:

  validates :price, presence: true
  validates :price,
    numericality: { greater_than_or_equal_to: 0 },

Then you end up with multiple identical symbol entries.

ProductVariant in Core has a lot of this. I can't think of a better approach, but just wanted to highlight it.

Copy link
Contributor

@andyw8 andyw8 left a comment

Choose a reason for hiding this comment

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

Tried on large files in Core and didn't see any issues. As mentioned in the PR description, we'll need to do some refactoring afterwards to help separate the different aspects relating to symbols.

@aryan-soni
Copy link
Contributor Author

Although it began with #280, I'm now thinking more that we should have a visual distinction between macros and plain methods: Screenshot 2024-03-11 at 3 43 49 PM

I agree, nothing in the set of symbols offered seems like a good fit.

It is fairly easy to change down the road, so if something new is eventually released, it will be easy for us to change things.

@aryan-soni
Copy link
Contributor Author

One slight oddity: if you have multiple validations for one field, such as:

  validates :price, presence: true
  validates :price,
    numericality: { greater_than_or_equal_to: 0 },

Then you end up with multiple identical symbol entries.

ProductVariant in Core has a lot of this. I can't think of a better approach, but just wanted to highlight it.

Yeah, it comes down to whether we leverage the additional arguments.

I'm reflecting on this for the changes needed for relationships as well. For example, something like has_many :clients, :through => :appointments should potentially be displayed as has_many(clients, through: appointments).

As you mentioned, I don't think it's optimal to leverage something like this for validations. If someone specifies many arguments, it'll introduce a lot of complexity.

For each use case, we have to decide the benefits and costs of factoring in the arguments.

@aryan-soni aryan-soni force-pushed the as/document-symbol-validations branch from ced1f6d to 6a3ce32 Compare March 11, 2024 20:45
@aryan-soni aryan-soni force-pushed the as/document-symbol-validations branch 2 times, most recently from f7135be to 175b6f7 Compare March 11, 2024 20:53
@aryan-soni aryan-soni force-pushed the as/document-symbol-validations branch from 175b6f7 to d349619 Compare March 11, 2024 21:06
@aryan-soni aryan-soni merged commit d1ed636 into main Mar 11, 2024
@aryan-soni aryan-soni deleted the as/document-symbol-validations branch March 11, 2024 21:29
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.

3 participants