@@ -113,20 +113,35 @@ func (s *Server) publishReports(ctx context.Context, snapshot source.Snapshot, r
113
113
withAnalysis : withAnalysis ,
114
114
snapshotID : snapshot .ID (),
115
115
}
116
+
116
117
// We use the zero values if this is an unknown file.
117
118
delivered := s .delivered [fileID .URI ]
118
119
119
- // Reuse cached diagnostics and update the delivered map.
120
- if fileID .Version >= delivered .version && equalDiagnostics (delivered .sorted , diagnostics ) {
120
+ // Snapshot IDs are always increasing, so we use them instead of file
121
+ // versions to create the correct order for diagnostics.
122
+
123
+ // If we've already delivered diagnostics for a future snapshot for this file,
124
+ // do not deliver them.
125
+ if delivered .snapshotID > toSend .snapshotID {
126
+ // Do not update the delivered map since it already contains newer diagnostics.
127
+ continue
128
+ }
129
+
130
+ // Check if we should reuse the cached diagnostics.
131
+ if equalDiagnostics (delivered .sorted , diagnostics ) {
132
+ // Make sure to update the delivered map.
121
133
s .delivered [fileID .URI ] = toSend
122
134
continue
123
135
}
124
- // If we've already delivered diagnostics with analyses for this file, for this snapshot,
125
- // at this version, do not send diagnostics without analyses.
136
+
137
+ // If we've already delivered diagnostics for this file, at this
138
+ // snapshot, with analyses, do not send diagnostics without analyses.
126
139
if delivered .snapshotID == toSend .snapshotID && delivered .version == toSend .version &&
127
140
delivered .withAnalysis && ! toSend .withAnalysis {
141
+ // Do not update the delivered map since it already contains better diagnostics.
128
142
continue
129
143
}
144
+
130
145
if err := s .client .PublishDiagnostics (ctx , & protocol.PublishDiagnosticsParams {
131
146
Diagnostics : toProtocolDiagnostics (diagnostics ),
132
147
URI : protocol .NewURI (fileID .URI ),
0 commit comments