Show diagnostic source in inline diagnostic
This commit is contained in:
parent
f7de0ad8ae
commit
185c1650df
2 changed files with 16 additions and 5 deletions
|
@ -677,7 +677,7 @@ impl Item for ProjectDiagnosticsEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
|
fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
|
||||||
let (message, highlights) = highlight_diagnostic_message(&diagnostic.message);
|
let (message, highlights) = highlight_diagnostic_message(Vec::new(), &diagnostic.message);
|
||||||
Arc::new(move |cx| {
|
Arc::new(move |cx| {
|
||||||
let settings = cx.global::<Settings>();
|
let settings = cx.global::<Settings>();
|
||||||
let theme = &settings.theme.editor;
|
let theme = &settings.theme.editor;
|
||||||
|
|
|
@ -7509,8 +7509,16 @@ impl Deref for EditorStyle {
|
||||||
|
|
||||||
pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock {
|
pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> RenderBlock {
|
||||||
let mut highlighted_lines = Vec::new();
|
let mut highlighted_lines = Vec::new();
|
||||||
for line in diagnostic.message.lines() {
|
for (index, line) in diagnostic.message.lines().enumerate() {
|
||||||
highlighted_lines.push(highlight_diagnostic_message(line));
|
let line = match &diagnostic.source {
|
||||||
|
Some(source) if index == 0 => {
|
||||||
|
let source_highlight = Vec::from_iter(0..source.len());
|
||||||
|
highlight_diagnostic_message(source_highlight, &format!("{source}: {line}"))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => highlight_diagnostic_message(Vec::new(), line),
|
||||||
|
};
|
||||||
|
highlighted_lines.push(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arc::new(move |cx: &mut BlockContext| {
|
Arc::new(move |cx: &mut BlockContext| {
|
||||||
|
@ -7534,11 +7542,14 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_diagnostic_message(message: &str) -> (String, Vec<usize>) {
|
pub fn highlight_diagnostic_message(
|
||||||
|
inital_highlights: Vec<usize>,
|
||||||
|
message: &str,
|
||||||
|
) -> (String, Vec<usize>) {
|
||||||
let mut message_without_backticks = String::new();
|
let mut message_without_backticks = String::new();
|
||||||
let mut prev_offset = 0;
|
let mut prev_offset = 0;
|
||||||
let mut inside_block = false;
|
let mut inside_block = false;
|
||||||
let mut highlights = Vec::new();
|
let mut highlights = inital_highlights;
|
||||||
for (match_ix, (offset, _)) in message
|
for (match_ix, (offset, _)) in message
|
||||||
.match_indices('`')
|
.match_indices('`')
|
||||||
.chain([(message.len(), "")])
|
.chain([(message.len(), "")])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue