From 4828c9ba62b10e35b46caf3db15d43714cb7e54c Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 13 Oct 2021 12:37:30 +0200 Subject: [PATCH] fmt --- ast/src/ast_error.rs | 2 +- ast/src/lang/core/def/def2.rs | 4 +- ast/src/lang/core/def/def_to_def2.rs | 8 +- ast/src/lang/core/expr/expr2.rs | 10 +- ast/src/lang/core/fun_def.rs | 4 +- ast/src/lang/env.rs | 17 ++- code_markup/src/markup/common_nodes.rs | 6 +- code_markup/src/markup/convert/from_ast.rs | 16 ++- code_markup/src/markup/convert/from_def2.rs | 22 ++- code_markup/src/markup/convert/from_expr2.rs | 135 ++++++++++-------- code_markup/src/markup/convert/from_header.rs | 16 ++- code_markup/src/markup/convert/mod.rs | 2 +- code_markup/src/markup/mod.rs | 2 +- code_markup/src/markup/nodes.rs | 18 +-- code_markup/src/markup/top_level_def.rs | 17 +-- editor/src/editor/main.rs | 7 +- editor/src/editor/mvc/ed_model.rs | 9 +- editor/src/editor/mvc/tld_value_update.rs | 18 +-- editor/src/editor/render_ast.rs | 7 +- 19 files changed, 177 insertions(+), 143 deletions(-) diff --git a/ast/src/ast_error.rs b/ast/src/ast_error.rs index b7e088eb5b..7a98609da9 100644 --- a/ast/src/ast_error.rs +++ b/ast/src/ast_error.rs @@ -1,4 +1,4 @@ -use roc_module::symbol::{IdentId}; +use roc_module::symbol::IdentId; use snafu::{Backtrace, Snafu}; use crate::lang::core::ast::ASTNodeId; diff --git a/ast/src/lang/core/def/def2.rs b/ast/src/lang/core/def/def2.rs index 5b62958305..0717ead70b 100644 --- a/ast/src/lang/core/def/def2.rs +++ b/ast/src/lang/core/def/def2.rs @@ -1,9 +1,7 @@ use roc_module::symbol::IdentId; use crate::{ - lang::core::{ - expr::{expr2::Expr2, expr2_to_string::expr2_to_string}, - }, + lang::core::expr::{expr2::Expr2, expr2_to_string::expr2_to_string}, mem_pool::pool::{NodeId, Pool}, }; diff --git a/ast/src/lang/core/def/def_to_def2.rs b/ast/src/lang/core/def/def_to_def2.rs index 48b6386c94..99e940e7c7 100644 --- a/ast/src/lang/core/def/def_to_def2.rs +++ b/ast/src/lang/core/def/def_to_def2.rs @@ -1,14 +1,10 @@ use bumpalo::collections::Vec as BumpVec; use bumpalo::Bump; use roc_module::ident::{Ident, IdentStr}; -use roc_parse::{parser::SyntaxError}; +use roc_parse::parser::SyntaxError; use roc_region::all::Region; -use crate::lang::{ - core::{expr::expr_to_expr2::loc_expr_to_expr2}, - env::Env, - scope::Scope, -}; +use crate::lang::{core::expr::expr_to_expr2::loc_expr_to_expr2, env::Env, scope::Scope}; use super::def2::Def2; diff --git a/ast/src/lang/core/expr/expr2.rs b/ast/src/lang/core/expr/expr2.rs index 9c571a8bdd..12bef3767e 100644 --- a/ast/src/lang/core/expr/expr2.rs +++ b/ast/src/lang/core/expr/expr2.rs @@ -108,11 +108,11 @@ pub enum Expr2 { }, Closure { args: PoolVec<(Variable, NodeId)>, // 8B - uniq_symbol: Symbol, // 8B This is a globally uniqe symbol for the function, not the name of the function - body_id: ExprId, // 4B - function_type: Variable, // 4B - recursive: Recursive, // 1B - extra: NodeId, // 4B + uniq_symbol: Symbol, // 8B This is a globally uniqe symbol for the function, not the name of the function + body_id: ExprId, // 4B + function_type: Variable, // 4B + recursive: Recursive, // 1B + extra: NodeId, // 4B }, // Product Types Record { diff --git a/ast/src/lang/core/fun_def.rs b/ast/src/lang/core/fun_def.rs index 14c1d6ff88..02d3bdbab4 100644 --- a/ast/src/lang/core/fun_def.rs +++ b/ast/src/lang/core/fun_def.rs @@ -18,13 +18,13 @@ pub enum FunctionDef { arguments: PoolVec<(PatternId, Type2)>, // 8B rigids: NodeId, // 4B return_type: TypeId, // 4B - body_id: ExprId, // 4B + body_id: ExprId, // 4B }, NoAnnotation { name: Symbol, // 8B arguments: PoolVec<(PatternId, Variable)>, // 8B return_var: Variable, // 4B - body_id: ExprId, // 4B + body_id: ExprId, // 4B }, } diff --git a/ast/src/lang/env.rs b/ast/src/lang/env.rs index 195d301577..2410e76f18 100644 --- a/ast/src/lang/env.rs +++ b/ast/src/lang/env.rs @@ -170,15 +170,14 @@ impl<'a> Env<'a> { } pub fn get_name_for_ident_id(&self, ident_id: IdentId) -> ASTResult<&str> { - Ok( - self.ident_ids.get_name(ident_id).with_context(|| - IdentIdNotFound { - ident_id, - env_ident_ids_str: format!("{:?}", self.ident_ids), - } - )? + Ok(self + .ident_ids + .get_name(ident_id) + .with_context(|| IdentIdNotFound { + ident_id, + env_ident_ids_str: format!("{:?}", self.ident_ids), + })? .as_inline_str() - .as_str() - ) + .as_str()) } } diff --git a/code_markup/src/markup/common_nodes.rs b/code_markup/src/markup/common_nodes.rs index 81394db163..1c98baab67 100644 --- a/code_markup/src/markup/common_nodes.rs +++ b/code_markup/src/markup/common_nodes.rs @@ -52,7 +52,11 @@ pub fn new_colon_mn(expr_id: ExprId, parent_id_opt: Option) -> Marku new_operator_mn(nodes::COLON.to_owned(), expr_id, parent_id_opt) } -pub fn new_operator_mn(content: String, expr_id: ExprId, parent_id_opt: Option) -> MarkupNode { +pub fn new_operator_mn( + content: String, + expr_id: ExprId, + parent_id_opt: Option, +) -> MarkupNode { MarkupNode::Text { content: content, ast_node_id: ASTNodeId::AExprId(expr_id), diff --git a/code_markup/src/markup/convert/from_ast.rs b/code_markup/src/markup/convert/from_ast.rs index e84a3ac58f..860857a58e 100644 --- a/code_markup/src/markup/convert/from_ast.rs +++ b/code_markup/src/markup/convert/from_ast.rs @@ -1,9 +1,17 @@ use bumpalo::Bump; -use roc_ast::{ast_error::ASTResult, lang::{core::ast::AST, env::Env}}; +use roc_ast::{ + ast_error::ASTResult, + lang::{core::ast::AST, env::Env}, +}; use roc_module::symbol::Interns; -use crate::{markup::{convert::{from_def2::def2_to_markup, from_header::header_to_markup}, nodes::set_parent_for_all}, slow_pool::{MarkNodeId, SlowPool}}; - +use crate::{ + markup::{ + convert::{from_def2::def2_to_markup, from_header::header_to_markup}, + nodes::set_parent_for_all, + }, + slow_pool::{MarkNodeId, SlowPool}, +}; pub fn ast_to_mark_nodes<'a, 'b>( arena: &'a Bump, @@ -25,4 +33,4 @@ pub fn ast_to_mark_nodes<'a, 'b>( } Ok(all_mark_node_ids) -} \ No newline at end of file +} diff --git a/code_markup/src/markup/convert/from_def2.rs b/code_markup/src/markup/convert/from_def2.rs index 8995cf95c1..e91a3a1a57 100644 --- a/code_markup/src/markup/convert/from_def2.rs +++ b/code_markup/src/markup/convert/from_def2.rs @@ -1,13 +1,16 @@ -use crate::{markup::{common_nodes::new_blank_mn_w_nls, top_level_def::tld_mark_node}, slow_pool::{MarkNodeId, SlowPool}}; +use crate::{ + markup::{common_nodes::new_blank_mn_w_nls, top_level_def::tld_mark_node}, + slow_pool::{MarkNodeId, SlowPool}, +}; -use super::{from_expr2::expr2_to_markup}; +use super::from_expr2::expr2_to_markup; use bumpalo::Bump; use roc_ast::{ ast_error::ASTResult, lang::{ core::{ - ast::{ASTNodeId}, + ast::ASTNodeId, def::def2::{Def2, DefId}, }, env::Env, @@ -37,16 +40,11 @@ pub fn def2_to_markup<'a, 'b>( *expr_id, mark_node_pool, interns, - 0 + 0, )?; - let tld_mn = tld_mark_node( - *identifier_id, - expr_mn_id, - ast_node_id, - mark_node_pool, - env - )?; + let tld_mn = + tld_mark_node(*identifier_id, expr_mn_id, ast_node_id, mark_node_pool, env)?; mark_node_pool.add(tld_mn) } @@ -54,4 +52,4 @@ pub fn def2_to_markup<'a, 'b>( }; Ok(mark_node_id) -} \ No newline at end of file +} diff --git a/code_markup/src/markup/convert/from_expr2.rs b/code_markup/src/markup/convert/from_expr2.rs index 5c43254f14..3ab17cdeb3 100644 --- a/code_markup/src/markup/convert/from_expr2.rs +++ b/code_markup/src/markup/convert/from_expr2.rs @@ -1,12 +1,34 @@ - -use crate::{markup::{attribute::Attributes, common_nodes::{new_arg_name_mn, new_arrow_mn, new_blank_mn, new_colon_mn, new_comma_mn, new_equals_mn, new_left_accolade_mn, new_left_square_mn, new_operator_mn, new_right_accolade_mn, new_right_square_mn}, nodes::{MarkupNode, get_string, new_markup_node}}, slow_pool::{MarkNodeId, SlowPool}, syntax_highlight::HighlightStyle}; +use crate::{ + markup::{ + attribute::Attributes, + common_nodes::{ + new_arg_name_mn, new_arrow_mn, new_blank_mn, new_colon_mn, new_comma_mn, new_equals_mn, + new_left_accolade_mn, new_left_square_mn, new_operator_mn, new_right_accolade_mn, + new_right_square_mn, + }, + nodes::{get_string, new_markup_node, MarkupNode}, + }, + slow_pool::{MarkNodeId, SlowPool}, + syntax_highlight::HighlightStyle, +}; use bumpalo::Bump; use itertools::Itertools; -use roc_ast::{ast_error::{ASTResult, IdentIdNotFound}, lang::{core::{ast::ASTNodeId, expr::{ +use roc_ast::{ + ast_error::{ASTResult, IdentIdNotFound}, + lang::{ + core::{ + ast::ASTNodeId, + expr::{ expr2::{Expr2, ExprId}, record_field::RecordField, - }, pattern::{Pattern2, get_identifier_string}, val_def::ValueDef}, env::Env}}; + }, + pattern::{get_identifier_string, Pattern2}, + val_def::ValueDef, + }, + env::Env, + }, +}; use roc_module::{ident::Ident, symbol::Interns}; use snafu::OptionExt; @@ -20,7 +42,6 @@ pub fn expr2_to_markup<'a, 'b>( interns: &Interns, indent_level: usize, ) -> ASTResult { - let ast_node_id = ASTNodeId::AExprId(expr2_node_id); println!("EXPR2 {:?}", expr2); @@ -50,7 +71,7 @@ pub fn expr2_to_markup<'a, 'b>( mark_node_pool, indent_level, ) - }, + } Expr2::GlobalTag { name, .. } => new_markup_node( with_indent(indent_level, &get_string(env, name)), ast_node_id, @@ -60,7 +81,15 @@ pub fn expr2_to_markup<'a, 'b>( ), Expr2::Call { expr: expr_id, .. } => { let expr = env.pool.get(*expr_id); - expr2_to_markup(arena, env, expr, *expr_id, mark_node_pool, interns, indent_level)? + expr2_to_markup( + arena, + env, + expr, + *expr_id, + mark_node_pool, + interns, + indent_level, + )? } Expr2::Var(symbol) => { let text = env.get_name_for_ident_id(symbol.ident_id())?; @@ -90,7 +119,7 @@ pub fn expr2_to_markup<'a, 'b>( *node_id, mark_node_pool, interns, - indent_level + indent_level, )?); if idx + 1 < elems.len() { @@ -154,7 +183,7 @@ pub fn expr2_to_markup<'a, 'b>( *sub_expr2_node_id, mark_node_pool, interns, - indent_level + indent_level, )?); } } @@ -215,7 +244,7 @@ pub fn expr2_to_markup<'a, 'b>( *expr_id, mark_node_pool, interns, - indent_level + indent_level, )?; let body_mn = mark_node_pool.get_mut(body_mn_id); @@ -238,79 +267,67 @@ pub fn expr2_to_markup<'a, 'b>( } } } - Expr2::Closure{ - function_type:_, - uniq_symbol:_, - recursive:_, + Expr2::Closure { + function_type: _, + uniq_symbol: _, + recursive: _, args, body_id, - extra:_ + extra: _, } => { let backslash_mn = new_operator_mn("\\".to_string(), expr2_node_id, None); let backslash_mn_id = mark_node_pool.add(backslash_mn); - let arg_idents: Vec<&Ident> = - args.iter(env.pool).map( - | (_, arg_node_id) | { + let arg_idents: Vec<&Ident> = + args.iter(env.pool) + .map(|(_, arg_node_id)| { let arg_pattern2 = env.pool.get(*arg_node_id); match arg_pattern2 { Pattern2::Identifier(id_symbol) => { let ident_id = id_symbol.ident_id(); - let ident = - env - .ident_ids - .get_name(ident_id) - .with_context(|| IdentIdNotFound { - ident_id, - env_ident_ids_str: format!("{:?}", env.ident_ids), - }); + let ident = env.ident_ids.get_name(ident_id).with_context(|| { + IdentIdNotFound { + ident_id, + env_ident_ids_str: format!("{:?}", env.ident_ids), + } + }); ident - }, + } other => { - todo!("TODO: support the following pattern2 as function arg: {:?}", other); + todo!( + "TODO: support the following pattern2 as function arg: {:?}", + other + ); } } - } - ) - .collect::>>()?; + }) + .collect::>>()?; - let arg_names = - arg_idents.iter().map(|ident| { - ident.as_inline_str().as_str() - }); + let arg_names = arg_idents + .iter() + .map(|ident| ident.as_inline_str().as_str()); + + let arg_mark_nodes = + arg_names.map(|arg_name| new_arg_name_mn(arg_name.to_string(), expr2_node_id)); + + let commas = (0..(arg_mark_nodes.len() - 1)).map(|_| new_comma_mn(expr2_node_id, None)); - let arg_mark_nodes = arg_names.map( - |arg_name| - new_arg_name_mn(arg_name.to_string(), expr2_node_id) - ); - - let commas = - (0..(arg_mark_nodes.len() - 1)).map( - |_| - new_comma_mn(expr2_node_id, None) - ); - let args_with_commas: Vec = arg_mark_nodes.interleave(commas).collect_vec(); - let mut args_with_commas_ids: Vec = - args_with_commas.into_iter().map( - |mark_node| - mark_node_pool.add(mark_node) - ).collect(); + let mut args_with_commas_ids: Vec = args_with_commas + .into_iter() + .map(|mark_node| mark_node_pool.add(mark_node)) + .collect(); - let arrow_mn = - new_arrow_mn( - ASTNodeId::AExprId(expr2_node_id), - 1 - ); + let arrow_mn = new_arrow_mn(ASTNodeId::AExprId(expr2_node_id), 1); let arrow_mn_id = mark_node_pool.add(arrow_mn); let mut children_ids = vec![backslash_mn_id]; children_ids.append(&mut args_with_commas_ids); children_ids.push(arrow_mn_id); - + let args_mn = MarkupNode::Nested { ast_node_id: ASTNodeId::AExprId(expr2_node_id), children_ids, @@ -327,7 +344,7 @@ pub fn expr2_to_markup<'a, 'b>( *body_id, mark_node_pool, interns, - indent_level + 1 + indent_level + 1, )?; let function_node = MarkupNode::Nested { @@ -359,4 +376,4 @@ fn with_indent(indent_level: usize, some_str: &str) -> String { full_string.push_str(some_str); full_string -} \ No newline at end of file +} diff --git a/code_markup/src/markup/convert/from_header.rs b/code_markup/src/markup/convert/from_header.rs index 376fafccb1..7500b44714 100644 --- a/code_markup/src/markup/convert/from_header.rs +++ b/code_markup/src/markup/convert/from_header.rs @@ -1,7 +1,17 @@ use roc_ast::lang::core::{ast::ASTNodeId, expr::expr2::ExprId, header::AppHeader}; -use crate::{markup::{attribute::Attributes, common_nodes::{new_comma_mn, new_left_accolade_mn, new_left_square_mn, new_right_accolade_mn, new_right_square_mn}, nodes::{MarkupNode, set_parent_for_all}}, slow_pool::{MarkNodeId, SlowPool}, syntax_highlight::HighlightStyle}; - +use crate::{ + markup::{ + attribute::Attributes, + common_nodes::{ + new_comma_mn, new_left_accolade_mn, new_left_square_mn, new_right_accolade_mn, + new_right_square_mn, + }, + nodes::{set_parent_for_all, MarkupNode}, + }, + slow_pool::{MarkNodeId, SlowPool}, + syntax_highlight::HighlightStyle, +}; pub fn header_to_markup(app_header: &AppHeader, mark_node_pool: &mut SlowPool) -> MarkNodeId { let expr_id = app_header.ast_node_id; @@ -192,4 +202,4 @@ fn header_val_mn( }; mark_node_pool.add(mark_node) -} \ No newline at end of file +} diff --git a/code_markup/src/markup/convert/mod.rs b/code_markup/src/markup/convert/mod.rs index 4e6d5618c7..57b87c5918 100644 --- a/code_markup/src/markup/convert/mod.rs +++ b/code_markup/src/markup/convert/mod.rs @@ -1,4 +1,4 @@ pub mod from_ast; pub mod from_def2; pub mod from_expr2; -pub mod from_header; \ No newline at end of file +pub mod from_header; diff --git a/code_markup/src/markup/mod.rs b/code_markup/src/markup/mod.rs index 05480f0f2c..5b6dca5dfb 100644 --- a/code_markup/src/markup/mod.rs +++ b/code_markup/src/markup/mod.rs @@ -1,5 +1,5 @@ pub mod attribute; pub mod common_nodes; -pub mod nodes; pub mod convert; +pub mod nodes; pub mod top_level_def; diff --git a/code_markup/src/markup/nodes.rs b/code_markup/src/markup/nodes.rs index 2da0181286..60c8670b58 100644 --- a/code_markup/src/markup/nodes.rs +++ b/code_markup/src/markup/nodes.rs @@ -4,12 +4,13 @@ use crate::{ syntax_highlight::HighlightStyle, }; -use super::{ - attribute::Attributes -}; +use super::attribute::Attributes; use crate::markup_error::{ExpectedTextNode, NestedNodeMissingChild, NestedNodeRequired}; -use roc_ast::{lang::{core::ast::ASTNodeId, env::Env}, mem_pool::pool_str::PoolStr}; +use roc_ast::{ + lang::{core::ast::ASTNodeId, env::Env}, + mem_pool::pool_str::PoolStr, +}; use roc_utils::{index_of, slice_get}; use std::fmt; @@ -39,7 +40,7 @@ pub enum MarkupNode { ast_node_id: ASTNodeId, indent_level: usize, parent_id_opt: Option, - } + }, } impl MarkupNode { @@ -161,7 +162,9 @@ impl MarkupNode { MarkupNode::Nested { .. } => "".to_owned(), MarkupNode::Text { content, .. } => content.clone(), MarkupNode::Blank { .. } => BLANK_PLACEHOLDER.to_owned(), - MarkupNode::Indent { indent_level, .. } => std::iter::repeat( SINGLE_INDENT).take(*indent_level).collect(), + MarkupNode::Indent { indent_level, .. } => std::iter::repeat(SINGLE_INDENT) + .take(*indent_level) + .collect(), } } @@ -294,7 +297,7 @@ pub fn new_markup_node( let indent_node = MarkupNode::Indent { ast_node_id: node_id, indent_level, - parent_id_opt: None + parent_id_opt: None, }; let indent_node_id = mark_node_pool.add(indent_node); @@ -359,7 +362,6 @@ pub fn set_parent_for_all_helper( } } - impl fmt::Display for MarkupNode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( diff --git a/code_markup/src/markup/top_level_def.rs b/code_markup/src/markup/top_level_def.rs index d60b3d9764..a456b0b115 100644 --- a/code_markup/src/markup/top_level_def.rs +++ b/code_markup/src/markup/top_level_def.rs @@ -1,10 +1,8 @@ -use roc_ast::{ast_error::{ASTResult}, lang::{ - core::{ - ast::ASTNodeId - }, - env::Env, - }}; -use roc_module::symbol::{IdentId}; +use roc_ast::{ + ast_error::ASTResult, + lang::{core::ast::ASTNodeId, env::Env}, +}; +use roc_module::symbol::IdentId; use crate::{ markup::{attribute::Attributes, common_nodes::new_equals_mn, nodes::MarkupNode}, @@ -17,10 +15,9 @@ pub fn tld_mark_node<'a>( expr_mark_node_id: MarkNodeId, ast_node_id: ASTNodeId, mark_node_pool: &mut SlowPool, - env: &Env<'a> + env: &Env<'a>, ) -> ASTResult { - let val_name = - env.get_name_for_ident_id(identifier_id)?; + let val_name = env.get_name_for_ident_id(identifier_id)?; let val_name_mn = MarkupNode::Text { content: val_name.to_owned(), diff --git a/editor/src/editor/main.rs b/editor/src/editor/main.rs index 7daa30fba7..87e315734b 100644 --- a/editor/src/editor/main.rs +++ b/editor/src/editor/main.rs @@ -137,7 +137,12 @@ fn run_event_loop(project_dir_path_opt: Option<&Path>) -> Result<(), Box( expr_mark_node_id: MarkNodeId, ast_node_id: ASTNodeId, mark_node_pool: &mut SlowPool, - env: &Env<'a> + env: &Env<'a>, ) -> EdResult { let val_name = env.get_name_for_ident_id(identifier_id)?; @@ -108,7 +102,7 @@ pub fn start_new_tld_value(ed_model: &mut EdModel, new_char: &char) -> EdResult< val_expr_mn_id, ast_node_id, &mut ed_model.mark_node_pool, - &ed_model.module.env + &ed_model.module.env, )?; let new_ast_node = Def2::ValueDef { diff --git a/editor/src/editor/render_ast.rs b/editor/src/editor/render_ast.rs index c827f94c65..3d1530fe3a 100644 --- a/editor/src/editor/render_ast.rs +++ b/editor/src/editor/render_ast.rs @@ -3,7 +3,7 @@ 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::{BLANK_PLACEHOLDER, MarkupNode, SINGLE_INDENT}; +use roc_code_markup::markup::nodes::{MarkupNode, BLANK_PLACEHOLDER, SINGLE_INDENT}; use roc_code_markup::slow_pool::{MarkNodeId, SlowPool}; use roc_code_markup::syntax_highlight::HighlightStyle; use winit::dpi::PhysicalSize; @@ -157,7 +157,8 @@ fn markup_to_wgpu_helper<'a>( .with_color(colors::to_slice(colors::WHITE)) .with_scale(code_style.font_size); - let highlight_color = map_get(&code_style.ed_theme.syntax_high_map, &HighlightStyle::Blank)?; + 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; @@ -193,7 +194,7 @@ fn markup_to_wgpu_helper<'a>( .with_color(colors::to_slice(colors::WHITE)) .with_scale(code_style.font_size); - wgpu_texts.push(glyph_text); + wgpu_texts.push(glyph_text); } };