@@ -22,6 +22,7 @@ import Lean.Elab.Tactic.Doc
2222import Lean.Data.EditDistance
2323public import Lean.Elab.DocString.Builtin.Keywords
2424import Lean.Server.InfoUtils
25+ import Lean.Meta.Hint
2526
2627
2728namespace Lean.Doc
@@ -132,6 +133,15 @@ meta def checkNameExists : PostponedCheckHandler := fun _ info => do
132133 | throwError "Expected `{.ofConstName ``PostponedName}`, got `{.ofConstName info.typeName}`"
133134 discard <| realizeGlobalConstNoOverload (mkIdent name)
134135
136+ private def getQualified (x : Name) : DocM (Array Name) := do
137+ let names := (← getEnv).constants.toList
138+ let names := names.filterMap fun (y, _) => if !isPrivateName y && x.isSuffixOf y then some y else none
139+ names.toArray.mapM fun y => do
140+ let y ← unresolveNameGlobalAvoidingLocals y
141+ pure y
142+
143+ open Lean.Doc
144+
135145/--
136146Displays a name, without attempting to elaborate implicit arguments.
137147-/
@@ -168,7 +178,20 @@ def name (full : Option Ident := none) (scope : DocScope := .local)
168178 addConstInfo n x
169179 pure x
170180 else
171- realizeGlobalConstNoOverloadWithInfo n
181+ try
182+ realizeGlobalConstNoOverloadWithInfo n
183+ catch
184+ | err => do
185+ let ref ← getRef
186+ if let `(inline|role{$_x $_args*}%$tok[$_*]) := ref then
187+ let ss ← getQualified n.raw.getId
188+ let h ←
189+ if ss.isEmpty then pure m!""
190+ else m!"Insert a fully-qualified name:" .hint (ref? := some tok) <|
191+ ss.map fun x => { suggestion := s! " (full := { x} )" ++ "}" , previewSpan? := ref}
192+ logErrorAt s m!"{err.toMessageData}{h}"
193+ else logErrorAt s m!"{err.toMessageData}"
194+ return .code s! "{ n.raw.getId} "
172195 return .other (.mk ``Data.Const (.mk (Data.Const.mk x))) #[.code s.getString]
173196 | .import xs =>
174197 let name :=
0 commit comments