@@ -85,7 +85,7 @@ structure WorkerContext where
85
85
/--
86
86
Diagnostics that are included in every single `textDocument/publishDiagnostics` notification.
87
87
-/
88
- stickyDiagnosticsRef : IO.Ref (Array ReportableDiagnostic )
88
+ stickyDiagnosticsRef : IO.Ref (Array InteractiveDiagnostic )
89
89
partialHandlersRef : IO.Ref (RBMap String PartialHandlerInfo compare)
90
90
pendingServerRequestsRef : IO.Ref (Std.TreeMap RequestID (IO.Promise (ServerRequestResponse Json)))
91
91
hLog : FS.Stream
@@ -192,7 +192,7 @@ This option can only be set on the command line, not in the lakefile or via `set
192
192
See also section "Communication" in Lean/Server/README.md.
193
193
-/
194
194
structure MemorizedInteractiveDiagnostics where
195
- diags : Array ReportableDiagnostic
195
+ diags : Array Widget.InteractiveDiagnostic
196
196
deriving TypeName
197
197
198
198
/--
@@ -205,7 +205,7 @@ This option can only be set on the command line, not in the lakefile or via `set
205
205
let docInteractiveDiagnostics ← doc.diagnosticsRef.get
206
206
let diagnostics :=
207
207
stickyInteractiveDiagnostics ++ docInteractiveDiagnostics
208
- |>.map (Widget.InteractiveDiagnostic.toDiagnostic ·.toDiagnosticWith )
208
+ |>.map (·.toDiagnostic )
209
209
let notification := mkPublishDiagnosticsNotification doc.meta diagnostics
210
210
ctx.chanOut.sync.send notification
211
211
@@ -300,8 +300,6 @@ This option can only be set on the command line, not in the lakefile or via `set
300
300
msgs := msgs.filter (! ·.isSilent)
301
301
let diags ← msgs.mapM
302
302
(Widget.msgToInteractiveDiagnostic doc.meta.text · ctx.clientHasWidgets)
303
- let diags ← diags.mapM fun diag => do
304
- return { diag with encodedDiag := ← IO.Promise.new }
305
303
if let some cacheRef := node.element.diagnostics.interactiveDiagsRef? then
306
304
cacheRef.set <| some <| .mk { diags : MemorizedInteractiveDiagnostics }
307
305
pure diags
@@ -464,7 +462,7 @@ section Initialization
464
462
}
465
463
let doc : EditableDocumentCore := {
466
464
meta, initSnap
467
- diagnosticsRef := ← IO.mkRef ∅
465
+ diagnosticsRef := ( ← IO.mkRef ∅)
468
466
}
469
467
let reporterCancelTk ← CancelToken.new
470
468
let reporter ← reportSnapshots ctx doc reporterCancelTk
@@ -550,7 +548,7 @@ section Updates
550
548
let initSnap ← ctx.processor meta.mkInputContext
551
549
let doc : EditableDocumentCore := {
552
550
meta, initSnap
553
- diagnosticsRef := ← IO.mkRef ∅
551
+ diagnosticsRef := ( ← IO.mkRef ∅)
554
552
}
555
553
let reporterCancelTk ← CancelToken.new
556
554
let reporter ← reportSnapshots ctx doc reporterCancelTk
@@ -610,7 +608,6 @@ section NotificationHandling
610
608
fullRange? := some ⟨⟨0 , 0 ⟩, text.utf8PosToLspPos text.source.endPos⟩
611
609
severity? := DiagnosticSeverity.information
612
610
message := importOutOfDataMessage
613
- encodedDiag := ← IO.Promise.new
614
611
}
615
612
ctx.stickyDiagnosticsRef.modify fun stickyDiagnostics =>
616
613
let stickyDiagnostics := stickyDiagnostics.filter
@@ -723,12 +720,8 @@ section MessageHandling
723
720
open Widget RequestM Language in
724
721
def handleGetInteractiveDiagnosticsRequest
725
722
(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
732
725
let doc ← readDoc
733
726
-- NOTE: always uses latest document (which is the only one we can retrieve diagnostics for);
734
727
-- any race should be temporary as the client should re-request interactive diagnostics when
@@ -738,7 +731,7 @@ section MessageHandling
738
731
-- NOTE: does not wait for `lineRange?` to be fully elaborated, which would be problematic with
739
732
-- fine-grained incremental reporting anyway; instead, the client is obligated to resend the
740
733
-- 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 =>
742
735
let r := diag.fullRange
743
736
let diagStartLine := r.start.line
744
737
let diagEndLine :=
@@ -750,18 +743,6 @@ section MessageHandling
750
743
-- does [s,e) intersect [diagStartLine,diagEndLine)?
751
744
s ≤ diagStartLine ∧ diagStartLine < e ∨
752
745
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 }
765
746
766
747
def handlePreRequestSpecialCases? (ctx : WorkerContext) (st : WorkerState)
767
748
(id : RequestID) (method : String) (params : Json)
@@ -771,8 +752,13 @@ section MessageHandling
771
752
let params ← RequestM.parseRequestParams Lsp.RpcCallParams params
772
753
if params.method != `Lean.Widget.getInteractiveDiagnostics then
773
754
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 }
776
762
| "codeAction/resolve" =>
777
763
let params ← RequestM.parseRequestParams CodeAction params
778
764
let some data := params.data?
0 commit comments