Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

dev: go first step to make typst-preview as a library #202

Merged
merged 3 commits into from
Dec 22, 2023

Conversation

Myriad-Dreamin
Copy link
Collaborator

@Myriad-Dreamin Myriad-Dreamin commented Dec 16, 2023

This PR makes typst-preview as a library, and provides the only API:

pub async fn preview(arguments: PreviewArgs, compiler_driver: CompileDriver) -> Previewer;

Though, the compiler is not decoupled but a fixed implementation: typst_ts_compiler::service::CompileDriver, we can discuss a nice interface in future. For example:

pub trait CompileHost {
    /// Host must provides a document to watch
    fn subscribe_doc(&self) -> Option<tokio::sync::watch::Receiver<Option<Arc<Document>>>>;
    /// Optional: watch compile status
    fn subscribe_status(&self) -> Option<tokio::sync::watch::Receiver<CompileStatus>> {
        None
    }

    // todo: sync or async
    /// fixme: character is 0-based, UTF-16 code unit. We treat it as UTF-8 now.
    /// Optional: resolve jump
    fn resolve_src_to_doc_jump(
        &mut self,
        _filepath: PathBuf,
        _line: usize,
        _character: usize,
    ) -> ZResult<Option<Position>> {
        Ok(None)
    }

    /// Optional: resolve span
    fn resolve_span(&mut self, _span_id: Span) -> ZResult<Option<DocToSrcJumpInfo>> {
        Ok(None)
    }
}

There are two major improvement based on typst-preview in future:

Integrate typst-preview into typst-lsp

Discussion:

Integrate typst-preview into other projects, such as Nólë

Same.

Run typst-preview in web workspace

Our first step is decoupling hyper, which is needless in web extension. see related issue, #172.

@Myriad-Dreamin Myriad-Dreamin marked this pull request as draft December 16, 2023 10:26
@Myriad-Dreamin Myriad-Dreamin marked this pull request as ready for review December 19, 2023 06:46
@Enter-tainer Enter-tainer merged commit e31b29c into main Dec 22, 2023
22 checks passed
@Enter-tainer Enter-tainer deleted the preview-as-a-lib branch December 22, 2023 05:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants