throw error in regular difficulty if tactic not unlocked

pull/120/head
Jon Eugster 1 year ago committed by joneugster
parent 8730c2067c
commit 3a3471c615

@ -284,7 +284,7 @@ function PlayableLevel({impressum, setImpressum}) {
// if the user inventory changes, notify the server // if the user inventory changes, notify the server
useEffect(() => { useEffect(() => {
let leanClient = connection.getLeanClient(gameId) let leanClient = connection.getLeanClient(gameId)
leanClient.sendNotification('$/game/setInventory', {inventory: inventory, checkEnabled: difficulty > 0}) leanClient.sendNotification('$/game/setInventory', {inventory: inventory, difficulty: difficulty})
}, [inventory]) }, [inventory])
useEffect(() => { useEffect(() => {

@ -61,13 +61,13 @@ section Elab
/-- Find all tactics in syntax object that are forbidden according to a /-- Find all tactics in syntax object that are forbidden according to a
set `allowed` of allowed tactics. -/ set `allowed` of allowed tactics. -/
partial def findForbiddenTactics (inputCtx : Parser.InputContext) partial def findForbiddenTactics (inputCtx : Parser.InputContext)
(levelParams : Game.DidOpenLevelParams) (stx : Syntax) : (levelParams : Game.DidOpenLevelParams) (stx : Syntax) (asError : Bool) :
Elab.Command.CommandElabM Unit := do Elab.Command.CommandElabM Unit := do
match stx with match stx with
| .missing => return () | .missing => return ()
| .node info kind args => | .node info kind args =>
for arg in args do for arg in args do
findForbiddenTactics inputCtx levelParams arg findForbiddenTactics inputCtx levelParams arg asError
| .atom info val => | .atom info val =>
-- ignore syntax elements that do not start with a letter -- ignore syntax elements that do not start with a letter
-- and ignore "with" keyword -- and ignore "with" keyword
@ -108,7 +108,7 @@ where addWarningMessage (info : SourceInfo) (s : MessageData) :=
modify fun st => { st with modify fun st => { st with
messages := st.messages.add { messages := st.messages.add {
fileName := inputCtx.fileName fileName := inputCtx.fileName
severity := MessageSeverity.warning severity := if asError then MessageSeverity.error else MessageSeverity.warning
pos := inputCtx.fileMap.toPosition (info.getPos?.getD 0) pos := inputCtx.fileMap.toPosition (info.getPos?.getD 0)
data := s data := s
} }
@ -170,8 +170,9 @@ def compileProof (inputCtx : Parser.InputContext) (snap : Snapshot) (hasWidgets
parseResultRef.set (tacticStx, cmdParserState) parseResultRef.set (tacticStx, cmdParserState)
-- Check for forbidden tactics -- Check for forbidden tactics
if levelParams.checkEnabled then if levelParams.difficulty > 0 then
findForbiddenTactics inputCtx levelParams tacticStx findForbiddenTactics inputCtx levelParams tacticStx
(asError := levelParams.difficulty > 1)
-- Insert invisible `skip` command to make sure we always display the initial goal -- Insert invisible `skip` command to make sure we always display the initial goal
let skip := Syntax.node (.original default 0 default endOfWhitespace) ``Lean.Parser.Tactic.skip #[] let skip := Syntax.node (.original default 0 default endOfWhitespace) ``Lean.Parser.Tactic.skip #[]
@ -533,7 +534,7 @@ section MainLoop
set {s with levelParams := {s.levelParams with set {s with levelParams := {s.levelParams with
inventory := p.inventory, inventory := p.inventory,
checkEnabled := p.checkEnabled}} difficulty := p.difficulty}}
mainLoop mainLoop
| Message.notification method (some params) => | Message.notification method (some params) =>
handleNotification method (toJson params) handleNotification method (toJson params)

@ -7,7 +7,7 @@ structure GameServerState :=
(game : Name) (game : Name)
(gameDir : String) (gameDir : String)
(inventory : Array String) (inventory : Array String)
(checkEnabled : Bool) (difficulty : Nat)
abbrev GameServerM := StateT GameServerState Server.Watchdog.ServerM abbrev GameServerM := StateT GameServerState Server.Watchdog.ServerM
@ -79,8 +79,13 @@ structure DidOpenLevelParams where
lemmas : Array InventoryTile lemmas : Array InventoryTile
definitions : Array InventoryTile definitions : Array InventoryTile
inventory : Array String inventory : Array String
/-- if true the server gives warnings for used tactics/lemmas that are not unlocked. -/ /--
checkEnabled : Bool Check for tactics/theorems that are not unlocked.
0: no check
1: give warnings
2: give errors
-/
difficulty : Nat
deriving ToJson, FromJson deriving ToJson, FromJson
structure LoadDocParams where structure LoadDocParams where
@ -90,7 +95,7 @@ deriving ToJson, FromJson
structure SetInventoryParams where structure SetInventoryParams where
inventory : Array String inventory : Array String
checkEnabled : Bool difficulty : Nat
deriving ToJson, FromJson deriving ToJson, FromJson
def handleDidOpenLevel (params : Json) : GameServerM Unit := do def handleDidOpenLevel (params : Json) : GameServerM Unit := do
@ -117,7 +122,7 @@ def handleDidOpenLevel (params : Json) : GameServerM Unit := do
lemmas := lvl.lemmas.tiles lemmas := lvl.lemmas.tiles
definitions := lvl.definitions.tiles definitions := lvl.definitions.tiles
inventory := s.inventory inventory := s.inventory
checkEnabled := s.checkEnabled difficulty := s.difficulty
: DidOpenLevelParams : DidOpenLevelParams
} }
} }
@ -205,7 +210,7 @@ partial def handleServerEvent (ev : ServerEvent) : GameServerM Bool := do
| Message.notification "$/game/setInventory" params => | Message.notification "$/game/setInventory" params =>
let p := (← parseParams SetInventoryParams (toJson params)) let p := (← parseParams SetInventoryParams (toJson params))
let s ← get let s ← get
set {s with inventory := p.inventory, checkEnabled := p.checkEnabled} set {s with inventory := p.inventory, difficulty := p.difficulty}
let st ← read let st ← read
let workers ← st.fileWorkersRef.get let workers ← st.fileWorkersRef.get
for (_, fw) in workers do for (_, fw) in workers do

@ -114,7 +114,7 @@ def initAndRunWatchdog (args : List String) (i o e : FS.Stream) : IO Unit := do
game := gameName, game := gameName,
gameDir := gameDir, gameDir := gameDir,
inventory := #[] inventory := #[]
checkEnabled := false difficulty := 0
} }
let initRequest ← i.readLspRequestAs "initialize" InitializeParams let initRequest ← i.readLspRequestAs "initialize" InitializeParams
-- We misuse the `rootUri` field to the gameName -- We misuse the `rootUri` field to the gameName

Loading…
Cancel
Save