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