feat: Module reading functions #159
|
@ -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 =>
|
||||
|
|
|
@ -112,6 +112,24 @@ structure ExprEchoResult where
|
|||
type: Expression
|
||||
deriving Lean.ToJson
|
||||
|
||||
-- Describe the current state of the environment
|
||||
structure EnvDescribe where
|
||||
deriving Lean.FromJson
|
||||
structure EnvDescribeResult where
|
||||
imports : Array String
|
||||
modules : Array String
|
||||
deriving Lean.ToJson
|
||||
|
||||
-- Describe a module
|
||||
structure EnvModuleRead where
|
||||
module : String
|
||||
deriving Lean.FromJson
|
||||
structure EnvModuleReadResult where
|
||||
imports: Array String
|
||||
constNames: Array String
|
||||
extraConstNames: Array String
|
||||
deriving Lean.ToJson
|
||||
|
||||
-- Print all symbols in environment
|
||||
structure EnvCatalog where
|
||||
deriving Lean.FromJson
|
||||
|
|
|
@ -48,6 +48,8 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
|||
| "reset" => run reset
|
||||
| "stat" => run stat
|
||||
| "expr.echo" => run expr_echo
|
||||
| "env.describe" => run env_describe
|
||||
| "env.module_read" => run env_module_read
|
||||
| "env.catalog" => run env_catalog
|
||||
| "env.inspect" => run env_inspect
|
||||
| "env.add" => run env_add
|
||||
|
@ -85,6 +87,11 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
|||
let state ← get
|
||||
let nGoals := state.goalStates.size
|
||||
return .ok { nGoals }
|
||||
env_describe (args: Protocol.EnvDescribe): MainM (CR Protocol.EnvDescribeResult) := do
|
||||
let result ← Environment.describe args
|
||||
return .ok result
|
||||
env_module_read (args: Protocol.EnvModuleRead): MainM (CR Protocol.EnvModuleReadResult) := do
|
||||
Environment.moduleRead args
|
||||
env_catalog (args: Protocol.EnvCatalog): MainM (CR Protocol.EnvCatalogResult) := do
|
||||
let result ← Environment.catalog args
|
||||
return .ok result
|
||||
|
|
Loading…
Reference in New Issue