Skip to content

Commit

Permalink
Fix error position for lines with unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 22, 2023
1 parent f28769a commit 02aea07
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions fift-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,19 @@ 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()
.set("depth", pos.offset)
.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(),
);
};
Expand Down

0 comments on commit 02aea07

Please sign in to comment.