tinymist/.github/copilot-instructions.md
Copilot fee9b27e00
Some checks are pending
tinymist::auto_tag / auto-tag (push) Waiting to run
tinymist::ci / announce (push) Blocked by required conditions
tinymist::ci / build (push) Blocked by required conditions
tinymist::ci / Duplicate Actions Detection (push) Waiting to run
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Waiting to run
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Waiting to run
tinymist::ci / prepare-build (push) Waiting to run
tinymist::gh_pages / build-gh-pages (push) Waiting to run
docs: add Neovim specification and canonical implementation documentation (#2082)
This PR adds comprehensive documentation for the Neovim Tinymist plugin,
establishing it as the canonical implementation of a Tinymist editor
language client.

## Changes Made

### Added `editors/neovim/Specification.md`
The specification was a mess, so I the reviewer deleted it.

### Enhanced `editors/neovim/CONTRIBUTING.md`
Expanded the contributing guide to document:
- **Canonical Implementation Status**: Establishes this as the
heavily-documented reference implementation for other editors
- **Bootstrap Script Commands**: 
  - `./bootstrap.sh editor` - Interactive editing experience in Docker
  - `./bootstrap.sh test` - Headless test execution
  - `./bootstrap.sh bash` - Development shell access
- **Test Suite Structure**: Overview of all spec files and their testing
purposes
- **Contribution Patterns**: Guidelines for maintaining the reference
implementation

### Updated `.github/copilot-instructions.md`
Added guidance for working with editor integrations:
- **Repository Structure**: Notes the Neovim plugin as canonical
implementation with documentation links
- **Editor Integration Guidelines**: New section specifically for
referencing Neovim patterns
- **Development Workflow**: References to bootstrap commands and
documentation

## Why This Matters

The Neovim plugin now serves as the **canonical implementation** that
other editor integrations can reference for:
- LSP client setup patterns and configuration handling
- Event subscription mechanisms for development events
- Project resolution modes (singleFile vs lockDatabase)
- Export functionality patterns (onSave, onType, never)
- Comprehensive test coverage examples

This documentation enables maintainers and contributors to understand
the complete scope of the Neovim integration and provides a reference
for implementing similar functionality in other editors.

Fixes #2081.

<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for
you](https://github.com/Myriad-Dreamin/tinymist/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Myriad-Dreamin <35292584+Myriad-Dreamin@users.noreply.github.com>
Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
2025-08-25 11:48:23 +08:00

4.9 KiB

This is a Rust+JavaScript repository. It builds:

  • A Rust binary serves language features:
    • lsp: Runs language server
    • dap: Runs debug adapter
    • preview: Runs preview server
  • The JavaScript VS Code extension.
  • The lua plugin for Neovim.

It is primarily responsible for providing integrated typst language service to various editors like VS Code, Neovim, Emacs, and Zed. Please follow these guidelines when contributing:

Specialized Instructions

  • Localization: See copilot-instructions-l10n.md for comprehensive guidance on adding, updating, and maintaining localization in the project.

Code Standards

Keep Good PR Title

Determine a good PR prefix only by the PR description before work. Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:

  • dev
  • feat
  • fix
  • docs
  • style
  • refactor
  • perf
  • test
  • build
  • ci
  • chore
  • revert

Required Before Each Commit

  • Run yarn fmt to format Rust/JavaScript files
  • This will run formatters on all necessary files to maintain consistent style

Development Flow

  • Build Server: cargo build
  • Build VS Code Extension: cd editors/vscode && yarn build
  • Full CI check: cargo clippy --workspace --all-targets
  • Test Server: cargo test --workspace -- --skip=e2e Note that, in the envoironment where network is not available (copilot or nix actions), we should also skip following tests:
    completion::tests::test_pkgs
    docs::package::tests::cetz
    docs::package::tests::fletcher
    docs::package::tests::tidy
    docs::package::tests::touying
    

Repository Structure

  • crates/: rust crates for the server and related functionality
  • editors/vscode/: VS Code extension code
  • editors/neovim/: Lua plugin for Neovim (canonical implementation - see CONTRIBUTING.md and Specification.md)
  • tools/editor-tools: utility GUI tools for typst
  • tools/typst-preview-frontend: Preview GUI for typst
  • docs/: documentation for the project
  • locales/: localization files for the entire project
  • tests/: integration tests for the server and editors
  • syntaxes/: textmate syntax definitions for typst

Key Guidelines

  1. Follow Rust and JavaScript best practices and idiomatic patterns
  2. Maintain existing code structure and organization
  3. Write unit tests for new functionality. Use snapshot-based unit tests when possible.
  4. Document public APIs and complex logic in code comments

Editor Integration Guidelines

Neovim Canonical Implementation

The Neovim plugin in editors/neovim/ serves as the canonical implementation of a Tinymist editor language client. When working on editor integrations:

  • Reference Implementation: Use the Neovim plugin as the reference for LSP client patterns, configuration handling, and event subscription mechanisms
  • Test Suite: Refer to editors/neovim/spec/ for comprehensive test coverage examples
  • Documentation: See editors/neovim/Specification.md for complete API and functionality documentation
  • Development Workflow: Use ./bootstrap.sh editor for interactive testing and ./bootstrap.sh test for automated validation
  • Contributing: Follow patterns established in editors/neovim/CONTRIBUTING.md

Development Guidelines

tools/editor-tools

The frontend-side and backend-side can be developed independently. For example, a data object passed from backend to frontend can be coded as van.state<T> as follows:

  • Intermediate arguments:

    const documentMetricsData = `:[[preview:DocumentMetrics]]:`;
    const docMetrics = van.state<DocumentMetrics>(
      documentMetricsData.startsWith(":") ? DOC_MOCK : JSON.parse(base64Decode(documentMetricsData)),
    );
    
  • Server-pushing arguments (e.g. programTrace in tools/editor-tools/src/vscode.ts):

    export const programTrace = van.state<TraceReport | undefined>(undefined /* init value */);
    
    export function setupVscodeChannel() {
      if (vscodeAPI?.postMessage) {
        // Handle messages sent from the extension to the webview
        window.addEventListener("message", (event: any) => {
          switch (event.data.type) {
            case "traceData": {
              programTrace.val = event.data.data;
              break;
            }
            // other cases
          }
        });
      }
    }
    
  • Tool request arguments (e.g. requestSaveFontsExportConfigure in tools/editor-tools/src/vscode.ts):

    export function requestSaveFontsExportConfigure(data: fontsExportConfigure) {
      if (vscodeAPI?.postMessage) {
        vscodeAPI.postMessage({ type: "saveFontsExportConfigure", data });
      }
    }
    

DOC_MOCK is a mock data object for the frontend to display so that the frontend can be developed directly with yarn dev.