Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to preview typst targeting html #947

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,17 @@ typst-eval = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "ti
# typst-render = { path = "../typst/crates/typst-render" }
# typst-syntax = { path = "../typst/crates/typst-syntax" }

reflexo = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-world = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst2vec = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-vec2svg = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst-shim = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }

# reflexo = { path = "../typst.ts/crates/reflexo/" }
# reflexo-world = { path = "../typst.ts/crates/reflexo-world/" }
# reflexo-typst = { path = "../typst.ts/crates/reflexo-typst/" }
# reflexo-typst2vec = { path = "../typst.ts/crates/conversion/typst2vec/" }
# reflexo-vec2svg = { path = "../typst.ts/crates/conversion/vec2svg/" }
# reflexo-typst-shim = { path = "../typst.ts/crates/reflexo-typst-shim/" }
# reflexo = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
# reflexo-world = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
# reflexo-typst = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
# reflexo-typst2vec = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
# reflexo-vec2svg = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
# reflexo-typst-shim = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }

reflexo = { path = "../typst.ts/crates/reflexo/" }
reflexo-world = { path = "../typst.ts/crates/reflexo-world/" }
reflexo-typst = { path = "../typst.ts/crates/reflexo-typst/" }
reflexo-typst2vec = { path = "../typst.ts/crates/conversion/typst2vec/" }
reflexo-vec2svg = { path = "../typst.ts/crates/conversion/vec2svg/" }
reflexo-typst-shim = { path = "../typst.ts/crates/reflexo-typst-shim/" }
# typstyle = { path = "../typstyle" }
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/analysis/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use reflexo::debug_loc::DataSource;
use reflexo::hash::{hash128, FxDashMap};
use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use reflexo_typst::{EntryReader, WorldDeps};
use rustc_hash::FxHashMap;
use tinymist_world::LspWorld;
Expand Down Expand Up @@ -882,7 +882,7 @@ impl SharedContext {
/// only generated when the document is available.
pub fn tooltip(
&self,
document: Option<&TypstDocument>,
document: Option<&TypstPagedDocument>,
source: &Source,
cursor: usize,
) -> Option<Tooltip> {
Expand Down
6 changes: 3 additions & 3 deletions crates/tinymist-query/src/analysis/track_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use comemo::Track;
use ecow::*;
use reflexo::typst::TypstDocument;
use reflexo::typst::TypstPagedDocument;
use typst::engine::{Engine, Route, Sink, Traced};
use typst::foundations::{Label, Styles, Value};
use typst::introspection::Introspector;
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn analyze_expr_(world: &dyn World, node: &SyntaxNode) -> EcoVec<(Value, Opt
}
}

return typst::trace::<TypstDocument>(world, node.span());
return typst::trace::<TypstPagedDocument>(world, node.span());
}
};

Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct DynLabel {
/// - All labels and descriptions for them, if available
/// - A split offset: All labels before this offset belong to nodes, all after
/// belong to a bibliography.
pub fn analyze_labels(document: &TypstDocument) -> (Vec<DynLabel>, usize) {
pub fn analyze_labels(document: &TypstPagedDocument) -> (Vec<DynLabel>, usize) {
let mut output = vec![];

// Labels in the document.
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/document_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf};

use reflexo::debug_loc::DataSource;
use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use serde::{Deserialize, Serialize};
use typst::text::{Font, FontStretch, FontStyle, FontWeight};
use typst::{
Expand Down Expand Up @@ -142,7 +142,7 @@ struct DocumentMetricsWorker<'a> {
}

impl DocumentMetricsWorker<'_> {
fn work(&mut self, doc: &TypstDocument) -> Option<()> {
fn work(&mut self, doc: &TypstPagedDocument) -> Option<()> {
for page in &doc.pages {
self.work_frame(&page.frame)?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::num::NonZeroUsize;

use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use typst::{
layout::{Frame, FrameItem, Point, Position},
syntax::{LinkedNode, Source, Span, SyntaxKind},
Expand All @@ -13,7 +13,7 @@ use typst_shim::syntax::LinkedNodeExt;

/// Find the output location in the document for a cursor position.
pub fn jump_from_cursor(
document: &TypstDocument,
document: &TypstPagedDocument,
source: &Source,
cursor: usize,
) -> Option<Position> {
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod prelude;

use std::sync::Arc;

use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use typst::syntax::Source;

/// The physical position in a document.
Expand All @@ -98,7 +98,7 @@ pub struct VersionedDocument {
/// The version of the document.
pub version: usize,
/// The compiled document.
pub document: Arc<TypstDocument>,
pub document: Arc<TypstPagedDocument>,
}

/// A request handler with given syntax information.
Expand Down
6 changes: 3 additions & 3 deletions crates/tinymist-query/src/upstream/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::Range;
use ecow::{eco_format, EcoString};
use if_chain::if_chain;
use lsp_types::TextEdit;
use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use serde::{Deserialize, Serialize};
use typst::foundations::{fields_on, format_str, repr, Repr, StyleChain, Styles, Value};
use typst::syntax::{ast, is_id_continue, is_id_start, is_ident, LinkedNode, Source, SyntaxKind};
Expand Down Expand Up @@ -801,7 +801,7 @@ fn code_completions(ctx: &mut CompletionContext, hash: bool) {
/// Context for autocompletion.
pub struct CompletionContext<'a> {
pub ctx: &'a mut LocalContext,
pub document: Option<&'a TypstDocument>,
pub document: Option<&'a TypstPagedDocument>,
pub text: &'a str,
pub before: &'a str,
pub after: &'a str,
Expand All @@ -825,7 +825,7 @@ impl<'a> CompletionContext<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ctx: &'a mut LocalContext,
document: Option<&'a TypstDocument>,
document: Option<&'a TypstPagedDocument>,
source: &'a Source,
cursor: usize,
explicit: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/tinymist-query/src/upstream/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Write;

use ecow::{eco_format, EcoString};
use if_chain::if_chain;
use reflexo_typst::TypstDocument;
use reflexo_typst::TypstPagedDocument;
use typst::engine::Sink;
use typst::foundations::{repr, Capturer, CastInfo, Value};
use typst::layout::Length;
Expand All @@ -23,7 +23,7 @@ use crate::analysis::{analyze_expr, analyze_labels, DynLabel};
/// when the document is available.
pub fn tooltip_(
world: &dyn World,
document: Option<&TypstDocument>,
document: Option<&TypstPagedDocument>,
source: &Source,
cursor: usize,
) -> Option<Tooltip> {
Expand Down Expand Up @@ -157,7 +157,7 @@ fn length_tooltip(length: Length) -> Option<Tooltip> {
}

/// Tooltip for a hovered reference or label.
fn label_tooltip(document: &TypstDocument, leaf: &LinkedNode) -> Option<Tooltip> {
fn label_tooltip(document: &TypstPagedDocument, leaf: &LinkedNode) -> Option<Tooltip> {
let target = match leaf.kind() {
SyntaxKind::RefMarker => leaf.text().trim_start_matches('@'),
SyntaxKind::Label => leaf.text().trim_start_matches('<').trim_end_matches('>'),
Expand Down
26 changes: 21 additions & 5 deletions crates/tinymist/src/actor/typ_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use anyhow::bail;
use log::{error, info, trace};
use reflexo_typst::{
error::prelude::*, typst::prelude::*, vfs::notify::MemoryEvent, world::EntryState,
CompileReport, EntryReader, Error, ImmutPath, TaskInputs,
CompileReport, EntryReader, Error, ImmutPath, TaskInputs, TypstDocument,
};
use sync_lsp::{just_future, QueryFuture};
use tinymist_query::{
Expand Down Expand Up @@ -138,14 +138,21 @@ impl CompileHandler {
&self,
world: &LspWorld,
errors: EcoVec<SourceDiagnostic>,
html_errors: EcoVec<SourceDiagnostic>,
warnings: EcoVec<SourceDiagnostic>,
html_warnings: EcoVec<SourceDiagnostic>,
) {
let revision = world.revision().get();
trace!("notify diagnostics({revision}): {errors:#?} {warnings:#?}");
log::info!("notify diagnostics({revision}): {errors:#?} {warnings:#?} {html_warnings:#?}");

let diagnostics = tinymist_query::convert_diagnostics(
world,
errors.iter().chain(warnings.iter()),
errors
.iter()
// todo: deduplicate html errors
.chain(html_errors.iter())
.chain(warnings.iter())
.chain(html_warnings.iter()),
self.analysis.position_encoding,
);

Expand Down Expand Up @@ -235,7 +242,9 @@ impl CompilationHandle<LspCompilerFeat> for CompileHandler {
self.notify_diagnostics(
&snap.world,
snap.doc.clone().err().unwrap_or_default(),
snap.html_doc.clone().err().unwrap_or_default(),
snap.warnings.clone(),
snap.html_warnings.clone(),
);

self.export.signal(snap, snap.signal);
Expand All @@ -253,10 +262,17 @@ impl CompilationHandle<LspCompilerFeat> for CompileHandler {

#[cfg(feature = "preview")]
if let Some(inner) = self.inner.read().as_ref() {
// todo: html feature or not
// let res = snap
// .doc
// .clone()
// .map_err(|_| typst_preview::CompileStatus::CompileError);
log::info!("html it: {:?}", snap.html_doc);
let res = snap
.doc
.html_doc
.clone()
.map_err(|_| typst_preview::CompileStatus::CompileError);
.map_err(|_| typst_preview::CompileStatus::CompileError)
.map(TypstDocument::Html);
inner.notify_compile(res, snap.signal.by_fs_events, snap.signal.by_entry_update);
}
}
Expand Down
Loading
Loading