Skip to content

Commit

Permalink
feat: make go-to-definition on a typeclass projection application go …
Browse files Browse the repository at this point in the history
…to the instance(s)
  • Loading branch information
rish987 committed Oct 22, 2022
1 parent 1e00eff commit e06e665
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Lean/Server/FileWorker/RequestHandling.lean
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def locationLinksOfInfo (kind : GoToKind) (ci : Elab.ContextInfo) (i : Elab.Info
| Expr.const n .. => return ← ci.runMetaM i.lctx <| locationLinksFromDecl i n
| Expr.fvar id .. => return ← ci.runMetaM i.lctx <| locationLinksFromBinder i id
| _ => pure ()
expr ← ci.runMetaM i.lctx do instantiateMVars expr
-- go-to-definition on a projection application of a typeclass
-- should return all instances generated by TC
match expr.getAppFn with
| .const n _ => if let some info := ci.env.getProjectionFnInfo? n then
let instIdx := info.numParams + info.i
let appArgs := expr.getAppArgs
let rec extractInstances : Expr → RequestM (Array Name)
| .const declName _ => do
if ← ci.runMetaM i.lctx do Lean.Meta.isInstance declName then pure #[declName] else pure #[]
| .app fn arg => do pure $ (← extractInstances fn).append (← extractInstances arg)
| _ => pure #[]
if appArgs.size > instIdx then
let instArg := appArgs.get! instIdx
return ← (← extractInstances instArg).foldlM (init := #[]) fun acc n => do
pure $ acc.append (← ci.runMetaM i.lctx <| locationLinksFromDecl i n)
| _ => pure ()
if let Info.ofFieldInfo fi := i then
if kind == type then
let expr ← ci.runMetaM i.lctx do
Expand Down

0 comments on commit e06e665

Please sign in to comment.