From 9166af8616851a2bb4b8095adf204b08d4400708 Mon Sep 17 00:00:00 2001 From: Martin Verzilli Date: Tue, 17 Oct 2023 13:01:17 +0200 Subject: [PATCH] feat(debugger): highlight current src code loc (#3174) --- Cargo.lock | 1 + tooling/debugger/Cargo.toml | 3 ++- tooling/debugger/src/lib.rs | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21a8b3d8f27..5601dbae53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2545,6 +2545,7 @@ dependencies = [ "easy-repl", "nargo", "noirc_printable_type", + "owo-colors", "thiserror", ] diff --git a/tooling/debugger/Cargo.toml b/tooling/debugger/Cargo.toml index 5b8248345a0..e01abd9ac61 100644 --- a/tooling/debugger/Cargo.toml +++ b/tooling/debugger/Cargo.toml @@ -13,4 +13,5 @@ acvm.workspace = true nargo.workspace = true noirc_printable_type.workspace = true thiserror.workspace = true -easy-repl = "0.2.1" \ No newline at end of file +easy-repl = "0.2.1" +owo-colors = "3" \ No newline at end of file diff --git a/tooling/debugger/src/lib.rs b/tooling/debugger/src/lib.rs index 2df5eb74206..f8e9db19234 100644 --- a/tooling/debugger/src/lib.rs +++ b/tooling/debugger/src/lib.rs @@ -12,6 +12,8 @@ use nargo::ops::ForeignCallExecutor; use easy_repl::{command, CommandStatus, Critical, Repl}; use std::cell::{Cell, RefCell}; +use owo_colors::OwoColorize; + enum SolveResult { Done, Ok, @@ -85,7 +87,12 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { let start = loc.span.start() as usize; let end = loc.span.end() as usize; println!("At {}:{start}-{end}", file.path.as_path().display()); - println!("\n{}\n", &source[start..end]); + println!( + "\n{}{}{}\n", + &source[0..start].to_string().dimmed(), + &source[start..end], + &source[end..].to_string().dimmed(), + ); } } }