Skip to content

Commit

Permalink
dev: split sync part
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Jan 13, 2025
1 parent 2777ffa commit da907a0
Show file tree
Hide file tree
Showing 14 changed files with 1,095 additions and 287 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

13 changes: 13 additions & 0 deletions crates/sync-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ impl<S: 'static> TypedLspClient<S> {
self.client
.send_request_::<R>(params, move |s, resp| handler(caster(s), resp))
}

/// Sends a event to the client itself.
pub fn send_event<T: std::any::Any + Send + 'static>(&self, event: T) {
let Some(sender) = self.sender.upgrade() else {
log::warn!("failed to send request: connection closed");
return;
};

let Err(res) = sender.event.send(Box::new(event)) else {
return;
};
log::warn!("failed to send event: {res:?}");
}
}

impl<S> Clone for TypedLspClient<S> {
Expand Down
3 changes: 3 additions & 0 deletions crates/tinymist-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ rayon.workspace = true
reflexo-typst.workspace = true
reflexo-typst-shim = { workspace = true, features = ["nightly"] }
typst.workspace = true
codespan-reporting = "0.11"

tinymist-assets = { workspace = true }
tinymist-project.workspace = true
tinymist-fs.workspace = true
typst-assets = { workspace = true, features = ["fonts"] }

dirs.workspace = true
Expand Down
26 changes: 21 additions & 5 deletions crates/tinymist-world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! World implementation of typst for tinymist.
use font::TinymistFontResolver;
pub mod font;
pub mod package;
pub mod project;

pub use reflexo_typst;
pub use reflexo_typst::config::CompileFontOpts;
pub use reflexo_typst::error::prelude;
Expand All @@ -21,10 +24,9 @@ use reflexo_typst::vfs::{system::SystemAccessModel, Vfs};
use reflexo_typst::{CompilerFeat, CompilerUniverse, CompilerWorld, ImmutPath, TypstDict};
use serde::{Deserialize, Serialize};

pub mod font;
pub mod package;
pub mod typ_server;
use package::HttpsRegistry;
use crate::font::TinymistFontResolver;
use crate::package::HttpsRegistry;
use crate::project::ProjectInterrupt;

const ENV_PATH_SEP: char = if cfg!(windows) { ';' } else { ':' };

Expand Down Expand Up @@ -201,6 +203,8 @@ pub type LspUniverse = TypstSystemUniverseExtend;
pub type LspWorld = TypstSystemWorldExtend;
/// Immutable prehashed reference to dictionary.
pub type ImmutDict = Arc<LazyHash<TypstDict>>;
/// LSP interrupt.
pub type LspInterrupt = ProjectInterrupt<LspCompilerFeat>;

/// Builder for LSP universe.
pub struct LspUniverseBuilder;
Expand All @@ -223,6 +227,18 @@ impl LspUniverseBuilder {
))
}

/// Resolve fonts from given options.
pub fn only_embedded_fonts() -> ZResult<TinymistFontResolver> {
let mut searcher = SystemFontSearcher::new();
searcher.resolve_opts(CompileFontOpts {
font_profile_cache_path: Default::default(),
font_paths: vec![],
no_system_fonts: true,
with_embedded_fonts: typst_assets::fonts().map(Cow::Borrowed).collect(),
})?;
Ok(searcher.into())
}

/// Resolve fonts from given options.
pub fn resolve_fonts(args: CompileFontArgs) -> ZResult<TinymistFontResolver> {
let mut searcher = SystemFontSearcher::new();
Expand Down
Loading

0 comments on commit da907a0

Please sign in to comment.