atom-haskell-archive / haskell-ghc-mod

haskell-ghc-mod atom package
https://atom.io/packages/haskell-ghc-mod
MIT License
69 stars 20 forks source link

Add case-split ability #103

Closed JoeyEremondi closed 8 years ago

JoeyEremondi commented 8 years ago

This was my favorite feature when using ghc-mod with emacs: being able to put the cursor over a variable in a case-split, do M-t, and have it create the pattern match for me with all the possible constructors.

Is this currently possible with atom? If not, consider this a feature request in what's already a pretty great package.

Thanks!

lierdakil commented 8 years ago

No, it's not implemented at the moment, and yes, I can do that.

lierdakil commented 8 years ago

Sorry it took so long.

DanielG commented 8 years ago

Are you doing this via ghc-mod legacy-interactive or a separate ghc-mod invocation? There is a bug in all currently released versions that will break case splitting when you use check in the same session as case-split iirc.

lierdakil commented 8 years ago

Former. But that should be relatively easy to change.

lierdakil commented 8 years ago

I do however occasionally run into Prelude.head: empty list crash with case split with master.

DanielG commented 8 years ago

You can change it back to interactive after the next release it's just a workaround. As for that empty list crash I haven't seen that before. I see like four usages of head in CaseSplit.hs and some in FillSig.hs. We should probably replace them with headNote so we can identify which one is failing.

Gurkenglas commented 8 years ago

Selecting fromJust and invoking a command should import Data.Maybe, and there should be an option to automatically resolve not-in-scope errors by importing (and automatically remove unused imports). (Make sure not to let it move the line the cursor is on relative to the screen.)

lierdakil commented 8 years ago

@Gurkenglas, that is not possible in general case. Auto-imports are available, although those are work-in-progress. In any case, this is unrelated. In the future, please file separate issues.

lierdakil commented 8 years ago

@DanielG, apparently, it's this one: https://github.com/DanielG/ghc-mod/blob/master/Language/Haskell/GhcMod/CaseSplit.hs#L214

This happens primarily with stupid cases, e.g.

test :: Maybe a
test x = _body

Running case split on x will crash ghc-mod then.

DanielG commented 8 years ago

Can you make a testcase so we can track this crash?

lierdakil commented 8 years ago

Um. Sure. Should I add it to case-split tests with a PR then?

DanielG commented 8 years ago

Sure.