Skip to content

Commit e8e4ff0

Browse files
committed
fix JSON agda API
1 parent 8f7bdfe commit e8e4ff0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Cornelis/Types.hs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import GHC.Stack
4242
import Neovim hiding (err)
4343
import Neovim.API.Text (Buffer(..), Window)
4444
import System.Process (ProcessHandle)
45+
import Data.Bool (bool)
4546

4647
deriving stock instance Ord Buffer
4748

@@ -143,6 +144,13 @@ instance MonadState CornelisState (Neovim CornelisEnv) where
143144
mv <- asks ce_state
144145
liftIO $ writeIORef mv a
145146

147+
data GiveResult
148+
= Give_String Text
149+
| Give_Paren
150+
| Give_NoParen
151+
deriving (Eq, Ord, Show)
152+
153+
146154
data Response
147155
= DisplayInfo DisplayInfo
148156
| ClearHighlighting -- TokenBased
@@ -156,7 +164,7 @@ data Response
156164
}
157165
| JumpToError FilePath AgdaIndex
158166
| InteractionPoints [InteractionPoint Maybe]
159-
| GiveAction Text (InteractionPoint (Const ()))
167+
| GiveAction GiveResult (InteractionPoint (Const ()))
160168
| MakeCase MakeCase
161169
| SolveAll [Solution]
162170
| Unknown Text Value
@@ -390,7 +398,9 @@ instance FromJSON Response where
390398
SolveAll <$> obj .: "solutions"
391399
"GiveAction" ->
392400
(obj .: "giveResult") >>= \result ->
393-
GiveAction <$> result .: "str" <*> obj .: "interactionPoint"
401+
GiveAction
402+
<$> (Give_String <$> result .: "str" <|> bool Give_NoParen Give_Paren <$> result .: "paren")
403+
<*> obj .: "interactionPoint"
394404
"DisplayInfo" ->
395405
DisplayInfo <$> obj .: "info"
396406
"JumpToError" ->

src/Lib.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ respond b (GiveAction result ip) = do
6868
Nothing -> reportError $ T.pack $ "Can't find interaction point " <> show i
6969
Just ip' -> do
7070
int <- getIpInterval b ip'
71-
replaceInterval b int $ replaceQuestion result
71+
goalContents <- getGoalContents b ip'
72+
--replacement <- case result of
73+
replaceInterval b int $ replaceQuestion $ case result of
74+
Give_String text -> text
75+
Give_Paren -> "(" <> goalContents <> ")"
76+
Give_NoParen -> goalContents
7277
load
7378
-- Replace the interaction point with a result
7479
respond b (SolveAll solutions) = do

0 commit comments

Comments
 (0)