Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions crates/collab/src/tests/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3072,13 +3072,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!(
Expand Down Expand Up @@ -3139,13 +3138,12 @@ async fn test_lsp_pull_diagnostics(
.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,
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!(
Expand Down Expand Up @@ -3277,7 +3275,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()),
Expand Down
32 changes: 24 additions & 8 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7015,8 +7015,9 @@ impl LspStore {
.merge_lsp_diagnostics(
DiagnosticSourceKind::Pulled,
diagnostic_updates,
|buffer, old_diagnostic, cx| {
File::from_dyn(buffer.file())
|diagnostic_buffer, old_diagnostic, cx| {
diagnostic_buffer
.and_then(|buffer| File::from_dyn(buffer.file()))
.and_then(|file| {
let abs_path = file.as_local()?.abs_path(cx);
lsp::Uri::from_file_path(abs_path).ok()
Expand Down Expand Up @@ -8062,7 +8063,7 @@ impl LspStore {
pub fn merge_diagnostic_entries<'a>(
&mut self,
diagnostic_updates: Vec<DocumentDiagnosticsUpdate<'a, DocumentDiagnostics>>,
merge: impl Fn(&Buffer, &Diagnostic, &App) -> bool + Clone,
merge: impl Fn(Option<&Buffer>, &Diagnostic, &App) -> bool + Clone,
cx: &mut Context<Self>,
) -> anyhow::Result<()> {
let mut diagnostics_summary = None::<proto::UpdateDiagnosticSummary>;
Expand All @@ -8089,7 +8090,7 @@ impl LspStore {
let reused_diagnostics = buffer
.buffer_diagnostics(Some(server_id))
.iter()
.filter(|v| merge(buffer, &v.diagnostic, cx))
.filter(|v| merge(Some(buffer), &v.diagnostic, cx))
.map(|v| {
let start = Unclipped(v.range.start.to_point_utf16(&snapshot));
let end = Unclipped(v.range.end.to_point_utf16(&snapshot));
Expand All @@ -8113,6 +8114,20 @@ impl LspStore {
)?;

update.diagnostics.diagnostics.extend(reused_diagnostics);
} else if let Some(local) = self.as_local_mut() {
let diagnostics_for_tree = local.diagnostics.entry(worktree_id).or_default();
let diagnostics_by_server_id = diagnostics_for_tree
.entry(project_path.path.clone())
.or_default();
if let Ok(ix) = diagnostics_by_server_id.binary_search_by_key(&server_id, |e| e.0) {
let reused_diagnostics = diagnostics_by_server_id[ix]
.1
.iter()
.filter(|v| merge(None, &v.diagnostic, cx))
.cloned()
.collect::<Vec<_>>();
update.diagnostics.diagnostics.extend(reused_diagnostics);
}
}

let updated = worktree.update(cx, |worktree, cx| {
Expand Down Expand Up @@ -8197,7 +8212,7 @@ impl LspStore {
.unwrap_or_default();

let new_summary = DiagnosticSummary::new(&diagnostics);
if new_summary.is_empty() {
if diagnostics.is_empty() {
if let Some(diagnostics_by_server_id) = diagnostics_for_tree.get_mut(&path_in_worktree)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One unrelated thing I noticed but wasn't sure about was that in this branch summaries_by_server_id.insert isn't updated. It doesn't seem to matter for this particular issue so left it as is.

{
if let Ok(ix) = diagnostics_by_server_id.binary_search_by_key(&server_id, |e| e.0) {
Expand Down Expand Up @@ -10762,7 +10777,7 @@ impl LspStore {
&mut self,
source_kind: DiagnosticSourceKind,
lsp_diagnostics: Vec<DocumentDiagnosticsUpdate<lsp::PublishDiagnosticsParams>>,
merge: impl Fn(&Buffer, &Diagnostic, &App) -> bool + Clone,
merge: impl Fn(Option<&Buffer>, &Diagnostic, &App) -> bool + Clone,
cx: &mut Context<Self>,
) -> Result<()> {
anyhow::ensure!(self.mode.is_local(), "called update_diagnostics on remote");
Expand Down Expand Up @@ -11781,8 +11796,9 @@ impl LspStore {
self.merge_lsp_diagnostics(
DiagnosticSourceKind::Pulled,
diagnostic_updates,
|buffer, old_diagnostic, cx| {
File::from_dyn(buffer.file())
|diagnostic_buffer, old_diagnostic, cx| {
diagnostic_buffer
.and_then(|buffer| File::from_dyn(buffer.file()))
.and_then(|file| {
let abs_path = file.as_local()?.abs_path(cx);
lsp::Uri::from_file_path(abs_path).ok()
Expand Down
Loading