@@ -212,7 +212,7 @@ where
212
212
}
213
213
214
214
/--
215
- Annotates the term with the current expression position and registers `TermInfo`
215
+ Annotate the term with the current expression position and register `TermInfo`
216
216
to associate the term to the current expression.
217
217
-/
218
218
def annotateTermInfo (stx : Term) : Delab := do
@@ -221,13 +221,31 @@ def annotateTermInfo (stx : Term) : Delab := do
221
221
pure stx
222
222
223
223
/--
224
- Modifies the delaborator so that it annotates the resulting term with the current expression
225
- position and registers `TermInfo` to associate the term to the current expression.
224
+ Annotates the term with the current expression position and registers `TermInfo`
225
+ to associate the term to the current expression, unless (1) the syntax has a position and it is for the current position
226
+ and (2) there is already `TermInfo` at this position.
227
+ -/
228
+ def annotateTermInfoUnlessAnnotated (stx : Term) : Delab := do
229
+ if let .synthetic ⟨pos⟩ ⟨pos'⟩ := stx.raw.getHeadInfo then
230
+ if pos == pos' && pos == (← getPos) then
231
+ if (← get).infos.contains pos then
232
+ return stx
233
+ annotateTermInfo stx
234
+
235
+ /--
236
+ Modifies the delaborator so that it annotates the resulting term using `annotateTermInfo`.
226
237
-/
227
238
def withAnnotateTermInfo (d : Delab) : Delab := do
228
239
let stx ← d
229
240
annotateTermInfo stx
230
241
242
+ /--
243
+ Modifies the delaborator so that it ensures resulting term is annotated using `annotateTermInfoUnlessAnnotated`.
244
+ -/
245
+ def withAnnotateTermInfoUnlessAnnotated (d : Delab) : Delab := do
246
+ let stx ← d
247
+ annotateTermInfoUnlessAnnotated stx
248
+
231
249
def getUnusedName (suggestion : Name) (body : Expr) : DelabM Name := do
232
250
-- Use a nicer binder name than `[anonymous]`. We probably shouldn't do this in all LocalContext use cases, so do it here.
233
251
let suggestion := if suggestion.isAnonymous then `a else suggestion
@@ -271,11 +289,13 @@ inductive OmissionReason
271
289
| deep
272
290
| proof
273
291
| maxSteps
292
+ | uniqueSorry
274
293
275
294
def OmissionReason.toString : OmissionReason → String
276
295
| deep => "Term omitted due to its depth (see option `pp.deepTerms`)."
277
296
| proof => "Proof omitted (see option `pp.proofs`)."
278
297
| maxSteps => "Term omitted due to reaching the maximum number of steps allowed for pretty printing this expression (see option `pp.maxSteps`)."
298
+ | uniqueSorry => "This is a `sorry` term associated to a source position. Use 'Go to definition' to go there."
279
299
280
300
def addOmissionInfo (pos : Pos) (stx : Syntax) (e : Expr) (reason : OmissionReason) : DelabM Unit := do
281
301
let info := Info.ofOmissionInfo <| ← mkOmissionInfo stx e
@@ -365,7 +385,7 @@ def omission (reason : OmissionReason) : Delab := do
365
385
partial def delabFor : Name → Delab
366
386
| Name.anonymous => failure
367
387
| k =>
368
- (do annotateTermInfo (← (delabAttribute.getValues (← getEnv) k).firstM id))
388
+ (do annotateTermInfoUnlessAnnotated (← (delabAttribute.getValues (← getEnv) k).firstM id))
369
389
-- have `app.Option.some` fall back to `app` etc.
370
390
<|> if k.isAtomic then failure else delabFor k.getRoot
371
391
0 commit comments