feat: Implement `env.describe` and `env.module_read`
This commit is contained in:
parent
4f5ffc1ffb
commit
c9f524b9ae
|
@ -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 =>
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue