From 3e1765e8102f78a7349b4728233d895def94d618 Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 13 Jan 2024 13:30:50 -0500 Subject: [PATCH] Add simple logging --- Cargo.toml | 1 + src/error.rs | 2 ++ src/main.rs | 12 +++++------- src/value/map.rs | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5c6c07d..b331803 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ toml = "0.8.1" tree-sitter = "0.20.10" egui_extras = "0.24.2" enum-iterator = "1.4.1" +env_logger = "0.10" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger = "0.10" diff --git a/src/error.rs b/src/error.rs index 7efdcc4..73cb9a8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -196,6 +196,8 @@ impl Error { } pub fn expect_syntax_node(source: &str, expected: &str, actual: Node) -> Result<()> { + log::info!("Converting {} to abstract node", actual.kind()); + if expected == actual.kind() { Ok(()) } else if actual.is_error() { diff --git a/src/main.rs b/src/main.rs index 008c33a..be91620 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,8 @@ pub enum CliCommand { } fn main() { + env_logger::init(); + let args = Args::parse(); if args.path.is_none() && args.command.is_none() { @@ -152,7 +154,7 @@ impl ToolHint { impl Hinter for DustReadline { type Hint = ToolHint; - fn hint(&self, line: &str, pos: usize, _ctx: &Context<'_>) -> Option { + fn hint(&self, line: &str, pos: usize, _ctx: &Context) -> Option { if line.is_empty() || pos < line.len() { return None; } @@ -168,7 +170,7 @@ impl Hinter for DustReadline { } impl Highlighter for DustReadline { - fn highlight_hint<'h>(&self, hint: &'h str) -> std::borrow::Cow<'h, str> { + fn highlight_hint<'h>(&self, hint: &'h str) -> Cow<'h, str> { let highlighted = ansi_term::Colour::Red.paint(hint).to_string(); Cow::Owned(highlighted) @@ -179,7 +181,6 @@ fn run_cli_shell() { let context = Map::new(); let mut interpreter = Interpreter::new(context); let mut rl: Editor = Editor::new().unwrap(); - let mut input = String::new(); rl.set_helper(Some(DustReadline::new())); @@ -191,10 +192,8 @@ fn run_cli_shell() { let readline = rl.readline("* "); match readline { Ok(line) => { - let line = line.as_str(); + let input = line.to_string(); - input.push('\n'); - input.push_str(line); rl.add_history_entry(line).unwrap(); let eval_result = interpreter.run(&input); @@ -202,7 +201,6 @@ fn run_cli_shell() { match eval_result { Ok(value) => println!("{value}"), Err(error) => { - input = input.trim_end_matches(line).to_string(); eprintln!("{error}") } } diff --git a/src/value/map.rs b/src/value/map.rs index ed2bed0..c7c71ec 100644 --- a/src/value/map.rs +++ b/src/value/map.rs @@ -65,6 +65,8 @@ impl Map { } pub fn set(&self, key: String, value: Value) -> Result> { + log::info!("Setting variable {key} = {value}"); + let value_type = value.r#type(); let previous = self .variables