fix: fix warnings in publish dry runs (#1681)

This commit is contained in:
Myriad-Dreamin 2025-04-18 03:42:49 +08:00 committed by GitHub
parent 923155a2e2
commit d3134926e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 72 additions and 12 deletions

View file

@ -186,16 +186,17 @@ impl Message {
}
/// Writes the message to the given writer.
pub fn write<W: std::io::Write>(self, writer: &mut W) -> std::io::Result<()> {
pub fn write<W: std::io::Write>(self, _writer: &mut W) -> std::io::Result<()> {
match self {
#[cfg(feature = "lsp")]
Message::Lsp(msg) => msg.write(writer),
Message::Lsp(msg) => msg.write(_writer),
#[cfg(feature = "dap")]
Message::Dap(msg) => msg.write(writer),
Message::Dap(msg) => msg.write(_writer),
}
}
}
#[allow(unused)]
pub(crate) enum LspOrDapResponse {
#[cfg(feature = "lsp")]
Lsp(lsp::Response),
@ -203,6 +204,7 @@ pub(crate) enum LspOrDapResponse {
Dap(dap::Response),
}
#[cfg(any(feature = "lsp", feature = "dap"))]
pub(crate) fn read_msg_text(inp: &mut dyn BufRead) -> io::Result<Option<String>> {
let mut size = None;
let mut buf = String::new();
@ -236,6 +238,7 @@ pub(crate) fn read_msg_text(inp: &mut dyn BufRead) -> io::Result<Option<String>>
Ok(Some(buf))
}
#[cfg(any(feature = "lsp", feature = "dap"))]
pub(crate) fn write_msg_text(out: &mut dyn Write, msg: &str) -> io::Result<()> {
log::debug!("> {msg}");
write!(out, "Content-Length: {}\r\n\r\n", msg.len())?;
@ -244,6 +247,7 @@ pub(crate) fn write_msg_text(out: &mut dyn Write, msg: &str) -> io::Result<()> {
Ok(())
}
#[cfg(any(feature = "lsp", feature = "dap"))]
pub(crate) fn invalid_data(
error: impl Into<Box<dyn std::error::Error + Send + Sync>>,
) -> io::Error {

View file

@ -10,7 +10,7 @@ repository.workspace = true
rust-version.workspace = true
[features]
default = ["nightly"]
default = []
nightly = []
[dependencies]

View file

@ -1,17 +1,17 @@
//! Typst Evaluation
use comemo::Track;
use typst::engine::{Route, Sink, Traced};
use typst::foundations::Module;
use typst::diag::SourceResult;
use typst::engine::{Engine, Route, Sink, Traced};
use typst::foundations::{Context, Func, Module, Value};
use typst::introspection::Introspector;
use typst::syntax::Source;
use typst::World;
pub use typst_eval::*;
/// Evaluates a source file and return the resulting module.
pub fn eval_compat(
world: &dyn World,
source: &typst::syntax::Source,
) -> typst::diag::SourceResult<Module> {
pub fn eval_compat(world: &dyn World, source: &Source) -> SourceResult<Module> {
let route = Route::default();
let traced = Traced::default();
let mut sink = Sink::default();
@ -25,3 +25,57 @@ pub fn eval_compat(
source,
)
}
/// The Typst Engine.
pub struct TypstEngine<'a> {
/// The introspector to be queried for elements and their positions.
pub introspector: Introspector,
/// May hold a span that is currently under inspection.
pub traced: Traced,
/// The route the engine took during compilation. This is used to detect
/// cyclic imports and excessive nesting.
pub route: Route<'static>,
/// A push-only sink for delayed errors, warnings, and traced values.
///
/// All tracked methods of this type are of the form `(&mut self, ..) ->
/// ()`, so in principle they do not need validation (though that
/// optimization is not yet implemented in comemo).
pub sink: Sink,
/// The environment in which typesetting occurs.
pub world: &'a dyn World,
}
impl<'a> TypstEngine<'a> {
/// Creates a new Typst Engine.
pub fn new(world: &'a dyn World) -> Self {
Self {
introspector: Introspector::default(),
traced: Traced::default(),
route: Route::default(),
sink: Sink::default(),
world,
}
}
/// Creates the engine.
pub fn as_engine(&'a mut self) -> Engine<'a> {
Engine {
routines: &typst::ROUTINES,
world: self.world.track(),
introspector: self.introspector.track(),
traced: self.traced.track(),
sink: self.sink.track_mut(),
route: self.route.clone(),
}
}
/// Applies a function.
pub fn apply(&'a mut self, func: &Func, ctx: Context, args: Vec<Value>) -> SourceResult<Value> {
func.call(&mut self.as_engine(), ctx.track(), args)
}
/// Calls a function.
pub fn call(&'a mut self, func: &Func, ctx: Context) -> SourceResult<Value> {
self.apply(func, ctx, vec![])
}
}