diff --git a/src/builtin_parser.rs b/src/builtin_parser.rs index c7bc222..83d79ee 100644 --- a/src/builtin_parser.rs +++ b/src/builtin_parser.rs @@ -63,8 +63,6 @@ impl CommandParser for BuiltinCommandParser { let ast = parse(&mut tokens, &environment); world.insert_non_send_resource(environment); - dbg!(&ast); - match ast { Ok(ast) => { runner::run(ast, world); diff --git a/src/builtin_parser/runner.rs b/src/builtin_parser/runner.rs index 6ea8fa0..a1ca5ef 100644 --- a/src/builtin_parser/runner.rs +++ b/src/builtin_parser/runner.rs @@ -108,7 +108,9 @@ pub fn run(ast: Ast, world: &mut World) { match value { Ok(Value::None) => {} Ok(value) => match value.try_format(span, world, ®istrations) { - Ok(value) => info!(name: COMMAND_RESULT_NAME, "{value}"), + Ok(value) => { + info!(name: COMMAND_RESULT_NAME, "{}{value}", crate::ui::COMMAND_RESULT_PREFIX) + } Err(err) => error!("{err:?}"), }, Err(err) => { @@ -520,17 +522,31 @@ fn eval_path( } } Expression::Dereference(inner) => { - if let Expression::Variable(variable) = inner.value { - let value = environment.get(&variable, inner.span)?; - if let Value::Reference(ref reference) = &*value.borrow_inner().borrow() { - Ok(expr.span.wrap(Path::Variable(reference.clone()))) - } else { - Err(RunError::CouldntDereferenceValue( - expr.span.wrap(value.borrow_inner().borrow().kind()), - )) + let path = eval_path( + *inner, + EvalParams { + world, + environment, + registrations, + }, + )?; + match path.value { + Path::Variable(value) => { + let strong = value + .upgrade() + .ok_or(RunError::ReferenceToMovedData(path.span))?; + let borrow = strong.borrow(); + + if let Value::Reference(ref reference) = &*borrow { + Ok(expr.span.wrap(Path::Variable(reference.clone()))) + } else { + Err(RunError::CouldntDereferenceValue( + expr.span.wrap(borrow.kind()), + )) + } } - } else { - todo_error!() + Path::NewVariable(_) => todo_error!(), + Path::Resource(_) => todo_error!(), } } expr => todo_error!("{expr:#?}"), diff --git a/src/ui.rs b/src/ui.rs index 3686d25..144b5ed 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -220,17 +220,19 @@ fn format_line( *command_index += 1; + let message_stripped = message + .strip_prefix(COMMAND_MESSAGE_PREFIX) + .unwrap_or(message); + text.append(COMMAND_MESSAGE_PREFIX, 0.0, config.theme.format_dark()); // TODO: Handle more than just the first element if let Some(hint) = hints.first() { - const PREFIX_LEN: usize = COMMAND_MESSAGE_PREFIX.len(); - text.append( - &message[..hint.span.start + PREFIX_LEN], + &message_stripped[..hint.span.start], 0., config.theme.format_text(), ); text.append( - &message[hint.span.start + PREFIX_LEN..hint.span.end + PREFIX_LEN], + &message_stripped[hint.span.start..hint.span.end], 0., TextFormat { underline: Stroke::new(1.0, config.theme.error.to_color32()), @@ -238,18 +240,24 @@ fn format_line( }, ); text.append( - &message[hint.span.end + PREFIX_LEN..], + &message_stripped[hint.span.end..], 0., config.theme.format_text(), ); return text; } - text.append(message.as_str(), 0.0, config.theme.format_text()); + text.append(message_stripped, 0.0, config.theme.format_text()); text } COMMAND_RESULT_NAME => { text.append(COMMAND_RESULT_PREFIX, 0.0, config.theme.format_dark()); - text.append(message.as_str(), 0.0, config.theme.format_text()); + text.append( + message + .strip_prefix(COMMAND_RESULT_PREFIX) + .unwrap_or(message), + 0.0, + config.theme.format_text(), + ); text } _ => {