feat: add term info at resolveId?
This commit is contained in:
parent
66c0f6ae9d
commit
6303c134a9
7 changed files with 39 additions and 7 deletions
|
|
@ -418,7 +418,7 @@ where
|
|||
|
||||
/- Check whether `stx` is a pattern variable or constructor-like (i.e., constructor or constant tagged with `[matchPattern]` attribute) -/
|
||||
processId (stx : Syntax) : M Syntax := do
|
||||
match (← resolveId? stx "pattern") with
|
||||
match (← resolveId? stx "pattern" (withInfo := true)) with
|
||||
| none => processVar stx
|
||||
| some f => match f with
|
||||
| Expr.const fName _ _ =>
|
||||
|
|
@ -480,7 +480,7 @@ where
|
|||
| `($fId:ident) => pure (fId, false)
|
||||
| `(@$fId:ident) => pure (fId, true)
|
||||
| _ => throwError "identifier expected"
|
||||
let some (Expr.const fName _ _) ← resolveId? fId "pattern" | throwCtorExpected
|
||||
let some (Expr.const fName _ _) ← resolveId? fId "pattern" (withInfo := true) | throwCtorExpected
|
||||
let fInfo ← getConstInfo fName
|
||||
let paramDecls ← forallTelescopeReducing fInfo.type fun xs _ => xs.mapM fun x => do
|
||||
let d ← getFVarLocalDecl x
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ def refineCore (stx : Syntax) (tagSuffix : Name) (allowNaturalHoles : Bool) : Ta
|
|||
-/
|
||||
def elabTermForApply (stx : Syntax) : TacticM Expr := do
|
||||
if stx.isIdent then
|
||||
match (← Term.resolveId? stx) with
|
||||
match (← Term.resolveId? stx (withInfo := true)) with
|
||||
| some e => return e
|
||||
| _ => pure ()
|
||||
elabTerm stx none (mayPostpone := true)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ where
|
|||
resolveSimpIdLemma? (simpArgTerm : Syntax) : TacticM (Option Expr) := do
|
||||
if simpArgTerm.isIdent then
|
||||
try
|
||||
Term.resolveId? simpArgTerm
|
||||
Term.resolveId? simpArgTerm (withInfo := true)
|
||||
catch _ =>
|
||||
return none
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1475,7 +1475,7 @@ def resolveName' (ident : Syntax) (explicitLevels : List Level) (expectedType? :
|
|||
return (c, id, newFields.toList)
|
||||
| _ => throwError "identifier expected"
|
||||
|
||||
def resolveId? (stx : Syntax) (kind := "term") : TermElabM (Option Expr) :=
|
||||
def resolveId? (stx : Syntax) (kind := "term") (withInfo := false) : TermElabM (Option Expr) :=
|
||||
match stx with
|
||||
| Syntax.ident _ _ val preresolved => do
|
||||
let rs ← try resolveName stx val preresolved [] catch _ => pure []
|
||||
|
|
@ -1483,8 +1483,11 @@ def resolveId? (stx : Syntax) (kind := "term") : TermElabM (Option Expr) :=
|
|||
let fs := rs.map fun (f, _) => f
|
||||
match fs with
|
||||
| [] => pure none
|
||||
| [f] => pure (some f)
|
||||
| _ => throwError "ambiguous {kind}, use fully qualified name, possible interpretations {fs}"
|
||||
| [f] =>
|
||||
if withInfo then
|
||||
addTermInfo stx f
|
||||
pure (some f)
|
||||
| _ => throwError "ambiguous {kind}, use fully qualified name, possible interpretations {fs}"
|
||||
| _ => throwError "identifier expected"
|
||||
|
||||
@[builtinTermElab cdot] def elabBadCDot : TermElab := fun stx _ =>
|
||||
|
|
|
|||
|
|
@ -189,6 +189,7 @@
|
|||
| (z, w) =>
|
||||
let z1 : Nat := z + w;
|
||||
z + z1 : Nat @ ⟨23, 4⟩†-⟨25, 10⟩
|
||||
Prod.mk : {α : Type ?u} → {β : Type ?u} → α → β → α × β @ ⟨23, 4⟩†-⟨25, 10⟩†
|
||||
[.] `z : none @ ⟨23, 9⟩-⟨23, 10⟩
|
||||
[.] `w : none @ ⟨23, 12⟩-⟨23, 13⟩
|
||||
(z, w) : Nat × Nat @ ⟨23, 4⟩†-⟨23, 13⟩
|
||||
|
|
|
|||
13
tests/lean/interactive/hover.lean
Normal file
13
tests/lean/interactive/hover.lean
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
example : True := by
|
||||
apply True.intro
|
||||
--^ textDocument/hover
|
||||
|
||||
example : True := by
|
||||
simp [True.intro]
|
||||
--^ textDocument/hover
|
||||
|
||||
example (n : Nat) : True := by
|
||||
match n with
|
||||
| Nat.zero => _
|
||||
--^ textDocument/hover
|
||||
| n + 1 => _
|
||||
15
tests/lean/interactive/hover.lean.expected.out
Normal file
15
tests/lean/interactive/hover.lean.expected.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{"textDocument": {"uri": "file://hover.lean"},
|
||||
"position": {"line": 1, "character": 8}}
|
||||
{"range":
|
||||
{"start": {"line": 1, "character": 8}, "end": {"line": 1, "character": 18}},
|
||||
"contents": {"value": "```lean\nTrue.intro : True\n```", "kind": "markdown"}}
|
||||
{"textDocument": {"uri": "file://hover.lean"},
|
||||
"position": {"line": 5, "character": 8}}
|
||||
{"range":
|
||||
{"start": {"line": 5, "character": 8}, "end": {"line": 5, "character": 18}},
|
||||
"contents": {"value": "```lean\nTrue.intro : True\n```", "kind": "markdown"}}
|
||||
{"textDocument": {"uri": "file://hover.lean"},
|
||||
"position": {"line": 10, "character": 4}}
|
||||
{"range":
|
||||
{"start": {"line": 10, "character": 4}, "end": {"line": 10, "character": 12}},
|
||||
"contents": {"value": "```lean\nNat.zero : Nat\n```", "kind": "markdown"}}
|
||||
Loading…
Add table
Reference in a new issue