Skip to content

Commit 8195f70

Browse files
authored
chore: revert "fix: trace nodes collapsing while file is elaborating (#8056)" (#8095)
This PR reverts #8056 because the implementation there has a bug that is best fixed with a different approach, and which we should preferably only merge next release cycle.
1 parent 3fe195a commit 8195f70

File tree

2 files changed

+16
-39
lines changed

2 files changed

+16
-39
lines changed

src/Lean/Server/FileWorker.lean

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ structure WorkerContext where
8585
/--
8686
Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
8787
-/
88-
stickyDiagnosticsRef : IO.Ref (Array ReportableDiagnostic)
88+
stickyDiagnosticsRef : IO.Ref (Array InteractiveDiagnostic)
8989
partialHandlersRef : IO.Ref (RBMap String PartialHandlerInfo compare)
9090
pendingServerRequestsRef : IO.Ref (Std.TreeMap RequestID (IO.Promise (ServerRequestResponse Json)))
9191
hLog : FS.Stream
@@ -192,7 +192,7 @@ This option can only be set on the command line, not in the lakefile or via `set
192192
See also section "Communication" in Lean/Server/README.md.
193193
-/
194194
structure MemorizedInteractiveDiagnostics where
195-
diags : Array ReportableDiagnostic
195+
diags : Array Widget.InteractiveDiagnostic
196196
deriving TypeName
197197

198198
/--
@@ -205,7 +205,7 @@ This option can only be set on the command line, not in the lakefile or via `set
205205
let docInteractiveDiagnostics ← doc.diagnosticsRef.get
206206
let diagnostics :=
207207
stickyInteractiveDiagnostics ++ docInteractiveDiagnostics
208-
|>.map (Widget.InteractiveDiagnostic.toDiagnostic ·.toDiagnosticWith)
208+
|>.map (·.toDiagnostic)
209209
let notification := mkPublishDiagnosticsNotification doc.meta diagnostics
210210
ctx.chanOut.sync.send notification
211211

@@ -300,8 +300,6 @@ This option can only be set on the command line, not in the lakefile or via `set
300300
msgs := msgs.filter (! ·.isSilent)
301301
let diags ← msgs.mapM
302302
(Widget.msgToInteractiveDiagnostic doc.meta.text · ctx.clientHasWidgets)
303-
let diags ← diags.mapM fun diag => do
304-
return { diag with encodedDiag := ← IO.Promise.new }
305303
if let some cacheRef := node.element.diagnostics.interactiveDiagsRef? then
306304
cacheRef.set <| some <| .mk { diags : MemorizedInteractiveDiagnostics }
307305
pure diags
@@ -464,7 +462,7 @@ section Initialization
464462
}
465463
let doc : EditableDocumentCore := {
466464
meta, initSnap
467-
diagnosticsRef := ← IO.mkRef ∅
465+
diagnosticsRef := (← IO.mkRef ∅)
468466
}
469467
let reporterCancelTk ← CancelToken.new
470468
let reporter ← reportSnapshots ctx doc reporterCancelTk
@@ -550,7 +548,7 @@ section Updates
550548
let initSnap ← ctx.processor meta.mkInputContext
551549
let doc : EditableDocumentCore := {
552550
meta, initSnap
553-
diagnosticsRef := ← IO.mkRef ∅
551+
diagnosticsRef := (← IO.mkRef ∅)
554552
}
555553
let reporterCancelTk ← CancelToken.new
556554
let reporter ← reportSnapshots ctx doc reporterCancelTk
@@ -610,7 +608,6 @@ section NotificationHandling
610608
fullRange? := some ⟨⟨0, 0⟩, text.utf8PosToLspPos text.source.endPos⟩
611609
severity? := DiagnosticSeverity.information
612610
message := importOutOfDataMessage
613-
encodedDiag := ← IO.Promise.new
614611
}
615612
ctx.stickyDiagnosticsRef.modify fun stickyDiagnostics =>
616613
let stickyDiagnostics := stickyDiagnostics.filter
@@ -723,12 +720,8 @@ section MessageHandling
723720
open Widget RequestM Language in
724721
def handleGetInteractiveDiagnosticsRequest
725722
(ctx : WorkerContext)
726-
(st : WorkerState)
727-
(params : RpcCallParams)
728-
: RequestM (LspResponse Json) := do
729-
let some seshRef := st.rpcSessions.find? params.sessionId
730-
| throw RequestError.rpcNeedsReconnect
731-
let params ← RequestM.parseRequestParams Widget.GetInteractiveDiagnosticsParams params.params
723+
(params : GetInteractiveDiagnosticsParams)
724+
: RequestM (Array InteractiveDiagnostic) := do
732725
let doc ← readDoc
733726
-- NOTE: always uses latest document (which is the only one we can retrieve diagnostics for);
734727
-- any race should be temporary as the client should re-request interactive diagnostics when
@@ -738,7 +731,7 @@ section MessageHandling
738731
-- NOTE: does not wait for `lineRange?` to be fully elaborated, which would be problematic with
739732
-- fine-grained incremental reporting anyway; instead, the client is obligated to resend the
740733
-- request when the non-interactive diagnostics of this range have changed
741-
let matchedDiags := (stickyDiags ++ diags).filter fun diag =>
734+
return (stickyDiags ++ diags).filter fun diag =>
742735
let r := diag.fullRange
743736
let diagStartLine := r.start.line
744737
let diagEndLine :=
@@ -750,18 +743,6 @@ section MessageHandling
750743
-- does [s,e) intersect [diagStartLine,diagEndLine)?
751744
s ≤ diagStartLine ∧ diagStartLine < e ∨
752745
diagStartLine ≤ s ∧ s < diagEndLine
753-
for diag in matchedDiags do
754-
if ← diag.encodedDiag.isResolved then
755-
continue
756-
let encodedDiag ← seshRef.modifyGet fun st =>
757-
let (encoded, objects') := StateT.run (s := st.objects) <| rpcEncode diag.toDiagnosticWith
758-
(encoded, { st with objects := objects' })
759-
diag.encodedDiag.resolve encodedDiag
760-
let encodedDiags := matchedDiags.map (·.encodedDiag.result!.get)
761-
let resp ← seshRef.modifyGet fun st =>
762-
let (encoded, objects') := StateT.run (s := st.objects) <| rpcEncode encodedDiags
763-
(encoded, { st with objects := objects' })
764-
return { response := resp, isComplete := true }
765746

766747
def handlePreRequestSpecialCases? (ctx : WorkerContext) (st : WorkerState)
767748
(id : RequestID) (method : String) (params : Json)
@@ -771,8 +752,13 @@ section MessageHandling
771752
let params ← RequestM.parseRequestParams Lsp.RpcCallParams params
772753
if params.method != `Lean.Widget.getInteractiveDiagnostics then
773754
return none
774-
let resp ← handleGetInteractiveDiagnosticsRequest ctx st params
775-
return some <| .pure resp
755+
let some seshRef := st.rpcSessions.find? params.sessionId
756+
| throw RequestError.rpcNeedsReconnect
757+
let params ← RequestM.parseRequestParams Widget.GetInteractiveDiagnosticsParams params.params
758+
let resp ← handleGetInteractiveDiagnosticsRequest ctx params
759+
let resp ← seshRef.modifyGet fun st =>
760+
rpcEncode resp st.objects |>.map (·) ({st with objects := ·})
761+
return some <| .pure { response := resp, isComplete := true }
776762
| "codeAction/resolve" =>
777763
let params ← RequestM.parseRequestParams CodeAction params
778764
let some data := params.data?

src/Lean/Server/FileWorker/Utils.lean

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ where
3737
| some next => .delayed <| next.task.asServerTask.bindCheap go
3838
| none => .nil)
3939

40-
structure ReportableDiagnostic extends Widget.InteractiveDiagnostic where
41-
/--
42-
Memorized encoded representation of this diagnostic.
43-
We store the encoded representation so that the RPC references in this `InteractiveDiagnostic`
44-
are stable when this diagnostic is reused.
45-
Otherwise, clients are forced to reset the UI when the reference changes.
46-
-/
47-
encodedDiag : IO.Promise Json
48-
4940
/--
5041
A document bundled with processing information. Turned into `EditableDocument` as soon as the
5142
reporter task has been started.
@@ -61,7 +52,7 @@ structure EditableDocumentCore where
6152
Interactive versions of diagnostics reported so far. Filled by `reportSnapshots` and read by
6253
`handleGetInteractiveDiagnosticsRequest`.
6354
-/
64-
diagnosticsRef : IO.Ref (Array ReportableDiagnostic)
55+
diagnosticsRef : IO.Ref (Array Widget.InteractiveDiagnostic)
6556

6657
/-- `EditableDocumentCore` with reporter task. -/
6758
structure EditableDocument extends EditableDocumentCore where

0 commit comments

Comments
 (0)