feat: Display whether a symbol is private

This commit is contained in:
Leni Aniva 2023-12-05 19:07:00 -08:00
parent 07ade4c822
commit 9f2b07757f
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
6 changed files with 46 additions and 8 deletions

View File

@ -85,6 +85,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
return .ok {
type := ← serialize_expression state.options info.type,
value? := ← value?.mapM (λ v => serialize_expression state.options v),
isPrivate := Lean.isPrivateName name,
typeDependency? := if args.dependency?.getD false then .some <| info.type.getUsedConstants.map (λ n => name_to_ast n) else .none,
valueDependency? := if args.dependency?.getD false then info.value?.map (·.getUsedConstants.map (λ n => name_to_ast n)) else .none,
module? := module?

View File

@ -120,6 +120,7 @@ structure LibInspectResult where
type: Expression
value?: Option Expression := .none
module?: Option String
isPrivate: Bool
typeDependency?: Option (Array String) := .none
valueDependency?: Option (Array String) := .none
deriving Lean.ToJson

View File

@ -1,12 +1,13 @@
import Lean.Declaration
import Lean
namespace Pantograph
def is_symbol_unsafe_or_internal (n: Lean.Name) (info: Lean.ConstantInfo): Bool :=
let nameDeduce: Bool := match n.getRoot with
isLeanSymbol n (Lean.privateToUserName? n |>.map isLeanSymbol |>.getD false) info.isUnsafe
where
isLeanSymbol (name: Lean.Name): Bool := match name.getRoot with
| .str _ name => name == "Lean"
| _ => true
nameDeduce info.isUnsafe
def to_compact_symbol_name (n: Lean.Name) (info: Lean.ConstantInfo): String :=
let pref := match info with

33
Test/Catalog.lean Normal file
View File

@ -0,0 +1,33 @@
import LSpec
import Pantograph.Serial
import Pantograph.Symbol
namespace Pantograph.Test.Catalog
open Pantograph
open Lean
def test_symbol_visibility (env: Environment): IO LSpec.TestSeq := do
let entries: List (Name × Bool) := [
("Nat.add_comm".toName, false),
("Lean.Name".toName, true),
("_private.Init.0.Lean.Name".toName, true)
]
let suite := entries.foldl (λ suites (symbol, target) =>
let constant := env.constants.find! symbol
let test := LSpec.check symbol.toString ((is_symbol_unsafe_or_internal symbol constant) == target)
LSpec.TestSeq.append suites test) LSpec.TestSeq.done
return suite
def suite: IO LSpec.TestSeq := do
let env: Environment ← importModules
(imports := #["Init"].map (λ str => { module := str.toName, runtimeOnly := false }))
(opts := {})
(trustLevel := 1)
return LSpec.group "Catalog" $
(LSpec.group "Symbol visibility" (← test_symbol_visibility env))
end Pantograph.Test.Catalog

View File

@ -52,7 +52,7 @@ def test_option_modify : IO LSpec.TestSeq :=
subroutine_step "lib.inspect"
[("name", .str "Nat.add_one")]
(Lean.toJson ({
type := { pp? }, module? }:
type := { pp? }, module?, isPrivate := false }:
Protocol.LibInspectResult)),
subroutine_step "options.set"
[("printExprAST", .bool true)]
@ -61,7 +61,7 @@ def test_option_modify : IO LSpec.TestSeq :=
subroutine_step "lib.inspect"
[("name", .str "Nat.add_one")]
(Lean.toJson ({
type := { pp?, sexp? }, module? }:
type := { pp?, sexp? }, module?, isPrivate := false }:
Protocol.LibInspectResult)),
subroutine_step "options.print"
[]

View File

@ -1,4 +1,5 @@
import LSpec
import Test.Catalog
import Test.Holes
import Test.Integration
import Test.Proofs
@ -13,7 +14,8 @@ def main := do
Holes.suite,
Integration.suite,
Proofs.suite,
Serial.suite
Serial.suite,
Catalog.suite
]
let all ← suites.foldlM (λ acc m => do pure $ acc ++ (← m)) LSpec.TestSeq.done
LSpec.lspecIO $ all