Fix diagnostics randomized tests (#21775)
These were silently passing after the delay in updating diagnostics was added. Co-Authored-By: Max <max@zed.dev> cc @someonetoignore Release Notes: - N/A --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
8a85d6ef96
commit
a35ef5b79f
5 changed files with 66 additions and 61 deletions
|
@ -1013,7 +1013,7 @@ impl LspStore {
|
|||
) {
|
||||
match event {
|
||||
BufferStoreEvent::BufferAdded(buffer) => {
|
||||
self.register_buffer(buffer, cx).log_err();
|
||||
self.on_buffer_added(buffer, cx).log_err();
|
||||
}
|
||||
BufferStoreEvent::BufferChangedFilePath { buffer, old_file } => {
|
||||
if let Some(old_file) = File::from_dyn(old_file.as_ref()) {
|
||||
|
@ -1120,7 +1120,7 @@ impl LspStore {
|
|||
}
|
||||
}
|
||||
|
||||
fn register_buffer(
|
||||
fn on_buffer_added(
|
||||
&mut self,
|
||||
buffer: &Model<Buffer>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
|
@ -2913,6 +2913,15 @@ impl LspStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn diagnostic_summary(&self, include_ignored: bool, cx: &AppContext) -> DiagnosticSummary {
|
||||
let mut summary = DiagnosticSummary::default();
|
||||
for (_, _, path_summary) in self.diagnostic_summaries(include_ignored, cx) {
|
||||
summary.error_count += path_summary.error_count;
|
||||
summary.warning_count += path_summary.warning_count;
|
||||
}
|
||||
summary
|
||||
}
|
||||
|
||||
pub fn diagnostic_summaries<'a>(
|
||||
&'a self,
|
||||
include_ignored: bool,
|
||||
|
|
|
@ -47,9 +47,9 @@ use gpui::{
|
|||
use itertools::Itertools;
|
||||
use language::{
|
||||
language_settings::InlayHintKind, proto::split_operations, Buffer, BufferEvent,
|
||||
CachedLspAdapter, Capability, CodeLabel, DiagnosticEntry, Documentation, File as _, Language,
|
||||
LanguageName, LanguageRegistry, PointUtf16, ToOffset, ToPointUtf16, Toolchain, ToolchainList,
|
||||
Transaction, Unclipped,
|
||||
CachedLspAdapter, Capability, CodeLabel, Documentation, File as _, Language, LanguageName,
|
||||
LanguageRegistry, PointUtf16, ToOffset, ToPointUtf16, Toolchain, ToolchainList, Transaction,
|
||||
Unclipped,
|
||||
};
|
||||
use lsp::{
|
||||
CodeActionKind, CompletionContext, CompletionItemKind, DocumentHighlightKind, LanguageServer,
|
||||
|
@ -2568,31 +2568,6 @@ impl Project {
|
|||
.update(cx, |store, _| store.reset_last_formatting_failure());
|
||||
}
|
||||
|
||||
pub fn update_diagnostics(
|
||||
&mut self,
|
||||
language_server_id: LanguageServerId,
|
||||
params: lsp::PublishDiagnosticsParams,
|
||||
disk_based_sources: &[String],
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<()> {
|
||||
self.lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store.update_diagnostics(language_server_id, params, disk_based_sources, cx)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_diagnostic_entries(
|
||||
&mut self,
|
||||
server_id: LanguageServerId,
|
||||
abs_path: PathBuf,
|
||||
version: Option<i32>,
|
||||
diagnostics: Vec<DiagnosticEntry<Unclipped<PointUtf16>>>,
|
||||
cx: &mut ModelContext<Project>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
self.lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store.update_diagnostic_entries(server_id, abs_path, version, diagnostics, cx)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reload_buffers(
|
||||
&self,
|
||||
buffers: HashSet<Model<Buffer>>,
|
||||
|
@ -3446,12 +3421,9 @@ impl Project {
|
|||
}
|
||||
|
||||
pub fn diagnostic_summary(&self, include_ignored: bool, cx: &AppContext) -> DiagnosticSummary {
|
||||
let mut summary = DiagnosticSummary::default();
|
||||
for (_, _, path_summary) in self.diagnostic_summaries(include_ignored, cx) {
|
||||
summary.error_count += path_summary.error_count;
|
||||
summary.warning_count += path_summary.warning_count;
|
||||
}
|
||||
summary
|
||||
self.lsp_store
|
||||
.read(cx)
|
||||
.diagnostic_summary(include_ignored, cx)
|
||||
}
|
||||
|
||||
pub fn diagnostic_summaries<'a>(
|
||||
|
|
|
@ -6,8 +6,9 @@ use gpui::{AppContext, SemanticVersion, UpdateGlobal};
|
|||
use http_client::Url;
|
||||
use language::{
|
||||
language_settings::{language_settings, AllLanguageSettings, LanguageSettingsContent},
|
||||
tree_sitter_rust, tree_sitter_typescript, Diagnostic, DiagnosticSet, DiskState, FakeLspAdapter,
|
||||
LanguageConfig, LanguageMatcher, LanguageName, LineEnding, OffsetRangeExt, Point, ToPoint,
|
||||
tree_sitter_rust, tree_sitter_typescript, Diagnostic, DiagnosticEntry, DiagnosticSet,
|
||||
DiskState, FakeLspAdapter, LanguageConfig, LanguageMatcher, LanguageName, LineEnding,
|
||||
OffsetRangeExt, Point, ToPoint,
|
||||
};
|
||||
use lsp::{
|
||||
notification::DidRenameFiles, DiagnosticSeverity, DocumentChanges, FileOperationFilter,
|
||||
|
@ -987,6 +988,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/dir/a.rs".as_ref(), "/dir/b.rs".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
|
||||
let buffer_a = project
|
||||
.update(cx, |project, cx| project.open_local_buffer("/dir/a.rs", cx))
|
||||
|
@ -997,8 +999,8 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
project.update(cx, |project, cx| {
|
||||
project
|
||||
lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store
|
||||
.update_diagnostics(
|
||||
LanguageServerId(0),
|
||||
lsp::PublishDiagnosticsParams {
|
||||
|
@ -1015,7 +1017,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
project
|
||||
lsp_store
|
||||
.update_diagnostics(
|
||||
LanguageServerId(0),
|
||||
lsp::PublishDiagnosticsParams {
|
||||
|
@ -1086,6 +1088,7 @@ async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/root/dir".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
let (worktree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_worktree("/root/dir", true, cx)
|
||||
|
@ -1103,8 +1106,8 @@ async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
let other_worktree_id = worktree.update(cx, |tree, _| tree.id());
|
||||
|
||||
let server_id = LanguageServerId(0);
|
||||
project.update(cx, |project, cx| {
|
||||
project
|
||||
lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store
|
||||
.update_diagnostics(
|
||||
server_id,
|
||||
lsp::PublishDiagnosticsParams {
|
||||
|
@ -1121,7 +1124,7 @@ async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
project
|
||||
lsp_store
|
||||
.update_diagnostics(
|
||||
server_id,
|
||||
lsp::PublishDiagnosticsParams {
|
||||
|
@ -2018,9 +2021,9 @@ async fn test_empty_diagnostic_ranges(cx: &mut gpui::TestAppContext) {
|
|||
project.update(cx, |project, cx| {
|
||||
project.lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store
|
||||
.update_buffer_diagnostics(
|
||||
&buffer,
|
||||
.update_diagnostic_entries(
|
||||
LanguageServerId(0),
|
||||
PathBuf::from("/dir/a.rs"),
|
||||
None,
|
||||
vec![
|
||||
DiagnosticEntry {
|
||||
|
@ -2078,9 +2081,10 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/dir".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store.clone());
|
||||
|
||||
project.update(cx, |project, cx| {
|
||||
project
|
||||
lsp_store.update(cx, |lsp_store, cx| {
|
||||
lsp_store
|
||||
.update_diagnostic_entries(
|
||||
LanguageServerId(0),
|
||||
Path::new("/dir/a.rs").to_owned(),
|
||||
|
@ -2097,7 +2101,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
|
|||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
project
|
||||
lsp_store
|
||||
.update_diagnostic_entries(
|
||||
LanguageServerId(1),
|
||||
Path::new("/dir/a.rs").to_owned(),
|
||||
|
@ -2116,7 +2120,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
project.diagnostic_summary(false, cx),
|
||||
lsp_store.diagnostic_summary(false, cx),
|
||||
DiagnosticSummary {
|
||||
error_count: 2,
|
||||
warning_count: 0,
|
||||
|
@ -3698,6 +3702,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs.clone(), ["/the-dir".as_ref()], cx).await;
|
||||
let lsp_store = project.read_with(cx, |project, _| project.lsp_store());
|
||||
let buffer = project
|
||||
.update(cx, |p, cx| p.open_local_buffer("/the-dir/a.rs", cx))
|
||||
.await
|
||||
|
@ -3791,9 +3796,9 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
version: None,
|
||||
};
|
||||
|
||||
project
|
||||
.update(cx, |p, cx| {
|
||||
p.update_diagnostics(LanguageServerId(0), message, &[], cx)
|
||||
lsp_store
|
||||
.update(cx, |lsp_store, cx| {
|
||||
lsp_store.update_diagnostics(LanguageServerId(0), message, &[], cx)
|
||||
})
|
||||
.unwrap();
|
||||
let buffer = buffer.update(cx, |buffer, _| buffer.snapshot());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue