Skip to content

Commit

Permalink
fix: compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Oct 2, 2024
1 parent f387d4b commit dcb7069
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
7 changes: 5 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ use std::{
};

use clap::FromArgMatches;
use reflexo_typst::config::{entry::EntryOpts, CompileOpts};
use reflexo_typst::error::prelude::*;
use reflexo_typst::exporter_builtins::GroupExporter;
use reflexo_typst::exporter_utils::map_err;
use reflexo_typst::path::{unix_slash, PathClean};
use reflexo_typst::TypstSystemUniverse;
use reflexo_typst::{
config::{entry::EntryOpts, CompileOpts},
typst_shim::model::TypstDocumentExt,
};
use typst::{model::Document, text::FontVariant, World};
use typst_assets::fonts;
use typst_ts_cli::compile::compile_export;
Expand Down Expand Up @@ -114,7 +117,7 @@ pub fn query(args: QueryArgs) -> ! {

exporter.push_front(Box::new(move |world: &dyn World, output: Arc<Document>| {
if args.selector == "document_title" {
let title = output.title.clone().unwrap_or("null".into());
let title = output.title().map(|e| e.as_str()).unwrap_or("null");
let serialized = serialize(&title, "json").map_err(map_err)?;
println!("{}", serialized);
return Ok(());
Expand Down
7 changes: 2 additions & 5 deletions cli/src/query_repl.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use comemo::{Track, TrackedMut};
use std::borrow::Cow::{self, Owned};
use std::cell::{RefCell, RefMut};
use std::sync::Arc;

use reflexo_typst::typst::prelude::*;
use reflexo_typst::{
CompileDriver, CompileReport, CompilerWorld, ConsoleDiagReporter, PureCompiler,
};
use reflexo_typst::{CompileDriver, CompileReport, ConsoleDiagReporter, PureCompiler};
use reflexo_typst::{GenericExporter, ShadowApiExt, TypstSystemWorld};
use rustyline::completion::{Completer, Pair};
use rustyline::error::ReadlineError;
Expand All @@ -16,7 +13,7 @@ use rustyline::validate::MatchingBracketValidator;
use rustyline::{Cmd, CompletionType, Config, EditMode, Editor, KeyEvent};
use rustyline::{Helper, Validator};
use typst::diag::SourceDiagnostic;
use typst::{hint_invalid_main_file, World};
use typst::World;
use typst_ide::autocomplete;

use crate::query::serialize;
Expand Down
10 changes: 5 additions & 5 deletions crates/conversion/typst2vec/src/pass/typst2vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<const ENABLE_REF_CNT: bool> Typst2VecPassImpl<ENABLE_REF_CNT> {
inner
}
FrameItem::Text(text) => {
let i = self.text(state, &text);
let i = self.text(state, text);

self.spans.push_span(SourceRegion {
region: src_reg,
Expand All @@ -318,7 +318,7 @@ impl<const ENABLE_REF_CNT: bool> Typst2VecPassImpl<ENABLE_REF_CNT> {
i
}
FrameItem::Shape(shape, s) => {
let i = self.shape(state, &shape);
let i = self.shape(state, shape);

self.spans.push_span(SourceRegion {
region: src_reg,
Expand All @@ -330,7 +330,7 @@ impl<const ENABLE_REF_CNT: bool> Typst2VecPassImpl<ENABLE_REF_CNT> {
i
}
FrameItem::Image(image, size, s) => {
let i = self.image(&image, *size);
let i = self.image(image, *size);

self.spans.push_span(SourceRegion {
region: src_reg,
Expand Down Expand Up @@ -361,8 +361,8 @@ impl<const ENABLE_REF_CNT: bool> Typst2VecPassImpl<ENABLE_REF_CNT> {

self.store(VecItem::ContentHint('\n'))
}
// #[cfg(not(feature = "no-content-hint"))]
// FrameItem::ContentHint(c) => self.store(VecItem::ContentHint(*c)),
#[cfg(not(feature = "no-content-hint"))]
FrameItem::ContentHint(c) => self.store(VecItem::ContentHint(*c)),
// todo: support page label
};

Expand Down
4 changes: 2 additions & 2 deletions crates/reflexo-typst/src/exporter/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ impl FullTextDigest {
match item {
Group(g) => Self::export_frame(f, &g.frame),
Text(t) => f.write_str(t.text.as_str()),
// #[cfg(not(feature = "no-content-hint"))]
// ContentHint(c) => f.write_char(*c),
#[cfg(not(feature = "no-content-hint"))]
ContentHint(c) => f.write_char(*c),
Link(..) | Tag(..) | Shape(..) | Image(..) => Ok(()),
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/reflexo-typst/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub use exporter::{
GenericTransformer, Transformer,
};
// pub use font::{FontLoader, FontResolver, FontSlot};
pub use reflexo::typst_shim as compat;
pub use reflexo::*;

pub mod build_info {
Expand Down Expand Up @@ -406,7 +407,7 @@ pub trait Compiler {
self.reset()?;

let res = match env.sink.as_mut() {
Some(sink) => ::typst::compile(world),
Some(_sink) => ::typst::compile(world),
None => ::typst::compile(world),
};

Expand Down
2 changes: 1 addition & 1 deletion crates/reflexo-typst/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use comemo::Track;
use typst::{
diag::{EcoString, HintedString, StrResult},
diag::{EcoString, StrResult},
eval::{eval_string, EvalMode},
foundations::{Content, LocatableSelector, Scope},
model::Document,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub use reflexo_typst::*;
use core::fmt;
use std::{fmt::Write, path::Path, sync::Arc};

use ::typst::utils::LazyHash;
use error::TypstSourceDiagnostic;
use font::cache::FontInfoCache;
use js_sys::{Array, JsString, Uint32Array, Uint8Array};
use reflexo_typst::compat::utils::LazyHash;
use reflexo_typst::error::{long_diag_from_std, prelude::*, DiagMessage};
use reflexo_typst::font::web::BrowserFontSearcher;
use reflexo_typst::package::browser::ProxyRegistry;
Expand Down Expand Up @@ -266,7 +266,7 @@ impl TypstCompiler {
return Err(error_once!("Unsupported offset encoding", offset_encoding: offset_encoding).into());
}
},
);
)?;
let mut result = Vec::new();
for token in tokens.iter() {
result.push(token.delta_line);
Expand Down
6 changes: 3 additions & 3 deletions packages/typst.node/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use reflexo_typst::config::{entry::EntryState, CompileFontOpts};
use reflexo_typst::error::prelude::*;
use reflexo_typst::font::system::SystemFontSearcher;
use reflexo_typst::package::http::HttpRegistry;
use reflexo_typst::typst::{foundations::IntoValue, prelude::Prehashed};
use reflexo_typst::vfs::{system::SystemAccessModel, Vfs};
use reflexo_typst::{compat::LazyHash, typst::foundations::IntoValue};
use reflexo_typst::{
Bytes, CompileDriver, PureCompiler, TypstDict, TypstSystemUniverse, TypstSystemWorld,
};
Expand Down Expand Up @@ -133,8 +133,8 @@ pub fn create_driver(
}

/// Convert the input pairs to a dictionary.
fn create_inputs(inputs: HashMap<String, String>) -> Arc<Prehashed<TypstDict>> {
Arc::new(Prehashed::new(
fn create_inputs(inputs: HashMap<String, String>) -> Arc<LazyHash<TypstDict>> {
Arc::new(LazyHash::new(
inputs
.iter()
.map(|(k, v)| (k.as_str().into(), v.as_str().into_value()))
Expand Down
14 changes: 7 additions & 7 deletions packages/typst.node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use std::{
use chrono::{DateTime, Datelike, Timelike, Utc};
use napi::bindgen_prelude::*;
use napi_derive::napi;
use reflexo_typst::error::prelude::*;
use reflexo_typst::foundations::IntoValue;
use reflexo_typst::syntax::Span;
use reflexo_typst::typst::diag::{At, SourceResult};
use reflexo_typst::{compat::model::TypstDocumentExt, error::prelude::*};
use reflexo_typst::{
Bytes, Compiler, DynamicLayoutCompiler, Exporter, ShadowApi, SystemCompilerFeat, TypstAbs,
TypstDatetime, TypstDocument, TypstSystemWorld, TypstWorld,
Expand All @@ -45,20 +45,20 @@ impl NodeTypstDocument {
/// Gets the title of the document.
#[napi(getter)]
pub fn title(&self) -> Option<String> {
self.0.title.as_ref().map(ToString::to_string)
self.0.title().as_ref().map(ToString::to_string)
}

/// Gets the authors of the document.
#[napi(getter)]
pub fn authors(&self) -> Option<Vec<String>> {
let authors = self.0.author.iter();
let authors = self.0.author().iter();
Some(authors.map(ToString::to_string).collect::<Vec<_>>())
}

/// Gets the keywords of the document.
#[napi(getter)]
pub fn keywords(&self) -> Option<Vec<String>> {
let keywords = self.0.keywords.iter();
let keywords = self.0.keywords().iter();
Some(keywords.map(ToString::to_string).collect::<Vec<_>>())
}

Expand All @@ -69,7 +69,7 @@ impl NodeTypstDocument {
#[napi(getter)]
pub fn date(&self) -> Option<i64> {
self.0
.date
.date()
.custom()
.flatten()
.and_then(typst_datetime_to_unix_nanoseconds)
Expand All @@ -81,7 +81,7 @@ impl NodeTypstDocument {
/// explicitly.
#[napi(getter)]
pub fn enabled_auto_date(&self) -> bool {
self.0.date.is_auto()
self.0.date().is_auto()
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ impl NodeCompiler {
let mapped: Vec<_> = elements
.into_iter()
.filter_map(|c| match &args.field {
Some(field) => c.get_by_name(field),
Some(field) => c.get_by_name(field).ok(),
_ => Some(c.into_value()),
})
.collect();
Expand Down

0 comments on commit dcb7069

Please sign in to comment.