docs: maintain readme and command docs (#733)

* docs: maintain readme and command docs

* docs: update inline images

* test: update snapshot

* test: update baseline

* test: update baseline
This commit is contained in:
Myriad-Dreamin 2024-10-26 22:47:12 +08:00 committed by GitHub
parent 81ebc8a635
commit 2c38695b6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 402 additions and 159 deletions

View file

@ -45,9 +45,11 @@ jobs:
run: |
mkdir -p assets/fonts/
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.2/font-assets.tar.gz | tar -xvz -C assets/fonts
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.0/charter-font-assets.tar.gz | tar -xvz -C assets/fonts
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.5/source-han-serif-font-assets.tar.gz | tar -xvz -C assets/fonts
- name: Download & install shiroa
run: |
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.2.0-nightly4/shiroa-x86_64-unknown-linux-gnu.tar.gz | tar -xvz
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.2.0-nightly5/shiroa-x86_64-unknown-linux-gnu.tar.gz | tar -xvz
chmod +x shiroa-x86_64-unknown-linux-gnu/bin/shiroa
sudo cp shiroa-x86_64-unknown-linux-gnu/bin/shiroa /usr/bin/shiroa
- name: Install Node.js

View file

@ -2,5 +2,8 @@
"eslint.format.enable": true,
"eslint.workingDirectories": [
"editors/vscode"
]
],
"tinymist.fontPaths": [
"assets/fonts"
],
}

View file

@ -6,7 +6,6 @@ Tinymist provides a single integrated language service for Typst.
**Multiple Actors** The main component, [tinymist](./crates/tinymist/), starts as a thread or process, obeying the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/). tinymist will bootstrap multiple actors, each of which provides some typst feature.
**Multi-level Analysis** The most critical features are lsp functions, built on the [tinymist-query](./crates/tinymist-query/) crate. To achieve low latency, functions are classified into different levels of analysis.
+ `query_token_cache` `TokenRequest` locks and accesses token cache.
+ `query_source` `SyntaxRequest` locks and accesses a single source unit.
+ `query_world` `SemanticRequest` locks and accesses multiple source units.
+ `query_state` `StatefulRequest` acquires to accesses a specific version of compile results.

View file

