1
0

Add simple logging

This commit is contained in:
Jeff 2024-01-13 13:30:50 -05:00
parent 9538caf330
commit 3e1765e810
4 changed files with 10 additions and 7 deletions

View File

@ -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"

View File

@ -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() {

View File

@ -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<Self::Hint> {
fn hint(&self, line: &str, pos: usize, _ctx: &Context) -> Option<Self::Hint> {
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<DustReadline, DefaultHistory> = 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}")
}
}

View File

@ -65,6 +65,8 @@ impl Map {
}
pub fn set(&self, key: String, value: Value) -> Result<Option<(Value, Type)>> {
log::info!("Setting variable {key} = {value}");
let value_type = value.r#type();
let previous = self
.variables