@@ -12,6 +12,7 @@ prelude
12
12
import Init.System.Promise
13
13
import Lean.Message
14
14
import Lean.Parser.Types
15
+ import Lean.Elab.InfoTree
15
16
16
17
set_option linter.missingDocs true
17
18
@@ -46,6 +47,8 @@ def Snapshot.Diagnostics.empty : Snapshot.Diagnostics where
46
47
The base class of all snapshots: all the generic information the language server needs about a
47
48
snapshot. -/
48
49
structure Snapshot where
50
+ /-- Debug description shown by `trace.Elab.snapshotTree`, defaults to the caller's decl name. -/
51
+ desc : String := by exact decl_name%.toString
49
52
/--
50
53
The messages produced by this step. The union of message logs of all finished snapshots is
51
54
reported to the user. -/
@@ -71,7 +74,7 @@ structure SnapshotTask (α : Type) where
71
74
range? : Option String.Range
72
75
/-- Underlying task producing the snapshot. -/
73
76
task : Task α
74
- deriving Nonempty
77
+ deriving Nonempty, Inhabited
75
78
76
79
/-- Creates a snapshot task from a reporting range and a `BaseIO` action. -/
77
80
def SnapshotTask.ofIO (range? : Option String.Range) (act : BaseIO α) : BaseIO (SnapshotTask α) := do
@@ -203,15 +206,19 @@ abbrev SnapshotTree.children : SnapshotTree → Array (SnapshotTask SnapshotTree
203
206
| mk _ children => children
204
207
205
208
/-- Produces debug tree format of given snapshot tree, synchronously waiting on all children. -/
206
- partial def SnapshotTree.format : SnapshotTree → Format := go none
207
- where go range? s :=
208
- let range := match range? with
209
- | some range => f!"{range.start}..{range.stop} "
210
- | none => ""
211
- let element := f!"{s.element.diagnostics.msgLog.unreported.size} diagnostics"
212
- let children := Std.Format.prefixJoin .line <|
213
- s.children.toList.map fun c => go c.range? c.get
214
- .nestD f!"• {range}{element}{children}"
209
+ partial def SnapshotTree.format [Monad m] [MonadFileMap m] [MonadLiftT IO m] :
210
+ SnapshotTree → m Format :=
211
+ go none
212
+ where go range? s := do
213
+ let file ← getFileMap
214
+ let mut desc := f!"• {s.element.desc}"
215
+ if let some range := range? then
216
+ desc := desc ++ f!"{file.toPosition range.start}-{file.toPosition range.stop} "
217
+ desc := desc ++ .prefixJoin "\n • " (← s.element.diagnostics.msgLog.toList.mapM (·.toString))
218
+ if let some t := s.element.infoTree? then
219
+ desc := desc ++ f!"\n {← t.format}"
220
+ desc := desc ++ .prefixJoin "\n " (← s.children.toList.mapM fun c => go c.range? c.get)
221
+ return .nestD desc
215
222
216
223
/--
217
224
Helper class for projecting a heterogeneous hierarchy of snapshot classes to a homogeneous
0 commit comments