mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
Merge pull request #2579 from rtfeldman/underline_error
Editor: Underline Error
This commit is contained in:
commit
1e20ff1a9a
6 changed files with 86 additions and 11 deletions
10
cli_utils/Cargo.lock
generated
10
cli_utils/Cargo.lock
generated
|
@ -897,6 +897,12 @@ version = "0.4.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||
|
||||
[[package]]
|
||||
name = "dunce"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
|
@ -2504,6 +2510,7 @@ dependencies = [
|
|||
name = "roc_builtins"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dunce",
|
||||
"roc_collections",
|
||||
"roc_module",
|
||||
"roc_region",
|
||||
|
@ -2518,6 +2525,7 @@ dependencies = [
|
|||
"bumpalo",
|
||||
"roc_builtins",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_parse",
|
||||
"roc_problem",
|
||||
|
@ -2587,6 +2595,7 @@ dependencies = [
|
|||
"roc_builtins",
|
||||
"roc_can",
|
||||
"roc_collections",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_parse",
|
||||
"roc_region",
|
||||
|
@ -2760,6 +2769,7 @@ dependencies = [
|
|||
"roc_can",
|
||||
"roc_collections",
|
||||
"roc_constrain",
|
||||
"roc_error_macros",
|
||||
"roc_module",
|
||||
"roc_mono",
|
||||
"roc_parse",
|
||||
|
|
|
@ -3,3 +3,4 @@ pub mod markup;
|
|||
pub mod markup_error;
|
||||
pub mod slow_pool;
|
||||
pub mod syntax_highlight;
|
||||
pub mod underline_style;
|
||||
|
|
|
@ -55,8 +55,13 @@ pub enum Attribute {
|
|||
HighlightStart { highlight_start: HighlightStart },
|
||||
HighlightEnd { highlight_end: HighlightEnd },
|
||||
|
||||
UnderlineStart { underline_start: UnderlineStart },
|
||||
UnderlineEnd { underline_end: UnderlineEnd },
|
||||
Underline { underline_spec: UnderlineSpec },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UnderlineSpec {
|
||||
Partial { start: usize, end: usize },
|
||||
Full,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
|
20
code_markup/src/underline_style.rs
Normal file
20
code_markup/src/underline_style.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::colors::{from_hsb, RgbaTup};
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum UnderlineStyle {
|
||||
Error,
|
||||
Warning,
|
||||
}
|
||||
|
||||
pub fn default_underline_color_map() -> HashMap<UnderlineStyle, RgbaTup> {
|
||||
let mut underline_colors = HashMap::new();
|
||||
|
||||
underline_colors.insert(UnderlineStyle::Error, from_hsb(0, 50, 75));
|
||||
underline_colors.insert(UnderlineStyle::Warning, from_hsb(60, 50, 75));
|
||||
|
||||
underline_colors
|
||||
}
|
|
@ -3,9 +3,15 @@ use crate::editor::{ed_error::EdResult, theme::EdTheme, util::map_get};
|
|||
use crate::graphics::primitives::rect::Rect;
|
||||
use crate::graphics::primitives::text as gr_text;
|
||||
use cgmath::Vector2;
|
||||
use roc_code_markup::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER};
|
||||
use roc_code_markup::slow_pool::{MarkNodeId, SlowPool};
|
||||
use roc_code_markup::syntax_highlight::HighlightStyle;
|
||||
use roc_code_markup::{
|
||||
markup::{
|
||||
attribute::Attribute,
|
||||
nodes::{MarkupNode, BLANK_PLACEHOLDER},
|
||||
},
|
||||
slow_pool::{MarkNodeId, SlowPool},
|
||||
syntax_highlight::HighlightStyle,
|
||||
underline_style::UnderlineStyle,
|
||||
};
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use crate::{editor::config::Config, graphics::colors};
|
||||
|
@ -94,6 +100,9 @@ fn markup_to_wgpu_helper<'a>(
|
|||
txt_row_col: &mut (usize, usize),
|
||||
mark_node_pool: &'a SlowPool,
|
||||
) -> EdResult<()> {
|
||||
let char_width = code_style.glyph_dim_rect.width;
|
||||
let char_height = code_style.glyph_dim_rect.height;
|
||||
|
||||
match markup_node {
|
||||
MarkupNode::Nested {
|
||||
ast_node_id: _,
|
||||
|
@ -124,7 +133,7 @@ fn markup_to_wgpu_helper<'a>(
|
|||
content,
|
||||
ast_node_id: _,
|
||||
syn_high_style,
|
||||
attributes: _,
|
||||
attributes,
|
||||
parent_id_opt: _,
|
||||
newlines_at_end,
|
||||
} => {
|
||||
|
@ -132,10 +141,38 @@ fn markup_to_wgpu_helper<'a>(
|
|||
|
||||
let full_content = markup_node.get_full_content().replace("\n", "\\n"); // any \n left here should be escaped so that it can be shown as \n
|
||||
|
||||
let glyph_text = glyph_brush::OwnedText::new(full_content)
|
||||
let glyph_text = glyph_brush::OwnedText::new(&full_content)
|
||||
.with_color(colors::to_slice(*highlight_color))
|
||||
.with_scale(code_style.font_size);
|
||||
|
||||
for attribute in &attributes.all {
|
||||
match attribute {
|
||||
Attribute::Underline { underline_spec: _ } => {
|
||||
// TODO use underline_spec
|
||||
let top_left_coords = (
|
||||
code_style.txt_coords.x + (txt_row_col.1 as f32) * char_width,
|
||||
code_style.txt_coords.y
|
||||
+ (txt_row_col.0 as f32) * char_height
|
||||
+ 1.0 * char_height,
|
||||
);
|
||||
|
||||
let underline_rect = Rect {
|
||||
top_left_coords: top_left_coords.into(),
|
||||
width: char_width * (full_content.len() as f32),
|
||||
height: 5.0,
|
||||
color: *code_style
|
||||
.ed_theme
|
||||
.underline_color_map
|
||||
.get(&UnderlineStyle::Error)
|
||||
.unwrap(),
|
||||
};
|
||||
|
||||
rects.push(underline_rect);
|
||||
}
|
||||
rest => todo!("handle Attribute: {:?}", rest),
|
||||
}
|
||||
}
|
||||
|
||||
txt_row_col.1 += content.len();
|
||||
|
||||
for _ in 0..*newlines_at_end {
|
||||
|
@ -160,9 +197,6 @@ fn markup_to_wgpu_helper<'a>(
|
|||
let highlight_color =
|
||||
map_get(&code_style.ed_theme.syntax_high_map, &HighlightStyle::Blank)?;
|
||||
|
||||
let char_width = code_style.glyph_dim_rect.width;
|
||||
let char_height = code_style.glyph_dim_rect.height;
|
||||
|
||||
let blank_rect = Rect {
|
||||
top_left_coords: (
|
||||
code_style.txt_coords.x + (txt_row_col.1 as f32) * char_width,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use gr_colors::{from_hsb, RgbaTup};
|
||||
use roc_code_markup::syntax_highlight::{default_highlight_map, HighlightStyle};
|
||||
use roc_code_markup::{
|
||||
syntax_highlight::{default_highlight_map, HighlightStyle},
|
||||
underline_style::{default_underline_color_map, UnderlineStyle},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
@ -12,6 +15,7 @@ pub struct EdTheme {
|
|||
pub subtle_text: RgbaTup,
|
||||
pub syntax_high_map: HashMap<HighlightStyle, RgbaTup>,
|
||||
pub ui_theme: UITheme,
|
||||
pub underline_color_map: HashMap<UnderlineStyle, RgbaTup>,
|
||||
}
|
||||
|
||||
impl Default for EdTheme {
|
||||
|
@ -21,6 +25,7 @@ impl Default for EdTheme {
|
|||
subtle_text: from_hsb(240, 5, 60),
|
||||
syntax_high_map: default_highlight_map(),
|
||||
ui_theme: UITheme::default(),
|
||||
underline_color_map: default_underline_color_map(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue