From 4084ba36f9f7b7aefddb1935a163372de1419b99 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 1 Nov 2024 13:28:34 -0600 Subject: [PATCH] Fix clang popovers (#20090) Closes #15498 Release Notes: - Fixed info popups from clangd missing information --- crates/editor/src/hover_popover.rs | 55 ++++++++++++++++++++++++++++++ crates/markdown/src/parser.rs | 1 + 2 files changed, 56 insertions(+) diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rs index fb198c837c3fa5dc7ca9e6eb9cb10c166c7f4cfa..f079939787d0fb303785754a2cf45f4970cb15a9 100644 --- a/crates/editor/src/hover_popover.rs +++ b/crates/editor/src/hover_popover.rs @@ -1351,6 +1351,61 @@ mod tests { }); } + #[gpui::test] + // https://github.com/zed-industries/zed/issues/15498 + async fn test_info_hover_with_hrs(cx: &mut gpui::TestAppContext) { + init_test(cx, |_| {}); + + let mut cx = EditorLspTestContext::new_rust( + lsp::ServerCapabilities { + hover_provider: Some(lsp::HoverProviderCapability::Simple(true)), + ..Default::default() + }, + cx, + ) + .await; + + cx.set_state(indoc! {" + fn fuˇnc(abc def: i32) -> u32 { + } + "}); + + cx.lsp.handle_request::({ + |_, _| async move { + Ok(Some(lsp::Hover { + contents: lsp::HoverContents::Markup(lsp::MarkupContent { + kind: lsp::MarkupKind::Markdown, + value: indoc!( + r#" + ### function `errands_data_read` + + --- + → `char *` + Function to read a file into a string + + --- + ```cpp + static char *errands_data_read() + ``` + "# + ) + .to_string(), + }), + range: None, + })) + } + }); + cx.update_editor(|editor, cx| hover(editor, &Default::default(), cx)); + cx.run_until_parked(); + + cx.update_editor(|editor, cx| { + let popover = editor.hover_state.info_popovers.first().unwrap(); + let content = popover.get_rendered_text(cx); + + assert!(content.contains("Function to read a file")); + }); + } + #[gpui::test] async fn test_hover_inlay_label_parts(cx: &mut gpui::TestAppContext) { init_test(cx, |settings| { diff --git a/crates/markdown/src/parser.rs b/crates/markdown/src/parser.rs index 7d349e29efce929ec062f45da317cd48c5ff579d..d21892b7ded83a956484e6ed169cc0e3bc7f330c 100644 --- a/crates/markdown/src/parser.rs +++ b/crates/markdown/src/parser.rs @@ -7,6 +7,7 @@ use std::ops::Range; pub fn parse_markdown(text: &str) -> Vec<(Range, MarkdownEvent)> { let mut options = Options::all(); options.remove(pulldown_cmark::Options::ENABLE_DEFINITION_LIST); + options.remove(pulldown_cmark::Options::ENABLE_YAML_STYLE_METADATA_BLOCKS); let mut events = Vec::new(); let mut within_link = false;