From a368acec96b1bf1b014749edc97035530f3884f1 Mon Sep 17 00:00:00 2001 From: Cubxity Date: Sat, 13 May 2023 21:34:32 +0200 Subject: [PATCH] fix(ipc): typst compiler error char offset Fixes #17 --- src-tauri/src/ipc/commands/typst.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/ipc/commands/typst.rs b/src-tauri/src/ipc/commands/typst.rs index da48fff..06e9199 100644 --- a/src-tauri/src/ipc/commands/typst.rs +++ b/src-tauri/src/ipc/commands/typst.rs @@ -4,7 +4,7 @@ use crate::ipc::model::TypstRenderResponse; use crate::ipc::{TypstCompileEvent, TypstDocument, TypstSourceError}; use crate::project::ProjectManager; use base64::Engine; -use log::{debug, trace}; +use log::debug; use serde::Serialize; use serde_repr::Serialize_repr; use siphasher::sip128::{Hasher128, SipHasher}; @@ -70,7 +70,7 @@ pub async fn typst_compile( let mut world = project.world.lock().unwrap(); let source_id = world - .slot_update(path.as_path(), Some(content)) + .slot_update(path.as_path(), Some(content.clone())) .map_err(Into::::into)?; if !world.is_main_set() { @@ -133,8 +133,14 @@ pub async fn typst_compile( ErrorPos::Start => span.start..span.start, ErrorPos::End => span.end..span.end, }; + let start = content[..range.start].chars().count(); + let size = content[range.start..range.end].chars().count(); + let message = e.message.to_string(); - TypstSourceError { range, message } + TypstSourceError { + range: start..start + size, + message, + } }) .collect();