mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
debug view for mark_node_pool, code_lines, grid_node_map
This commit is contained in:
parent
98f0d1a749
commit
ffd592289f
12 changed files with 149 additions and 16 deletions
|
@ -4,6 +4,7 @@ use crate::ui::util::slice_get;
|
|||
use crate::ui::util::slice_get_mut;
|
||||
use bumpalo::collections::String as BumpString;
|
||||
use bumpalo::Bump;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CodeLines {
|
||||
|
@ -104,3 +105,22 @@ impl Lines for CodeLines {
|
|||
Ok(self.get_line(line_nr)?.chars().last())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for CodeLines {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
for row in &self.lines {
|
||||
let row_str =
|
||||
row
|
||||
.chars()
|
||||
.map(|code_char| format!("'{}'", code_char))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
|
||||
write!(f, "\n{}", row_str)?;
|
||||
}
|
||||
|
||||
write!(f, " (code_lines)")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::editor::util::index_of;
|
|||
use crate::ui::text::text_pos::TextPos;
|
||||
use crate::ui::ui_error::UIResult;
|
||||
use crate::ui::util::{slice_get, slice_get_mut};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GridNodeMap {
|
||||
|
@ -72,3 +73,22 @@ impl GridNodeMap {
|
|||
Ok(caret_pos.column - first_node_index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GridNodeMap {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
for row in &self.lines {
|
||||
let row_str =
|
||||
row
|
||||
.iter()
|
||||
.map(|mark_node_id| format!(" {} ", mark_node_id))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
|
||||
write!(f, "{}", row_str)?;
|
||||
}
|
||||
|
||||
write!(f, " (grid_node_map)")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ pub fn handle_keydown(
|
|||
|
||||
A | Home | End => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?,
|
||||
|
||||
F11 => pass_keydown_to_focused(&modifiers, virtual_keycode, app_model)?,
|
||||
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ use crate::graphics::{
|
|||
primitives::text::{build_glyph_brush, example_code_glyph_rect, queue_text_draw, Text},
|
||||
};
|
||||
use crate::lang::expr::Env;
|
||||
use crate::lang::pool::Pool;
|
||||
use crate::lang::pool::{Pool};
|
||||
use crate::ui::ui_error::UIError::FileOpenFailed;
|
||||
use crate::ui::util::slice_get;
|
||||
use bumpalo::collections::String as BumpString;
|
||||
|
@ -307,9 +307,11 @@ fn run_event_loop(file_path_opt: Option<&Path>) -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
|
||||
if let Some(ref rendered_wgpu) = rendered_wgpu_opt {
|
||||
let borrowed_text = rendered_wgpu.text.to_borrowed();
|
||||
for text_section in &rendered_wgpu.text_sections {
|
||||
let borrowed_text = text_section.to_borrowed();
|
||||
|
||||
glyph_brush.queue(borrowed_text);
|
||||
}
|
||||
|
||||
draw_all_rects(
|
||||
&rendered_wgpu.rects,
|
||||
|
|
|
@ -7,6 +7,7 @@ pub mod main;
|
|||
mod markup;
|
||||
mod mvc;
|
||||
mod render_ast;
|
||||
mod render_debug;
|
||||
mod resources;
|
||||
mod slow_pool;
|
||||
mod style;
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::editor::{
|
|||
use crate::graphics::primitives::rect::Rect;
|
||||
use crate::lang::ast::Expr2;
|
||||
use crate::lang::expr::{str_to_expr2, Env};
|
||||
use crate::lang::pool::NodeId;
|
||||
use crate::lang::pool::{NodeId};
|
||||
use crate::lang::scope::Scope;
|
||||
use crate::ui::text::caret_w_select::CaretWSelect;
|
||||
use bumpalo::collections::String as BumpString;
|
||||
|
@ -34,6 +34,7 @@ pub struct EdModel<'a> {
|
|||
pub has_focus: bool,
|
||||
// Option<MarkNodeId>: MarkupNode that corresponds to caret position, Option because this MarkNodeId is only calculated when it needs to be used.
|
||||
pub caret_w_select_vec: NonEmpty<(CaretWSelect, Option<MarkNodeId>)>,
|
||||
pub show_debug_view: bool,
|
||||
// EdModel is dirty if it has changed since the previous render.
|
||||
pub dirty: bool,
|
||||
}
|
||||
|
@ -83,6 +84,7 @@ pub fn init_model<'a>(
|
|||
glyph_dim_rect_opt: None,
|
||||
has_focus: true,
|
||||
caret_w_select_vec: NonEmpty::new((CaretWSelect::default(), None)),
|
||||
show_debug_view: false,
|
||||
dirty: true,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::editor::mvc::string_update::update_string;
|
|||
use crate::editor::slow_pool::MarkNodeId;
|
||||
use crate::editor::slow_pool::SlowPool;
|
||||
use crate::lang::ast::Expr2;
|
||||
use crate::lang::pool::NodeId;
|
||||
use crate::lang::pool::{NodeId};
|
||||
use crate::ui::text::caret_w_select::CaretWSelect;
|
||||
use crate::ui::text::lines::MoveCaretFun;
|
||||
use crate::ui::text::selection::validate_raw_sel;
|
||||
|
@ -281,6 +281,11 @@ impl<'a> SelectableLines for EdModel<'a> {
|
|||
}
|
||||
Home => self.move_caret_home(modifiers),
|
||||
End => self.move_caret_end(modifiers),
|
||||
F11 => {
|
||||
self.show_debug_view = !self.show_debug_view;
|
||||
self.dirty = true;
|
||||
Ok(())
|
||||
},
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
@ -371,9 +376,6 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
|
|||
};
|
||||
|
||||
let ast_node_id = curr_mark_node.get_ast_node_id();
|
||||
|
||||
|
||||
|
||||
let ast_node_ref = ed_model.module.env.pool.get(ast_node_id);
|
||||
|
||||
match ast_node_ref {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::editor::render_debug::build_debug_graphics;
|
||||
use super::ed_model::EdModel;
|
||||
use crate::editor::config::Config;
|
||||
use crate::editor::ed_error::EdResult;
|
||||
|
@ -12,7 +13,7 @@ use winit::dpi::PhysicalSize;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct RenderedWgpu {
|
||||
pub text: glyph_brush::OwnedSection,
|
||||
pub text_sections: Vec<glyph_brush::OwnedSection>,
|
||||
pub rects: Vec<Rect>,
|
||||
}
|
||||
|
||||
|
@ -25,7 +26,9 @@ pub fn model_to_wgpu<'a>(
|
|||
) -> EdResult<RenderedWgpu> {
|
||||
let glyph_dim_rect = ed_model.glyph_dim_rect_opt.context(MissingGlyphDims {})?;
|
||||
|
||||
let (section, mut rects) = build_code_graphics(
|
||||
let mut all_text_sections = Vec::new();
|
||||
|
||||
let (code_section, mut rects) = build_code_graphics(
|
||||
ed_model.markup_node_pool.get(ed_model.markup_root_id),
|
||||
size,
|
||||
txt_coords,
|
||||
|
@ -34,6 +37,8 @@ pub fn model_to_wgpu<'a>(
|
|||
&ed_model.markup_node_pool,
|
||||
)?;
|
||||
|
||||
all_text_sections.push(code_section);
|
||||
|
||||
let caret_w_sel_vec = ed_model
|
||||
.caret_w_select_vec
|
||||
.iter()
|
||||
|
@ -45,8 +50,14 @@ pub fn model_to_wgpu<'a>(
|
|||
|
||||
rects.append(&mut sel_rects);
|
||||
|
||||
if ed_model.show_debug_view {
|
||||
all_text_sections.push(
|
||||
build_debug_graphics(size, txt_coords, config, ed_model)?
|
||||
);
|
||||
}
|
||||
|
||||
Ok(RenderedWgpu {
|
||||
text: section,
|
||||
text_sections: all_text_sections,
|
||||
rects,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,9 +11,7 @@ use crate::editor::slow_pool::MarkNodeId;
|
|||
use crate::editor::syntax_highlight::HighlightStyle;
|
||||
use crate::editor::util::index_of;
|
||||
use crate::lang::ast::Expr2;
|
||||
use crate::lang::pool::NodeId;
|
||||
use crate::lang::pool::PoolStr;
|
||||
use crate::lang::pool::PoolVec;
|
||||
use crate::lang::pool::{NodeId, PoolStr, PoolVec};
|
||||
use crate::ui::text::text_pos::TextPos;
|
||||
use roc_types::subs::Variable;
|
||||
use snafu::OptionExt;
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::editor::mvc::ed_update::NodeContext;
|
|||
use crate::editor::syntax_highlight::HighlightStyle;
|
||||
use crate::lang::ast::ArrString;
|
||||
use crate::lang::ast::Expr2;
|
||||
use crate::lang::pool::PoolStr;
|
||||
use crate::lang::pool::{PoolStr};
|
||||
|
||||
pub fn update_small_string(
|
||||
new_char: &char,
|
||||
|
|
56
editor/src/editor/render_debug.rs
Normal file
56
editor/src/editor/render_debug.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use crate::graphics::colors;
|
||||
use crate::graphics::colors::from_hsb;
|
||||
use crate::editor::mvc::ed_model::EdModel;
|
||||
use crate::editor::{ed_error::EdResult};
|
||||
use crate::graphics::primitives::text as gr_text;
|
||||
use cgmath::Vector2;
|
||||
use winit::dpi::PhysicalSize;
|
||||
|
||||
use crate::{editor::config::Config};
|
||||
|
||||
pub fn build_debug_graphics(
|
||||
size: &PhysicalSize<u32>,
|
||||
txt_coords: Vector2<f32>,
|
||||
config: &Config,
|
||||
ed_model: &EdModel,
|
||||
) -> EdResult<glyph_brush::OwnedSection> {
|
||||
let area_bounds = (size.width as f32, size.height as f32);
|
||||
let layout = wgpu_glyph::Layout::default().h_align(wgpu_glyph::HorizontalAlign::Left);
|
||||
|
||||
let debug_txt_coords: Vector2<f32> = (txt_coords.x, txt_coords.y * 6.0).into();
|
||||
|
||||
let grid_node_map_text =
|
||||
glyph_brush::OwnedText::new(
|
||||
format!("{}", ed_model.grid_node_map)
|
||||
)
|
||||
.with_color(colors::to_slice(from_hsb(25, 82, 96)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let code_lines_text =
|
||||
glyph_brush::OwnedText::new(
|
||||
format!("{}", ed_model.code_lines)
|
||||
)
|
||||
.with_color(colors::to_slice(from_hsb(73, 22, 78)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let mark_node_pool_text =
|
||||
glyph_brush::OwnedText::new(
|
||||
format!("{}", ed_model.markup_node_pool)
|
||||
)
|
||||
.with_color(colors::to_slice(from_hsb(151, 36, 44)))
|
||||
.with_scale(config.code_font_size);
|
||||
|
||||
let section =
|
||||
gr_text::section_from_glyph_text(
|
||||
vec![
|
||||
grid_node_map_text,
|
||||
code_lines_text,
|
||||
mark_node_pool_text
|
||||
],
|
||||
debug_txt_coords.into(),
|
||||
area_bounds,
|
||||
layout
|
||||
);
|
||||
|
||||
Ok(section)
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
use crate::editor::markup::nodes::MarkupNode;
|
||||
use std::fmt;
|
||||
|
||||
pub type MarkNodeId = usize;
|
||||
|
||||
|
@ -34,3 +35,21 @@ impl SlowPool {
|
|||
self.nodes[node_id] = new_node;
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SlowPool {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "\n\n(mark_node_pool)\n")?;
|
||||
|
||||
for (index, node) in self.nodes.iter().enumerate() {
|
||||
write!(
|
||||
f,
|
||||
"{}: {} ({})\n",
|
||||
index,
|
||||
node.node_type_as_string(),
|
||||
node.get_content().unwrap_or_else(|_| "".to_string()),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue