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

overloaded record dot plugin intial version (closes #3350) #3560

Merged
merged 22 commits into from
May 26, 2023

Conversation

joyfulmantis
Copy link
Collaborator

This is my first attempt at writing a plugin to provide codeActions that convert record selectors to record dot syntax. Please let me know any areas that can be improved.

@joyfulmantis
Copy link
Collaborator Author

Upon investigation of the failing builds, the GHC parsed syntax has changed enough that this is incompatible with GHC 9.2 (I tested myself only with 9.4). I'll see what I can do about a compatibility layer for 9.2 tomorrow.

Also update the CI to test overloaded-record-dot-plugin
and added overloaded-record-dot-plugin to stack.yml
Copy link
Collaborator

@July541 July541 left a comment

Choose a reason for hiding this comment

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

LGTM! Please add yourself to CODE_OWNERS.

I'm a little worried about the correctness of different scenarios. It would be great if more test cases were available!

Since most codes are similar to hls-explicit-record-fields-plugin, do we have the opportunity to extract some common patterns?

@July541
Copy link
Collaborator

July541 commented Apr 17, 2023

Your gif is 17.9 MB, can we reduce the size?😄

@joyfulmantis
Copy link
Collaborator Author

Your gif is 17.9 MB, can we reduce the size?

Done

I'm a little worried about the correctness of different scenarios. It would be great if more test cases were available!

Hmm, it's a relatively simple plugin, so there is not much to test. Could you give some examples of areas that need better coverage?

Since most codes are similar to hls-explicit-record-fields-plugin, do we have the opportunity to extract some common patterns?

While the explicit record fields plugin was used as a template, a lot of code had to be changed. There still certainly are some functions that share a lot of similar code, but nothing that I would think makes sense isolating to a shared function at this point.

@July541
Copy link
Collaborator

July541 commented Apr 18, 2023

Hmm, it's a relatively simple plugin, so there is not much to test. Could you give some examples of areas that need better coverage?

Sigh, I don't have a complete test range. I think it's also acceptable if we complement tests when necessary.

.github/workflows/test.yml Outdated Show resolved Hide resolved
@michaelpj
Copy link
Collaborator

I'd like to take a look in a bit. A high level comment is that we do have a lot of plugins, so we might want to consider whether we want to merge this into something else. Could potentially go in hls-refactor-plugin? Unsure.

@joyfulmantis
Copy link
Collaborator Author

I'd like to take a look in a bit. A high level comment is that we do have a lot of plugins, so we might want to consider whether we want to merge this into something else. Could potentially go in hls-refactor-plugin? Unsure.

Yes, I wasn't sure exactly how to integrate this functionality into the codebase. hls being very flexible with its plugin architecture coupled with lacking specific guidelines for what should be written as an individual plugin means that there are mammoth plugins, like hlint, and really small ones, like explicit record wildcard fields or explicit imports.

The flexibility in the plugin architecture is certainly helpful for easily including external and legacy tools. Still, an official policy on when to develop a new plugin for hls specific code (and perhaps some work to make legacy hls specific plugins conform to said policy) would be beneficial.

I decided to write this as a separate plugin after comparing it against standalone plugins with similar scopes, such as the explicit record fields plugin. However, I am happy to rewrite this into another plugin, such as hls refactor, if that architecturally would make more sense.

@July541
Copy link
Collaborator

July541 commented Apr 19, 2023

The problem is: if we move this plugin into hls-refactor-plugin, should hls-explicit-record-fields-plugin be treated the same? Furthermore, should we have hls-code-actions-plugin? I don't think the answer is yes, in my opinion, the only shortcoming is the release process, we need to update the version manually.

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Code generally looks good! Mostly high-level suggestions.

@joyfulmantis joyfulmantis requested a review from pepeiborra as a code owner May 2, 2023 23:37
@joyfulmantis
Copy link
Collaborator Author

Code generally looks good! Mostly high-level suggestions.

Thanks for all the suggestions!

This way we don't need to switch back and forward between the two,
and we can also return more than one match from inside a HsExpanded
@joyfulmantis
Copy link
Collaborator Author

joyfulmantis commented May 16, 2023

All of the comments have been resolved, with decisions that would most appropriately be decided for the whole project moved to #3597

@joyfulmantis joyfulmantis requested a review from michaelpj May 16, 2023 08:28
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Great stuff! Just some nits then I think we can merge.

CODEOWNERS Show resolved Hide resolved
ghcide/src/Development/IDE/GHC/Orphans.hs Show resolved Hide resolved

-- | Where we store our collected record selectors
data RecordSelectorExpr =
RecordSelectorExpr { -- | the location of the matched record selector, and record
Copy link
Collaborator

Choose a reason for hiding this comment

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

generally this haddock reads rather weirdly, like you meant it to flow between the documentation on the various fields? I'm not quite sure what you're trying to do here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

then title
else title <> " (needs extension: OverloadedRecordDot)"
where
title = "Convert `" <> name <> "` to record dot syntax"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just thinking about how this will read. If I understand right, for something like

foo bar

we'll get "Convert foo to record dot syntax". This reads a little weirdly to me, since "foo" is not really the thing being converted? What about something like "Use record dot syntax to access foo"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is not really a limit to how long the "record" will be, because we only require it to be an expression that eventually evaluates to a record. The record selector, on the other hand, should be relatively short. I like the "Convert foo to record syntax" option, because, that's the part that's actually changing. I feel "Use record dot syntax to access foo" would be incorrect, as we are not accessing foo, rather we are using foo to access bar. (foo as a record selector, is effectively a function that allows us to acesss part of bar)

@joyfulmantis joyfulmantis enabled auto-merge (squash) May 25, 2023 11:19
@joyfulmantis joyfulmantis merged commit 1edb489 into haskell:master May 26, 2023
@joyfulmantis joyfulmantis deleted the overloaded-record-dot branch May 26, 2023 11:39
@fendor fendor mentioned this pull request Aug 8, 2023
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants