Improve support for multiple registrations of textDocument/diagnostic (#43703)
Closes https://github.com/zed-industries/zed/issues/41935 The registration ID responsible for generating each diagnostic is now tracked. This allows us to replace only the diagnostics from the same registration ID when a pull diagnostics report is applied. Additionally, various deficiencies in our support for pull diagnostics have been fixed: - Document pulls are issued for all open buffers, not just the edited one. A shorter debounce is used for the edited buffer. Workspace diagnostics are also now ignored for open buffers. - Tracking of `lastResultId` is improved. - Stored pull diagnostics are discarded when the corresponding buffer is closed. Release Notes: - Improved compatibility with language servers that use the "pull diagnostics" feature of Language Server Protocol. --------- Co-authored-by: Kirill Bulatov <mail4score@gmail.com> Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
co-authored by
Kirill Bulatov
Kirill Bulatov
parent
493cfadb42
commit
a51e975b81
@@ -25,6 +25,7 @@ use gpui::{
|
||||
use indoc::indoc;
|
||||
use language::FakeLspAdapter;
|
||||
use lsp::LSP_REQUEST_TIMEOUT;
|
||||
use pretty_assertions::assert_eq;
|
||||
use project::{
|
||||
ProgressToken, ProjectPath, SERVER_PROGRESS_THROTTLE_TIMEOUT,
|
||||
lsp_store::lsp_ext_command::{ExpandedMacro, LspExtExpandMacro},
|
||||
@@ -3192,13 +3193,12 @@ async fn test_lsp_pull_diagnostics(
|
||||
.collect::<Vec<_>>();
|
||||
let expected_messages = [
|
||||
expected_pull_diagnostic_lib_message,
|
||||
// TODO bug: the pushed diagnostics are not being sent to the client when they open the corresponding buffer.
|
||||
// expected_push_diagnostic_lib_message,
|
||||
expected_push_diagnostic_lib_message,
|
||||
];
|
||||
assert_eq!(
|
||||
all_diagnostics.len(),
|
||||
1,
|
||||
"Expected pull diagnostics, but got: {all_diagnostics:?}"
|
||||
2,
|
||||
"Expected pull and push diagnostics, but got: {all_diagnostics:?}"
|
||||
);
|
||||
for diagnostic in all_diagnostics {
|
||||
assert!(
|
||||
@@ -3258,14 +3258,15 @@ async fn test_lsp_pull_diagnostics(
|
||||
.diagnostics_in_range(MultiBufferOffset(0)..snapshot.len())
|
||||
.collect::<Vec<_>>();
|
||||
let expected_messages = [
|
||||
expected_workspace_pull_diagnostics_lib_message,
|
||||
// TODO bug: the pushed diagnostics are not being sent to the client when they open the corresponding buffer.
|
||||
// expected_push_diagnostic_lib_message,
|
||||
// Despite workspace diagnostics provided,
|
||||
// the currently open file's diagnostics should be preferred, as LSP suggests.
|
||||
expected_pull_diagnostic_lib_message,
|
||||
expected_push_diagnostic_lib_message,
|
||||
];
|
||||
assert_eq!(
|
||||
all_diagnostics.len(),
|
||||
1,
|
||||
"Expected pull diagnostics, but got: {all_diagnostics:?}"
|
||||
2,
|
||||
"Expected pull and push diagnostics, but got: {all_diagnostics:?}"
|
||||
);
|
||||
for diagnostic in all_diagnostics {
|
||||
assert!(
|
||||
@@ -3378,8 +3379,9 @@ async fn test_lsp_pull_diagnostics(
|
||||
"Another workspace diagnostics pull should happen after the diagnostics refresh server request"
|
||||
);
|
||||
{
|
||||
assert!(
|
||||
diagnostics_pulls_result_ids.lock().await.len() == diagnostic_pulls_result_ids,
|
||||
assert_eq!(
|
||||
diagnostics_pulls_result_ids.lock().await.len(),
|
||||
diagnostic_pulls_result_ids,
|
||||
"Pulls should not happen hence no extra ids should appear"
|
||||
);
|
||||
assert!(
|
||||
@@ -3397,7 +3399,7 @@ async fn test_lsp_pull_diagnostics(
|
||||
expected_pull_diagnostic_lib_message,
|
||||
expected_push_diagnostic_lib_message,
|
||||
];
|
||||
assert_eq!(all_diagnostics.len(), 1);
|
||||
assert_eq!(all_diagnostics.len(), 2);
|
||||
for diagnostic in &all_diagnostics {
|
||||
assert!(
|
||||
expected_messages.contains(&diagnostic.diagnostic.message.as_str()),
|
||||
|
||||
Reference in New Issue
Block a user