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 Python docstring formatting in hover popovers (#59480)

Darshan Sithan91ff38aee2cd
diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs
index c915232ba5f..96aeae19933 100644
--- a/crates/editor/src/hover_popover.rs
+++ b/crates/editor/src/hover_popover.rs
@@ -739,6 +739,7 @@ pub fn hover_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
.mt(rems(1.))
.mb_0(),
table_columns_min_size: true,
+ soft_break_as_hard_break: true,
..Default::default()
}
}
@@ -1275,6 +1276,46 @@ mod tests {
cx.read(|cx: &App| -> u64 { EditorSettings::get_global(cx).hover_popover_delay.0 })
}
+ #[gpui::test]
+ fn test_hover_markdown_preserves_soft_breaks(cx: &mut gpui::TestAppContext) {
+ init_test(cx, |_| {});
+
+ let cx = cx.add_empty_window();
+ let text = concat!(
+ "class super(object)\n",
+ "| super(type) -> unbound super object\n",
+ "| super(type, obj) -> bound super object"
+ );
+ let markdown = cx.new(|cx| Markdown::new(text.into(), None, None, cx));
+ cx.run_until_parked();
+
+ let rendered = MarkdownElement::rendered_text(markdown, cx, hover_markdown_style);
+
+ // The two soft breaks must render as real newline characters rather
+ // than being collapsed into spaces.
+ assert_eq!(
+ rendered.matches('\n').count(),
+ 2,
+ "expected two hard line breaks, got {rendered:?}"
+ );
+ let lines: Vec<&str> = rendered.split('\n').collect();
+ assert_eq!(
+ lines,
+ [
+ "class super(object)",
+ "| super(type) -> unbound super object",
+ "| super(type, obj) -> bound super object",
+ ]
+ );
+ // The two spaces after each `|` continuation marker are preserved verbatim.
+ assert!(lines[1].starts_with("| super"));
+ assert!(lines[2].starts_with("| super"));
+ // No tabs are introduced anywhere in the rendered output.
+ assert!(!rendered.contains('\t'));
+ // And the full rendering matches the source exactly.
+ assert_eq!(rendered, text);
+ }
+
impl InfoPopover {
fn get_rendered_text(&self, cx: &gpui::App) -> String {
let mut rendered_text = String::new();