Skip to content

Commit fe0d445

Browse files
committed
add version support to textDocument/publishDiagnostics
1 parent ee50c14 commit fe0d445

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pyrefly/lib/lsp/non_wasm/server.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,17 @@ impl ServerConnection {
285285
));
286286
}
287287

288-
fn publish_diagnostics(&self, diags: SmallMap<PathBuf, Vec<Diagnostic>>) {
288+
fn publish_diagnostics(
289+
&self,
290+
diags: SmallMap<PathBuf, Vec<Diagnostic>>,
291+
version_info: &HashMap<PathBuf, i32>,
292+
) {
289293
for (path, diags) in diags {
290294
let path = std::fs::canonicalize(&path).unwrap_or(path);
291295
match Url::from_file_path(&path) {
292-
Ok(uri) => self.publish_diagnostics_for_uri(uri, diags, None),
296+
Ok(uri) => {
297+
self.publish_diagnostics_for_uri(uri, diags, version_info.get(&path).copied())
298+
}
293299
Err(_) => eprint!("Unable to convert path to uri: {path:?}"),
294300
}
295301
}
@@ -1175,7 +1181,8 @@ impl Server {
11751181
diags.entry(path.to_owned()).or_default().push(diag);
11761182
}
11771183
}
1178-
self.connection.publish_diagnostics(diags);
1184+
self.connection
1185+
.publish_diagnostics(diags, &*self.version_info.lock());
11791186
};
11801187

11811188
match possibly_committable_transaction {
@@ -1512,6 +1519,7 @@ impl Server {
15121519
self.version_info.lock().remove(&uri);
15131520
let open_files = self.open_files.dupe();
15141521
open_files.write().remove(&uri);
1522+
// TODO: should we use the last version or None?
15151523
self.connection
15161524
.publish_diagnostics_for_uri(params.text_document.uri, Vec::new(), None);
15171525
let state = self.state.dupe();

0 commit comments

Comments
 (0)