### Start LSP Server with Stdio Transport Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/sync-lsp/README.md Initiates an LSP server using stdio transport. This example demonstrates setting up request and event handlers, and starting the server with a given client and connection. ```rust with_stdio_transport::(args.mirror.clone(), |conn| { let client = LspClientRoot::new(tokio_handle, conn.sender); LspBuilder::new(args, client.weak()) // Adds request handlers .with_request::(State::shutdown) // Adds event handlers .with_event(&LspInterrupt::Settle, State::interrupt) .build() .start(conn.receiver, is_replay) })?; ``` -------------------------------- ### Install tinymist with mason.nvim Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/neovim/README.md Recommended installation method for tinymist using the mason.nvim plugin manager. ```lua { "mason-org/mason.nvim", opts = { ensure_installed = { "tinymist", }, }, } ``` -------------------------------- ### Install typst-preview.nvim with lazy.nvim Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/neovim/README.md Use this snippet to install the typst-preview.nvim plugin using the lazy.nvim package manager for live web previews. ```lua -- lazy.nvim { 'chomosuke/typst-preview.nvim', lazy = false, -- or ft = 'typst' version = '1.*', opts = {}, -- lazy.nvim will implicitly calls `setup {}` } ``` -------------------------------- ### Build typst-preview.html Frontend Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/tinymist-assets/README.md Run these commands in the root of the repository to install dependencies and build the preview's frontend. Ensure you have yarn installed. ```bash cd ../.. yarn install yarn build:preview ``` -------------------------------- ### Install Typlite via Shell Script Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/typlite/README.md Installs prebuilt binaries of Typlite using a shell script. Ensure you have curl installed. ```shell curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.15.2/typlite-installer.sh | sh ``` -------------------------------- ### Example Typst CLI Command Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/vscode/README.md This is an example of how the `typst-cli` command would look when using the arguments specified in the `tinymist.typstExtraArgs` configuration. ```bash typst watch --input=awa=1 --input=abaaba=2 main.typ ``` -------------------------------- ### Install Tinymist Nightly (Windows) Source: https://github.com/myriad-dreamin/tinymist/blob/main/README.md Use this PowerShell command to automatically install the latest nightly prebuilts of tinymist on Windows. ```powershell iwr https://github.com/hongjr03/tinymist-nightly-installer/releases/latest/download/run.ps1 -UseBasicParsing | iex ``` -------------------------------- ### Generate Documentation Locally Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide/tinymist-query.md Run this command to generate the documentation locally. Ensure you have Yarn installed or copy-run the command. ```bash yarn docs:rs --open ``` -------------------------------- ### Install tinymist CLI using Cargo Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/emacs/README.md Install the latest tinymist CLI from source using Cargo. Ensure you have Rust and Cargo installed. ```bash cargo install --git https://github.com/Myriad-Dreamin/tinymist --locked tinymist-cli ``` -------------------------------- ### Example Changelog Entry Format Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/release-instruction.md Illustrates the required format for changelog entries, including prefixes for different change types and author attribution. Adhere to these rules for CI compatibility. ```markdown ## v0.14.6 - [2026-01-02] * Bumped typst to v0.14.2 in https://github.com/Myriad-Dreamin/tinymist/pull/2312 ### Server * (Fix) Correctly handled relative user-specified output paths in compile command by @moeleak and @Myriad-Dreamin in https://github.com/Myriad-Dreamin/tinymist/pull/1941 and https://github.com/Myriad-Dreamin/tinymist/pull/1942 * Added `--input` flag to CLI commands by @xiyihan0 in https://github.com/Myriad-Dreamin/tinymist/pull/2328 ``` -------------------------------- ### Install Typlite via PowerShell Script Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/typlite/README.md Installs prebuilt binaries of Typlite using a PowerShell script. Requires PowerShell execution policy bypass. ```powershell powershell -ExecutionPolicy Bypass -c "irm https://github.com/Myriad-Dreamin/tinymist/releases/download/v0.15.2/typlite-installer.ps1 | iex" ``` -------------------------------- ### Install Tinymist Nightly (Unix) Source: https://github.com/myriad-dreamin/tinymist/blob/main/README.md Use this command to automatically install the latest nightly prebuilts of tinymist on Unix-based systems using curl. ```bash curl -sSL https://github.com/hongjr03/tinymist-nightly-installer/releases/latest/download/run.sh | bash ``` -------------------------------- ### Bundle Local Frontend Assets in Cargo.toml Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide.md Patch example for Cargo.toml to bundle a locally built frontend for 'typst-preview' into Tinymist's CLI binary. Ensure the 'typst-preview' feature is enabled. ```diff @@ -207,1 +207,1 @@ # This patch is used to bundle a locally built frontend (HTML) of `typst-preview`. # tinymist-assets = { path = "./crates/tinymist-assets/" } +tinymist-assets = { path = "./crates/tinymist-assets/" } ``` -------------------------------- ### Typst Benchmark Example Code Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/crityp/README.md This Typst code defines a recursive Fibonacci function and two benchmark functions that call it. Ensure functions to be benchmarked are named starting with 'bench'. ```typst #let fib(n) = if n < 2 { n } else { fib(n - 1) + fib(n - 2) } #let bench-fib() = fib(20) #let bench-fib2() = fib(20) ``` -------------------------------- ### Serve Local Documentation with Yarn Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide.md Command to serve the project's documentation locally using Yarn. ```bash yarn docs ``` -------------------------------- ### Initialize New Project with Template Source: https://github.com/myriad-dreamin/tinymist/blob/main/README.md Initializes a new project using a selected template from the gallery. ```typescript tinymist.initTemplate ``` -------------------------------- ### Initialize New Project in Place with Template Source: https://github.com/myriad-dreamin/tinymist/blob/main/README.md Initializes a new project in the current directory using a selected template from the gallery. ```typescript tinymist.initTemplateInPlace ``` -------------------------------- ### Build Frontend Assets for Preview Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide.md Command to build the frontend assets for the typst-preview feature and copy them to the tinymist-assets folder. ```bash yarn build:preview ``` -------------------------------- ### Prepare Release Candidate with Codex Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/release-instruction.md Use this command to ask Codex to prepare a release candidate. Replace `{version}` with the target release version. ```shell /tinymist-dev:release v0.14.12-rc1 ``` -------------------------------- ### Initiate Release Process Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/release-instruction.md This command initiates the external release process after local preparations are complete and the readiness report is clean. Replace `{version}` with the release version. ```shell yarn release {version} ``` -------------------------------- ### TOML Locale File Example Source: https://github.com/myriad-dreamin/tinymist/blob/main/locales/README.md This is an example of a TOML locale file used in the Tinymist application. It demonstrates the structure for defining locale strings with keys and translations for different languages. ```toml [extension.tinymist.command.tinymist.pinMainToCurrent] # K en = "Pin the Main File to the Currently Open Document" # V-en zh-CN = "将主文件固定到当前打开的文档" # zh-CN ``` -------------------------------- ### Enable Clippy on Save (Rust) Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide.md Configures rust-analyzer to use clippy for code checking when saving files. Ensure clippy is installed. ```json { "rust-analyzer.check.command": "clippy" } ``` -------------------------------- ### Configure Tinymist with Built-in LSP Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/neovim/README.md Set up Tinymist using Neovim's built-in LSP client configuration. This method requires defining the command, filetypes, and settings. ```lua vim.lsp.config["tinymist"] = { cmd = { "tinymist" }, filetypes = { "typst" }, settings = { -- ... } } ``` -------------------------------- ### Typlite sys.inputs Example Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/typlite/README.md Demonstrates how to use `sys.inputs.at("x-target")` in Typst to conditionally render content based on the export target (e.g., 'md' or 'pdf'). ```typst #let x-target = sys.inputs.at("x-target", default: "pdf") #let my-function = if x-target == "md" { md-impl } else { pdf-impl or html-impl } ``` -------------------------------- ### Configure Tinymist Previewer Source: https://github.com/myriad-dreamin/tinymist/blob/main/contrib/tinymist-gpu-viewer/editors/vscode/README.md Set the 'tinymist.previewer' configuration to use the GPU viewer extension. This tells Tinymist to activate this extension and pass preview data to the native viewer. ```json { "tinymist.previewer": "myriad-dreamin.tinymist-gpu-viewer" } ``` -------------------------------- ### JavaScript Performance Example Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/thinking-ide.md A JavaScript code snippet demonstrating a loop that can cause significant delays when analyzed by dynamic analysis tools, highlighting the need for static analysis. ```javascript for i in range(5000000) {} ``` -------------------------------- ### Run Crityp Benchmark Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/crityp/README.md Use `crityp` to benchmark functions in a Typst file. The CLI arguments are compatible with `typst-cli compile`. This example shows the output of a benchmark run. ```shell crityp test-bench.typ Benchmarking /test-bench.typ@bench-fib Benchmarking /test-bench.typ@bench-fib: Warming up for 3.0000 s Benchmarking /test-bench.typ@bench-fib: Collecting 100 samples in estimated 5.3151 s (56k iterations) Benchmarking /test-bench.typ@bench-fib: Analyzing /test-bench.typ@bench-fib time: [93.919 µs 94.631 µs 95.459 µs] change: [-7.2275% -5.2111% -3.4660%] (p = 0.00 < 0.05) Performance has improved. Found 7 outliers among 100 measurements (7.00%) 2 (2.00%) low mild 4 (4.00%) high mild 1 (1.00%) high severe Benchmarking /test-bench.typ@bench-fib2 ... ``` -------------------------------- ### Creating Tables with TableBuilder Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/cmark-writer/README.md Illustrates how to construct Markdown tables using the `TableBuilder` pattern, including defining headers and adding rows with cell content. This is useful for structured data presentation. ```rust use cmark_writer::ast::{Node, tables::TableBuilder}; // Create tables with the builder pattern let table = TableBuilder::new() .headers(vec![ Node::Text("Name".into()), Node::Text("Age".into()) ]) .add_row(vec![ Node::Text("John".into()), Node::Text("30".into()), ]) .add_row(vec![ Node::Text("Alice".into()), Node::Text("25".into()), ]) .build(); ``` -------------------------------- ### Configure Format on Save for JavaScript and JSON Source: https://github.com/myriad-dreamin/tinymist/blob/main/docs/dev-guide.md Enables automatic code formatting on save for JavaScript and JSON files using the Prettier VS Code extension. Ensure Prettier is installed and configured. ```json { "[javascript]":{ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }, "[json]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" } } ``` -------------------------------- ### Defining Custom Nodes for cmark-writer Source: https://github.com/myriad-dreamin/tinymist/blob/main/crates/cmark-writer/README.md Provides an example of defining a custom inline node (`HighlightNode`) with both CommonMark and HTML rendering implementations. This allows extending the writer's capabilities for custom markup. The `#[custom_node]` attribute simplifies the process. ```rust use cmark_writer::{HtmlWriteResult, HtmlWriter, Node, WriteResult}; use cmark_writer::writer::InlineWriterProxy; use cmark_writer::custom_node; use ecow::EcoString; #[derive(Debug, Clone, PartialEq)] #[custom_node(block=false, html_impl=true)] struct HighlightNode { content: EcoString, color: EcoString, } impl HighlightNode { // Implementation for CommonMark output fn write_custom(&self, writer: &mut InlineWriterProxy) -> WriteResult<()> { writer.write_str(" ")?; writer.write_str(&self.content)?; writer.write_str("")?; Ok(()) } // Optional HTML-specific implementation fn write_html_custom(&self, writer: &mut HtmlWriter) -> HtmlWriteResult<()> { writer.start_tag("span")?; writer.attribute("style", &format!("background-color: {}", self.color))?; writer.finish_tag()?; writer.text(&self.content)?; writer.end_tag("span")?; Ok(()) } } ``` -------------------------------- ### Code Style: Validation Helpers Source: https://github.com/myriad-dreamin/tinymist/blob/main/editors/vscode/AGENTS.md This example illustrates the use of small validation helpers and straightforward control flow, particularly when interacting with VS Code's input and quick pick interfaces. It keeps the main logic clean by delegating validation tasks. ```typescript import { workspace, type WorkspaceConfiguration } from 'vscode'; async function getPackageManager() { const config: WorkspaceConfiguration = workspace.getConfiguration('tinymist'); const packageManager: string = config.get('packageManager') ?? 'npm'; if (!['npm', 'yarn', 'pnpm'].includes(packageManager)) { // ... handle invalid package manager ... } // ... proceed with valid package manager ... } ```