From 02aea07807a5ca470cf57aabc23a4b563b3d1b82 Mon Sep 17 00:00:00 2001 From: Ivan Kalinin Date: Tue, 22 Aug 2023 13:51:45 +0200 Subject: [PATCH] Fix error position for lines with unicode --- fift-wasm/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fift-wasm/src/lib.rs b/fift-wasm/src/lib.rs index c8e270c..e6eb96f 100644 --- a/fift-wasm/src/lib.rs +++ b/fift-wasm/src/lib.rs @@ -79,6 +79,10 @@ impl FiftState { output = output.set("success", false).set("stderr", format!("{e:?}")); if let Some(pos) = self.context.input.get_position() { + let word_start = pos.line[..pos.word_start].chars().count(); + let word_end = + word_start + pos.line[pos.word_start..pos.word_end].chars().count(); + output = output.set( "errorPosition", ObjectBuilder::new() @@ -86,8 +90,8 @@ impl FiftState { .set("blockName", pos.source_block_name) .set("line", pos.line) .set("lineNumber", pos.line_number) - .set("wordStart", pos.word_start) - .set("wordEnd", pos.word_end) + .set("wordStart", word_start) + .set("wordEnd", word_end) .build(), ); };