Skip to content

Commit

Permalink
also display loading of constants
Browse files Browse the repository at this point in the history
  • Loading branch information
abentkamp committed Nov 28, 2023
1 parent 946a7fa commit a57a5af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions client/src/components/infoview/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,13 @@ export function TypewriterInterface({props}) {


useServerNotificationEffect("$/game/loading", (params : any) => {
setLoadingProgress(params.counter)
if (params.kind == "loadConstants") {
setLoadingProgress(params.counter/100*50)
} else if (params.kind == "finalizeExtensions") {
setLoadingProgress(50 + params.counter/150*50)
} else {
console.error(`Unknown loading kind: ${params.kind}`)
}
})

return <div className="typewriter-interface">
Expand Down Expand Up @@ -527,7 +533,7 @@ export function TypewriterInterface({props}) {
}
</div>
}
</> : <CircularProgress variant="determinate" value={loadingProgress/1.5 + 30} />
</> : <CircularProgress variant="determinate" value={loadingProgress} />
}
</div>
</div>
Expand Down
13 changes: 12 additions & 1 deletion server/GameServer/ImportModules.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import Lean.Data.Lsp.Communication

open Lean

inductive LoadingKind := | finalizeExtensions | loadConstants
deriving ToJson

structure LoadingParams : Type where
counter : Nat
kind : LoadingKind
deriving ToJson

-- Code adapted from `Lean/Environment.lean`
Expand Down Expand Up @@ -33,7 +37,9 @@ private partial def finalizePersistentExtensions' (env : Environment) (mods : Ar
loop 0 env
where
loop (i : Nat) (env : Environment) : IO Environment := do
(← IO.getStdout).writeLspNotification { method := "$/game/loading", param := {counter := i : LoadingParams} }
(← IO.getStdout).writeLspNotification {
method := "$/game/loading",
param := {counter := i, kind := .finalizeExtensions : LoadingParams} }
-- Recall that the size of the array stored `persistentEnvExtensionRef` may increase when we import user-defined environment extensions.
let pExtDescrs ← persistentEnvExtensionsRef.get
if i < pExtDescrs.size then
Expand Down Expand Up @@ -61,6 +67,11 @@ def finalizeImport' (s : ImportState) (imports : Array Import) (opts : Options)
let mut const2ModIdx : HashMap Name ModuleIdx := mkHashMap (capacity := numConsts)
let mut constantMap : HashMap Name ConstantInfo := mkHashMap (capacity := numConsts)
for h:modIdx in [0:s.moduleData.size] do
if modIdx % 100 = 0 then
let percentage := modIdx * 100 / s.moduleData.size
(← IO.getStdout).writeLspNotification {
method := "$/game/loading",
param := {counter := percentage, kind := .loadConstants : LoadingParams} }
let mod := s.moduleData[modIdx]'h.upper
for cname in mod.constNames, cinfo in mod.constants do
match constantMap.insert' cname cinfo with
Expand Down

0 comments on commit a57a5af

Please sign in to comment.