fmt+clippy

This commit is contained in:
Anton-4 2022-02-21 16:51:54 +01:00
parent cd2b83c503
commit 272e6f9ca0
No known key found for this signature in database
GPG key ID: C954D6E0F9C0ABFD
15 changed files with 155 additions and 283 deletions

View file

@ -155,20 +155,16 @@ fn canonicalize_field<'a>(
expr_to_expr2(env, scope, &loc_expr.value, loc_expr.region);
match loc_can_expr {
Expr2::RuntimeError() => {
Ok(CanonicalField::InvalidLabelOnly {
label: label.value,
var: field_var,
})
}
_ => {
Ok(CanonicalField::LabelAndValue {
label: label.value,
value_expr: loc_can_expr,
value_output: output,
var: field_var,
})
}
Expr2::RuntimeError() => Ok(CanonicalField::InvalidLabelOnly {
label: label.value,
var: field_var,
}),
_ => Ok(CanonicalField::LabelAndValue {
label: label.value,
value_expr: loc_can_expr,
value_output: output,
var: field_var,
}),
}
}

View file

@ -33,8 +33,6 @@ impl AST {
}
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum ASTNodeId {
ADefId(DefId),

35
cli_utils/Cargo.lock generated
View file

@ -964,12 +964,6 @@ dependencies = [
"toml",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "flate2"
version = "1.0.22"
@ -2047,14 +2041,11 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216"
dependencies = [
"backtrace",
"cfg-if 1.0.0",
"instant",
"libc",
"petgraph",
"redox_syscall",
"smallvec",
"thread-id",
"winapi",
]
@ -2107,16 +2098,6 @@ dependencies = [
"sha-1",
]
[[package]]
name = "petgraph"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "phf"
version = "0.9.0"
@ -2799,6 +2780,7 @@ dependencies = [
"bumpalo",
"lazy_static",
"roc_collections",
"roc_error_macros",
"roc_ident",
"roc_region",
"snafu",
@ -2815,6 +2797,7 @@ dependencies = [
"roc_builtins",
"roc_can",
"roc_collections",
"roc_error_macros",
"roc_module",
"roc_problem",
"roc_region",
@ -2865,6 +2848,7 @@ dependencies = [
"inkwell 0.1.0",
"libloading 0.7.1",
"roc_build",
"roc_builtins",
"roc_collections",
"roc_gen_llvm",
"roc_load",
@ -2946,6 +2930,7 @@ version = "0.1.0"
dependencies = [
"bumpalo",
"roc_collections",
"roc_error_macros",
"roc_module",
"roc_region",
"static_assertions",
@ -2956,6 +2941,7 @@ dependencies = [
name = "roc_unify"
version = "0.1.0"
dependencies = [
"bitflags",
"roc_collections",
"roc_module",
"roc_types",
@ -3402,17 +3388,6 @@ dependencies = [
"syn",
]
[[package]]
name = "thread-id"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f"
dependencies = [
"libc",
"redox_syscall",
"winapi",
]
[[package]]
name = "threadpool"
version = "1.8.1"

View file

@ -387,9 +387,14 @@ fn with_indent(indent_level: usize, some_str: &str) -> String {
full_string
}
fn string_mark_node(content: &str, indent_level: usize, ast_node_id: ASTNodeId, mark_node_pool: &mut SlowPool) -> MarkNodeId {
fn string_mark_node(
content: &str,
indent_level: usize,
ast_node_id: ASTNodeId,
mark_node_pool: &mut SlowPool,
) -> MarkNodeId {
new_markup_node(
with_indent(indent_level, &content),
with_indent(indent_level, content),
ast_node_id,
HighlightStyle::String,
mark_node_pool,

View file

@ -469,10 +469,7 @@ pub fn join_mark_nodes_commas(
mark_nodes.into_iter().interleave(join_nodes).collect()
}
pub fn mark_nodes_to_string(
markup_node_ids: &[MarkNodeId],
mark_node_pool: &SlowPool,
) -> String {
pub fn mark_nodes_to_string(markup_node_ids: &[MarkNodeId], mark_node_pool: &SlowPool) -> String {
let mut all_code_string = String::new();
for mark_node_id in markup_node_ids.iter() {
@ -482,7 +479,11 @@ pub fn mark_nodes_to_string(
all_code_string
}
pub fn node_to_string_w_children(node_id: MarkNodeId, str_buffer: &mut String, mark_node_pool: &SlowPool) {
pub fn node_to_string_w_children(
node_id: MarkNodeId,
str_buffer: &mut String,
mark_node_pool: &SlowPool,
) {
let node = mark_node_pool.get(node_id);
if node.is_nested() {

View file

@ -1,6 +1,6 @@
use crate::ui::text::lines::Lines;
use crate::ui::text::text_pos::TextPos;
use crate::ui::ui_error::{ UIResult};
use crate::ui::ui_error::UIResult;
use crate::ui::util::slice_get;
use std::fmt;
@ -13,14 +13,11 @@ pub struct CodeLines {
impl CodeLines {
pub fn from_str(code_str: &str) -> CodeLines {
CodeLines {
lines: code_str
.split('\n')
.map(|s| s.to_owned())
.collect(),
lines: code_str.split('\n').map(|s| s.to_owned()).collect(),
nr_of_chars: code_str.len(),
}
}
// last column of last line
pub fn end_txt_pos(&self) -> TextPos {
let last_line_nr = self.nr_of_lines() - 1;

View file

@ -28,19 +28,10 @@ pub fn break_line(ed_model: &mut EdModel) -> EdResult<InputOutcome> {
&& ed_model.code_lines.line_len(new_blank_line_nr).unwrap() == 0)
{
// two blank lines between top level definitions
EdModel::insert_empty_line(
caret_line_nr + 1,
&mut ed_model.grid_node_map,
)?;
EdModel::insert_empty_line(
caret_line_nr + 2,
&mut ed_model.grid_node_map,
)?;
EdModel::insert_empty_line(caret_line_nr + 1, &mut ed_model.grid_node_map)?;
EdModel::insert_empty_line(caret_line_nr + 2, &mut ed_model.grid_node_map)?;
// third "empty" line will be filled by the blank
EdModel::insert_empty_line(
caret_line_nr + 3,
&mut ed_model.grid_node_map,
)?;
EdModel::insert_empty_line(caret_line_nr + 3, &mut ed_model.grid_node_map)?;
insert_new_blank(ed_model, caret_pos.line + 3)?;
}
@ -52,24 +43,25 @@ pub fn break_line(ed_model: &mut EdModel) -> EdResult<InputOutcome> {
Ok(InputOutcome::Accepted)
}
pub fn insert_new_blank(
ed_model: &mut EdModel,
insert_on_line_nr: usize,
) -> EdResult<()> {
println!("{}", ed_model.module.ast.ast_to_string(ed_model.module.env.pool));
pub fn insert_new_blank(ed_model: &mut EdModel, insert_on_line_nr: usize) -> EdResult<()> {
println!(
"{}",
ed_model.module.ast.ast_to_string(ed_model.module.env.pool)
);
// find position of the previous ASTNode to figure out where to add this new Blank ASTNode
let def_mark_node_id = ed_model.grid_node_map.get_def_mark_node_id_before_line(
insert_on_line_nr,
&ed_model.mark_node_pool,
)?;
let def_mark_node_id = ed_model
.grid_node_map
.get_def_mark_node_id_before_line(insert_on_line_nr, &ed_model.mark_node_pool)?;
let new_line_blank = Def2::Blank;
let new_line_blank_id = ed_model.module.env.pool.add(new_line_blank);
let insertion_index = index_of(def_mark_node_id, &ed_model.markup_ids)?;
ed_model.module.ast.insert_def_at_index(new_line_blank_id, insertion_index);
ed_model
.module
.ast
.insert_def_at_index(new_line_blank_id, insertion_index);
Ok(())
}

View file

@ -75,10 +75,8 @@ pub fn init_model<'a>(
)?)
}?;
let code_lines = CodeLines::from_str(
&nodes::mark_nodes_to_string(&markup_ids, &mark_node_pool)
);
let code_lines =
CodeLines::from_str(&nodes::mark_nodes_to_string(&markup_ids, &mark_node_pool));
let mut grid_node_map = GridNodeMap::default();
let mut line_nr = 0;

View file

@ -300,10 +300,7 @@ impl<'a> EdModel<'a> {
grid_node_map.break_line(line_nr, col_nr)
}
pub fn insert_empty_line(
line_nr: usize,
grid_node_map: &mut GridNodeMap,
) -> UIResult<()> {
pub fn insert_empty_line(line_nr: usize, grid_node_map: &mut GridNodeMap) -> UIResult<()> {
grid_node_map.insert_empty_line(line_nr)
}
@ -330,7 +327,7 @@ impl<'a> EdModel<'a> {
col_range: std::ops::Range<usize>,
) -> UIResult<()> {
self.grid_node_map
.del_range_at_line(line_nr, col_range.clone())
.del_range_at_line(line_nr, col_range)
}
pub fn del_blank_expr_node(&mut self, txt_pos: TextPos) -> UIResult<()> {
@ -663,20 +660,21 @@ impl<'a> EdModel<'a> {
//dbg!("{}",self.module.ast.ast_to_string(self.module.env.pool));
self.markup_ids = ast_to_mark_nodes(
&mut self.module.env,
&self.module.ast,
&mut self.mark_node_pool,
&self.loaded_module.interns,
)?;
self.code_lines = CodeLines::from_str(
&nodes::mark_nodes_to_string(&self.markup_ids, &self.mark_node_pool)
);
&mut self.module.env,
&self.module.ast,
&mut self.mark_node_pool,
&self.loaded_module.interns,
)?;
self.code_lines = CodeLines::from_str(&nodes::mark_nodes_to_string(
&self.markup_ids,
&self.mark_node_pool,
));
self.grid_node_map = GridNodeMap::default();
let mut line_nr = 0;
let mut col_nr = 0;
for mark_node_id in &self.markup_ids {
// for debugging:
//println!("{}", tree_as_string(*mark_node_id, &mark_node_pool));
@ -1198,7 +1196,7 @@ pub fn handle_new_char_diff_mark_nodes_prev_is_expr(
// updates the ed_model based on the char the user just typed if the result would be syntactically correct.
pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
//dbg!("{}", ed_model.module.ast.ast_to_string(ed_model.module.env.pool));
let input_outcome = match received_char {
'\u{e000}'..='\u{f8ff}' // http://www.unicode.org/faq/private_use.html
| '\u{f0000}'..='\u{ffffd}' // ^
@ -1703,89 +1701,29 @@ pub mod test_ed_update {
fn test_record() -> Result<(), String> {
assert_insert_in_def_nls(ovec!["{ ┃ }"], '{')?;
assert_insert_nls(ovec!["val = { ┃ }"], ovec!["val = { a┃ }"], 'a')?;
assert_insert_nls(
ovec!["val = { a┃ }"],
ovec!["val = { ab┃ }"],
'b',
)?;
assert_insert_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a1┃ }"],
'1',
)?;
assert_insert_nls(
ovec!["val = { a1┃ }"],
ovec!["val = { a1z┃ }"],
'z',
)?;
assert_insert_nls(
ovec!["val = { a1┃ }"],
ovec!["val = { a15┃ }"],
'5',
)?;
assert_insert_nls(
ovec!["val = { ab┃ }"],
ovec!["val = { abc┃ }"],
'c',
)?;
assert_insert_nls(
ovec!["val = { ┃abc }"],
ovec!["val = { z┃abc }"],
'z',
)?;
assert_insert_nls(
ovec!["val = { a┃b }"],
ovec!["val = { az┃b }"],
'z',
)?;
assert_insert_nls(
ovec!["val = { a┃b }"],
ovec!["val = { a9┃b }"],
'9',
)?;
assert_insert_nls(ovec!["val = { a┃ }"], ovec!["val = { ab┃ }"], 'b')?;
assert_insert_nls(ovec!["val = { a┃ }"], ovec!["val = { a1┃ }"], '1')?;
assert_insert_nls(ovec!["val = { a1┃ }"], ovec!["val = { a1z┃ }"], 'z')?;
assert_insert_nls(ovec!["val = { a1┃ }"], ovec!["val = { a15┃ }"], '5')?;
assert_insert_nls(ovec!["val = { ab┃ }"], ovec!["val = { abc┃ }"], 'c')?;
assert_insert_nls(ovec!["val = { ┃abc }"], ovec!["val = { z┃abc }"], 'z')?;
assert_insert_nls(ovec!["val = { a┃b }"], ovec!["val = { az┃b }"], 'z')?;
assert_insert_nls(ovec!["val = { a┃b }"], ovec!["val = { a9┃b }"], '9')?;
assert_insert_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a: ┃ }"],
':',
)?;
assert_insert_nls(
ovec!["val = { abc┃ }"],
ovec!["val = { abc: ┃ }"],
':',
)?;
assert_insert_nls(
ovec!["val = { aBc┃ }"],
ovec!["val = { aBc: ┃ }"],
':',
)?;
assert_insert_nls(ovec!["val = { a┃ }"], ovec!["val = { a: ┃ }"], ':')?;
assert_insert_nls(ovec!["val = { abc┃ }"], ovec!["val = { abc: ┃ }"], ':')?;
assert_insert_nls(ovec!["val = { aBc┃ }"], ovec!["val = { aBc: ┃ }"], ':')?;
assert_insert_seq_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a: \"\" }"],
":\"",
)?;
assert_insert_seq_nls(ovec!["val = { a┃ }"], ovec!["val = { a: \"\" }"], ":\"")?;
assert_insert_seq_nls(
ovec!["val = { abc┃ }"],
ovec!["val = { abc: \"\" }"],
":\"",
)?;
assert_insert_seq_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a: 0┃ }"],
":0",
)?;
assert_insert_seq_nls(
ovec!["val = { abc┃ }"],
ovec!["val = { abc: 9┃ }"],
":9",
)?;
assert_insert_seq_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a: 1000┃ }"],
":1000",
)?;
assert_insert_seq_nls(ovec!["val = { a┃ }"], ovec!["val = { a: 0┃ }"], ":0")?;
assert_insert_seq_nls(ovec!["val = { abc┃ }"], ovec!["val = { abc: 9┃ }"], ":9")?;
assert_insert_seq_nls(ovec!["val = { a┃ }"], ovec!["val = { a: 1000┃ }"], ":1000")?;
assert_insert_seq_nls(
ovec!["val = { abc┃ }"],
ovec!["val = { abc: 98761┃ }"],
@ -1938,16 +1876,8 @@ pub mod test_ed_update {
#[test]
fn test_nested_record() -> Result<(), String> {
assert_insert_seq_nls(
ovec!["val = { a┃ }"],
ovec!["val = { a: { ┃ } }"],
":{",
)?;
assert_insert_seq_nls(
ovec!["val = { abc┃ }"],
ovec!["val = { abc: { ┃ } }"],
":{",
)?;
assert_insert_seq_nls(ovec!["val = { a┃ }"], ovec!["val = { a: { ┃ } }"], ":{")?;
assert_insert_seq_nls(ovec!["val = { abc┃ }"], ovec!["val = { abc: { ┃ } }"], ":{")?;
assert_insert_seq_nls(
ovec!["val = { camelCase┃ }"],
ovec!["val = { camelCase: { ┃ } }"],
@ -2239,14 +2169,8 @@ pub mod test_ed_update {
assert_insert_seq_ignore_nls(ovec!["val = ┃{ a: { } }"], IGNORE_NO_LTR)?;
assert_insert_seq_ignore_nls(ovec!["val = { ┃a: { } }"], "1")?;
assert_insert_seq_ignore_nls(
ovec!["val = { camelCaseB1: {┃ z15a } }"],
IGNORE_NO_LTR,
)?;
assert_insert_seq_ignore_nls(
ovec!["val = { camelCaseB1: ┃{ z15a } }"],
IGNORE_NO_LTR,
)?;
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: {┃ z15a } }"], IGNORE_NO_LTR)?;
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: ┃{ z15a } }"], IGNORE_NO_LTR)?;
assert_insert_seq_nls(
ovec!["val = { camelCaseB1: { z15a┃ } }"],
ovec!["val = { camelCaseB1: { z15a:┃ } }"],
@ -2257,18 +2181,9 @@ pub mod test_ed_update {
ovec!["val = { camelCaseB1: { z15a: ┃ } }"],
&concat_strings(":🡲", IGNORE_CHARS),
)?;
assert_insert_seq_ignore_nls(
ovec!["val = { camelCaseB1:┃ { z15a } }"],
IGNORE_NO_LTR,
)?;
assert_insert_seq_ignore_nls(
ovec!["val = {┃ camelCaseB1: { z15a } }"],
IGNORE_NO_LTR,
)?;
assert_insert_seq_ignore_nls(
ovec!["val = ┃{ camelCaseB1: { z15a } }"],
IGNORE_NO_LTR,
)?;
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1:┃ { z15a } }"], IGNORE_NO_LTR)?;
assert_insert_seq_ignore_nls(ovec!["val = {┃ camelCaseB1: { z15a } }"], IGNORE_NO_LTR)?;
assert_insert_seq_ignore_nls(ovec!["val = ┃{ camelCaseB1: { z15a } }"], IGNORE_NO_LTR)?;
assert_insert_seq_ignore_nls(ovec!["val = { ┃camelCaseB1: { z15a } }"], "1")?;
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { ┃z15a } }"], "1")?;

View file

@ -15,10 +15,10 @@ use crate::ui::text::lines::SelectableLines;
// digit_char should be verified to be a digit before calling this function
pub fn start_new_int(ed_model: &mut EdModel, digit_char: &char) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
curr_mark_node_id:_,
old_caret_pos: _,
curr_mark_node_id: _,
curr_mark_node,
parent_id_opt:_,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;

View file

@ -11,10 +11,10 @@ use crate::editor::mvc::ed_update::NodeContext;
pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
curr_mark_node_id:_,
old_caret_pos: _,
curr_mark_node_id: _,
curr_mark_node,
parent_id_opt:_,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;
@ -29,7 +29,7 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<
.module
.env
.ident_ids
.add(val_name_string.clone().into());
.add(val_name_string.into());
let var_symbol = Symbol::new(ed_model.module.env.home, ident_id);
let body = Expr2::Var(var_symbol);
let body_id = ed_model.module.env.pool.add(body);

View file

@ -1,4 +1,4 @@
use roc_ast::lang::core::ast::{ast_node_to_string};
use roc_ast::lang::core::ast::ast_node_to_string;
use roc_ast::lang::core::expr::expr2::{Expr2, ExprId};
use roc_ast::mem_pool::pool_vec::PoolVec;
use roc_code_markup::markup::nodes::{self};
@ -13,10 +13,10 @@ use crate::editor::mvc::ed_update::NodeContext;
pub fn start_new_list(ed_model: &mut EdModel) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
curr_mark_node_id:_,
old_caret_pos: _,
curr_mark_node_id: _,
curr_mark_node,
parent_id_opt:_,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;
@ -49,7 +49,7 @@ pub fn add_blank_child(
ed_model: &mut EdModel,
) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
old_caret_pos: _,
curr_mark_node_id,
curr_mark_node: _,
parent_id_opt,

View file

@ -15,18 +15,18 @@ use roc_ast::mem_pool::pool_str::PoolStr;
use roc_ast::mem_pool::pool_vec::PoolVec;
use roc_code_markup::markup::attribute::Attributes;
use roc_code_markup::markup::nodes;
use roc_code_markup::markup::nodes::COLON;
use roc_code_markup::markup::nodes::MarkupNode;
use roc_code_markup::markup::nodes::COLON;
use roc_code_markup::slow_pool::MarkNodeId;
use roc_code_markup::syntax_highlight::HighlightStyle;
use snafu::OptionExt;
pub fn start_new_record(ed_model: &mut EdModel) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
curr_mark_node_id:_,
old_caret_pos: _,
curr_mark_node_id: _,
curr_mark_node,
parent_id_opt:_,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;
@ -140,77 +140,75 @@ pub fn update_record_colon(
) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos,
curr_mark_node_id:_,
curr_mark_node:_,
parent_id_opt:_,
curr_mark_node_id: _,
curr_mark_node: _,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;
let curr_ast_node = ed_model.module.env.pool.get(ast_node_id.to_expr_id()?);
let curr_ast_node = ed_model.module.env.pool.get(ast_node_id.to_expr_id()?);
let prev_mark_node_id_opt = ed_model.get_prev_mark_node_id()?;
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
let prev_mark_node_id_opt = ed_model.get_prev_mark_node_id()?;
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
match prev_mark_node.get_ast_node_id() {
ASTNodeId::ADefId(_) => Ok(InputOutcome::Ignored),
ASTNodeId::AExprId(prev_expr_id) => {
let prev_expr = ed_model.module.env.pool.get(prev_expr_id);
match prev_mark_node.get_ast_node_id() {
ASTNodeId::ADefId(_) => Ok(InputOutcome::Ignored),
ASTNodeId::AExprId(prev_expr_id) => {
let prev_expr = ed_model.module.env.pool.get(prev_expr_id);
// current and prev node should always point to record when in valid position to add ':'
if matches!(prev_expr, Expr2::Record { .. })
&& matches!(curr_ast_node, Expr2::Record { .. })
{
// current and prev node should always point to record when in valid position to add ':'
if matches!(prev_expr, Expr2::Record { .. })
&& matches!(curr_ast_node, Expr2::Record { .. })
{
let ast_node_ref = ed_model.module.env.pool.get(record_ast_node_id);
let ast_node_ref = ed_model.module.env.pool.get(record_ast_node_id);
match ast_node_ref {
Expr2::Record {
record_var: _,
fields,
} => {
if ed_model.node_exists_at_caret() {
let next_mark_node_id =
ed_model.grid_node_map.get_id_at_row_col(old_caret_pos)?;
let next_mark_node = ed_model.mark_node_pool.get(next_mark_node_id);
if next_mark_node.get_content() == nodes::RIGHT_ACCOLADE {
// update AST node
let new_field_val = Expr2::Blank;
let new_field_val_id =
ed_model.module.env.pool.add(new_field_val);
match ast_node_ref {
Expr2::Record {
record_var: _,
fields,
} => {
if ed_model.node_exists_at_caret() {
let next_mark_node_id =
ed_model.grid_node_map.get_id_at_row_col(old_caret_pos)?;
let next_mark_node =
ed_model.mark_node_pool.get(next_mark_node_id);
if next_mark_node.get_content() == nodes::RIGHT_ACCOLADE {
// update AST node
let new_field_val = Expr2::Blank;
let new_field_val_id =
ed_model.module.env.pool.add(new_field_val);
let first_field_mut = fields
.iter_mut(ed_model.module.env.pool)
.next()
.with_context(|| RecordWithoutFields {})?;
let first_field_mut = fields
.iter_mut(ed_model.module.env.pool)
.next()
.with_context(|| RecordWithoutFields {})?;
*first_field_mut = RecordField::LabeledValue(
*first_field_mut.get_record_field_pool_str(),
*first_field_mut.get_record_field_var(),
new_field_val_id,
);
*first_field_mut = RecordField::LabeledValue(
*first_field_mut.get_record_field_pool_str(),
*first_field_mut.get_record_field_var(),
new_field_val_id,
);
// update caret
ed_model.simple_move_carets_right(COLON.len());
// update caret
ed_model.simple_move_carets_right(COLON.len());
Ok(InputOutcome::Accepted)
} else {
Ok(InputOutcome::Ignored)
}
Ok(InputOutcome::Accepted)
} else {
Ok(InputOutcome::Ignored)
}
} else {
Ok(InputOutcome::Ignored)
}
_ => Ok(InputOutcome::Ignored),
}
} else {
Ok(InputOutcome::Ignored)
_ => Ok(InputOutcome::Ignored),
}
} else {
Ok(InputOutcome::Ignored)
}
}
} else {
Ok(InputOutcome::Ignored)
}
} else {
Ok(InputOutcome::Ignored)
}
}
pub fn update_record_field(

View file

@ -76,7 +76,6 @@ pub fn update_string(new_char: char, ed_model: &mut EdModel) -> EdResult<InputOu
.get_offset_to_node_id(old_caret_pos, curr_mark_node_id)?;
if node_caret_offset != 0 && node_caret_offset < content_str.len() {
// update ast
update_str_expr(
ast_node_id.to_expr_id()?,
@ -96,10 +95,10 @@ pub fn update_string(new_char: char, ed_model: &mut EdModel) -> EdResult<InputOu
pub fn start_new_string(ed_model: &mut EdModel) -> EdResult<InputOutcome> {
let NodeContext {
old_caret_pos:_,
curr_mark_node_id:_,
old_caret_pos: _,
curr_mark_node_id: _,
curr_mark_node,
parent_id_opt:_,
parent_id_opt: _,
ast_node_id,
} = get_node_context(ed_model)?;

View file

@ -1,7 +1,5 @@
use roc_ast::lang::core::{def::def2::Def2, expr::expr2::Expr2};
use roc_code_markup::{
slow_pool::MarkNodeId,
};
use roc_code_markup::slow_pool::MarkNodeId;
use crate::{
editor::ed_error::{EdResult, FailedToUpdateIdentIdName, KeyNotFound},