@ -19,8 +19,11 @@ Language service (LSP) features:
- [Semantic highlighting](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide)
- The "semantic highlighting" is supplementary to ["syntax highlighting"](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide).
- [Diagnostics](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#provide-diagnostics)
- Also known as "error checking" or "error reporting".
- [Code actions](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#provide-code-actions)
- Also known as "quick fixes" or "refactorings".
- [Formatting (Reformatting)](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#format-source-code-in-an-editor)
- Provide the user with support for formatting whole documents, using [typstfmt](https://github.com/astrale-sharp/typstfmt) or [typstyle](https://github.com/Enter-tainer/typstyle).
- [Document highlight](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#highlight-all-occurrences-of-a-symbol-in-a-document)
- Highlight all break points in a loop context.
- (Todo) Highlight all exit points in a function context.
@ -47,7 +50,7 @@ Language service (LSP) features:
- Change the color literal's value by a color picker or its code presentation.
- [Code Lens](https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup)
- Should give contextual buttons along with code. For example, a button for exporting your document to various formats at the start of the document.
- [Rename symbols](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#rename-symbols)
- [Rename symbols and embedded paths](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#rename-symbols)
- [Help with function and method signatures](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#help-with-function-and-method-signatures)
- [Workspace Symbols](https://code.visualstudio.com/api/language-extensions/programmatic-language-features#show-all-symbol-definitions-in-folder)
- [Code Action](https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-code-actions)
@ -69,9 +72,14 @@ Extra features:
- Trace execution in current document (`tinymist.profileCurrentFile`).
## Release Cycle
## Versioning and Release Cycle
Tinymist follows the [Semantic Versioning](https://semver.org/) scheme. The version number is in the format of `MAJOR.MINOR.PATCH`. The release cycle is as follows:
Tinymist's versions follow the [Semantic Versioning](https://semver.org/) scheme, in format of `MAJOR.MINOR.PATCH`. Besides, tinymist follows special rules for the version number:
- If a version is suffixed with `-rcN` (<picture><source media="(prefers-color-scheme: dark)" srcset="./assets/images/introduction.typ-inlined0.svg"><img style="vertical-align: -0.35em" alt="typst-block" src="./assets/images/introduction.typ-inlined1.svg"/></picture>), e.g. `0.11.0-rc1` and `0.12.1-rc1`, it means this version is a release candidate. It is used to test publish script and E2E functionalities. These versions will not be published to the marketplace.
- If the `PATCH` number is odd, e.g. `0.11.1` and `0.12.3`, it means this version is a nightly release. The nightly release will use both [tinymist](https://github.com/Myriad-Dreamin/tinymist/tree/main) and [typst](https://github.com/typst/typst/tree/main) at **main branch**. They will be published as prerelease version to the marketplace.
- Otherwise, if the `PATCH` number is even, e.g. `0.11.0` and `0.12.2`, it means this version is a regular release. The regular release will always use the recent stable version of tinymist and typst.
The release cycle is as follows:
- If there is a typst version update, a new major or minor version will be released intermediately. This means tinymist will always align the minor version with typst.
- If there is at least a bug or feature added this week, a new patch version will be released.
@ -102,19 +110,21 @@ See [Online Documentation](https://myriad-dreamin.github.io/tinymist/).
## Packaging
Stable Channel:
[![Packaging status](https://repology.org/badge/vertical-allrepos/tinymist.svg)](https://repology.org/project/tinymist/versions)
Nightly Channel:
[![Packaging status](https://repology.org/badge/vertical-allrepos/tinymist-nightly.svg)](https://repology.org/project/tinymist-nightly/versions)
## Roadmap
After development for two months, most of the features are implemented. There are still some features to be implemented, but I would like to leave them in typst v0.12.0. I'll also pick some of them to implement on my weekends. Also please feel free to contribute if you are interested in the following features.
- Documentation and refactoring: It is my current focus.
- Spell checking: There is already a branch but no suitable (default) spell checking library is found.
- Periscope renderer: It is disabled since vscode reject to render SVGs containing foreignObjects.
- Inlay hint: It is disabled _by default_ because of performance issues.
- Find references of labels, dictionary fields, and named function arguments.
- Find references of dictionary fields and named function arguments.
- Go to definition of dictionary fields and named function arguments.
- Autocompletion for raw language tags.
- Improve symbol view's appearance.
## Contributing
@ -125,4 +135,5 @@ Please read the [CONTRIBUTING.md](CONTRIBUTING.md) file for contribution guideli
- Partially code is inherited from [typst-lsp](https://github.com/nvarner/typst-lsp)
- The [integrating](https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#symbol-view) **offline** handwritten-stroke recognizer is powered by [Detypify](https://detypify.quarticcat.com/).
- The [integrating](https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#preview) preview service is powered by [typst-preview](https://github.com/Enter-tainer/typst-preview).
- The [integrating](https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#preview-command) preview service is powered by [typst-preview](https://github.com/Enter-tainer/typst-preview).
- The [integrating](https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#managing-local-packages) local package management functions are adopted from [vscode-typst-sync](https://github.com/OrangeX4/vscode-typst-sync).

1
assets/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
fonts

View file

@ -0,0 +1,31 @@
<svg class="typst-doc" viewBox="0 0 30.168111111111113 17.413" width="30.168111111111113pt" height="17.413pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:h5="http://www.w3.org/1999/xhtml">
<path class="typst-shape" fill="#ffffff00" fill-rule="nonzero" d="M 0 0 L 0 17.413 L 30.168112 17.413 L 30.168112 0 Z "/>
<g>
<g transform="translate(0 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#gDC2432172D1C7540AF3060D5F5816930" x="0" fill="#c0caf5" fill-rule="nonzero"/>
</g>
</g>
<g transform="translate(13.054555555555556 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#g314767091687453EB900D8E794E80805" x="0" fill="#c0caf5" fill-rule="nonzero"/>
</g>
</g>
<g transform="translate(24.668111111111113 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#g5950DEE49BBD32410D709EF7B482EDA" x="0" fill="#c0caf5" fill-rule="nonzero"/>
</g>
</g>
</g>
<defs id="glyph">
<symbol id="gDC2432172D1C7540AF3060D5F5816930" overflow="visible">
<path d="M 9.504 7.513 C 9.295 7.513 8.613 7.48 8.404 7.48 C 8.195 7.48 7.502 7.513 7.2929997 7.513 C 7.128 7.513 7.051 7.425 7.051 7.249 C 7.051 7.15 7.128 7.095 7.2929997 7.084 C 7.755 7.084 7.986 6.941 7.986 6.6549997 C 7.986 6.5889997 7.975 6.512 7.9639997 6.435 L 6.776 1.727 L 4.411 7.282 C 4.323 7.491 4.301 7.513 4.026 7.513 L 2.563 7.513 C 2.299 7.513 2.2 7.491 2.2 7.249 C 2.2 7.139 2.321 7.084 2.552 7.084 C 3.014 7.084 3.245 7.073 3.256 7.04 L 1.793 1.21 C 1.694 0.781 1.441 0.539 1.045 0.462 C 0.759 0.429 0.429 0.473 0.429 0.16499999 C 0.429 0.055 0.495 0 0.616 0 C 0.814 0 1.496 0.033 1.705 0.033 C 1.914 0.033 2.618 0 2.827 0 C 2.992 0 3.069 0.088 3.069 0.264 C 3.069 0.363 2.981 0.41799998 2.805 0.429 C 2.354 0.44 2.134 0.583 2.134 0.858 C 2.134 0.913 2.145 0.99 2.167 1.1 L 3.586 6.721 L 6.336 0.231 C 6.402 0.077 6.49 0 6.5889997 0 C 6.6879997 0 6.754 0.088 6.798 0.264 L 8.327 6.314 C 8.47 6.875 8.778 7.073 9.46 7.084 C 9.614 7.095 9.691 7.183 9.691 7.3589997 C 9.658 7.458 9.647 7.513 9.504 7.513 Z "/>
</symbol>
<symbol id="g314767091687453EB900D8E794E80805" overflow="visible">
<path d="M 7.546 2.497 C 7.656 2.552 7.711 2.629 7.711 2.75 C 7.711 2.871 7.656 2.948 7.546 3.003 L 1.232 5.995 C 1.199 6.006 1.155 6.017 1.111 6.017 C 0.935 6.017 0.847 5.929 0.847 5.742 C 0.847 5.643 0.902 5.566 1.001 5.522 L 6.875 2.75 L 1.001 -0.022 C 0.902 -0.066 0.847 -0.143 0.847 -0.242 C 0.847 -0.429 0.935 -0.517 1.111 -0.517 C 1.155 -0.517 1.199 -0.506 1.232 -0.495 Z "/>
</symbol>
<symbol id="g5950DEE49BBD32410D709EF7B482EDA" overflow="visible">
<path d="M 2.739 -0.242 C 4.29 -0.242 5.06 1.012 5.06 3.52 C 5.06 5.203 4.708 6.325 4.015 6.875 C 3.6299999 7.172 3.201 7.3259997 2.75 7.3259997 C 1.199 7.3259997 0.429 6.061 0.429 3.52 C 0.429 1.496 0.968 -0.242 2.739 -0.242 Z M 3.971 5.764 C 4.048 5.379 4.081 4.675 4.081 3.652 C 4.081 2.6399999 4.037 1.892 3.96 1.408 C 3.817 0.528 3.41 0.088 2.739 0.088 C 2.486 0.088 2.233 0.187 2.002 0.374 C 1.705 0.627 1.529 1.144 1.452 1.936 C 1.419 2.211 1.408 2.783 1.408 3.652 C 1.408 4.609 1.441 5.2799997 1.496 5.643 C 1.595 6.248 1.793 6.633 2.101 6.798 C 2.343 6.93 2.552 6.996 2.739 6.996 C 3.454 6.996 3.85 6.413 3.971 5.764 Z "/>
</symbol>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -0,0 +1,31 @@
<svg class="typst-doc" viewBox="0 0 30.168111111111113 17.413" width="30.168111111111113pt" height="17.413pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:h5="http://www.w3.org/1999/xhtml">
<path class="typst-shape" fill="#ffffff00" fill-rule="nonzero" d="M 0 0 L 0 17.413 L 30.168112 17.413 L 30.168112 0 Z "/>
<g>
<g transform="translate(0 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#gDC2432172D1C7540AF3060D5F5816930" x="0" fill="#000000" fill-rule="nonzero"/>
</g>
</g>
<g transform="translate(13.054555555555556 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#g314767091687453EB900D8E794E80805" x="0" fill="#000000" fill-rule="nonzero"/>
</g>
</g>
<g transform="translate(24.668111111111113 12.463)">
<g class="typst-text" transform="scale(1, -1)">
<use xlink:href="#g5950DEE49BBD32410D709EF7B482EDA" x="0" fill="#000000" fill-rule="nonzero"/>
</g>
</g>
</g>
<defs id="glyph">
<symbol id="gDC2432172D1C7540AF3060D5F5816930" overflow="visible">
<path d="M 9.504 7.513 C 9.295 7.513 8.613 7.48 8.404 7.48 C 8.195 7.48 7.502 7.513 7.2929997 7.513 C 7.128 7.513 7.051 7.425 7.051 7.249 C 7.051 7.15 7.128 7.095 7.2929997 7.084 C 7.755 7.084 7.986 6.941 7.986 6.6549997 C 7.986 6.5889997 7.975 6.512 7.9639997 6.435 L 6.776 1.727 L 4.411 7.282 C 4.323 7.491 4.301 7.513 4.026 7.513 L 2.563 7.513 C 2.299 7.513 2.2 7.491 2.2 7.249 C 2.2 7.139 2.321 7.084 2.552 7.084 C 3.014 7.084 3.245 7.073 3.256 7.04 L 1.793 1.21 C 1.694 0.781 1.441 0.539 1.045 0.462 C 0.759 0.429 0.429 0.473 0.429 0.16499999 C 0.429 0.055 0.495 0 0.616 0 C 0.814 0 1.496 0.033 1.705 0.033 C 1.914 0.033 2.618 0 2.827 0 C 2.992 0 3.069 0.088 3.069 0.264 C 3.069 0.363 2.981 0.41799998 2.805 0.429 C 2.354 0.44 2.134 0.583 2.134 0.858 C 2.134 0.913 2.145 0.99 2.167 1.1 L 3.586 6.721 L 6.336 0.231 C 6.402 0.077 6.49 0 6.5889997 0 C 6.6879997 0 6.754 0.088 6.798 0.264 L 8.327 6.314 C 8.47 6.875 8.778 7.073 9.46 7.084 C 9.614 7.095 9.691 7.183 9.691 7.3589997 C 9.658 7.458 9.647 7.513 9.504 7.513 Z "/>
</symbol>
<symbol id="g314767091687453EB900D8E794E80805" overflow="visible">
<path d="M 7.546 2.497 C 7.656 2.552 7.711 2.629 7.711 2.75 C 7.711 2.871 7.656 2.948 7.546 3.003 L 1.232 5.995 C 1.199 6.006 1.155 6.017 1.111 6.017 C 0.935 6.017 0.847 5.929 0.847 5.742 C 0.847 5.643 0.902 5.566 1.001 5.522 L 6.875 2.75 L 1.001 -0.022 C 0.902 -0.066 0.847 -0.143 0.847 -0.242 C 0.847 -0.429 0.935 -0.517 1.111 -0.517 C 1.155 -0.517 1.199 -0.506 1.232 -0.495 Z "/>
</symbol>
<symbol id="g5950DEE49BBD32410D709EF7B482EDA" overflow="visible">
<path d="M 2.739 -0.242 C 4.29 -0.242 5.06 1.012 5.06 3.52 C 5.06 5.203 4.708 6.325 4.015 6.875 C 3.6299999 7.172 3.201 7.3259997 2.75 7.3259997 C 1.199 7.3259997 0.429 6.061 0.429 3.52 C 0.429 1.496 0.968 -0.242 2.739 -0.242 Z M 3.971 5.764 C 4.048 5.379 4.081 4.675 4.081 3.652 C 4.081 2.6399999 4.037 1.892 3.96 1.408 C 3.817 0.528 3.41 0.088 2.739 0.088 C 2.486 0.088 2.233 0.187 2.002 0.374 C 1.705 0.627 1.529 1.144 1.452 1.936 C 1.419 2.211 1.408 2.783 1.408 3.652 C 1.408 4.609 1.441 5.2799997 1.496 5.643 C 1.595 6.248 1.793 6.633 2.101 6.798 C 2.343 6.93 2.552 6.996 2.739 6.996 C 3.454 6.996 3.85 6.413 3.971 5.764 Z "/>
</symbol>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

View file

@ -102,14 +102,14 @@ pub fn completion(args: ShellCompletionArgs) -> anyhow::Result<()> {
Ok(())
}
/// The main entry point for the LSP server.
/// The main entry point for the language server.
pub fn lsp_main(args: LspArgs) -> anyhow::Result<()> {
let pairs = LONG_VERSION.trim().split('\n');
let pairs = pairs
.map(|e| e.splitn(2, ":").map(|e| e.trim()).collect::<Vec<_>>())
.collect::<Vec<_>>();
log::info!("tinymist LSP version information: {pairs:?}");
log::info!("starting LSP server: {args:#?}");
log::info!("tinymist version information: {pairs:?}");
log::info!("starting Language server: {args:#?}");
let is_replay = !args.mirror.replay.is_empty();
with_stdio_transport(args.mirror.clone(), |conn| {
@ -126,7 +126,7 @@ pub fn lsp_main(args: LspArgs) -> anyhow::Result<()> {
.start(conn.receiver, is_replay)
})?;
log::info!("LSP server did shut down");
log::info!("language server did shut down");
Ok(())
}

View file

@ -1,4 +1,4 @@
//! tinymist LSP server
//! tinymist's language server
use std::collections::HashMap;
use std::path::{Path, PathBuf};

View file

@ -291,10 +291,27 @@ impl TypliteWorker {
}
fn render(&mut self, node: &SyntaxNode, inline: bool) -> Result<Value> {
let color = "#c0caf5";
let dark = self.render_inner(node, true)?;
let light = self.render_inner(node, false)?;
if inline {
Ok(Value::Content(eco_format!(
r#"<picture><source media="(prefers-color-scheme: dark)" srcset="data:image/svg+xml;base64,{dark}"><img style="vertical-align: -0.35em" alt="typst-block" src="data:image/svg+xml;base64,{light}"/></picture>"#
)))
} else {
Ok(Value::Content(eco_format!(
r#"<p align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="data:image/svg+xml;base64,{dark}"><img alt="typst-block" src="data:image/svg+xml;base64,{light}"/></picture></p>"#
)))
}
}
fn render_inner(&mut self, node: &SyntaxNode, is_dark: bool) -> Result<String> {
let color = if is_dark {
r##"#set text(rgb("#c0caf5"))"##
} else {
""
};
let main = Bytes::from(eco_format!(
r##"#set page(width: auto, height: auto, margin: (y: 0.45em, rest: 0em));#set text(rgb("{color}"))
r##"#set page(width: auto, height: auto, margin: (y: 0.45em, rest: 0em), fill: rgb("#ffffff00"));{color}
{}"##,
node.clone().into_text()
).as_bytes().to_owned());
@ -305,6 +322,7 @@ impl TypliteWorker {
entry: Some(entry),
inputs: None,
});
world.source_db.take_state();
world.map_shadow_by_id(main_id, main).unwrap();
let document = typst::compile(&world)
@ -312,17 +330,7 @@ impl TypliteWorker {
.map_err(|e| format!("compiling math node: {e:?}"))?;
let svg_payload = typst_svg::svg_merged(&document, Abs::zero());
let base64 = base64::engine::general_purpose::STANDARD.encode(svg_payload);
if inline {
Ok(Value::Content(eco_format!(
r#"<img style="vertical-align: -0.35em" src="data:image/svg+xml;base64,{base64}" alt="typst-block" />"#
)))
} else {
Ok(Value::Content(eco_format!(
r#"<p align="center"><img src="data:image/svg+xml;base64,{base64}" alt="typst-block" /></p>"#
)))
}
Ok(base64::engine::general_purpose::STANDARD.encode(svg_payload))
}
fn char(arg: char) -> Result<Value> {

View file

@ -24,7 +24,7 @@ fn conv_(s: &str, for_docs: bool) -> EcoString {
EntryState::new_rooted(cwd.as_path().into(), Some(main.id())),
font_resolver.unwrap(),
Default::default(),
Default::default()
Default::default(),
)
.unwrap();
universe
@ -36,7 +36,7 @@ fn conv_(s: &str, for_docs: bool) -> EcoString {
let res = converter.convert().unwrap();
static REG: OnceLock<Regex> = OnceLock::new();
let reg = REG.get_or_init(|| Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap());
let res = reg.replace(&res, |_captures: &regex::Captures| {
let res = reg.replace_all(&res, |_captures: &regex::Captures| {
// let hash = _captures.get(1).unwrap().as_str();
// format!(
// "data:image-hash/svg+xml;base64,siphash128:{:x}",
@ -93,7 +93,11 @@ Some inlined raw `a`, ```c b```
$
1/2 + 1/3 = 5/6
$
"###), @r###"<p align="center"><img src="data:image-hash/svg+xml;base64,redacted" alt="typst-block" /></p>"###);
"###), @r###"
<p align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="data:image-hash/svg+xml;base64,redacted"><img alt="typst-block" src="data:image-hash/svg+xml;base64,redacted"/></picture></p>
"###);
}
#[test]

View file

@ -4,8 +4,16 @@ use crate::tests::*;
fn test_math_equation() {
insta::assert_snapshot!(conv(r###"
$integral x dif x$
"###), @r###"<img style="vertical-align: -0.35em" src="data:image-hash/svg+xml;base64,redacted" alt="typst-block" />"###);
"###), @r###"
<picture><source media="(prefers-color-scheme: dark)" srcset="data:image-hash/svg+xml;base64,redacted"><img style="vertical-align: -0.35em" alt="typst-block" src="data:image-hash/svg+xml;base64,redacted"/></picture>
"###);
insta::assert_snapshot!(conv(r###"
$ integral x dif x $
"###), @r###"<p align="center"><img src="data:image-hash/svg+xml;base64,redacted" alt="typst-block" /></p>"###);
"###), @r###"
<p align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="data:image-hash/svg+xml;base64,redacted"><img alt="typst-block" src="data:image-hash/svg+xml;base64,redacted"/></picture></p>
"###);
}

View file

@ -1,5 +1,5 @@
#import "@preview/shiroa:0.1.1": *
#import "@preview/shiroa:0.1.2": *
#show: book

View file

@ -1,4 +1,4 @@
#import "@preview/shiroa:0.1.1": *
#import "@preview/shiroa:0.1.2": *
#import "/typ/templates/ebook.typ"

View file

@ -2,7 +2,7 @@
#show: book-page.with(title: "Tinymist Command Line Interface (CLI)")
== Starting a LSP Server
== Starting a Language Server
To start a language server following the #link("https://microsoft.github.io/language-server-protocol/")[Language Server Protocol].

View file

@ -5,8 +5,11 @@ Language service (LSP) features:
- #link("https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide")[Semantic highlighting]
- The "semantic highlighting" is supplementary to #link("https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide")["syntax highlighting"].
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#provide-diagnostics")[Diagnostics]
- Also known as "error checking" or "error reporting".
// formatting
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#provide-code-actions")[Code actions]
- Also known as "quick fixes" or "refactorings".
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#format-source-code-in-an-editor")[Formatting (Reformatting)]
- Provide the user with support for formatting whole documents, using #link("https://github.com/astrale-sharp/typstfmt")[typstfmt] or #link("https://github.com/Enter-tainer/typstyle")[typstyle].
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#highlight-all-occurrences-of-a-symbol-in-a-document")[Document highlight]
- Highlight all break points in a loop context.
- (Todo) Highlight all exit points in a function context.
@ -33,7 +36,7 @@ Language service (LSP) features:
- Change the color literal's value by a color picker or its code presentation.
- #link("https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup")[Code Lens]
- Should give contextual buttons along with code. For example, a button for exporting your document to various formats at the start of the document.
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#rename-symbols")[Rename symbols]
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#rename-symbols")[Rename symbols and embedded paths]
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#help-with-function-and-method-signatures")[Help with function and method signatures]
- #link("https://code.visualstudio.com/api/language-extensions/programmatic-language-features#show-all-symbol-definitions-in-folder")[Workspace Symbols]
- #link("https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-code-actions")[Code Action]

View file

@ -70,7 +70,7 @@ tinymist preview /abs-path/to/main.typ --partial-rendering
#pro-tip[
=== VSCode:
The preview feature is also integrated into the LSP server. You can use the preview feature like when you were using it in `mgt19937.typst-preview` extension.
The preview feature is also integrated into the language server. You can use the preview feature like when you were using it in `mgt19937.typst-preview` extension.
]
#pro-tip[

View file

@ -29,8 +29,8 @@ your PATH and `typst-lsp` in your `PATH` to the `typst-ts-mode` entry of `eglot-
== Extra Settings
<extra-settings>
=== Configuring LSP Server
<configuring-lsp-server>
=== Configuring Language Server
<configuring-language-server>
You can either use `eglot-workspace-configuration` or specifying launch
arguments for `tinymist`.

View file

@ -48,7 +48,7 @@ Note: With that configuration, if youre seeing a file that is not reachable b
== Extra Settings
<extra-settings>
To configure LSP server, you can edit the `language-server.tinymist` section. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
To configure language server, you can edit the `language-server.tinymist` section. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
```toml
[language-server.tinymist]

View file

@ -32,7 +32,7 @@ This section shows you a minimal way to setup tinymist in Neovim (LazyVim).
+ Check and restart Neovim.
// todo: heading link support
Please see #md-alter(link(<extra-settings>)[Extra Settings], () => link("#extra-settings")[Extra Settings]) for more configuration.
Please see #md-alter(link(<neovim-extra-settings>)[Extra Settings], () => link("#extra-settings")[Extra Settings]) for more configuration.
== Tips
<tips>
@ -72,10 +72,10 @@ autocmd BufNewFile,BufRead *.typ setfiletype typst
```
== Extra Settings
<extra-settings>
=== Configuring LSP Server
<configuring-lsp-server>
To configure LSP server, you can edit the `opts.servers.tinymist.settings`. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
<neovim-extra-settings>
=== Configuring Language Server
<neovim-configuring-language-server>
To configure language server, you can edit the `opts.servers.tinymist.settings`. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
```lua
return {
@ -121,7 +121,7 @@ Enable LSP-based folding range with `kevinhwang91/nvim-ufo`:
```lua
return {
{ -- configure LSP servers
{ -- configure language servers
"neovim/nvim-lspconfig",
dependencies = "kevinhwang91/nvim-ufo", -- enable LSP-based folds
},

View file

@ -24,7 +24,7 @@ To initialize a Typst project:
🎉 If your template contains only a single file, you can also insert the template content in place with command:
- Use command `Typst template in place` (tinymist.initTemplateInPlace) and input a template specifier for initialization.
=== Configuring LSP-enhanced formatters
=== Configuring LSP-Enhanced Formatters
<configuring-lsp-enhanced-formatters>
+ Open settings.
+ Search for "Tinymist Formatter" and modify the value.
@ -92,6 +92,12 @@ To configure the root path resolved for Typst compiler:
+ Search for "Tinymist Root Path" and modify the value.
+ Reload the window or restart the vscode editor to make the settings take effect. *Note:* you must provide absolute paths.
=== Managing Local Packages
+ Use `Typst: Create Typst Local Package` command to create a local package.
+ Use `Typst: Open Typst Local Package` command to open a local package.
+ View and manage a list of available local packages in the "PACKAGE" view in the activity bar.
=== Compiling PDF
<compiling-pdf>
This extension compiles to PDF, but it doesnt have a PDF viewer yet. To view the output as you work, install a PDF viewer extension, such as `vscode-pdf`.
@ -161,6 +167,7 @@ Supported arguments:
- `--font-path` (environment variable: `TYPST_FONT_PATHS`), Font paths, maybe overriden by `tinymist.fontPaths`.
- `--ignore-system-fonts`: Ensures system fonts wont be searched, maybe overriden by `tinymist.systemFonts`.
- `--creation-timestamp` (environment variable: `SOURCE_DATE_EPOCH`): The documents creation date formatted as a #link("https://reproducible-builds.org/specs/source-date-epoch/")[UNIX timestamp];.
- `--cert` (environment variable: `TYPST_CERT`): Path to CA certificate file for network access, especially for downloading typst packages.
*Note:* Fix entry to `main.typ` may help multiple-file projects
but you may loss diagnostics and autocompletions in unrelated files.

View file

@ -16,9 +16,14 @@ It contains:
#include "feature/language-content.typ"
== Release Cycle
== Versioning and Release Cycle
Tinymist follows the #link("https://semver.org/")[Semantic Versioning] scheme. The version number is in the format of `MAJOR.MINOR.PATCH`. The release cycle is as follows:
Tinymist's versions follow the #link("https://semver.org/")[Semantic Versioning] scheme, in format of `MAJOR.MINOR.PATCH`. Besides, tinymist follows special rules for the version number:
- If a version is suffixed with `-rcN` ($N > 0$), e.g. `0.11.0-rc1` and `0.12.1-rc1`, it means this version is a release candidate. It is used to test publish script and E2E functionalities. These versions will not be published to the marketplace.
- If the `PATCH` number is odd, e.g. `0.11.1` and `0.12.3`, it means this version is a nightly release. The nightly release will use both #link("https://github.com/Myriad-Dreamin/tinymist/tree/main")[tinymist] and #link("https://github.com/typst/typst/tree/main")[typst] at *main branch*. They will be published as prerelease version to the marketplace.
- Otherwise, if the `PATCH` number is even, e.g. `0.11.0` and `0.12.2`, it means this version is a regular release. The regular release will always use the recent stable version of tinymist and typst.
The release cycle is as follows:
- If there is a typst version update, a new major or minor version will be released intermediately. This means tinymist will always align the minor version with typst.
- If there is at least a bug or feature added this week, a new patch version will be released.
@ -49,6 +54,8 @@ See #link("https://myriad-dreamin.github.io/tinymist/")[Online Documentation].
== Packaging
Stable Channel:
#link(
"https://repology.org/project/tinymist/versions",
md-alter(
@ -57,17 +64,23 @@ See #link("https://myriad-dreamin.github.io/tinymist/")[Online Documentation].
),
)
Nightly Channel:
#link(
"https://repology.org/project/tinymist-nightly/versions",
md-alter(
"Packaging status",
() => image("https://repology.org/badge/vertical-allrepos/tinymist-nightly.svg", alt: "Packaging status"),
),
)
== Roadmap
After development for two months, most of the features are implemented. There are still some features to be implemented, but I would like to leave them in typst v0.12.0. I'll also pick some of them to implement on my weekends. Also please feel free to contribute if you are interested in the following features.
- Documentation and refactoring: It is my current focus.
- Spell checking: There is already a branch but no suitable (default) spell checking library is found.
- Periscope renderer: It is disabled since vscode reject to render SVGs containing foreignObjects.
- Inlay hint: It is disabled _by default_ because of performance issues.
- Find references of labels, dictionary fields, and named function arguments.
- Find references of dictionary fields and named function arguments.
- Go to definition of dictionary fields and named function arguments.
- Autocompletion for raw language tags.
- Improve symbol view's appearance.
== Contributing
@ -78,4 +91,5 @@ Please read the #link("CONTRIBUTING.md")[CONTRIBUTING.md] file for contribution
- Partially code is inherited from #link("https://github.com/nvarner/typst-lsp")[typst-lsp]
- The #link("https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#symbol-view")[integrating] *offline* handwritten-stroke recognizer is powered by #link("https://detypify.quarticcat.com/")[Detypify].
- The #link("https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#preview")[integrating] preview service is powered by #link("https://github.com/Enter-tainer/typst-preview")[typst-preview].
- The #link("https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#preview-command")[integrating] preview service is powered by #link("https://github.com/Enter-tainer/typst-preview")[typst-preview].
- The #link("https://github.com/Myriad-Dreamin/tinymist/tree/main/editors/vscode#managing-local-packages")[integrating] local package management functions are adopted from #link("https://github.com/OrangeX4/vscode-typst-sync")[vscode-typst-sync].

View file

@ -24,18 +24,20 @@
#import fletcher.shapes: diamond
#let fg-blue = main-color.mix(rgb("#0074d9"))
#let pro-tip(content) = locate(loc => {
block(
width: 100%,
breakable: false,
inset: (x: 0.65em, y: 0.65em, left: 0.65em * 0.6),
radius: 4pt,
fill: rgb("#0074d920"),
{
set text(fill: fg-blue)
content
},
)
})
#let pro-tip(content) = (
context {
block(
width: 100%,
breakable: false,
inset: (x: 0.65em, y: 0.65em, left: 0.65em * 0.6),
radius: 4pt,
fill: rgb("#0074d920"),
{
set text(fill: fg-blue)
content
},
)
}
)
#let note-box = pro-tip

View file

@ -4,16 +4,89 @@
== Base Analyses
There are five basic analysis APIs:
There are seven basic analyzers:
- _lexical hierarchy_ matches crucial lexical structures in the source file.
- _def use info_ is computed based on _lexical hierarchy_\s.
- _type check info_ is computed with _def use info_.
- _find definition_ finds the definition based on _def use info_.
- _find references_ finds the references based on _def use info_.
- _expression info_ is computed incrementally on source files.
- _type check info_ is computed with _expression info_.
- _definition finder_ finds the definition based on _expression info_ and _type check info_.
- _references finder_ finds the references based on _definitions_ and _expression info_.
- _signature resolver_ summarizes signature based on _definitions_ and _type check info_.
- _call resolver_ check calls based on _signatures_ and _type check info_.
#let pg-node = node.with(corner-radius: 2pt, shape: "rect");
#let ref-n = (0.6, 1);
#let def-n = (1.9, 1);
#let sig-n = (3.1, 1);
#let call-n = (4.3, 1);
#let expr-n = (2.2, 0);
#let type-n = (3.3, 0);
#figure(
align(
center,
diagram(
node-stroke: 1pt,
edge-stroke: 1pt,
// edge("-|>", align(center)[Analysis\ Request], label-pos: 0.1),
pg-node((0.3, 0.2), [`Lexical`\ `Heirarchy`]),
edge("<|-", []),
pg-node((1.2, 0), [`Source`]),
edge("-|>", []),
pg-node(expr-n, [`ExprInfo`]),
edge("-|>"),
pg-node(type-n, [`TypeInfo`]),
edge("-|>"),
pg-node(def-n, [`Definition`]),
edge(expr-n, def-n, "-|>"),
pg-node(ref-n, [`References`]),
edge(def-n, ref-n, "-|>"),
edge(expr-n, ref-n, "-|>"),
pg-node(sig-n, [`Signature`]),
edge(def-n, sig-n, "-|>"),
edge(type-n, sig-n, "-|>"),
pg-node(call-n, [`Call`]),
edge(sig-n, call-n, "-|>"),
edge(type-n, call-n, "-|>"),
for i in range(9) {
let j = 1 + i * 0.25;
edge((j, 1.4), (j, 1.8), "-|>")
},
pg-node((2, 2.3), [`Extented`\
`Language Features`]),
// for i in (1, 3, 5) {
// edge((i, 0), (i, -0.5), (5.5, -0.5), (5.6, 0), "-|>")
// },
// edge(
// (0.3, 0.4),
// (0.3, 0),
// "-|>",
// align(center)[clone #typst-func("Source")],
// label-anchor: "center",
// label-pos: -0.5,
// ),
// edge(
// (2, 0.4),
// (2, 0),
// "-|>",
// align(center)[snapshot ```rs trait World```],
// label-anchor: "center",
// label-pos: -0.5,
// ),
// edge(
// (4, 0.4),
// (4, 0),
// "-|>",
// align(center)[acquire #typst-func("Document")],
// label-anchor: "center",
// label-pos: -0.5,
// ),
),
),
caption: [The relationship of analyzers.],
) <fig:analyses-relationship>
== Extending Language Features
Language features are implemented based on basic analysis APIs:
Typicial language features are implemented based on basic analyzers:
- The `textDocument/documentSymbol` returns a tree of nodes converted from the _lexical hierarchy_.

View file

@ -47,7 +47,6 @@ The `RenderActor`s don't do compilations, but own project-specific rendering cac
== Multi-level Analysis
he most critical features are lsp functions, built on the #link("https://github.com/Myriad-Dreamin/tinymist/tree/main/crates/tinymist-query")[tinymist-query] crate. To achieve higher concurrency, functions are classified into different levels of analysis.
// + `query_token_cache` `TokenRequest` locks and accesses token cache.
+ `query_source` `SyntaxRequest` locks and accesses a single source unit.
+ `query_world` `SemanticRequest` locks and accesses multiple source units.
+ `query_state` `StatefulRequest` acquires to accesses a specific version of compile results.

View file

@ -48,7 +48,7 @@ your PATH and `typst-lsp` in your `PATH` to the `typst-ts-mode` entry of `eglot-
## Extra Settings
### Configuring LSP Server
### Configuring Language Server
You can either use `eglot-workspace-configuration` or specifying launch

View file

@ -67,7 +67,7 @@ Note: With that configuration, if youre seeing a file that is not reachable b
## Extra Settings
To configure LSP server, you can edit the `language-server.tinymist` section. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
To configure language server, you can edit the `language-server.tinymist` section. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
```toml
[language-server.tinymist]

View file

@ -93,9 +93,9 @@ autocmd BufNewFile,BufRead *.typ setfiletype typst
## Extra Settings
### Configuring LSP Server
### Configuring Language Server
To configure LSP server, you can edit the `opts.servers.tinymist.settings`. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
To configure language server, you can edit the `opts.servers.tinymist.settings`. For example, if you want to export PDF on typing and output files in `$root_dir/target` directory:
```lua
return {
@ -141,7 +141,7 @@ Enable LSP-based folding range with `kevinhwang91/nvim-ufo`:
```lua
return {
{ -- configure LSP servers
{ -- configure language servers
"neovim/nvim-lspconfig",
dependencies = "kevinhwang91/nvim-ufo", -- enable LSP-based folds
},

View file

@ -23,7 +23,7 @@ To initialize a Typst project:
🎉 If your template contains only a single file, you can also insert the template content in place with command:
- Use command `Typst template in place` (tinymist.initTemplateInPlace) and input a template specifier for initialization.
### Configuring LSP-enhanced formatters
### Configuring LSP-Enhanced Formatters
1. Open settings.
1. Search for "Tinymist Formatter" and modify the value.
@ -91,6 +91,12 @@ To configure the root path resolved for Typst compiler:
1. Search for "Tinymist Root Path" and modify the value.
1. Reload the window or restart the vscode editor to make the settings take effect. **Note:** you must provide absolute paths.
### Managing Local Packages
1. Use `Typst: Create Typst Local Package` command to create a local package.
1. Use `Typst: Open Typst Local Package` command to open a local package.
1. View and manage a list of available local packages in the "PACKAGE" view in the activity bar.
### Compiling PDF
This extension compiles to PDF, but it doesnt have a PDF viewer yet. To view the output as you work, install a PDF viewer extension, such as `vscode-pdf`.
@ -161,6 +167,7 @@ Supported arguments:
- `--font-path` (environment variable: `TYPST_FONT_PATHS`), Font paths, maybe overriden by `tinymist.fontPaths`.
- `--ignore-system-fonts`: Ensures system fonts wont be searched, maybe overriden by `tinymist.systemFonts`.
- `--creation-timestamp` (environment variable: `SOURCE_DATE_EPOCH`): The documents creation date formatted as a [UNIX timestamp](https://reproducible-builds.org/specs/source-date-epoch/).
- `--cert` (environment variable: `TYPST_CERT`): Path to CA certificate file for network access, especially for downloading typst packages.
**Note:** Fix entry to `main.typ` may help multiple-file projects
but you may loss diagnostics and autocompletions in unrelated files.

View file

@ -2,13 +2,18 @@
"name": "tinymist",
"version": "0.12.0",
"description": "An integrated language service for Typst",
"keywords": [
"typst",
"lsp",
"language-server"
],
"categories": [
"Programming Languages",
"Formatters"
],
"repository": {
"type": "git",
"url": "https://github.com/Myriad-Dreamin/tinymist"
"url": "https://github.com/Myriad-Dreamin/tinymist.git"
},
"displayName": "Tinymist Typst",
"author": "Myriad-Dreamin",
@ -815,12 +820,12 @@
"commands": [
{
"command": "tinymist.exportCurrentPdf",
"title": "Export the currently open file as PDF",
"title": "Export the Opened File as PDF",
"category": "Typst"
},
{
"command": "tinymist.pinMainToCurrent",
"title": "Pin the main file to the currently opened document",
"title": "Pin the Main file to the Opening Document",
"category": "Typst"
},
{
@ -842,28 +847,28 @@
{
"command": "tinymist.showLog",
"title": "Tinymist: Show Log",
"description": "Show log of LSP Server",
"description": "Show log of the language server",
"category": "Typst",
"icon": "$(list-flat)"
},
{
"command": "tinymist.clearCache",
"title": "Clear all cached resources",
"title": "Clear all Cached Resources",
"category": "Typst"
},
{
"command": "tinymist.initTemplate",
"title": "Initialize a new Typst project based on a template",
"title": "Initialize a New Typst Project based on a Template",
"category": "Typst"
},
{
"command": "tinymist.initTemplateInPlace",
"title": "Insert the content of template entry in place",
"title": "Insert the Content of Template Entry in Place",
"category": "Typst"
},
{
"command": "tinymist.showTemplateGallery",
"title": "Show available Typst templates (gallery) for picking up a template to initialize",
"title": "Show Available Typst Templates (Gallery) for Picking up a Template to Initialize",
"category": "Typst"
},
{
@ -894,39 +899,40 @@
{
"command": "tinymist.syncLabel",
"title": "Scan workspace and collect all labels again",
"icon": "$(extensions-sync-enabled)"
"icon": "$(extensions-sync-enabled)",
"category": "Typst"
},
{
"command": "typst-preview.preview",
"title": "Typst Preview: Preview current file",
"title": "Typst Preview: Preview Opened File",
"description": "Launch typst-preview server",
"icon": "$(open-preview)",
"when": "resourceLangId == typst && editorTextFocus"
},
{
"command": "typst-preview.browser",
"title": "Typst Preview: Preview current file in browser",
"title": "Typst Preview: Preview Opened File in Browser",
"description": "Launch typst-preview server and open the preview in your browser",
"icon": "$(open-preview)",
"when": "resourceLangId == typst && editorTextFocus"
},
{
"command": "typst-preview.preview-slide",
"title": "Typst Preview: Preview current file in slide mode",
"title": "Typst Preview: Preview Opened File in Slide Mode",
"description": "Launch typst-preview server in slide mode",
"icon": "$(open-preview)",
"when": "resourceLangId == typst && editorTextFocus"
},
{
"command": "typst-preview.browser-slide",
"title": "Typst Preview: Preview current file in browser and slide mode",
"title": "Typst Preview: Preview Opened file in Browser and Slide Mode",
"description": "Launch typst-preview server in slide mode and open the preview in your browser",
"icon": "$(open-preview)",
"when": "resourceLangId == typst && editorTextFocus"
},
{
"command": "typst-preview.sync",
"title": "Typst Preview: Sync preview with current cursor",
"title": "Typst Preview: Sync Preview with Current Cursor",
"description": "Scroll preview to current cursor position",
"icon": "$(sync)",
"when": "resourceLangId == typst && editorTextFocus"

View file

@ -14,7 +14,7 @@
"scripts": {
"build:editor-tools": "cd tools/editor-tools/ && yarn run build",
"build:preview": "cd tools/typst-preview-frontend && yarn run build && rimraf ../../crates/tinymist-assets/src/typst-preview.html && cpr ./dist/index.html ../../crates/tinymist-assets/src/typst-preview.html",
"docs": "shiroa serve -w . docs/tinymist",
"docs": "shiroa serve --font-path assets/fonts -w . docs/tinymist",
"docs:typ": "node scripts/link-docs.mjs",
"docs:rs": "cargo doc --workspace --no-deps",
"test:grammar": "cd syntaxes/textmate && yarn run test",
@ -32,4 +32,4 @@
"vite-plugin-wasm": "^3.2.2",
"vitest": "^0.32.2"
}
}
}

View file

@ -1,54 +1,96 @@
import {resolve} from 'path';
import {fileURLToPath} from 'url';
import * as fs from 'fs';
import {execSync} from 'child_process';
import { resolve, basename } from "path";
import { fileURLToPath } from "url";
import * as fs from "fs";
import { execSync } from "child_process";
const filename = fileURLToPath(import.meta.url);
const root = resolve(filename, '../..');
const dry = process.argv.includes('--dry');
const root = resolve(filename, "../..");
const dry = process.argv.includes("--dry");
const yarn = (cmd, stdio = 'inherit') => {
const script = `yarn run ${cmd}`;
if (dry) {
return script;
}
return execSync(script, {stdio});
const bytes2utf8 = new TextDecoder();
/**
* Base64 to UTF-8
* @param encoded Base64 encoded string
* @returns UTF-8 string
*/
export const base64Decode = (encoded) =>
bytes2utf8.decode(Uint8Array.from(atob(encoded), (m) => m.charCodeAt(0)));
const yarn = (cmd, stdio = "inherit") => {
const script = `yarn run ${cmd}`;
if (dry) {
return script;
}
return execSync(script, { stdio });
};
const typlite = (input, output = "-") => {
if (output === "-") {
// return stdout
const res = yarn(`--silent typlite ${input} -`, 'pipe');
return res.toString();
}
if (output === "-") {
// return stdout
const res = yarn(`--silent typlite ${input} -`, "pipe");
return res.toString();
}
return yarn(`typlite ${input} ${output}`);
return yarn(`typlite ${input} ${output}`);
};
const convert = async (inp, out, opts) => {
const input = resolve(root, inp);
const output = resolve(root, out);
const { before } = opts || {};
const input = resolve(root, inp);
const output = resolve(root, out);
const { before } = opts || {};
const res = typlite(input).trim();
if (dry) {
console.log(res);
return;
}
const res = typlite(input).trim();
if (dry) {
console.log(res);
return;
}
await fs.promises.writeFile(output, `<!-- This file is generated by scripts/link-docs.mjs from ${inp}. Do not edit manually. -->\n${before || ''}${res}\n`);
const assetsDir = resolve(output, "../assets/images");
fs.mkdirSync(assetsDir, { recursive: true });
// outline all data "data:image/svg+xml;base64," to render on GitHub correctly
const inputName = basename(input);
let imageCnt = 0;
const outputContent =
`<!-- This file is generated by scripts/link-docs.mjs from ${inp}. Do not edit manually. -->\n${before || ""}${res}\n`.replace(
/\"data\:image\/svg\+xml\;base64,([^\"]*)\"/g,
(_, content) => {
const fileName = `${inputName}-inlined${imageCnt}.svg`;
imageCnt += 1;
fs.writeFileSync(resolve(assetsDir, fileName), base64Decode(content));
return `"./assets/images/${fileName}"`;
}
);
await fs.promises.writeFile(output, outputContent);
};
const main = async () => {
await Promise.all([
convert('docs/tinymist/introduction.typ', 'README.md', { before: "# Tinymist\n\n" }),
convert('docs/tinymist/frontend/emacs.typ', 'editors/emacs/README.md', { before: "# Tinymist Emacs Support for Typst\n\n" }),
convert('docs/tinymist/frontend/helix.typ', 'editors/helix/README.md', { before: "# Tinymist Helix Support for Typst\n\n" }),
convert('docs/tinymist/frontend/neovim.typ', 'editors/neovim/README.md', { before: "# Tinymist Neovim Support for Typst\n\n" }),
convert('docs/tinymist/frontend/sublime-text.typ', 'editors/sublime-text/README.md', { before: "# Tinymist Sublime Support for Typst\n\n" }),
convert('docs/tinymist/frontend/vscode.typ', 'editors/vscode/README.md', { before: "# Tinymist Typst VS Code Extension\n\n" }),
convert('docs/tinymist/frontend/zed.typ', 'editors/zed/README.md', { before: "# Tinymist Zed Support for Typst\n\n" }),
])
await Promise.all([
convert("docs/tinymist/introduction.typ", "README.md", {
before: "# Tinymist\n\n",
}),
convert("docs/tinymist/frontend/emacs.typ", "editors/emacs/README.md", {
before: "# Tinymist Emacs Support for Typst\n\n",
}),
convert("docs/tinymist/frontend/helix.typ", "editors/helix/README.md", {
before: "# Tinymist Helix Support for Typst\n\n",
}),
convert("docs/tinymist/frontend/neovim.typ", "editors/neovim/README.md", {
before: "# Tinymist Neovim Support for Typst\n\n",
}),
convert(
"docs/tinymist/frontend/sublime-text.typ",
"editors/sublime-text/README.md",
{ before: "# Tinymist Sublime Support for Typst\n\n" }
),
convert("docs/tinymist/frontend/vscode.typ", "editors/vscode/README.md", {
before: "# Tinymist Typst VS Code Extension\n\n",
}),
convert("docs/tinymist/frontend/zed.typ", "editors/zed/README.md", {
before: "# Tinymist Zed Support for Typst\n\n",
}),
]);
};
main().catch(console.error);

View file

@ -15,7 +15,7 @@ interface ServerInfo {
root: string;
fontPaths: string[];
inputs: Record<string, string>;
estimatedMemoryUsage: Record<string, number>;
stats: Record<string, string>;
}
type ServerInfoMap = Record<string, ServerInfo>;
@ -153,9 +153,12 @@ export const Summary = () => {
)
);
for (const [key, usage] of Object.entries(val.estimatedMemoryUsage)) {
for (const [key, htmlContent] of Object.entries(val.stats)) {
res.push(
div(a(code(`memoryUsage (${key})`)), ": ", code(humanSize(usage)))
div(
div({ href: "javascript:void(0)" }, code(key)),
div({ innerHTML: htmlContent })
)
);
}
}
@ -890,20 +893,10 @@ const SERVER_INFO_MOCK: ServerInfoMap = {
theme: "dark",
context: '{"preview":true}',
},
estimatedMemoryUsage: {},
stats: {},
},
};
function humanSize(size: number) {
const units = ["B", "KB", "MB", "GB", "TB"];
let unit = 0;
while (size >= 768 && unit < units.length) {
size /= 1024;
unit++;
}
return `${size.toFixed(2)} ${units[unit]}`;
}
function almost(value: number, target: number, threshold = 0.01) {
return Math.abs(value - target) < threshold;
}

View file

@ -1,4 +1,4 @@
#import "@preview/shiroa:0.1.1": *
#import "@preview/shiroa:0.1.2": *
#import "/typ/templates/page.typ": project, part-style
#let _page-project = project

View file

@ -1,6 +1,6 @@
// This is important for shiroa to produce a responsive layout
// and multiple targets.
#import "@preview/shiroa:0.1.1": get-page-width, target, is-web-target, is-pdf-target, plain-text, templates
#import "@preview/shiroa:0.1.2": get-page-width, target, is-web-target, is-pdf-target, plain-text, templates
#import templates: *
// Metadata
@ -22,9 +22,8 @@
#let main-font = (
"Charter",
// shiroa's embedded font
"Linux Libertine",
"Libertinus Serif",
"Source Han Serif SC",
"Source Han Serif TC",
)
#let code-font = (