Skip to content

Commit

Permalink
refactor!: ParamKindAction does not take ID, use SetCursor instead
Browse files Browse the repository at this point in the history
This is consistent with other actions.

BREAKING CHANGE: this changes the richly-typed API

Signed-off-by: Ben Price <[email protected]>
  • Loading branch information
brprice committed Sep 19, 2023
1 parent 6a30798 commit 36ed018
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion primer/src/Primer/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ toProgActionNoInput defs def0 sel0 = \case
SelectionTypeDef sel -> case sel.node of
Just (TypeDefParamNodeSelection _) -> do
(t, p, id) <- typeParamKindSel
pure [ParamKindAction t p id actions]
pure [ParamKindAction t p $ SetCursor id : actions]
Just (TypeDefConsNodeSelection _) -> do
(t, c, f) <- conFieldSel
pure [ConFieldAction t c f.index $ SetCursor f.meta : actions]
Expand Down
2 changes: 1 addition & 1 deletion primer/src/Primer/Action/ProgAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ data ProgAction
| -- | Execute a sequence of actions on the type of a field of a constructor in a typedef
ConFieldAction TyConName ValConName Int [Action]
| -- | Execute a sequence of actions on the kind of a parameter in a typedef
ParamKindAction TyConName TyVarName ID [Action]
ParamKindAction TyConName TyVarName [Action]
| SetSmartHoles SmartHoles
| -- | CopyPaste (d,i) as
-- remembers the tree in def d, node i
Expand Down
4 changes: 2 additions & 2 deletions primer/src/Primer/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,9 +1021,9 @@ applyProgAction prog = \case
}
}
)
ParamKindAction tyName paramName id actions -> editModuleOfCrossType (Just tyName) prog $ \(mod, mods) defName def -> do
ParamKindAction tyName paramName actions -> editModuleOfCrossType (Just tyName) prog $ \(mod, mods) defName def -> do
let smartHoles = progSmartHoles prog
res <- applyActionsToParam smartHoles (paramName, def) $ SetCursor id : actions
res <- applyActionsToParam smartHoles (paramName, def) actions
case res of
Left err -> throwError $ ActionError err
Right (def', kz) -> do
Expand Down
19 changes: 10 additions & 9 deletions primer/test/Tests/Action/Prog.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import Primer.Action (
Delete,
EnterType,
Move,
RemoveAnn
RemoveAnn,
SetCursor
),
ActionError (CustomFailure, IDNotFound, ImportNameClash),
BranchMove (Pattern),
Expand Down Expand Up @@ -1183,7 +1184,7 @@ unit_ParamKindAction_1 =
progActionTest
( defaultProgEditableTypeDefs (pure [])
)
[ParamKindAction tT pB 30 [ConstructKFun]]
[ParamKindAction tT pB [SetCursor 30, ConstructKFun]]
$ expectSuccess
$ \_ prog' -> do
td <- findTypeDef tT prog'
Expand All @@ -1197,8 +1198,8 @@ unit_ParamKindAction_2 =
progActionTest
( defaultProgEditableTypeDefs (pure [])
)
[ ParamKindAction tT pB 30 [ConstructKFun]
, ParamKindAction tT pB 36 [ConstructKType]
[ ParamKindAction tT pB [SetCursor 30, ConstructKFun]
, ParamKindAction tT pB [SetCursor 36, ConstructKType]
]
$ expectError (@?= ActionError (CustomFailure ConstructKType "can only construct the kind 'Type' in hole"))

Expand All @@ -1207,8 +1208,8 @@ unit_ParamKindAction_2b =
progActionTest
( defaultProgEditableTypeDefs (pure [])
)
[ ParamKindAction tT pB 30 [ConstructKFun]
, ParamKindAction tT pB 36 [Delete]
[ ParamKindAction tT pB [SetCursor 30, ConstructKFun]
, ParamKindAction tT pB [SetCursor 36, Delete]
]
$ expectSuccess
$ \_ prog' -> do
Expand All @@ -1223,7 +1224,7 @@ unit_ParamKindAction_3 =
progActionTest
( defaultProgEditableTypeDefs (pure [])
)
[ ParamKindAction tT pA 29 [Delete]
[ ParamKindAction tT pA [SetCursor 29, Delete]
]
$ expectSuccess
$ \_ prog' -> do
Expand All @@ -1238,8 +1239,8 @@ unit_ParamKindAction_bad_id =
progActionTest
( defaultProgEditableTypeDefs (pure [])
)
[ ParamKindAction tT pB 30 [ConstructKFun]
, ParamKindAction tT pB 0 [ConstructKType]
[ ParamKindAction tT pB [SetCursor 30, ConstructKFun]
, ParamKindAction tT pB [SetCursor 0, ConstructKType]
]
$ expectError (@?= ActionError (IDNotFound 0))

Expand Down

0 comments on commit 36ed018

Please sign in to comment.