mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
merge fixes
This commit is contained in:
parent
169520f956
commit
fe1a2c35ff
@ -553,24 +553,26 @@ impl IdentIds {
|
|||||||
|
|
||||||
pub fn update_key(
|
pub fn update_key(
|
||||||
&mut self,
|
&mut self,
|
||||||
old_ident_name: InlinableString,
|
old_ident_name: &str,
|
||||||
new_ident_name: InlinableString,
|
new_ident_name: &str,
|
||||||
) -> Result<IdentId, String> {
|
) -> Result<IdentId, String> {
|
||||||
let ident_id_ref_opt = self.by_ident.get(&old_ident_name);
|
let old_ident: Ident = old_ident_name.into();
|
||||||
|
|
||||||
|
let ident_id_ref_opt = self.by_ident.get(&old_ident);
|
||||||
|
|
||||||
match ident_id_ref_opt {
|
match ident_id_ref_opt {
|
||||||
Some(ident_id_ref) => {
|
Some(ident_id_ref) => {
|
||||||
let ident_id = (*ident_id_ref).clone();
|
let ident_id = (*ident_id_ref).clone();
|
||||||
|
|
||||||
self.by_ident.remove(&old_ident_name);
|
self.by_ident.remove(&old_ident);
|
||||||
self.by_ident.insert(new_ident_name.clone(), ident_id);
|
self.by_ident.insert(new_ident_name.into(), ident_id);
|
||||||
|
|
||||||
let by_id = &mut self.by_id;
|
let by_id = &mut self.by_id;
|
||||||
let key_index_opt = by_id.iter().position(|x| *x == old_ident_name);
|
let key_index_opt = by_id.iter().position(|x| *x == old_ident);
|
||||||
|
|
||||||
if let Some(key_index) = key_index_opt {
|
if let Some(key_index) = key_index_opt {
|
||||||
if let Some(vec_elt) = by_id.get_mut(key_index) {
|
if let Some(vec_elt) = by_id.get_mut(key_index) {
|
||||||
*vec_elt = new_ident_name;
|
*vec_elt = new_ident_name.into();
|
||||||
} else {
|
} else {
|
||||||
// we get the index from by_id so unless there is a bug in the rust std lib, this is unreachable
|
// we get the index from by_id so unless there is a bug in the rust std lib, this is unreachable
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
@ -23,10 +23,8 @@ use crate::lang::pattern::get_identifier_string;
|
|||||||
use crate::lang::{
|
use crate::lang::{
|
||||||
ast::Expr2,
|
ast::Expr2,
|
||||||
expr::Env,
|
expr::Env,
|
||||||
pool::{NodeId, PoolStr},
|
pool::{PoolStr},
|
||||||
};
|
};
|
||||||
use crate::lang::ast::{Expr2, ExprId, RecordField};
|
|
||||||
use crate::lang::{expr::Env, pool::PoolStr};
|
|
||||||
use crate::ui::util::slice_get;
|
use crate::ui::util::slice_get;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_module::symbol::Interns;
|
use roc_module::symbol::Interns;
|
||||||
|
@ -7,11 +7,9 @@ use crate::editor::{
|
|||||||
ed_error::{EdResult, EmptyCodeString, MissingParent, NoNodeAtCaretPosition},
|
ed_error::{EdResult, EmptyCodeString, MissingParent, NoNodeAtCaretPosition},
|
||||||
};
|
};
|
||||||
use crate::graphics::primitives::rect::Rect;
|
use crate::graphics::primitives::rect::Rect;
|
||||||
|
use crate::lang::ast::ExprId;
|
||||||
use crate::lang::expr::Env;
|
use crate::lang::expr::Env;
|
||||||
use crate::lang::parse::AST;
|
use crate::lang::parse::AST;
|
||||||
use crate::lang::pool::NodeId;
|
|
||||||
use crate::lang::ast::{Expr2, ExprId};
|
|
||||||
use crate::lang::expr::{str_to_expr2, Env};
|
|
||||||
use crate::lang::pool::PoolStr;
|
use crate::lang::pool::PoolStr;
|
||||||
use crate::ui::text::caret_w_select::CaretWSelect;
|
use crate::ui::text::caret_w_select::CaretWSelect;
|
||||||
use crate::ui::text::lines::SelectableLines;
|
use crate::ui::text::lines::SelectableLines;
|
||||||
@ -56,11 +54,7 @@ pub fn init_model<'a>(
|
|||||||
loaded_module: LoadedModule,
|
loaded_module: LoadedModule,
|
||||||
code_arena: &'a Bump,
|
code_arena: &'a Bump,
|
||||||
) -> EdResult<EdModel<'a>> {
|
) -> EdResult<EdModel<'a>> {
|
||||||
<<<<<<< HEAD
|
|
||||||
let mut module = EdModule::new(&code_str, env, &code_arena)?;
|
let mut module = EdModule::new(&code_str, env, &code_arena)?;
|
||||||
=======
|
|
||||||
let mut module = EdModule::new(code_str, env, code_arena)?;
|
|
||||||
>>>>>>> 1348ec433b56d0919fa3c25ce2fd8d879d99f681
|
|
||||||
|
|
||||||
let mut markup_node_pool = SlowPool::new();
|
let mut markup_node_pool = SlowPool::new();
|
||||||
|
|
||||||
@ -150,11 +144,7 @@ impl<'a> EdModel<'a> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EdModule<'a> {
|
pub struct EdModule<'a> {
|
||||||
pub env: Env<'a>,
|
pub env: Env<'a>,
|
||||||
<<<<<<< HEAD
|
|
||||||
pub ast: AST,
|
pub ast: AST,
|
||||||
=======
|
|
||||||
pub ast_root_id: ExprId,
|
|
||||||
>>>>>>> 1348ec433b56d0919fa3c25ce2fd8d879d99f681
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
@ -165,24 +155,9 @@ impl<'a> EdModule<'a> {
|
|||||||
if !code_str.is_empty() {
|
if !code_str.is_empty() {
|
||||||
let parse_res = AST::parse_from_string(code_str, &mut env, ast_arena);
|
let parse_res = AST::parse_from_string(code_str, &mut env, ast_arena);
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
match parse_res {
|
match parse_res {
|
||||||
Ok(ast) => Ok(EdModule { env, ast }),
|
Ok(ast) => Ok(EdModule { env, ast }),
|
||||||
Err(err) => SrcParseError {
|
Err(err) => SrcParseError {
|
||||||
=======
|
|
||||||
let expr2_result = str_to_expr2(ast_arena, code_str, &mut env, &mut scope, region);
|
|
||||||
|
|
||||||
match expr2_result {
|
|
||||||
Ok((expr2, _output)) => {
|
|
||||||
let ast_root_id = env.pool.add(expr2);
|
|
||||||
|
|
||||||
// for debugging
|
|
||||||
// dbg!(expr2_to_string(ast_root_id, env.pool));
|
|
||||||
|
|
||||||
Ok(EdModule { env, ast_root_id })
|
|
||||||
}
|
|
||||||
Err(err) => Err(ParseError {
|
|
||||||
>>>>>>> 1348ec433b56d0919fa3c25ce2fd8d879d99f681
|
|
||||||
syntax_err: format!("{:?}", err),
|
syntax_err: format!("{:?}", err),
|
||||||
}
|
}
|
||||||
.fail(),
|
.fail(),
|
||||||
@ -239,17 +214,7 @@ pub mod test_ed_model {
|
|||||||
exposed_ident_ids,
|
exposed_ident_ids,
|
||||||
);
|
);
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
ed_model::init_model(code_str, file_path, env, loaded_module, code_arena)
|
ed_model::init_model(code_str, file_path, env, loaded_module, code_arena)
|
||||||
=======
|
|
||||||
ed_model::init_model(
|
|
||||||
code_str,
|
|
||||||
file_path,
|
|
||||||
env,
|
|
||||||
&ed_model_refs.interns,
|
|
||||||
&ed_model_refs.code_arena,
|
|
||||||
)
|
|
||||||
>>>>>>> 1348ec433b56d0919fa3c25ce2fd8d879d99f681
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EdModelRefs {
|
pub struct EdModelRefs {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use inlinable_string::InlinableString;
|
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
|
|
||||||
use crate::editor::ed_error::EdResult;
|
use crate::editor::ed_error::EdResult;
|
||||||
@ -16,7 +15,6 @@ use crate::lang::ast::{Expr2, ValueDef};
|
|||||||
use crate::lang::pattern::Pattern2;
|
use crate::lang::pattern::Pattern2;
|
||||||
use crate::lang::pool::NodeId;
|
use crate::lang::pool::NodeId;
|
||||||
use crate::ui::text::lines::SelectableLines;
|
use crate::ui::text::lines::SelectableLines;
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<InputOutcome> {
|
pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<InputOutcome> {
|
||||||
let NodeContext {
|
let NodeContext {
|
||||||
@ -34,8 +32,7 @@ pub fn start_new_let_value(ed_model: &mut EdModel, new_char: &char) -> EdResult<
|
|||||||
let val_expr2_node = Expr2::Blank;
|
let val_expr2_node = Expr2::Blank;
|
||||||
let val_expr_id = ed_model.module.env.pool.add(val_expr2_node);
|
let val_expr_id = ed_model.module.env.pool.add(val_expr2_node);
|
||||||
|
|
||||||
let ident_string = InlinableString::from_iter(val_name_string.chars());
|
let ident_id = ed_model.module.env.ident_ids.add(val_name_string.clone().into());
|
||||||
let ident_id = ed_model.module.env.ident_ids.add(ident_string);
|
|
||||||
let var_symbol = Symbol::new(ed_model.module.env.home, ident_id);
|
let var_symbol = Symbol::new(ed_model.module.env.home, ident_id);
|
||||||
let body = Expr2::Var(var_symbol);
|
let body = Expr2::Var(var_symbol);
|
||||||
let body_id = ed_model.module.env.pool.add(body);
|
let body_id = ed_model.module.env.pool.add(body);
|
||||||
@ -117,7 +114,6 @@ pub fn update_let_value(
|
|||||||
let content_str_mut = val_name_mn_mut.get_content_mut()?;
|
let content_str_mut = val_name_mn_mut.get_content_mut()?;
|
||||||
|
|
||||||
let old_val_name = content_str_mut.clone();
|
let old_val_name = content_str_mut.clone();
|
||||||
let old_val_ident_string = InlinableString::from_iter(old_val_name.chars());
|
|
||||||
|
|
||||||
let node_caret_offset = ed_model
|
let node_caret_offset = ed_model
|
||||||
.grid_node_map
|
.grid_node_map
|
||||||
@ -130,13 +126,12 @@ pub fn update_let_value(
|
|||||||
let value_def = ed_model.module.env.pool.get(def_id);
|
let value_def = ed_model.module.env.pool.get(def_id);
|
||||||
let value_ident_pattern_id = value_def.get_pattern_id();
|
let value_ident_pattern_id = value_def.get_pattern_id();
|
||||||
|
|
||||||
let ident_string = InlinableString::from_iter(content_str_mut.chars());
|
|
||||||
// TODO no unwrap
|
// TODO no unwrap
|
||||||
let ident_id = ed_model
|
let ident_id = ed_model
|
||||||
.module
|
.module
|
||||||
.env
|
.env
|
||||||
.ident_ids
|
.ident_ids
|
||||||
.update_key(old_val_ident_string, ident_string)
|
.update_key(&old_val_name, content_str_mut)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let new_var_symbol = Symbol::new(ed_model.module.env.home, ident_id);
|
let new_var_symbol = Symbol::new(ed_model.module.env.home, ident_id);
|
||||||
|
@ -1045,9 +1045,7 @@ pub fn to_expr2_from_def<'a>(
|
|||||||
|
|
||||||
let value_def_id = env.pool.add(value_def);
|
let value_def_id = env.pool.add(value_def);
|
||||||
|
|
||||||
let ident_string =
|
let ident_id = env.ident_ids.add(str_ref.into());
|
||||||
inlinable_string::InlinableString::from_iter(str_ref.chars());
|
|
||||||
let ident_id = env.ident_ids.add(ident_string);
|
|
||||||
let var_symbol = Symbol::new(env.home, ident_id);
|
let var_symbol = Symbol::new(env.home, ident_id);
|
||||||
let body = Expr2::Var(var_symbol);
|
let body = Expr2::Var(var_symbol);
|
||||||
let body_id = env.pool.add(body);
|
let body_id = env.pool.add(body);
|
||||||
|
@ -485,7 +485,7 @@ pub fn symbols_from_pattern(pool: &Pool, initial: &Pattern2) -> Vec<Symbol> {
|
|||||||
|
|
||||||
pub fn get_identifier_string(pattern: &Pattern2, interns: &Interns) -> EdResult<String> {
|
pub fn get_identifier_string(pattern: &Pattern2, interns: &Interns) -> EdResult<String> {
|
||||||
match pattern {
|
match pattern {
|
||||||
Pattern2::Identifier(symbol) => Ok(symbol.ident_string(interns).to_string()),
|
Pattern2::Identifier(symbol) => Ok(symbol.ident_str(interns).to_string()),
|
||||||
other => UnexpectedPattern2Variant {
|
other => UnexpectedPattern2Variant {
|
||||||
required_pattern2: "Identifier".to_string(),
|
required_pattern2: "Identifier".to_string(),
|
||||||
encountered_pattern2: format!("{:?}", other),
|
encountered_pattern2: format!("{:?}", other),
|
||||||
|
Loading…
Reference in New Issue
Block a user