@@ -130,9 +130,22 @@ func (s *Server) publishReports(ctx context.Context, reports map[source.FileIden
130
130
sorted : diagnostics ,
131
131
}
132
132
delivered , ok := s .delivered [fileID .URI ]
133
+ // If diagnostics are empty and not previously delivered,
134
+ // only send them if we are publishing empty diagnostics.
135
+ if ! ok && len (diagnostics ) == 0 && ! publishEmpty {
136
+ // Update the delivered map to cache the diagnostics.
137
+ s .delivered [fileID .URI ] = toSend
138
+ continue
139
+ }
133
140
// Reuse equivalent cached diagnostics for subsequent file versions (if known),
134
141
// or identical files (if versions are not known).
135
142
if ok {
143
+ // If the file is open, and we've already delivered diagnostics for
144
+ // a later version, do nothing. This only works for open files,
145
+ // since their contents in the editor are the source of truth.
146
+ if s .session .IsOpen (fileID .URI ) && fileID .Version < delivered .version {
147
+ continue
148
+ }
136
149
geqVersion := fileID .Version >= delivered .version && delivered .version > 0
137
150
noVersions := (fileID .Version == 0 && delivered .version == 0 ) && delivered .identifier == fileID .Identifier
138
151
if (geqVersion || noVersions ) && equalDiagnostics (delivered .sorted , diagnostics ) {
@@ -141,13 +154,7 @@ func (s *Server) publishReports(ctx context.Context, reports map[source.FileIden
141
154
continue
142
155
}
143
156
}
144
- // If diagnostics are empty and not previously delivered,
145
- // only send them if we are publishing empty diagnostics.
146
- if ! ok && len (diagnostics ) == 0 && ! publishEmpty {
147
- // Update the delivered map to cache the diagnostics.
148
- s .delivered [fileID .URI ] = toSend
149
- continue
150
- }
157
+
151
158
if err := s .client .PublishDiagnostics (ctx , & protocol.PublishDiagnosticsParams {
152
159
Diagnostics : toProtocolDiagnostics (ctx , diagnostics ),
153
160
URI : protocol .NewURI (fileID .URI ),
0 commit comments