Remove summaries that don't contain any errors or warnings
When opening a buffer, some language servers might start reporting diagnostics. When closing a buffer, they might report that no diagnostics are present for that buffer. Previously, we would keep an empty summary entry which would cause us to open a buffer in the project diagnostics view, only to drop it because it contained no diagnostics. However, the act of opening it caused the language server to asynchronously report non-empty diagnostics. We would therefore handle this as an update, but the previous closing of the buffer would cause the language server to report empty diagnostics again. This would cause the project diagnostics view to thrash infinitely between these two states, pegging the CPU and constantly refreshing the UI. With this commit we won't maintain empty summary entries for files that contain no diagnostics, which fixes the above issue. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
1cd23df4d8
commit
ef784cf21e
5 changed files with 43 additions and 29 deletions
|
@ -233,8 +233,6 @@ impl Worktree {
|
|||
DiagnosticSummary {
|
||||
error_count: summary.error_count as usize,
|
||||
warning_count: summary.warning_count as usize,
|
||||
info_count: summary.info_count as usize,
|
||||
hint_count: summary.hint_count as usize,
|
||||
},
|
||||
)
|
||||
}),
|
||||
|
@ -568,9 +566,15 @@ impl LocalWorktree {
|
|||
_: &mut ModelContext<Worktree>,
|
||||
) -> Result<()> {
|
||||
let summary = DiagnosticSummary::new(&diagnostics);
|
||||
self.diagnostic_summaries
|
||||
.insert(PathKey(worktree_path.clone()), summary.clone());
|
||||
self.diagnostics.insert(worktree_path.clone(), diagnostics);
|
||||
if summary.is_empty() {
|
||||
self.diagnostic_summaries
|
||||
.remove(&PathKey(worktree_path.clone()));
|
||||
self.diagnostics.remove(&worktree_path);
|
||||
} else {
|
||||
self.diagnostic_summaries
|
||||
.insert(PathKey(worktree_path.clone()), summary.clone());
|
||||
self.diagnostics.insert(worktree_path.clone(), diagnostics);
|
||||
}
|
||||
|
||||
if let Some(share) = self.share.as_ref() {
|
||||
self.client
|
||||
|
@ -581,8 +585,6 @@ impl LocalWorktree {
|
|||
path: worktree_path.to_string_lossy().to_string(),
|
||||
error_count: summary.error_count as u32,
|
||||
warning_count: summary.warning_count as u32,
|
||||
info_count: summary.info_count as u32,
|
||||
hint_count: summary.hint_count as u32,
|
||||
}),
|
||||
})
|
||||
.log_err();
|
||||
|
@ -846,15 +848,16 @@ impl RemoteWorktree {
|
|||
path: Arc<Path>,
|
||||
summary: &proto::DiagnosticSummary,
|
||||
) {
|
||||
self.diagnostic_summaries.insert(
|
||||
PathKey(path.clone()),
|
||||
DiagnosticSummary {
|
||||
error_count: summary.error_count as usize,
|
||||
warning_count: summary.warning_count as usize,
|
||||
info_count: summary.info_count as usize,
|
||||
hint_count: summary.hint_count as usize,
|
||||
},
|
||||
);
|
||||
let summary = DiagnosticSummary {
|
||||
error_count: summary.error_count as usize,
|
||||
warning_count: summary.warning_count as usize,
|
||||
};
|
||||
if summary.is_empty() {
|
||||
self.diagnostic_summaries.remove(&PathKey(path.clone()));
|
||||
} else {
|
||||
self.diagnostic_summaries
|
||||
.insert(PathKey(path.clone()), summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue