Exclude gitignored files' diagnostics from project panel and its indicator.
The diagnostics are collected and available still, since that might become a settings/UI toggle later. Also, buffer diagnostics are still updated for gitignored files.
This commit is contained in:
parent
7b76db4b50
commit
69bfd47cf9
5 changed files with 118 additions and 29 deletions
|
@ -6533,9 +6533,15 @@ impl Project {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn diagnostic_summary(&self, cx: &AppContext) -> DiagnosticSummary {
|
||||
pub fn diagnostic_summary(&self, include_ignored: bool, cx: &AppContext) -> DiagnosticSummary {
|
||||
let mut summary = DiagnosticSummary::default();
|
||||
for (_, _, path_summary) in self.diagnostic_summaries(cx) {
|
||||
for (_, _, path_summary) in
|
||||
self.diagnostic_summaries(include_ignored, cx)
|
||||
.filter(|(path, _, _)| {
|
||||
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
|
||||
include_ignored || worktree == Some(false)
|
||||
})
|
||||
{
|
||||
summary.error_count += path_summary.error_count;
|
||||
summary.warning_count += path_summary.warning_count;
|
||||
}
|
||||
|
@ -6544,6 +6550,7 @@ impl Project {
|
|||
|
||||
pub fn diagnostic_summaries<'a>(
|
||||
&'a self,
|
||||
include_ignored: bool,
|
||||
cx: &'a AppContext,
|
||||
) -> impl Iterator<Item = (ProjectPath, LanguageServerId, DiagnosticSummary)> + 'a {
|
||||
self.visible_worktrees(cx).flat_map(move |worktree| {
|
||||
|
@ -6554,6 +6561,10 @@ impl Project {
|
|||
.map(move |(path, server_id, summary)| {
|
||||
(ProjectPath { worktree_id, path }, server_id, summary)
|
||||
})
|
||||
.filter(move |(path, _, _)| {
|
||||
let worktree = self.entry_for_path(&path, cx).map(|entry| entry.is_ignored);
|
||||
include_ignored || worktree == Some(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -806,7 +806,7 @@ async fn test_single_file_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
||||
async fn test_omitted_diagnostics(cx: &mut gpui::TestAppContext) {
|
||||
init_test(cx);
|
||||
|
||||
let fs = FakeFs::new(cx.background());
|
||||
|
@ -814,7 +814,12 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
"/root",
|
||||
json!({
|
||||
"dir": {
|
||||
".git": {
|
||||
"HEAD": "ref: refs/heads/main",
|
||||
},
|
||||
".gitignore": "b.rs",
|
||||
"a.rs": "let a = 1;",
|
||||
"b.rs": "let b = 2;",
|
||||
},
|
||||
"other.rs": "let b = c;"
|
||||
}),
|
||||
|
@ -822,6 +827,13 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.await;
|
||||
|
||||
let project = Project::test(fs, ["/root/dir".as_ref()], cx).await;
|
||||
let (worktree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
project.find_or_create_local_worktree("/root/dir", true, cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let main_worktree_id = worktree.read_with(cx, |tree, _| tree.id());
|
||||
|
||||
let (worktree, _) = project
|
||||
.update(cx, |project, cx| {
|
||||
|
@ -829,12 +841,30 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let worktree_id = worktree.read_with(cx, |tree, _| tree.id());
|
||||
let other_worktree_id = worktree.read_with(cx, |tree, _| tree.id());
|
||||
|
||||
let server_id = LanguageServerId(0);
|
||||
project.update(cx, |project, cx| {
|
||||
project
|
||||
.update_diagnostics(
|
||||
LanguageServerId(0),
|
||||
server_id,
|
||||
lsp::PublishDiagnosticsParams {
|
||||
uri: Url::from_file_path("/root/dir/b.rs").unwrap(),
|
||||
version: None,
|
||||
diagnostics: vec![lsp::Diagnostic {
|
||||
range: lsp::Range::new(lsp::Position::new(0, 4), lsp::Position::new(0, 5)),
|
||||
severity: Some(lsp::DiagnosticSeverity::ERROR),
|
||||
message: "unused variable 'b'".to_string(),
|
||||
..Default::default()
|
||||
}],
|
||||
},
|
||||
&[],
|
||||
cx,
|
||||
)
|
||||
.unwrap();
|
||||
project
|
||||
.update_diagnostics(
|
||||
server_id,
|
||||
lsp::PublishDiagnosticsParams {
|
||||
uri: Url::from_file_path("/root/other.rs").unwrap(),
|
||||
version: None,
|
||||
|
@ -851,11 +881,34 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
.unwrap();
|
||||
});
|
||||
|
||||
let buffer = project
|
||||
.update(cx, |project, cx| project.open_buffer((worktree_id, ""), cx))
|
||||
let main_ignored_buffer = project
|
||||
.update(cx, |project, cx| {
|
||||
project.open_buffer((main_worktree_id, "b.rs"), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
buffer.read_with(cx, |buffer, _| {
|
||||
main_ignored_buffer.read_with(cx, |buffer, _| {
|
||||
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
|
||||
assert_eq!(
|
||||
chunks
|
||||
.iter()
|
||||
.map(|(s, d)| (s.as_str(), *d))
|
||||
.collect::<Vec<_>>(),
|
||||
&[
|
||||
("let ", None),
|
||||
("b", Some(DiagnosticSeverity::ERROR)),
|
||||
(" = 2;", None),
|
||||
],
|
||||
"Gigitnored buffers should still get in-buffer diagnostics",
|
||||
);
|
||||
});
|
||||
let other_buffer = project
|
||||
.update(cx, |project, cx| {
|
||||
project.open_buffer((other_worktree_id, ""), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
other_buffer.read_with(cx, |buffer, _| {
|
||||
let chunks = chunks_with_diagnostics(buffer, 0..buffer.len());
|
||||
assert_eq!(
|
||||
chunks
|
||||
|
@ -866,13 +919,29 @@ async fn test_hidden_worktrees_diagnostics(cx: &mut gpui::TestAppContext) {
|
|||
("let b = ", None),
|
||||
("c", Some(DiagnosticSeverity::ERROR)),
|
||||
(";", None),
|
||||
]
|
||||
],
|
||||
"Buffers from hidden projects should still get in-buffer diagnostics"
|
||||
);
|
||||
});
|
||||
|
||||
project.read_with(cx, |project, cx| {
|
||||
assert_eq!(project.diagnostic_summaries(cx).next(), None);
|
||||
assert_eq!(project.diagnostic_summary(cx).error_count, 0);
|
||||
assert_eq!(project.diagnostic_summaries(false, cx).next(), None);
|
||||
assert_eq!(
|
||||
project.diagnostic_summaries(true, cx).collect::<Vec<_>>(),
|
||||
vec![(
|
||||
ProjectPath {
|
||||
worktree_id: main_worktree_id,
|
||||
path: Arc::from(Path::new("b.rs")),
|
||||
},
|
||||
server_id,
|
||||
DiagnosticSummary {
|
||||
error_count: 1,
|
||||
warning_count: 0,
|
||||
}
|
||||
)]
|
||||
);
|
||||
assert_eq!(project.diagnostic_summary(false, cx).error_count, 0);
|
||||
assert_eq!(project.diagnostic_summary(true, cx).error_count, 1);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1145,7 +1214,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
|
|||
});
|
||||
project.read_with(cx, |project, cx| {
|
||||
assert_eq!(
|
||||
project.diagnostic_summary(cx),
|
||||
project.diagnostic_summary(false, cx),
|
||||
DiagnosticSummary {
|
||||
error_count: 1,
|
||||
warning_count: 0,
|
||||
|
@ -1171,7 +1240,7 @@ async fn test_restarting_server_with_diagnostics_published(cx: &mut gpui::TestAp
|
|||
});
|
||||
project.read_with(cx, |project, cx| {
|
||||
assert_eq!(
|
||||
project.diagnostic_summary(cx),
|
||||
project.diagnostic_summary(false, cx),
|
||||
DiagnosticSummary {
|
||||
error_count: 0,
|
||||
warning_count: 0,
|
||||
|
@ -1763,7 +1832,7 @@ async fn test_diagnostics_from_multiple_language_servers(cx: &mut gpui::TestAppC
|
|||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
project.diagnostic_summary(cx),
|
||||
project.diagnostic_summary(false, cx),
|
||||
DiagnosticSummary {
|
||||
error_count: 2,
|
||||
warning_count: 0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue