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

Split tactic for datatypes #30

Closed
wants to merge 4 commits into from

Conversation

WorldSEnder
Copy link

Implements #21 but allowing datatypes with more than one constructor: one code action per constructor is produced.

In the current state, the constructor is not scope checked. This works fine most of the time, but might cause troubles down the line. I'm not sure how to implement scope checking correctly: imports might be qualified, renamed or specific to some constructors only. Is there existing machinery to deal with that sort of backwards name resolution inplace of just using occName as I did here?

@isovector
Copy link
Owner

This is excellent work, thank you @WorldSEnder!

We don't have a good story around scoping rules yet, so I wouldn't worry about it in this PR. I'm more worried about unexported data cons than unqualified occnames, as other plugins will notice the issue and suggest fixes.

I'm happy to merge this if you're happy with it!

@isovector
Copy link
Owner

I'll merge this later today!

@WorldSEnder
Copy link
Author

And with the addition of not suggesting I# for goals of type Int by default I'm happy with the code

@@ -95,7 +96,9 @@ commandProvider Intros =
provide Intros ""
commandProvider Split =
foldMapGoalType (F.fold . tyDataCons) $ \dc ->
provide Split $ T.pack $ occNameString $ getOccName dc
let cname = occNameString $ getOccName dc
in requireExtensionWhen MagicHash ("#" `L.isSuffixOf` cname) $
Copy link
Owner

@isovector isovector Oct 15, 2020

Choose a reason for hiding this comment

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

Let's use the algebraicTyCon function to do this check instead, though I'd be open to moving this check there.

Copy link
Owner

Choose a reason for hiding this comment

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

algebraicTyCon :: Type -> Maybe TyCon

Copy link
Owner

@isovector isovector Oct 15, 2020

Choose a reason for hiding this comment

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

Oh sorry, I misunderstood the check here. I'd argue this behavior is so far out of the ordinary experience of most developers that it's not worth supporting. On second thought, maybe we should gate algebraicTyCon behind -XMagicHash as well. It's a small price to pay, and if someone is going to explicitly enable -XMagicHash we might as well support it.

Copy link
Author

Choose a reason for hiding this comment

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

For the moment, I will use the algebraicTyCon check, add an ignored test case refering to #31 and tackle it in a follow up PR.

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds good to me. I really appreciate your keen eye on this!

One code action per datatype constructor is produced.
suggesting I# for Int probably is not what you want
99% of the time

also reuse tyDataCons, tacname
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.

2 participants