Show diagnostic hover popover

This commit is contained in:
Antonio Scandurra 2023-11-27 19:07:55 +01:00
parent a5951df21f
commit 1e6214440d

View file

@ -6,13 +6,16 @@ use crate::{
}; };
use futures::FutureExt; use futures::FutureExt;
use gpui::{ use gpui::{
actions, div, px, AnyElement, AppContext, InteractiveElement, IntoElement, Model, MouseButton, actions, div, px, AnyElement, AppContext, CursorStyle, InteractiveElement, IntoElement, Model,
ParentElement, Pixels, Size, StatefulInteractiveElement, Styled, Task, ViewContext, WeakView, MouseButton, ParentElement, Pixels, SharedString, Size, StatefulInteractiveElement, Styled,
Task, ViewContext, WeakView,
}; };
use language::{markdown, Bias, DiagnosticEntry, Language, LanguageRegistry, ParsedMarkdown}; use language::{markdown, Bias, DiagnosticEntry, Language, LanguageRegistry, ParsedMarkdown};
use lsp::DiagnosticSeverity;
use project::{HoverBlock, HoverBlockKind, InlayHintLabelPart, Project}; use project::{HoverBlock, HoverBlockKind, InlayHintLabelPart, Project};
use settings::Settings; use settings::Settings;
use std::{ops::Range, sync::Arc, time::Duration}; use std::{ops::Range, sync::Arc, time::Duration};
use ui::Tooltip;
use util::TryFutureExt; use util::TryFutureExt;
use workspace::Workspace; use workspace::Workspace;
@ -507,56 +510,34 @@ impl DiagnosticPopover {
max_size: Size<Pixels>, max_size: Size<Pixels>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> AnyElement { ) -> AnyElement {
todo!() let text = match &self.local_diagnostic.diagnostic.source {
// enum PrimaryDiagnostic {} Some(source) => format!("{source}: {}", self.local_diagnostic.diagnostic.message),
None => self.local_diagnostic.diagnostic.message.clone(),
};
// let mut text_style = style.hover_popover.prose.clone(); let container_bg = crate::diagnostic_style(
// text_style.font_size = style.text.font_size; self.local_diagnostic.diagnostic.severity,
// let diagnostic_source_style = style.hover_popover.diagnostic_source_highlight.clone(); true,
&style.diagnostic_style,
);
// let text = match &self.local_diagnostic.diagnostic.source { div()
// Some(source) => Text::new( .id("diagnostic")
// format!("{source}: {}", self.local_diagnostic.diagnostic.message), .overflow_y_scroll()
// text_style, .bg(container_bg)
// ) .max_w(max_size.width)
// .with_highlights(vec![(0..source.len(), diagnostic_source_style)]), .max_h(max_size.height)
.cursor(CursorStyle::PointingHand)
// None => Text::new(self.local_diagnostic.diagnostic.message.clone(), text_style), .tooltip(move |cx| Tooltip::for_action("Go To Diagnostic", &crate::GoToDiagnostic, cx))
// }; // Prevent a mouse move on the popover from being propagated to the editor,
// because that would dismiss the popover.
// let container_style = match self.local_diagnostic.diagnostic.severity { .on_mouse_move(|_, cx| cx.stop_propagation())
// DiagnosticSeverity::HINT => style.hover_popover.info_container, // Prevent a mouse down on the popover from being propagated to the editor,
// DiagnosticSeverity::INFORMATION => style.hover_popover.info_container, // because that would move the cursor.
// DiagnosticSeverity::WARNING => style.hover_popover.warning_container, .on_mouse_down(MouseButton::Left, |_, cx| cx.stop_propagation())
// DiagnosticSeverity::ERROR => style.hover_popover.error_container, .on_click(cx.listener(|editor, _, cx| editor.go_to_diagnostic(&Default::default(), cx)))
// _ => style.hover_popover.container, .child(SharedString::from(text))
// }; .into_any_element()
// let tooltip_style = theme::current(cx).tooltip.clone();
// MouseEventHandler::new::<DiagnosticPopover, _>(0, cx, |_, _| {
// text.with_soft_wrap(true)
// .contained()
// .with_style(container_style)
// })
// .with_padding(Padding {
// top: HOVER_POPOVER_GAP,
// bottom: HOVER_POPOVER_GAP,
// ..Default::default()
// })
// .on_move(|_, _, _| {}) // Consume move events so they don't reach regions underneath.
// .on_click(MouseButton::Left, |_, this, cx| {
// this.go_to_diagnostic(&Default::default(), cx)
// })
// .with_cursor_style(CursorStyle::PointingHand)
// .with_tooltip::<PrimaryDiagnostic>(
// 0,
// "Go To Diagnostic".to_string(),
// Some(Box::new(crate::GoToDiagnostic)),
// tooltip_style,
// cx,
// )
// .into_any()
} }
pub fn activation_info(&self) -> (usize, Anchor) { pub fn activation_info(&self) -> (usize, Anchor) {