Skip to content

Commit

Permalink
fix(ipc): typst compiler error char offset
Browse files Browse the repository at this point in the history
Fixes #17
  • Loading branch information
Cubxity committed May 13, 2023
1 parent f82689f commit a368ace
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src-tauri/src/ipc/commands/typst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -70,7 +70,7 @@ pub async fn typst_compile<R: Runtime>(

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::<Error>::into)?;

if !world.is_main_set() {
Expand Down Expand Up @@ -133,8 +133,14 @@ pub async fn typst_compile<R: Runtime>(
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();

Expand Down

0 comments on commit a368ace

Please sign in to comment.