Skip to content

Commit

Permalink
Move code snippets to problem state file
Browse files Browse the repository at this point in the history
  • Loading branch information
slycelote committed Jan 26, 2022
1 parent 0551550 commit 41f6f60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions libcaide/src/Caide/Commands/ParseProblem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ initializeProblem problem = withLock $ do
hProblemConf <- createConf problemConfPath defaultProblemConfig
setProp hProblemConf "problem" "name" $ problemName problem
setProp hProblemConf "problem" "type" $ problemType problem
let snippets = problemCodeSnippets problem & Aeson.encode & LBS.toStrict & safeDecodeUtf8
unless (Map.null (problemCodeSnippets problem)) $
setProp hProblemConf "problem" "snippets" snippets

hProblemState <- createConf problemStatePath defaultProblemState
let snippets = problemCodeSnippets problem & Aeson.encode & LBS.toStrict & safeDecodeUtf8
unless (Map.null (problemCodeSnippets problem)) $
setProp hProblemState "problem" "snippets" snippets

flushConf hProblemConf
flushConf hProblemState
Expand Down
7 changes: 6 additions & 1 deletion libcaide/src/Caide/Problem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ readProblemInfo probId = do
pname <- getProp hProblemInfo "problem" "name"
ptype <- getProp hProblemInfo "problem" "type"
fpTolerance <- getProp hProblemInfo "problem" "double_precision"

-- We keep snippets in the state file to avoid huge chunk of text in problem.ini.
-- Users won't need to modify per-problem snippets anyway (if they do they'll modify
-- generated code).
hProblemState <- Conf.readProblemState probId
snippets <- (LBS.fromStrict . T.encodeUtf8) <$>
getProp hProblemInfo "problem" "snippets" `Conf.orDefault` "{}"
getProp hProblemState "problem" "snippets" `Conf.orDefault` "{}"
return $ Problem
{ problemName = pname
, problemId = probId
Expand Down

0 comments on commit 41f6f60

Please sign in to comment.