popover.rs

 1use crate::{Editor, EditorStyle};
 2use gpui::{
 3    div, AnyElement, InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels, Size,
 4    StatefulInteractiveElement, Styled, ViewContext, WeakView,
 5};
 6use language::ParsedMarkdown;
 7use ui::StyledExt;
 8use workspace::Workspace;
 9
10#[derive(Clone, Debug)]
11pub struct SignatureHelpPopover {
12    pub parsed_content: ParsedMarkdown,
13}
14
15impl PartialEq for SignatureHelpPopover {
16    fn eq(&self, other: &Self) -> bool {
17        let str_equality = self.parsed_content.text.as_str() == other.parsed_content.text.as_str();
18        let highlight_equality = self.parsed_content.highlights == other.parsed_content.highlights;
19        str_equality && highlight_equality
20    }
21}
22
23impl SignatureHelpPopover {
24    pub fn render(
25        &mut self,
26        style: &EditorStyle,
27        max_size: Size<Pixels>,
28        workspace: Option<WeakView<Workspace>>,
29        cx: &mut ViewContext<Editor>,
30    ) -> AnyElement {
31        div()
32            .id("signature_help_popover")
33            .elevation_2(cx)
34            .overflow_y_scroll()
35            .max_w(max_size.width)
36            .max_h(max_size.height)
37            .on_mouse_move(|_, cx| cx.stop_propagation())
38            .on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
39            .child(div().p_2().child(crate::render_parsed_markdown(
40                "signature_help_popover_content",
41                &self.parsed_content,
42                style,
43                workspace,
44                cx,
45            )))
46            .into_any_element()
47    }
48}