From f02bfe7b349ee3ce75831bfb2d27d18dac9edc76 Mon Sep 17 00:00:00 2001 From: servostar Date: Fri, 15 Sep 2023 23:46:46 +0200 Subject: [PATCH] diagnostics no longer copies entire source string --- src/parser/data.rs | 8 +++++++- src/token/mod.rs | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/parser/data.rs b/src/parser/data.rs index 5ab9b62..5925742 100644 --- a/src/parser/data.rs +++ b/src/parser/data.rs @@ -66,11 +66,17 @@ impl Diagnostics { let info: DebugInfo = source.clone().into(); + let context = self.source.get(&info.origin).unwrap() + .lines() + .nth(info.line) + .unwrap() + .trim(); + self.err = Some(DebugNotice { info, msg: message, ext: ext.into(), - source: self.source.get(&info.origin).unwrap().clone(), + source: context.to_string(), }); } diff --git a/src/token/mod.rs b/src/token/mod.rs index 301a97b..5535b95 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -446,10 +446,6 @@ impl std::fmt::Display for DebugNotice { f.write_fmt(format_args!( " somewhere in here:\n --> `{}`\n", self.source - .lines() - .nth(self.info.line) - .unwrap() - .trim() .bold() .bright_white() ))