Skip to content

Commit 4f2b2d2

Browse files
authored
fix: make the @[lts] attribute attach hover info correctly (#432)
Hovering over `foo` in `@[lts foo]` now shows the resulting `LTS` declaration. Also corrects the name resolution to respect `_root_` and similar.
1 parent 1d91c3f commit 4f2b2d2

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

Cslib/Foundations/Semantics/LTS/Basic.lean

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ open Lean Elab Meta Command Term
945945
elab "create_lts" lt:ident name:ident : command => do
946946
liftTermElabM do
947947
let lt ← realizeGlobalConstNoOverloadWithInfo lt
948+
let (declName, _) ← mkDeclName (← getCurrNamespace) default name.getId
948949
let ci ← getConstInfo lt
949950
forallTelescope ci.type fun args ty => do
950951
let throwNotLT := throwError m!"type{indentExpr ci.type}\nis not a labelled transition"
@@ -960,15 +961,15 @@ elab "create_lts" lt:ident name:ident : command => do
960961
let value ← mkLambdaFVars args[0:args.size-3] bundle
961962
let type ← inferType value
962963
addAndCompile <| .defnDecl {
963-
name := name.getId
964+
name := declName
964965
levelParams := ci.levelParams
965966
type
966967
value
967968
safety := .safe
968969
hints := Lean.ReducibilityHints.abbrev
969970
}
970-
addTermInfo' name (.const name.getId params) (isBinder := true)
971-
addDeclarationRangesFromSyntax name.getId name
971+
addTermInfo' name (.const declName params) (isBinder := true)
972+
addDeclarationRangesFromSyntax declName name
972973

973974
/--
974975
This command adds transition notations for an `LTS`. This should not usually be called directly,
@@ -1004,22 +1005,21 @@ initialize Lean.registerBuiltinAttribute {
10041005
name := `lts_attr
10051006
descr := "Register notation for an LTS"
10061007
add := fun decl stx _ => MetaM.run' do
1008+
let currNamespace ← getCurrNamespace
10071009
match stx with
10081010
| `(attr | lts $lts $sym) =>
10091011
let mut sym := sym
10101012
unless sym.getString.endsWith " " do
10111013
sym := Syntax.mkStrLit (sym.getString ++ " ")
1012-
let lts := lts.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
1013-
liftCommandElabM <| Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
1014-
liftCommandElabM <| (do
1015-
modifyScope ({ · with currNamespace := decl.getPrefix })
1016-
Command.elabCommand (← `(scoped lts_transition_notation $lts $sym)))
1014+
liftCommandElabM <| do
1015+
modifyScope ({ · with currNamespace })
1016+
Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
1017+
Command.elabCommand (← `(scoped lts_transition_notation $lts $sym))
10171018
| `(attr | lts $lts) =>
1018-
let lts := lts.getId.updatePrefix decl.getPrefix |> Lean.mkIdent
1019-
liftCommandElabM <| Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
1020-
liftCommandElabM <| (do
1021-
modifyScope ({ · with currNamespace := decl.getPrefix })
1022-
Command.elabCommand (← `(scoped lts_transition_notation $lts)))
1019+
liftCommandElabM <| do
1020+
modifyScope ({ · with currNamespace })
1021+
Command.elabCommand (← `(create_lts $(mkIdent decl) $lts))
1022+
Command.elabCommand (← `(scoped lts_transition_notation $lts))
10231023
| _ => throwError "invalid syntax for 'lts' attribute"
10241024
}
10251025

Cslib/Languages/CCS/Semantics.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ open Process
3232

3333
/-- The transition relation for CCS. This is a direct formalisation of the one found in
3434
[Sangiorgi2011]. -/
35-
@[lts CCS.lts]
35+
@[lts lts]
3636
inductive Tr : Process Name Constant → Act Name → Process Name Constant → Prop where
3737
| pre : Tr (pre μ p) μ p
3838
| parL : Tr p μ p' → Tr (par p q) μ (par p' q)

CslibTests/LTS.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ example (a b : Term) (μ : Label) : a [μ]⭢β b := by
108108
change labelled_transition a μ b
109109
simp
110110

111-
-- check that a "cannonical" notation works
112-
attribute [lts cannonical_lts] labelled_transition
111+
-- check that a "canonical" notation works
112+
attribute [lts _root_.CslibTests.canonical_lts] labelled_transition
113113

114114
example (a b : Term) (μ : Label) : a [μ]⭢ b := by
115115
change labelled_transition a μ b
@@ -119,11 +119,11 @@ example (a b : Term) (μ : Label) : a [μ]⭢ b := by
119119

120120
/-- info: CslibTests.labelled_transition {Term Label : Type} : Term → Label → Term → Prop -/
121121
#guard_msgs in
122-
#check CslibTests.labelled_transition
122+
#check labelled_transition
123123

124-
/-- info: CslibTests.cannonical_lts {Term Label : Type} : LTS Term Label -/
124+
/-- info: CslibTests.canonical_lts {Term Label : Type} : LTS Term Label -/
125125
#guard_msgs in
126-
#check CslibTests.cannonical_lts
126+
#check canonical_lts
127127

128128
-- check that delaborators work, including with variables
129129

0 commit comments

Comments
 (0)