Skip to content

Commit c92dc90

Browse files
[Repo Assist] fix: thread document version through PublishDiagnosticsParams (#1526)
* fix: thread document version through PublishDiagnosticsParams The LSP spec allows PublishDiagnosticsParams to include the document version for which diagnostics were computed. Clients can use this to discard stale diagnostics when the user has already made further edits. Previously the version was always None (a TODO existed noting this gap). This change: - Updates DiagnosticCollection.send to compute the max version across all diagnostic sources for a given URI and pass it to sendDiagnostics - Updates sendDiagnostics to accept and forward the version - Removes the TODO comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9e007f0 commit c92dc90

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/FsAutoComplete/LspServers/AdaptiveServerState.fs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,12 @@ type AdaptiveState
365365
FSIRefs.TFM.NetFx)
366366

367367

368-
let sendDiagnostics (uri: DocumentUri) (diags: Diagnostic[]) =
368+
let sendDiagnostics (uri: DocumentUri) (version: int option) (diags: Diagnostic[]) =
369369
logger.info (Log.setMessageI $"SendDiag for {uri:file}: {diags.Length:diags} entries")
370370

371-
// TODO: providing version would be very useful
372371
{ Uri = uri
373372
Diagnostics = diags
374-
Version = None }
373+
Version = version }
375374
|> lspClient.TextDocumentPublishDiagnostics
376375

377376

src/FsAutoComplete/LspServers/Common.fs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ type DiagnosticMessage =
5555
| Clear of source: string
5656

5757
/// a type that handles bookkeeping for sending file diagnostics. It will debounce calls and handle sending diagnostics via the configured function when safe
58-
type DiagnosticCollection(sendDiagnostics: DocumentUri -> Diagnostic[] -> Async<unit>) =
58+
type DiagnosticCollection(sendDiagnostics: DocumentUri -> int option -> Diagnostic[] -> Async<unit>) =
5959
let send uri (diags: Map<string, Version * Diagnostic[]>) =
60-
Map.toArray diags |> Array.collect (snd >> snd) |> sendDiagnostics uri
60+
let allDiags = Map.toArray diags |> Array.collect (snd >> snd)
61+
62+
let maxVersion =
63+
if Map.isEmpty diags then
64+
None
65+
else
66+
Map.toArray diags |> Array.map (snd >> fst) |> Array.max |> Some
67+
68+
sendDiagnostics uri maxVersion allDiags
6169

6270
let agents =
6371
System.Collections.Concurrent.ConcurrentDictionary<
@@ -134,7 +142,7 @@ type DiagnosticCollection(sendDiagnostics: DocumentUri -> Diagnostic[] -> Async<
134142
member x.ClearFor(fileUri: DocumentUri) =
135143
if x.ClientSupportsDiagnostics then
136144
removeAgent fileUri
137-
sendDiagnostics fileUri [||] |> Async.Start
145+
sendDiagnostics fileUri None [||] |> Async.Start
138146

139147
member x.ClearFor(fileUri: DocumentUri, kind: string) =
140148
if x.ClientSupportsDiagnostics then

0 commit comments

Comments
 (0)