feat: Implement `env.describe` and `env.module_read`

This commit is contained in:
Leni Aniva 2025-01-15 21:20:05 -08:00
parent 4f5ffc1ffb
commit c9f524b9ae
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
2 changed files with 18 additions and 2 deletions

View File

@ -43,6 +43,22 @@ def toFilteredSymbol (n: Lean.Name) (info: Lean.ConstantInfo): Option String :=
if isNameInternal n || info.isUnsafe if isNameInternal n || info.isUnsafe
then Option.none then Option.none
else Option.some <| toCompactSymbolName n info 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 def catalog (_: Protocol.EnvCatalog): CoreM Protocol.EnvCatalogResult := do
let env ← Lean.MonadEnv.getEnv let env ← Lean.MonadEnv.getEnv
let names := env.constants.fold (init := #[]) (λ acc name info => let names := env.constants.fold (init := #[]) (λ acc name info =>

View File

@ -121,10 +121,10 @@ structure EnvDescribeResult where
deriving Lean.ToJson deriving Lean.ToJson
-- Describe a module -- Describe a module
structure EnvModule where structure EnvModuleRead where
module : String module : String
deriving Lean.FromJson deriving Lean.FromJson
structure EnvModuleResult where structure EnvModuleReadResult where
imports: Array String imports: Array String
constNames: Array String constNames: Array String
extraConstNames: Array String extraConstNames: Array String