From c9f524b9aea1c475dc3085bd109fbd7ea9f4187a Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Wed, 15 Jan 2025 21:20:05 -0800 Subject: [PATCH] feat: Implement `env.describe` and `env.module_read` --- Pantograph/Environment.lean | 16 ++++++++++++++++ Pantograph/Protocol.lean | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Pantograph/Environment.lean b/Pantograph/Environment.lean index c48414a..6bd3f76 100644 --- a/Pantograph/Environment.lean +++ b/Pantograph/Environment.lean @@ -43,6 +43,22 @@ def toFilteredSymbol (n: Lean.Name) (info: Lean.ConstantInfo): Option String := if isNameInternal n || info.isUnsafe then Option.none else Option.some <| toCompactSymbolName n info +def describe (_: Protocol.EnvDescribe): CoreM Protocol.EnvDescribeResult := do + let env ← Lean.MonadEnv.getEnv + return { + imports := env.header.imports.map toString, + modules := env.header.moduleNames.map (·.toString), + } +def moduleRead (args: Protocol.EnvModuleRead): CoreM (Protocol.CR Protocol.EnvModuleReadResult) := do + let env ← Lean.MonadEnv.getEnv + let .some i := env.header.moduleNames.findIdx? (· == args.module.toName) | + return .error $ Protocol.errorIndex s!"Module not found {args.module}" + let data := env.header.moduleData[i]! + return .ok { + imports := data.imports.map toString, + constNames := data.constNames.map (·.toString), + extraConstNames := data.extraConstNames.map (·.toString), + } def catalog (_: Protocol.EnvCatalog): CoreM Protocol.EnvCatalogResult := do let env ← Lean.MonadEnv.getEnv let names := env.constants.fold (init := #[]) (λ acc name info => diff --git a/Pantograph/Protocol.lean b/Pantograph/Protocol.lean index c73e791..cab288c 100644 --- a/Pantograph/Protocol.lean +++ b/Pantograph/Protocol.lean @@ -121,10 +121,10 @@ structure EnvDescribeResult where deriving Lean.ToJson -- Describe a module -structure EnvModule where +structure EnvModuleRead where module : String deriving Lean.FromJson -structure EnvModuleResult where +structure EnvModuleReadResult where imports: Array String constNames: Array String extraConstNames: Array String