Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

editor: Fix missing IME composition underline in single-line editors (#65610)

Sha1rholderfaf96952a23d
diff --git a/crates/editor/src/diagnostics.rs b/crates/editor/src/diagnostics.rs
index 34f42c68f60..315ca8ede64 100644
--- a/crates/editor/src/diagnostics.rs
+++ b/crates/editor/src/diagnostics.rs
@@ -276,6 +276,7 @@ impl Editor {
pub fn disable_diagnostics(&mut self, cx: &mut Context<Self>) {
self.diagnostics_enabled = false;
+ self.set_max_diagnostics_severity(DiagnosticSeverity::Off, cx);
self.dismiss_diagnostics(cx);
self.inline_diagnostics_update = Task::ready(());
self.inline_diagnostics.clear();
@@ -304,7 +305,11 @@ impl Editor {
}
pub fn set_max_diagnostics_severity(&mut self, severity: DiagnosticSeverity, cx: &mut App) {
- self.diagnostics_max_severity = severity;
+ self.diagnostics_max_severity = if self.diagnostics_enabled() {
+ severity
+ } else {
+ DiagnosticSeverity::Off
+ };
self.display_map.update(cx, |display_map, _| {
display_map.diagnostics_max_severity = self.diagnostics_max_severity;
});
@@ -619,6 +624,7 @@ mod tests {
use indoc::indoc;
use language::DiagnosticSourceKind;
use lsp::LanguageServerId;
+ use project::project_settings::DiagnosticSeverity;
use settings::{DelayMs, SettingsStore};
use std::sync::{
Arc,
@@ -685,6 +691,22 @@ mod tests {
});
}
+ #[gpui::test]
+ async fn test_disabled_diagnostics_ignore_severity_changes(cx: &mut TestAppContext) {
+ init_test(cx, |_| {});
+ let mut cx = EditorTestContext::new(cx).await;
+
+ cx.update_editor(|editor, _, cx| {
+ assert!(editor.display_snapshot(cx).diagnostics_visible());
+
+ editor.disable_diagnostics(cx);
+ assert!(!editor.display_snapshot(cx).diagnostics_visible());
+
+ editor.set_max_diagnostics_severity(DiagnosticSeverity::Hint, cx);
+ assert!(!editor.display_snapshot(cx).diagnostics_visible());
+ });
+ }
+
#[gpui::test]
async fn test_toggle_diagnostics_refreshes_inline_diagnostics(cx: &mut TestAppContext) {
init_test(cx, |_| {});
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs
index b8c77c4af3e..7a8a9e2ddc0 100644
--- a/crates/editor/src/display_map.rs
+++ b/crates/editor/src/display_map.rs
@@ -1585,6 +1585,10 @@ impl DisplaySnapshot {
})
}
+ pub(crate) fn diagnostics_visible(&self) -> bool {
+ self.diagnostics_max_severity.into_lsp().is_some()
+ }
+
fn diagnostic_severity_is_visible(&self, severity: lsp::DiagnosticSeverity) -> bool {
self.diagnostics_max_severity
.into_lsp()
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs
index cb8f7e13f11..d290118fc97 100644
--- a/crates/editor/src/editor.rs
+++ b/crates/editor/src/editor.rs
@@ -11555,7 +11555,7 @@ impl Editor {
inlay_hints_style: make_inlay_hints_style(cx),
edit_prediction_styles: make_suggestion_styles(cx),
unnecessary_code_fade: settings.unnecessary_code_fade,
- show_underlines: self.diagnostics_enabled(),
+ show_underlines: !self.mode.is_minimap(),
}
}
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index be3f7cb64f0..262ec456373 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -3239,7 +3239,7 @@ impl EditorElement {
|| snapshot.use_tree_sitter_for_syntax(rows.start, cx);
let language_aware = LanguageAwareStyling {
tree_sitter: use_tree_sitter,
- diagnostics: true,
+ diagnostics: snapshot.display_snapshot.diagnostics_visible(),
};
let chunks = snapshot.highlighted_chunks(rows.clone(), language_aware, style);
LineWithInvisibles::from_chunks(
@@ -5742,7 +5742,7 @@ impl EditorElement {
visible_rows: Range<DisplayRow>,
line_layouts: &mut [LineWithInvisibles],
) {
- if visible_rows.is_empty() {
+ if !snapshot.display_snapshot.diagnostics_visible() || visible_rows.is_empty() {
return;
}
@@ -10974,7 +10974,7 @@ pub fn layout_line(
!snapshot.semantic_tokens_enabled || snapshot.use_tree_sitter_for_syntax(row, cx);
let language_aware = LanguageAwareStyling {
tree_sitter: use_tree_sitter,
- diagnostics: true,
+ diagnostics: snapshot.display_snapshot.diagnostics_visible(),
};
let chunks = snapshot.highlighted_chunks(row..row + DisplayRow(1), language_aware, style);
LineWithInvisibles::from_chunks(
@@ -11453,7 +11453,8 @@ mod tests {
};
use buffer_diff::BufferDiff;
use gpui::{
- Render, TestAppContext, Underline, UpdateGlobal, VisualTestContext, WindowHandle, font,
+ EntityInputHandler, Render, TestAppContext, Underline, UpdateGlobal, VisualTestContext,
+ WindowHandle, font,
};
use language::{
Buffer, Capability, Diagnostic, DiagnosticEntry, DiagnosticSet, SelectionGoal,
@@ -11467,6 +11468,53 @@ mod tests {
use text::PointUtf16;
use util::test::sample_text;
+ // Regression test for https://github.com/zed-industries/zed/issues/65453.
+ #[gpui::test]
+ fn test_highlight_underlines_are_only_hidden_in_minimap(cx: &mut TestAppContext) {
+ init_test(cx, |_| {});
+
+ fn has_highlight_underline(editor: &Editor, style: &EditorStyle, cx: &mut App) -> bool {
+ editor
+ .display_snapshot(cx)
+ .highlighted_chunks(
+ DisplayRow(0)..DisplayRow(1),
+ LanguageAwareStyling {
+ tree_sitter: false,
+ diagnostics: false,
+ },
+ style,
+ )
+ .any(|chunk| chunk.style.is_some_and(|style| style.underline.is_some()))
+ }
+
+ let single_line = cx.add_window(|window, cx| Editor::single_line(window, cx));
+ single_line
+ .update(cx, |editor, window, cx| {
+ editor.replace_and_mark_text_in_range(None, "ni", None, window, cx);
+ let style = editor.create_style(cx);
+ assert!(has_highlight_underline(editor, &style, cx));
+ })
+ .expect("checked single line editor");
+
+ let full = cx.add_window(|window, cx| {
+ let buffer = MultiBuffer::build_simple("", cx);
+ let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
+ editor.disable_diagnostics(cx);
+ editor
+ });
+ full.update(cx, |editor, window, cx| {
+ editor.replace_and_mark_text_in_range(None, "ni", None, window, cx);
+ let style = editor.create_style(cx);
+ assert!(has_highlight_underline(editor, &style, cx));
+
+ let minimap =
+ editor.initialize_new_minimap(EditorSettings::get_global(cx).minimap, window, cx);
+ let minimap_style = minimap.read(cx).create_style(cx);
+ assert!(!has_highlight_underline(editor, &minimap_style, cx));
+ })
+ .expect("checked full editor and minimap");
+ }
+
struct MinimapGeometry {
document_lines: f64,
visible_editor_lines: f64,