Skip to content

Case split plugin - #5014

Open
Aster89 wants to merge 1 commit into
haskell:masterfrom
Aster89:master
Open

Case split plugin#5014
Aster89 wants to merge 1 commit into
haskell:masterfrom
Aster89:master

Conversation

@Aster89

@Aster89 Aster89 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This PR is for (re-¹)introducing the so called case-split plugin, as requested in #5013, and it is part of my project for GSoC 2026.

To see the full summary of the project, click here. The summary also contains a list of stretch goals, some of which have been addressed already.

The work I've done and that I plan to submit via the present pull request, has consisted mainly of:

  • implementing the case-split plugin by incrementally focusing on several use-cases from less to more complex,
  • making use of ghc-exactprint for correctly layout out the patterns to be inserted,
  • contextually writing tests for guarding such use-cases as I enabled them,
  • finally, striving to address some stretch goals.

The result of such work is a plugin providing a code action for adding missing patterns to a case/\case expression that has a non-exhaustive list of patterns.

For instance, the plugin turns this

data X = A
       | B
       | C Int
       | D Int Int
       | E Int Int Int Int
       | F

foo :: X -> Int
foo x = case x of
          A -> 3;
                B -> 4;
              C _ -> 5

into this

data X = -- same as above

foo :: X -> Int
foo x = case x of
          A -> 3;
                B -> 4;
              C _ -> 5
          D _ _ -> _
          E {} -> _
          F -> _

¹ Earlier attempts

Indeed, there were some earlier attempts. See the summary for some pointers.

@dschrempf

Copy link
Copy Markdown
Collaborator

Everybody is eagerly anticipating this change, thank you!

Given the many WIP commits, I just wanted to ask if you could sqaush or reword them. I guess you had this in mind anyways.

@Aster89

Aster89 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Everybody is eagerly anticipating this change, thank you!

Glad to hear that!

Given the many WIP commits, I just wanted to ask if you could sqaush or reword them. I guess you had this in mind anyways.

Yep, see 3rd paragraph at the top :P

@dschrempf

Copy link
Copy Markdown
Collaborator

Ah, the second sub-clause :-P my attention had already shifted before that one, I apologize :-)! Thanks!

@fendor fendor changed the title Case split plugin - Fixes #5013 Case split plugin Jul 14, 2026
@fendor
fendor marked this pull request as draft July 20, 2026 09:21
Comment thread ghcide/src/Development/IDE/Core/Compile.hs

@MangoIV MangoIV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

First pass. I think after you clean up the main logic a bit more and add some documentation there, I can take another look. :)

Very good work, looking forward to having this in HLS!

Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated

@MangoIV MangoIV left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

another small round :)

Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
@Aster89
Aster89 force-pushed the master branch 7 times, most recently from 82aad14 to c7f9b61 Compare August 7, 2026 09:36
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
@Aster89
Aster89 requested a review from MangoIV August 7, 2026 09:42
@Aster89
Aster89 marked this pull request as ready for review August 7, 2026 10:52

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice, this looks like it is making great progress!

I reviewed the plugin, I have mostly comments regarding readability and suggestions for improvements that hopefully improve the maintainability in the long run.

Some things are nitpicks, and you should feel free to ignore them.

I think we need one Note that outlines what the implementation strategy of the case split plugin is (e.g., reads the structured error message, etc...) so that it is easier to tell what the individual steps for case splitting are.

Comment thread plugins/hls-case-split-plugin/test/Main.hs Outdated
Comment thread plugins/hls-case-split-plugin/test/Main.hs
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
@Aster89
Aster89 force-pushed the master branch 6 times, most recently from 1fe48da to 38c773c Compare August 17, 2026 05:56
@Aster89
Aster89 requested review from MangoIV and fendor August 17, 2026 05:56
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
Comment thread plugins/hls-case-split-plugin/src/Ide/Plugin/CaseSplit.hs Outdated
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