mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-21 12:18:32 +00:00
feat: disable typst::compile in syntax only mode
This commit is contained in:
parent
91312cb5f8
commit
0420558fd4
19 changed files with 58 additions and 13 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -4562,6 +4562,7 @@ dependencies = [
|
||||||
"tinymist-world",
|
"tinymist-world",
|
||||||
"typst",
|
"typst",
|
||||||
"typst-library",
|
"typst-library",
|
||||||
|
"typst-shim",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -4580,6 +4581,7 @@ dependencies = [
|
||||||
"tinymist-world",
|
"tinymist-world",
|
||||||
"typst",
|
"typst",
|
||||||
"typst-library",
|
"typst-library",
|
||||||
|
"typst-shim",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -4903,6 +4905,7 @@ dependencies = [
|
||||||
"ttf-parser",
|
"ttf-parser",
|
||||||
"typst",
|
"typst",
|
||||||
"typst-assets",
|
"typst-assets",
|
||||||
|
"typst-shim",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,7 @@ pub async fn test_main(args: TestArgs) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_once(world: &LspWorld, ctx: &TestContext) -> Result<bool> {
|
fn test_once(world: &LspWorld, ctx: &TestContext) -> Result<bool> {
|
||||||
let doc = typst::compile::<TypstPagedDocument>(&world).output?;
|
let doc = typst_shim::compile_opt::<TypstPagedDocument>(&world).output?;
|
||||||
|
|
||||||
let mut snap = CompileSnapshot::from_world(world.clone());
|
let mut snap = CompileSnapshot::from_world(world.clone());
|
||||||
snap.success_doc = Some(TypstDocument::Paged(Arc::new(doc)));
|
snap.success_doc = Some(TypstDocument::Paged(Arc::new(doc)));
|
||||||
|
|
@ -449,7 +449,7 @@ impl<'a> TestRunner<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_example<T: typst::Document>(&self, world: &dyn World) -> (bool, Option<T>) {
|
fn build_example<T: typst::Document>(&self, world: &dyn World) -> (bool, Option<T>) {
|
||||||
let result = typst::compile::<T>(world);
|
let result = typst_shim::compile_opt::<T>(world);
|
||||||
if !result.warnings.is_empty() {
|
if !result.warnings.is_empty() {
|
||||||
self.diagnostics.lock().push(result.warnings);
|
self.diagnostics.lock().push(result.warnings);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ rust-version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typst-library.workspace = true
|
typst-library.workspace = true
|
||||||
|
typst-shim.workspace = true
|
||||||
typst.workspace = true
|
typst.workspace = true
|
||||||
tinymist-std.workspace = true
|
tinymist-std.workspace = true
|
||||||
tinymist-analysis.workspace = true
|
tinymist-analysis.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ pub fn start_session<F: CompilerFeat>(
|
||||||
adaptor.before_compile();
|
adaptor.before_compile();
|
||||||
step_global(BreakpointKind::BeforeCompile, &world);
|
step_global(BreakpointKind::BeforeCompile, &world);
|
||||||
|
|
||||||
let result = typst::compile::<PagedDocument>(&world);
|
let result = typst_shim::compile_opt::<PagedDocument>(&world);
|
||||||
|
|
||||||
adaptor.after_compile(result);
|
adaptor.after_compile(result);
|
||||||
step_global(BreakpointKind::AfterCompile, &world);
|
step_global(BreakpointKind::AfterCompile, &world);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ rust-version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
typst-library.workspace = true
|
typst-library.workspace = true
|
||||||
|
typst-shim.workspace = true
|
||||||
typst.workspace = true
|
typst.workspace = true
|
||||||
tinymist-std.workspace = true
|
tinymist-std.workspace = true
|
||||||
tinymist-analysis.workspace = true
|
tinymist-analysis.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn collect_coverage<D: typst::Document, F: CompilerFeat>(
|
||||||
base: &CompilerWorld<F>,
|
base: &CompilerWorld<F>,
|
||||||
) -> Result<CoverageResult> {
|
) -> Result<CoverageResult> {
|
||||||
let (cov, result) = with_cov(base, |instr| {
|
let (cov, result) = with_cov(base, |instr| {
|
||||||
if let Err(e) = typst::compile::<D>(&instr).output {
|
if let Err(e) = typst_shim::compile_opt::<D>(&instr).output {
|
||||||
print_diagnostics(instr, e.iter(), tinymist_world::DiagnosticFormat::Human)
|
print_diagnostics(instr, e.iter(), tinymist_world::DiagnosticFormat::Human)
|
||||||
.context_ut("failed to print diagnostics")?;
|
.context_ut("failed to print diagnostics")?;
|
||||||
bail!("");
|
bail!("");
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ mod tests {
|
||||||
let Warned {
|
let Warned {
|
||||||
output,
|
output,
|
||||||
warnings: compiler_warnings,
|
warnings: compiler_warnings,
|
||||||
} = typst::compile::<PagedDocument>(ctx.world());
|
} = typst_shim::compile_opt::<PagedDocument>(ctx.world());
|
||||||
let compiler_errors = output.err().unwrap_or_default();
|
let compiler_errors = output.err().unwrap_or_default();
|
||||||
let compiler_diags = compiler_warnings.iter().chain(compiler_errors.iter());
|
let compiler_diags = compiler_warnings.iter().chain(compiler_errors.iter());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ pub fn compile_doc_for_test(
|
||||||
let mut snap = LspCompileSnapshot::from_world(world.into_owned());
|
let mut snap = LspCompileSnapshot::from_world(world.into_owned());
|
||||||
snap.world.set_is_compiling(true);
|
snap.world.set_is_compiling(true);
|
||||||
|
|
||||||
let doc = typst::compile(&snap.world).output.unwrap();
|
let doc = typst_shim::compile_opt(&snap.world).output.unwrap();
|
||||||
snap.success_doc = Some(TypstDocument::Paged(Arc::new(doc)));
|
snap.success_doc = Some(TypstDocument::Paged(Arc::new(doc)));
|
||||||
WorldComputeGraph::new(snap)
|
WorldComputeGraph::new(snap)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ tar.workspace = true
|
||||||
tinymist-package.workspace = true
|
tinymist-package.workspace = true
|
||||||
tinymist-std.workspace = true
|
tinymist-std.workspace = true
|
||||||
tinymist-vfs.workspace = true
|
tinymist-vfs.workspace = true
|
||||||
|
typst-shim.workspace = true
|
||||||
typst.workspace = true
|
typst.workspace = true
|
||||||
typst-assets.workspace = true
|
typst-assets.workspace = true
|
||||||
ttf-parser.workspace = true
|
ttf-parser.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,9 @@ let universe = args
|
||||||
```rust
|
```rust
|
||||||
let world = verse.snapshot();
|
let world = verse.snapshot();
|
||||||
// in current thread
|
// in current thread
|
||||||
let doc = typst::compile(&world)?;
|
let doc = typst_shim::compile_opt(&world)?;
|
||||||
// the snapshot is Send + Sync
|
// the snapshot is Send + Sync
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let doc = typst::compile(&world)?;
|
let doc = typst_shim::compile_opt(&world)?;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,7 @@ impl<D: typst::Document + Send + Sync + 'static> CompilationTask<D> {
|
||||||
};
|
};
|
||||||
|
|
||||||
world.to_mut().set_is_compiling(true);
|
world.to_mut().set_is_compiling(true);
|
||||||
let compiled = ::typst::compile::<D>(world.as_ref());
|
let compiled = ::typst_shim::compile_opt::<D>(world.as_ref());
|
||||||
world.to_mut().set_is_compiling(false);
|
world.to_mut().set_is_compiling(false);
|
||||||
|
|
||||||
let exclude_html_warnings = if !is_html_compilation {
|
let exclude_html_warnings = if !is_html_compilation {
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ mod tests {
|
||||||
.expect("failed to resolve system universe");
|
.expect("failed to resolve system universe");
|
||||||
|
|
||||||
let world = verse.snapshot();
|
let world = verse.snapshot();
|
||||||
let _res = typst::compile::<TypstPagedDocument>(&world);
|
let _res = typst_shim::compile_opt::<TypstPagedDocument>(&world);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FONT_COMPUTED: AtomicBool = AtomicBool::new(false);
|
static FONT_COMPUTED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ async fn trace_main(
|
||||||
req_id: RequestId,
|
req_id: RequestId,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
typst_timing::enable();
|
typst_timing::enable();
|
||||||
let res = typst::compile::<TypstPagedDocument>(g.world());
|
let res = typst_shim::compile_opt::<TypstPagedDocument>(g.world());
|
||||||
let diags = match &res.output {
|
let diags = match &res.output {
|
||||||
Ok(_res) => res.warnings,
|
Ok(_res) => res.warnings,
|
||||||
Err(errors) => errors.clone(),
|
Err(errors) => errors.clone(),
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,7 @@ impl Typlite {
|
||||||
format: Format,
|
format: Format,
|
||||||
world: Arc<LspWorld>,
|
world: Arc<LspWorld>,
|
||||||
) -> tinymist_std::Result<MarkdownDocument> {
|
) -> tinymist_std::Result<MarkdownDocument> {
|
||||||
|
// this is not affected by syntax-only mode (typst_shim::compile_opt)
|
||||||
let compiled = typst::compile(&world);
|
let compiled = typst::compile(&world);
|
||||||
let collector = WarningCollector::default();
|
let collector = WarningCollector::default();
|
||||||
collector.extend(
|
collector.extend(
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,7 @@ impl HtmlToAstParser {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// this is not affected by syntax-only mode (typst_shim::compile_opt)
|
||||||
let compiled = typst::compile(&world);
|
let compiled = typst::compile(&world);
|
||||||
self.warnings.extend(compiled.warnings.iter().cloned());
|
self.warnings.extend(compiled.warnings.iter().cloned());
|
||||||
let doc = match compiled.output {
|
let doc = match compiled.output {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
//! # typst-shim
|
//! # typst-shim
|
||||||
|
|
||||||
|
mod syntax_only;
|
||||||
|
pub use syntax_only::*;
|
||||||
|
|
||||||
pub use cfg_if::cfg_if;
|
pub use cfg_if::cfg_if;
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
|
|
|
||||||
34
crates/typst-shim/src/syntax_only.rs
Normal file
34
crates/typst-shim/src/syntax_only.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use typst::{
|
||||||
|
Document, World,
|
||||||
|
diag::{SourceDiagnostic, SourceResult, Warned},
|
||||||
|
ecow::eco_vec,
|
||||||
|
};
|
||||||
|
use typst_syntax::Span;
|
||||||
|
|
||||||
|
/// Global flag indicating whether syntax-only mode is enabled.
|
||||||
|
pub static SYNTAX_ONLY: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
|
/// Check if syntax-only mode is enabled.
|
||||||
|
pub fn is_syntax_only() -> bool {
|
||||||
|
SYNTAX_ONLY.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compile the document if syntax-only mode is disabled; otherwise, return an
|
||||||
|
/// error.
|
||||||
|
pub fn compile_opt<D>(world: &dyn World) -> Warned<SourceResult<D>>
|
||||||
|
where
|
||||||
|
D: Document,
|
||||||
|
{
|
||||||
|
if is_syntax_only() {
|
||||||
|
Warned {
|
||||||
|
output: Err(eco_vec![SourceDiagnostic::error(
|
||||||
|
Span::detached(),
|
||||||
|
"Compilation is disabled in syntax-only mode.",
|
||||||
|
)]),
|
||||||
|
warnings: Default::default(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
typst::compile::<D>(world)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ Given a file, tinymist will try to discover tests related to the file.
|
||||||
- All dependent files in the same workspace will be checked.
|
- All dependent files in the same workspace will be checked.
|
||||||
- For example, if file `a.typ` contains `import "b.typ"` or `include "b.typ"`, tinymist will check `b.typ` for tests as well.
|
- For example, if file `a.typ` contains `import "b.typ"` or `include "b.typ"`, tinymist will check `b.typ` for tests as well.
|
||||||
- For each file including the entry file itself, tinymist will check the file for tests.
|
- For each file including the entry file itself, tinymist will check the file for tests.
|
||||||
- If a file is named `example-*.typ`, it is considered an *example document* and will be compiled using `typst::compile`.
|
- If a file is named `example-*.typ`, it is considered an *example document* and will be compiled using `typst_shim::compile_opt`.
|
||||||
- Both png export and html export may be called.
|
- Both png export and html export may be called.
|
||||||
- For now, png export is always called for each example file.
|
- For now, png export is always called for each example file.
|
||||||
- If the label `<test-html-example>` can be found in the example file, html export will be called.
|
- If the label `<test-html-example>` can be found in the example file, html export will be called.
|
||||||
|
|
|
||||||
|
|
@ -1036,7 +1036,7 @@ en = "Configure whether to enable syntax-only mode for the language server. In s
|
||||||
zh = "配置是否为语言服务器启用仅语法模式。在仅语法模式下,语言服务器将仅提供语法检查和基本的代码补全,但不会执行完整的文档编译或代码分析。这对于提高低端设备的性能或处理大型文档时非常有用。"
|
zh = "配置是否为语言服务器启用仅语法模式。在仅语法模式下,语言服务器将仅提供语法检查和基本的代码补全,但不会执行完整的文档编译或代码分析。这对于提高低端设备的性能或处理大型文档时非常有用。"
|
||||||
|
|
||||||
[extension.tinymist.config.tinymist.lsp.syntaxOnly.string.enum.auto]
|
[extension.tinymist.config.tinymist.lsp.syntaxOnly.string.enum.auto]
|
||||||
en = "Always enable syntax-only mode. The strategy may be changed in the future, for example, automatically enable syntax-only mode when the system is in power-saving mode."
|
en = "Always disable syntax-only mode. The strategy may be changed in the future, for example, automatically enable syntax-only mode when the system is in power-saving mode."
|
||||||
zh = "始终启用仅语法模式。未来可能会更改策略,例如,当系统处于省电模式时自动启用仅语法模式。"
|
zh = "始终启用仅语法模式。未来可能会更改策略,例如,当系统处于省电模式时自动启用仅语法模式。"
|
||||||
|
|
||||||
[extension.tinymist.config.tinymist.lsp.syntaxOnly.string.enum.onPowerSaving]
|
[extension.tinymist.config.tinymist.lsp.syntaxOnly.string.enum.onPowerSaving]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue