Dismiss active diagnostics on invalidation (#25646)
When migrating to gpui2,
588976d27a (diff-a3da3181e4ab4f73aa1697d7b6dc0caa0c17b2a187fb83b076dfc0234ec91f54R21)
removed the diagnostic style for "active but invalid" case: presumably,
it served as some sort of a cursor to show where to move on after the
diagnostics update, on the next `GoTo[Prev]Diagnostic` action call.
As this change went unchanged for some time, another approach is tested
now, to be more integrated with inline diagnostics: now, the active
state is cleared
Same as before this change, another `GoTo[Prev]Diagnostic` action call
will be needed to re-expand a new diagnostics, but this change makes
this expansion to happen after the cursor — before the change, Zed would
continue from the stale diagnostics.
Release Notes:
- Fixed active diagnostics becoming stale
This commit is contained in:
parent
d694458659
commit
d2b49de0e4
3 changed files with 116 additions and 15 deletions
|
@ -562,9 +562,7 @@ impl ProjectDiagnosticsEditor {
|
||||||
)),
|
)),
|
||||||
height: diagnostic.message.matches('\n').count() as u32 + 1,
|
height: diagnostic.message.matches('\n').count() as u32 + 1,
|
||||||
style: BlockStyle::Fixed,
|
style: BlockStyle::Fixed,
|
||||||
render: diagnostic_block_renderer(
|
render: diagnostic_block_renderer(diagnostic, None, true),
|
||||||
diagnostic, None, true, true,
|
|
||||||
),
|
|
||||||
priority: 0,
|
priority: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -994,7 +994,7 @@ struct RegisteredInlineCompletionProvider {
|
||||||
_subscription: Subscription,
|
_subscription: Subscription,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct ActiveDiagnosticGroup {
|
struct ActiveDiagnosticGroup {
|
||||||
primary_range: Range<Anchor>,
|
primary_range: Range<Anchor>,
|
||||||
primary_message: String,
|
primary_message: String,
|
||||||
|
@ -12539,16 +12539,20 @@ impl Editor {
|
||||||
|
|
||||||
if is_valid != active_diagnostics.is_valid {
|
if is_valid != active_diagnostics.is_valid {
|
||||||
active_diagnostics.is_valid = is_valid;
|
active_diagnostics.is_valid = is_valid;
|
||||||
let mut new_styles = HashMap::default();
|
if is_valid {
|
||||||
for (block_id, diagnostic) in &active_diagnostics.blocks {
|
let mut new_styles = HashMap::default();
|
||||||
new_styles.insert(
|
for (block_id, diagnostic) in &active_diagnostics.blocks {
|
||||||
*block_id,
|
new_styles.insert(
|
||||||
diagnostic_block_renderer(diagnostic.clone(), None, true, is_valid),
|
*block_id,
|
||||||
);
|
diagnostic_block_renderer(diagnostic.clone(), None, true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
self.display_map.update(cx, |display_map, _cx| {
|
||||||
|
display_map.replace_blocks(new_styles);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.dismiss_diagnostics(cx);
|
||||||
}
|
}
|
||||||
self.display_map.update(cx, |display_map, _cx| {
|
|
||||||
display_map.replace_blocks(new_styles)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12599,7 +12603,7 @@ impl Editor {
|
||||||
buffer.anchor_after(entry.range.start),
|
buffer.anchor_after(entry.range.start),
|
||||||
),
|
),
|
||||||
height: message_height,
|
height: message_height,
|
||||||
render: diagnostic_block_renderer(diagnostic, None, true, true),
|
render: diagnostic_block_renderer(diagnostic, None, true),
|
||||||
priority: 0,
|
priority: 0,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
@ -17795,7 +17799,6 @@ pub fn diagnostic_block_renderer(
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
max_message_rows: Option<u8>,
|
max_message_rows: Option<u8>,
|
||||||
allow_closing: bool,
|
allow_closing: bool,
|
||||||
_is_valid: bool,
|
|
||||||
) -> RenderBlock {
|
) -> RenderBlock {
|
||||||
let (text_without_backticks, code_ranges) =
|
let (text_without_backticks, code_ranges) =
|
||||||
highlight_diagnostic_message(&diagnostic, max_message_rows);
|
highlight_diagnostic_message(&diagnostic, max_message_rows);
|
||||||
|
|
|
@ -10970,6 +10970,106 @@ async fn cycle_through_same_place_diagnostics(
|
||||||
"});
|
"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn active_diagnostics_dismiss_after_invalidation(
|
||||||
|
executor: BackgroundExecutor,
|
||||||
|
cx: &mut TestAppContext,
|
||||||
|
) {
|
||||||
|
init_test(cx, |_| {});
|
||||||
|
|
||||||
|
let mut cx = EditorTestContext::new(cx).await;
|
||||||
|
let lsp_store =
|
||||||
|
cx.update_editor(|editor, _, cx| editor.project.as_ref().unwrap().read(cx).lsp_store());
|
||||||
|
|
||||||
|
cx.set_state(indoc! {"
|
||||||
|
ˇfn func(abc def: i32) -> u32 {
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
let message = "Something's wrong!";
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
lsp_store.update(cx, |lsp_store, cx| {
|
||||||
|
lsp_store
|
||||||
|
.update_diagnostics(
|
||||||
|
LanguageServerId(0),
|
||||||
|
lsp::PublishDiagnosticsParams {
|
||||||
|
uri: lsp::Url::from_file_path(path!("/root/file")).unwrap(),
|
||||||
|
version: None,
|
||||||
|
diagnostics: vec![lsp::Diagnostic {
|
||||||
|
range: lsp::Range::new(
|
||||||
|
lsp::Position::new(0, 11),
|
||||||
|
lsp::Position::new(0, 12),
|
||||||
|
),
|
||||||
|
severity: Some(lsp::DiagnosticSeverity::ERROR),
|
||||||
|
message: message.to_string(),
|
||||||
|
..Default::default()
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
&[],
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
executor.run_until_parked();
|
||||||
|
|
||||||
|
cx.update_editor(|editor, window, cx| {
|
||||||
|
editor.go_to_diagnostic(&GoToDiagnostic, window, cx);
|
||||||
|
assert_eq!(
|
||||||
|
editor
|
||||||
|
.active_diagnostics
|
||||||
|
.as_ref()
|
||||||
|
.map(|diagnostics_group| diagnostics_group.primary_message.as_str()),
|
||||||
|
Some(message),
|
||||||
|
"Should have a diagnostics group activated"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn func(abcˇ def: i32) -> u32 {
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
lsp_store.update(cx, |lsp_store, cx| {
|
||||||
|
lsp_store
|
||||||
|
.update_diagnostics(
|
||||||
|
LanguageServerId(0),
|
||||||
|
lsp::PublishDiagnosticsParams {
|
||||||
|
uri: lsp::Url::from_file_path(path!("/root/file")).unwrap(),
|
||||||
|
version: None,
|
||||||
|
diagnostics: Vec::new(),
|
||||||
|
},
|
||||||
|
&[],
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
executor.run_until_parked();
|
||||||
|
cx.update_editor(|editor, _, _| {
|
||||||
|
assert_eq!(
|
||||||
|
editor.active_diagnostics, None,
|
||||||
|
"After no diagnostics set to the editor, no diagnostics should be active"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn func(abcˇ def: i32) -> u32 {
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
|
||||||
|
cx.update_editor(|editor, window, cx| {
|
||||||
|
editor.go_to_diagnostic(&GoToDiagnostic, window, cx);
|
||||||
|
assert_eq!(
|
||||||
|
editor.active_diagnostics, None,
|
||||||
|
"Should be no diagnostics to go to and activate"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
cx.assert_editor_state(indoc! {"
|
||||||
|
fn func(abcˇ def: i32) -> u32 {
|
||||||
|
}
|
||||||
|
"});
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_diagnostics_with_links(cx: &mut TestAppContext) {
|
async fn test_diagnostics_with_links(cx: &mut TestAppContext) {
|
||||||
init_test(cx, |_| {});
|
init_test(cx, |_| {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue