File tree 4 files changed +32
-8
lines changed
plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic
4 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ module Ide.Plugin.Tactic.CaseSplit
9
9
, splitToDecl
10
10
) where
11
11
12
- import Control.Lens
13
12
import Data.Bool (bool )
14
13
import Data.Data
15
14
import Data.Generics
@@ -37,13 +36,9 @@ mkFirstAgda pats body = AgdaMatch pats body
37
36
-- splitting it into multiple matches: one for each alternative of the case.
38
37
agdaSplit :: AgdaMatch -> [AgdaMatch ]
39
38
agdaSplit (AgdaMatch pats (Case (HsVar _ (L _ var)) matches)) = do
40
- (i, pat) <- zip [id @ Int 0 .. ] pats
41
- case pat of
42
- VarPat _ (L _ patname) | eqRdrName patname var -> do
43
- (case_pat, body) <- matches
44
- -- TODO(sandy): use an at pattern if necessary
45
- pure $ AgdaMatch (pats & ix i .~ case_pat) body
46
- _ -> []
39
+ (pat, body) <- matches
40
+ -- TODO(sandy): use an at pattern if necessary
41
+ pure $ AgdaMatch (rewriteVarPat var pat pats) body
47
42
agdaSplit x = [x]
48
43
49
44
@@ -63,6 +58,14 @@ wildifyT (S.map occNameString -> used) = everywhere $ mkT $ \case
63
58
(x :: Pat GhcPs ) -> x
64
59
65
60
61
+ ------------------------------------------------------------------------------
62
+ -- | Replace a 'VarPat' with the given @'Pat' GhcPs@.
63
+ rewriteVarPat :: Data a => RdrName -> Pat GhcPs -> a -> a
64
+ rewriteVarPat name rep = everywhere $ mkT $ \ case
65
+ VarPat _ (L _ var) | eqRdrName name var -> rep
66
+ (x :: Pat GhcPs ) -> x
67
+
68
+
66
69
------------------------------------------------------------------------------
67
70
-- | Construct an 'HsDecl' from a set of 'AgdaMatch'es.
68
71
splitToDecl
Original file line number Diff line number Diff line change @@ -128,6 +128,7 @@ tests = testGroup
128
128
, goldenTest " FmapJoin.hs" 2 14 Auto " "
129
129
, goldenTest " Fgmap.hs" 2 9 Auto " "
130
130
, goldenTest " FmapJoinInLet.hs" 4 19 Auto " "
131
+ , goldenTest " SplitPattern.hs" 7 25 Destruct " a"
131
132
]
132
133
133
134
Original file line number Diff line number Diff line change
1
+ data ADT = One | Two Int | Three | Four Bool ADT | Five
2
+
3
+ case_split :: ADT -> Int
4
+ case_split One = _
5
+ case_split (Two i) = _
6
+ case_split Three = _
7
+ case_split (Four b a) = _
8
+ case_split Five = _
Original file line number Diff line number Diff line change
1
+ data ADT = One | Two Int | Three | Four Bool ADT | Five
2
+
3
+ case_split :: ADT -> Int
4
+ case_split One = _
5
+ case_split (Two i) = _
6
+ case_split Three = _
7
+ case_split (Four b One) = _
8
+ case_split (Four b (Two i)) = _
9
+ case_split (Four b Three) = _
10
+ case_split (Four b (Four b2 a3)) = _
11
+ case_split (Four b Five) = _
12
+ case_split Five = _
You can’t perform that action at this time.
0 commit comments