Don't replace newer diagnostics with older ones

This commit is contained in:
Antonio Scandurra 2022-11-17 12:21:51 +01:00
parent 532a599239
commit 71eeeedc05
7 changed files with 33 additions and 13 deletions

View File

@ -82,6 +82,7 @@ CREATE TABLE "worktree_diagnostic_summaries" (
"language_server_id" INTEGER NOT NULL,
"error_count" INTEGER NOT NULL,
"warning_count" INTEGER NOT NULL,
"version" INTEGER NOT NULL,
PRIMARY KEY(project_id, worktree_id, path),
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
);

View File

@ -44,6 +44,7 @@ CREATE TABLE "worktree_diagnostic_summaries" (
"language_server_id" INTEGER NOT NULL,
"error_count" INTEGER NOT NULL,
"warning_count" INTEGER NOT NULL,
"version" INTEGER NOT NULL,
PRIMARY KEY(project_id, worktree_id, path),
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
);

View File

@ -1813,13 +1813,15 @@ where
path,
language_server_id,
error_count,
warning_count
warning_count,
version
)
VALUES ($1, $2, $3, $4, $5, $6)
VALUES ($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT (project_id, worktree_id, path) DO UPDATE SET
language_server_id = excluded.language_server_id,
error_count = excluded.error_count,
warning_count = excluded.warning_count
warning_count = excluded.warning_count,
version = excluded.version
",
)
.bind(project_id)
@ -1828,6 +1830,7 @@ where
.bind(summary.language_server_id as i64)
.bind(summary.error_count as i32)
.bind(summary.warning_count as i32)
.bind(summary.version as i32)
.execute(&mut tx)
.await?;
@ -2042,6 +2045,7 @@ where
language_server_id: summary.language_server_id as u64,
error_count: summary.error_count as u32,
warning_count: summary.warning_count as u32,
version: summary.version as u32,
});
}
}
@ -2666,6 +2670,7 @@ struct WorktreeDiagnosticSummary {
language_server_id: i64,
error_count: i32,
warning_count: i32,
version: i32,
}
id_type!(LanguageServerId);

View File

@ -2412,9 +2412,10 @@ async fn test_collaborating_with_diagnostics(
path: Arc::from(Path::new("a.rs")),
},
DiagnosticSummary {
language_server_id: 0,
error_count: 1,
warning_count: 0,
..Default::default()
version: 2,
},
)]
)
@ -2444,9 +2445,10 @@ async fn test_collaborating_with_diagnostics(
path: Arc::from(Path::new("a.rs")),
},
DiagnosticSummary {
language_server_id: 0,
error_count: 1,
warning_count: 0,
..Default::default()
version: 2,
},
)]
);
@ -2484,9 +2486,10 @@ async fn test_collaborating_with_diagnostics(
path: Arc::from(Path::new("a.rs")),
},
DiagnosticSummary {
language_server_id: 0,
error_count: 1,
warning_count: 1,
..Default::default()
version: 3,
},
)]
);
@ -2500,9 +2503,10 @@ async fn test_collaborating_with_diagnostics(
path: Arc::from(Path::new("a.rs")),
},
DiagnosticSummary {
language_server_id: 0,
error_count: 1,
warning_count: 1,
..Default::default()
version: 3,
},
)]
);

View File

@ -223,6 +223,7 @@ pub struct DiagnosticSummary {
pub language_server_id: usize,
pub error_count: usize,
pub warning_count: usize,
pub version: usize,
}
#[derive(Debug, Clone)]
@ -293,12 +294,14 @@ pub struct ProjectTransaction(pub HashMap<ModelHandle<Buffer>, language::Transac
impl DiagnosticSummary {
fn new<'a, T: 'a>(
language_server_id: usize,
version: usize,
diagnostics: impl IntoIterator<Item = &'a DiagnosticEntry<T>>,
) -> Self {
let mut this = Self {
language_server_id,
error_count: 0,
warning_count: 0,
version,
};
for entry in diagnostics {
@ -324,6 +327,7 @@ impl DiagnosticSummary {
language_server_id: self.language_server_id as u64,
error_count: self.error_count as u32,
warning_count: self.warning_count as u32,
version: self.version as u32,
}
}
}

View File

@ -366,6 +366,7 @@ impl Worktree {
Worktree::Remote(worktree) => &worktree.diagnostic_summaries,
}
.iter()
.filter(|(_, summary)| !summary.is_empty())
.map(|(path, summary)| (path.0.clone(), *summary))
}
@ -516,7 +517,8 @@ impl LocalWorktree {
.diagnostic_summaries
.remove(&PathKey(worktree_path.clone()))
.unwrap_or_default();
let new_summary = DiagnosticSummary::new(language_server_id, &diagnostics);
let new_summary =
DiagnosticSummary::new(language_server_id, old_summary.version + 1, &diagnostics);
if !new_summary.is_empty() {
self.diagnostic_summaries
.insert(PathKey(worktree_path.clone()), new_summary);
@ -1106,15 +1108,17 @@ impl RemoteWorktree {
path: Arc<Path>,
summary: &proto::DiagnosticSummary,
) {
let summary = DiagnosticSummary {
let old_summary = self.diagnostic_summaries.get(&PathKey(path.clone()));
let new_summary = DiagnosticSummary {
language_server_id: summary.language_server_id as usize,
error_count: summary.error_count as usize,
warning_count: summary.warning_count as usize,
version: summary.version as usize,
};
if summary.is_empty() {
self.diagnostic_summaries.remove(&PathKey(path));
} else {
self.diagnostic_summaries.insert(PathKey(path), summary);
if old_summary.map_or(true, |old_summary| {
new_summary.version >= old_summary.version
}) {
self.diagnostic_summaries.insert(PathKey(path), new_summary);
}
}

View File

@ -652,6 +652,7 @@ message DiagnosticSummary {
uint64 language_server_id = 2;
uint32 error_count = 3;
uint32 warning_count = 4;
uint32 version = 5;
}
message UpdateLanguageServer {