Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai bb1b3689b4 fix(java): recheck open files when Java sources change on disk
When another tool (an AI agent, a generator) rewrote an open Java file to
call a class or method it added in another file, the open file kept a
"cannot be resolved" error until it was closed and reopened. jdtls
rebuilds sources reported through workspace/didChangeWatchedFiles but
does not re-reconcile the open working copies it already checked. When
the open file's reload reaches it before the new class, the stale
error stays.

After sending Java source changes to jdtls, the open documents are sent
again (resync_documents, as after a configuration change), so jdtls
checks them against the new sources. Changes to other files (pom.xml,
resources) don't trigger it.

Fixes #6986
2026-12-01 07:02:49 +08:00
2 змінених файлів з 32 додано та 0 видалено

No files matched your search

+7
Переглянути файл
@@ -3405,10 +3405,17 @@ impl LspManager {
if changes.is_empty() {
continue;
}
// jdtls rebuilds a source file that changed on disk but keeps the diagnostics of the
// open files it checked before: a reference to a class another tool adds after
// rewriting the open file stays "cannot be resolved" until the file is reopened.
// Sending the open files again makes it check them against the new sources.
let recheck_open = jdtls && changes.iter().any(|(p, _)| p.extension().is_some_and(|e| e == "java"));
let changes: Vec<Value> =
changes.iter().map(|(p, c)| json!({ "uri": uri::path_to_uri(p), "type": *c as u8 })).collect();
if let Err(e) = run.peer.notify("workspace/didChangeWatchedFiles", json!({ "changes": changes })) {
tracing::debug!("{}: didChangeWatchedFiles: {e}", s.name);
} else if recheck_open {
self.resync_documents(&s, run.generation);
}
}
}
+25
Переглянути файл
@@ -482,6 +482,31 @@ async fn dart_file_watching_requires_an_explicit_registration() {
}
}
#[tokio::test(flavor = "multi_thread")]
async fn java_sources_changed_on_disk_send_the_open_files_to_jdtls_again() {
let h = harness_for("java", "java", &[("jdtls", incremental_caps())], &[]);
let (_, main) = h.open("Main.java", "class Main { String s = Helper.greet(); }");
h.wait_status("jdtls", ServerStatus::Ready).await;
let s = h.launcher.state("jdtls");
let resent = || {
s.notified("textDocument/didChange")
.iter()
.filter(|v| v["textDocument"]["uri"] == uri_of(&main) && v["contentChanges"][0]["text"].is_string())
.count()
};
// Another tool adds the class the open file refers to.
let helper = h.root.join("Helper.java");
h.mgr.watched_files_changed(std::slice::from_ref(&helper), &[], &[], &[]);
eventually(|| s.notified("workspace/didChangeWatchedFiles").len() == 1).await;
eventually(|| resent() == 1).await;
// Files that are not Java sources leave the open files alone.
h.mgr.watched_files_changed(&[], &[h.root.join("notes.txt")], &[], &[]);
h.mgr.watched_files_changed(&[], &[h.root.join("pom.xml")], &[], &[]);
tokio::time::sleep(Duration::from_millis(200)).await;
assert_eq!(resent(), 1);
h.mgr.shutdown_all().await;
}
// ------------------------------------------------------------------ tests
#[tokio::test(flavor = "multi_thread")]