load testgame
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import Lean
|
import Lean
|
||||||
|
import GameServer.EnvExtensions
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
open Lean
|
open Lean
|
||||||
@@ -7,15 +8,43 @@ open Watchdog
|
|||||||
open Lsp
|
open Lsp
|
||||||
open JsonRpc
|
open JsonRpc
|
||||||
|
|
||||||
|
/-- Dummy `Core.Context` value to be fed to `Lean.Core.CoreM.toIO` -/
|
||||||
|
def coreCtx : Core.Context := {
|
||||||
|
currNamespace := Name.anonymous,
|
||||||
|
openDecls := [],
|
||||||
|
fileName := "<Game>",
|
||||||
|
fileMap := { source := "", positions := #[0], lines := #[1] } }
|
||||||
|
|
||||||
partial def handleServerEvent (ev : ServerEvent) : ServerM Bool := do
|
partial def handleServerEvent (ev : ServerEvent) : ServerM Bool := do
|
||||||
match ev with
|
match ev with
|
||||||
| ServerEvent.clientMsg msg =>
|
| ServerEvent.clientMsg msg =>
|
||||||
match msg with
|
match msg with
|
||||||
| Message.request id "info" _ =>
|
| Message.request id "info" _ =>
|
||||||
(← read).hOut.writeLspResponse {
|
|
||||||
id := id
|
let gameDir := "testgame"
|
||||||
result := "Hello"
|
|
||||||
}
|
-- Determine search paths of the game project by running `lake env printenv LEAN_PATH`.
|
||||||
|
let out ← IO.Process.output
|
||||||
|
{ cwd := gameDir, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
|
||||||
|
if out.exitCode != 0 then
|
||||||
|
IO.eprintln out.stderr
|
||||||
|
return true
|
||||||
|
|
||||||
|
-- Make the paths relative to the current directory
|
||||||
|
let paths : List System.FilePath := System.SearchPath.parse out.stdout.trim
|
||||||
|
let currentDir ← IO.currentDir
|
||||||
|
let paths := paths.map fun p => currentDir / (gameDir : System.FilePath) / p
|
||||||
|
|
||||||
|
-- Set the search path
|
||||||
|
Lean.searchPathRef.set paths
|
||||||
|
|
||||||
|
let hOut := (← read).hOut
|
||||||
|
let gameName := `TestGame
|
||||||
|
let env ← importModules [{ module := `Init : Import }, { module := gameName : Import }] {} 0
|
||||||
|
discard <| Core.CoreM.toIO (ctx := coreCtx) (s := { env := env }) do
|
||||||
|
let levels := levelsExt.getState env
|
||||||
|
let game := {← gameExt.get with nb_levels := levels.size }
|
||||||
|
hOut.writeLspResponse ⟨id, game⟩
|
||||||
return true
|
return true
|
||||||
| _ => return false
|
| _ => return false
|
||||||
| _ => return false
|
| _ => return false
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ def initAndRunWatchdogAux : ServerM Unit := do
|
|||||||
| throwServerError "Got `shutdown` request, expected an `exit` notification"
|
| throwServerError "Got `shutdown` request, expected an `exit` notification"
|
||||||
|
|
||||||
def initAndRunWatchdog (args : List String) (i o e : FS.Stream) : IO Unit := do
|
def initAndRunWatchdog (args : List String) (i o e : FS.Stream) : IO Unit := do
|
||||||
|
-- TODO: Do the following commands slow us down?
|
||||||
let workerPath ← findWorkerPath
|
let workerPath ← findWorkerPath
|
||||||
let srcSearchPath ← initSrcSearchPath (← getBuildDir)
|
let srcSearchPath ← initSrcSearchPath (← getBuildDir)
|
||||||
let references ← IO.mkRef (← loadReferences)
|
let references ← IO.mkRef (← loadReferences)
|
||||||
|
|||||||
@@ -25,20 +25,6 @@ def main : List String → IO UInt32 := fun args => do
|
|||||||
-- let gameName := args[0]!
|
-- let gameName := args[0]!
|
||||||
-- let gameDir := args[1]!
|
-- let gameDir := args[1]!
|
||||||
|
|
||||||
-- -- Determine search paths of the game project by running `lake env printenv LEAN_PATH`.
|
|
||||||
-- let out ← IO.Process.output
|
|
||||||
-- { cwd := gameDir, cmd := "lake", args := #["env","printenv","LEAN_PATH"] }
|
|
||||||
-- if out.exitCode != 0 then
|
|
||||||
-- IO.eprintln out.stderr
|
|
||||||
-- return
|
|
||||||
|
|
||||||
-- -- Make the paths relative to the current directory
|
|
||||||
-- let paths : List System.FilePath := System.SearchPath.parse out.stdout.trim
|
|
||||||
-- let currentDir ← IO.currentDir
|
|
||||||
-- let paths := paths.map fun p => currentDir / (gameDir : System.FilePath) / p
|
|
||||||
|
|
||||||
-- -- Set the search path
|
|
||||||
-- Lean.searchPathRef.set paths
|
|
||||||
|
|
||||||
-- -- Run the game
|
-- -- Run the game
|
||||||
-- Server.runGame gameName
|
-- Server.runGame gameName
|
||||||
|
|||||||
Reference in New Issue
Block a user