Skip to content

Commit 9e32704

Browse files
committed
add version support to textDocument/publishDiagnostics
1 parent 3bd4f74 commit 9e32704

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
@@ -267,11 +267,17 @@ impl ServerConnection {
267267
));
268268
}
269269

270-
fn publish_diagnostics(&self, diags: SmallMap<PathBuf, Vec<Diagnostic>>) {
270+
fn publish_diagnostics(
271+
&self,
272+
diags: SmallMap<PathBuf, Vec<Diagnostic>>,
273+
version_info: &HashMap<PathBuf, i32>,
274+
) {
271275
for (path, diags) in diags {
272276
let path = std::fs::canonicalize(&path).unwrap_or(path);
273277
match Url::from_file_path(&path) {
274-
Ok(uri) => self.publish_diagnostics_for_uri(uri, diags, None),
278+
Ok(uri) => {
279+
self.publish_diagnostics_for_uri(uri, diags, version_info.get(&path).copied())
280+
}
275281
Err(_) => eprint!("Unable to convert path to uri: {path:?}"),
276282
}
277283
}
@@ -1154,7 +1160,8 @@ impl Server {
11541160
diags.entry(path.to_owned()).or_default().push(diag);
11551161
}
11561162
}
1157-
self.connection.publish_diagnostics(diags);
1163+
self.connection
1164+
.publish_diagnostics(diags, &*self.version_info.lock());
11581165
};
11591166

11601167
match possibly_committable_transaction {
@@ -1493,6 +1500,7 @@ impl Server {
14931500
let uri = params.text_document.uri.to_file_path().unwrap();
14941501
self.version_info.lock().remove(&uri);
14951502
self.open_files.write().remove(&uri);
1503+
// TODO: should we use the last version or None?
14961504
self.connection
14971505
.publish_diagnostics_for_uri(params.text_document.uri, Vec::new(), None);
14981506
let state = self.state.dupe();

0 commit comments

Comments
 (0)