From 36ed018a8204d422533dad714ac33cdf2c766874 Mon Sep 17 00:00:00 2001 From: Ben Price Date: Thu, 7 Sep 2023 13:24:10 +0100 Subject: [PATCH] refactor!: ParamKindAction does not take ID, use SetCursor instead This is consistent with other actions. BREAKING CHANGE: this changes the richly-typed API Signed-off-by: Ben Price --- primer/src/Primer/Action.hs | 2 +- primer/src/Primer/Action/ProgAction.hs | 2 +- primer/src/Primer/App.hs | 4 ++-- primer/test/Tests/Action/Prog.hs | 19 ++++++++++--------- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/primer/src/Primer/Action.hs b/primer/src/Primer/Action.hs index ca1cc906a..57dd47161 100644 --- a/primer/src/Primer/Action.hs +++ b/primer/src/Primer/Action.hs @@ -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] diff --git a/primer/src/Primer/Action/ProgAction.hs b/primer/src/Primer/Action/ProgAction.hs index 31b556fca..af953c65c 100644 --- a/primer/src/Primer/Action/ProgAction.hs +++ b/primer/src/Primer/Action/ProgAction.hs @@ -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 diff --git a/primer/src/Primer/App.hs b/primer/src/Primer/App.hs index 3eec0ba76..61cc55a74 100644 --- a/primer/src/Primer/App.hs +++ b/primer/src/Primer/App.hs @@ -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 diff --git a/primer/test/Tests/Action/Prog.hs b/primer/test/Tests/Action/Prog.hs index 59465fb67..b8e32bdcb 100644 --- a/primer/test/Tests/Action/Prog.hs +++ b/primer/test/Tests/Action/Prog.hs @@ -24,7 +24,8 @@ import Primer.Action ( Delete, EnterType, Move, - RemoveAnn + RemoveAnn, + SetCursor ), ActionError (CustomFailure, IDNotFound, ImportNameClash), BranchMove (Pattern), @@ -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' @@ -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")) @@ -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 @@ -1223,7 +1224,7 @@ unit_ParamKindAction_3 = progActionTest ( defaultProgEditableTypeDefs (pure []) ) - [ ParamKindAction tT pA 29 [Delete] + [ ParamKindAction tT pA [SetCursor 29, Delete] ] $ expectSuccess $ \_ prog' -> do @@ -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))