mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 19:10:24 +00:00
Show source of diagnostic hovers
This commit is contained in:
parent
45c7073934
commit
3f7533a0b4
9 changed files with 48 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions,
|
||||||
elements::{Flex, MouseEventHandler, Padding, Text},
|
elements::{Flex, MouseEventHandler, Padding, ParentElement, Text},
|
||||||
impl_internal_actions,
|
impl_internal_actions,
|
||||||
platform::{CursorStyle, MouseButton},
|
platform::{CursorStyle, MouseButton},
|
||||||
AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
|
AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
|
||||||
|
@ -378,6 +378,8 @@ impl DiagnosticPopover {
|
||||||
|
|
||||||
let mut text_style = style.hover_popover.prose.clone();
|
let mut text_style = style.hover_popover.prose.clone();
|
||||||
text_style.font_size = style.text.font_size;
|
text_style.font_size = style.text.font_size;
|
||||||
|
let mut diagnostic_source_style = style.hover_popover.diagnostic_source.clone();
|
||||||
|
diagnostic_source_style.font_size = style.text.font_size;
|
||||||
|
|
||||||
let container_style = match self.local_diagnostic.diagnostic.severity {
|
let container_style = match self.local_diagnostic.diagnostic.severity {
|
||||||
DiagnosticSeverity::HINT => style.hover_popover.info_container,
|
DiagnosticSeverity::HINT => style.hover_popover.info_container,
|
||||||
|
@ -390,8 +392,18 @@ impl DiagnosticPopover {
|
||||||
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
|
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
|
||||||
|
|
||||||
MouseEventHandler::<DiagnosticPopover, _>::new(0, cx, |_, _| {
|
MouseEventHandler::<DiagnosticPopover, _>::new(0, cx, |_, _| {
|
||||||
Text::new(self.local_diagnostic.diagnostic.message.clone(), text_style)
|
Flex::row()
|
||||||
.with_soft_wrap(true)
|
.with_children(
|
||||||
|
self.local_diagnostic
|
||||||
|
.diagnostic
|
||||||
|
.source
|
||||||
|
.as_ref()
|
||||||
|
.map(|source| Text::new(format!("{source}: "), diagnostic_source_style)),
|
||||||
|
)
|
||||||
|
.with_child(
|
||||||
|
Text::new(self.local_diagnostic.diagnostic.message.clone(), text_style)
|
||||||
|
.with_soft_wrap(true),
|
||||||
|
)
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(container_style)
|
.with_style(container_style)
|
||||||
})
|
})
|
||||||
|
|
|
@ -138,6 +138,7 @@ pub struct GroupId {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
|
pub source: Option<String>,
|
||||||
pub code: Option<String>,
|
pub code: Option<String>,
|
||||||
pub severity: DiagnosticSeverity,
|
pub severity: DiagnosticSeverity,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
@ -2881,6 +2882,7 @@ impl operation_queue::Operation for Operation {
|
||||||
impl Default for Diagnostic {
|
impl Default for Diagnostic {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
source: Default::default(),
|
||||||
code: None,
|
code: None,
|
||||||
severity: DiagnosticSeverity::ERROR,
|
severity: DiagnosticSeverity::ERROR,
|
||||||
message: Default::default(),
|
message: Default::default(),
|
||||||
|
|
|
@ -173,6 +173,7 @@ pub fn serialize_diagnostics<'a>(
|
||||||
diagnostics
|
diagnostics
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|entry| proto::Diagnostic {
|
.map(|entry| proto::Diagnostic {
|
||||||
|
source: entry.diagnostic.source.clone(),
|
||||||
start: Some(serialize_anchor(&entry.range.start)),
|
start: Some(serialize_anchor(&entry.range.start)),
|
||||||
end: Some(serialize_anchor(&entry.range.end)),
|
end: Some(serialize_anchor(&entry.range.end)),
|
||||||
message: entry.diagnostic.message.clone(),
|
message: entry.diagnostic.message.clone(),
|
||||||
|
@ -359,6 +360,7 @@ pub fn deserialize_diagnostics(
|
||||||
Some(DiagnosticEntry {
|
Some(DiagnosticEntry {
|
||||||
range: deserialize_anchor(diagnostic.start?)?..deserialize_anchor(diagnostic.end?)?,
|
range: deserialize_anchor(diagnostic.start?)?..deserialize_anchor(diagnostic.end?)?,
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
|
source: diagnostic.source,
|
||||||
severity: match proto::diagnostic::Severity::from_i32(diagnostic.severity)? {
|
severity: match proto::diagnostic::Severity::from_i32(diagnostic.severity)? {
|
||||||
proto::diagnostic::Severity::Error => DiagnosticSeverity::ERROR,
|
proto::diagnostic::Severity::Error => DiagnosticSeverity::ERROR,
|
||||||
proto::diagnostic::Severity::Warning => DiagnosticSeverity::WARNING,
|
proto::diagnostic::Severity::Warning => DiagnosticSeverity::WARNING,
|
||||||
|
|
|
@ -2954,6 +2954,7 @@ impl Project {
|
||||||
diagnostics.push(DiagnosticEntry {
|
diagnostics.push(DiagnosticEntry {
|
||||||
range,
|
range,
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
|
source: diagnostic.source.clone(),
|
||||||
code: code.clone(),
|
code: code.clone(),
|
||||||
severity: diagnostic.severity.unwrap_or(DiagnosticSeverity::ERROR),
|
severity: diagnostic.severity.unwrap_or(DiagnosticSeverity::ERROR),
|
||||||
message: diagnostic.message.clone(),
|
message: diagnostic.message.clone(),
|
||||||
|
@ -2971,6 +2972,7 @@ impl Project {
|
||||||
diagnostics.push(DiagnosticEntry {
|
diagnostics.push(DiagnosticEntry {
|
||||||
range,
|
range,
|
||||||
diagnostic: Diagnostic {
|
diagnostic: Diagnostic {
|
||||||
|
source: diagnostic.source.clone(),
|
||||||
code: code.clone(),
|
code: code.clone(),
|
||||||
severity: DiagnosticSeverity::INFORMATION,
|
severity: DiagnosticSeverity::INFORMATION,
|
||||||
message: info.message.clone(),
|
message: info.message.clone(),
|
||||||
|
|
|
@ -1049,14 +1049,15 @@ enum Bias {
|
||||||
message Diagnostic {
|
message Diagnostic {
|
||||||
Anchor start = 1;
|
Anchor start = 1;
|
||||||
Anchor end = 2;
|
Anchor end = 2;
|
||||||
Severity severity = 3;
|
optional string source = 3;
|
||||||
string message = 4;
|
Severity severity = 4;
|
||||||
optional string code = 5;
|
string message = 5;
|
||||||
uint64 group_id = 6;
|
optional string code = 6;
|
||||||
bool is_primary = 7;
|
uint64 group_id = 7;
|
||||||
bool is_valid = 8;
|
bool is_primary = 8;
|
||||||
bool is_disk_based = 9;
|
bool is_valid = 9;
|
||||||
bool is_unnecessary = 10;
|
bool is_disk_based = 10;
|
||||||
|
bool is_unnecessary = 11;
|
||||||
|
|
||||||
enum Severity {
|
enum Severity {
|
||||||
None = 0;
|
None = 0;
|
||||||
|
|
|
@ -6,4 +6,4 @@ pub use conn::Connection;
|
||||||
pub use peer::*;
|
pub use peer::*;
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
pub const PROTOCOL_VERSION: u32 = 52;
|
pub const PROTOCOL_VERSION: u32 = 53;
|
||||||
|
|
|
@ -887,6 +887,7 @@ pub struct HoverPopover {
|
||||||
pub error_container: ContainerStyle,
|
pub error_container: ContainerStyle,
|
||||||
pub block_style: ContainerStyle,
|
pub block_style: ContainerStyle,
|
||||||
pub prose: TextStyle,
|
pub prose: TextStyle,
|
||||||
|
pub diagnostic_source: TextStyle,
|
||||||
pub highlight: Color,
|
pub highlight: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,23 +89,26 @@ pub fn init(
|
||||||
(
|
(
|
||||||
"tsx",
|
"tsx",
|
||||||
tree_sitter_typescript::language_tsx(),
|
tree_sitter_typescript::language_tsx(),
|
||||||
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
|
vec![
|
||||||
node_runtime.clone(),
|
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
|
||||||
))],
|
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"typescript",
|
"typescript",
|
||||||
tree_sitter_typescript::language_typescript(),
|
tree_sitter_typescript::language_typescript(),
|
||||||
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
|
vec![
|
||||||
node_runtime.clone(),
|
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
|
||||||
))],
|
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"javascript",
|
"javascript",
|
||||||
tree_sitter_typescript::language_tsx(),
|
tree_sitter_typescript::language_tsx(),
|
||||||
vec![adapter_arc(typescript::TypeScriptLspAdapter::new(
|
vec![
|
||||||
node_runtime.clone(),
|
adapter_arc(typescript::TypeScriptLspAdapter::new(node_runtime.clone())),
|
||||||
))],
|
adapter_arc(typescript::EsLintLspAdapter::new(node_runtime.clone())),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"html",
|
"html",
|
||||||
|
@ -132,7 +135,7 @@ pub fn init(
|
||||||
(
|
(
|
||||||
"yaml",
|
"yaml",
|
||||||
tree_sitter_yaml::language(),
|
tree_sitter_yaml::language(),
|
||||||
vec![adapter_arc(yaml::YamlLspAdapter::new(node_runtime.clone()))],
|
vec![adapter_arc(yaml::YamlLspAdapter::new(node_runtime))],
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ColorScheme } from "../themes/common/colorScheme"
|
import { ColorScheme } from "../themes/common/colorScheme"
|
||||||
import { background, border, text } from "./components"
|
import { background, border, foreground, text } from "./components"
|
||||||
|
|
||||||
export default function HoverPopover(colorScheme: ColorScheme) {
|
export default function HoverPopover(colorScheme: ColorScheme) {
|
||||||
let layer = colorScheme.middle
|
let layer = colorScheme.middle
|
||||||
|
@ -36,10 +36,11 @@ export default function HoverPopover(colorScheme: ColorScheme) {
|
||||||
background: background(layer, "negative"),
|
background: background(layer, "negative"),
|
||||||
border: border(layer, "negative"),
|
border: border(layer, "negative"),
|
||||||
},
|
},
|
||||||
block_style: {
|
blockStyle: {
|
||||||
padding: { top: 4 },
|
padding: { top: 4 },
|
||||||
},
|
},
|
||||||
prose: text(layer, "sans", { size: "sm" }),
|
prose: text(layer, "sans", { size: "sm" }),
|
||||||
|
diagnosticSource: text(layer, "sans", { size: "sm", underline: true, color: foreground(layer, "accent") }),
|
||||||
highlight: colorScheme.ramps.neutral(0.5).alpha(0.2).hex(), // TODO: blend was used here. Replace with something better
|
highlight: colorScheme.ramps.neutral(0.5).alpha(0.2).hex(), // TODO: blend was used here. Replace with something better
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue