Skip to content

feat: highlight code with limn - #933

Open
Niox1337 wants to merge 21 commits into
DEEIX-AI:devfrom
Niox1337:feat/limn-highlighting-899
Open

Niox1337 wants to merge 21 commits into
DEEIX-AI:devfrom
Niox1337:feat/limn-highlighting-899

Conversation

@Niox1337

@Niox1337 Niox1337 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #899

Every language is now highlighted by limn (limn-hl 0.7.0, MIT, no dependencies of its own). That covers all 81 built-in definitions, including HTML, Astro, Vue, Svelte, PHP, Shell, SQL, XML, LaTeX, Typst, Mermaid, Nix and MATLAB. The DFA engine and its compiled tables are removed. Languages can still be defined in the existing .syntax format at runtime, compiled lazily off the UI thread and run through limn as custom grammars.

  • Languages. ArkTS, Jai, GDScript, Nushell, Device Tree, Objective-C, Objective-C++, Nunjucks, Liquid, WXML, WXSS, Fish and indented Sass use the grammars limn 0.7.0 added. Perl heredocs, HTML in Markdown, SVG styles and scripts, ### separated HTTP requests, dotenv values and dates and UUIDs in logs use limn too, after Perl: heredoc bodies are tokenized as code ekesti/limn#14 to log: UUIDs and syslog dates are only partly highlighted ekesti/limn#19 were fixed. CSV and TSV stay plain text with column colors. Verilog and SystemVerilog are new. Godot scenes, resources and project.godot open as INI. The new extensions are registered in the Windows installers and the macOS bundle. These also cover the earlier requests [Feature]: 增加对 verilog/systemverilog 的高亮显示 #849, [Feature]: 希望考虑支持 Godot 项目常用文件(特别是 .gd / GDScript)的语法高亮 #881, [Feature]: NuShell language supports #756 and [Feature]: 文件高亮配色能支持更多文件,或者支持自定义配色吗 #524.
  • Scanning. winc-syntax caches limn tokens per line in compact spans and keeps the checkpoints limn reports at line starts. After an edit, scanning resumes from the last checkpoint before the changed line and stops once a checkpoint matches the cached one again, so an edit rescans only the lines it affects. Exact scanning extends at most 512 KiB past the last exact checkpoint. Farther jumps scan aligned windows with lookback on demand and the result is approximate, so no scan grows with the size of the file.
  • Runtime languages. LanguageRegistry takes .syntax definitions at runtime. Each mode compiles to a regex-automata hybrid DFA (already in the binary through regex, so no new crate) with the old match semantics: anchored, longest match, rule order on ties, word boundary look-behind and end of input. The grammar reports a checkpoint at every line start with a 4 byte state, so runtime languages share the line cache, checkpoint resume and window limits of built-in ones. embed can delegate to any limn grammar or another runtime language. Compilation starts on a background thread the first time a document needs tokens, the document shows plain text until then and redraws once it is ready. Definitions are capped at 64 KiB, 128 modes, 512 rules and 64 KiB per automaton, and every error is a value with file:line. The registry is a value the caller owns, so the plugins module can keep one per window. Replacing or removing a definition drops its automata and the cached tokens of documents that use it. Ignore files are the first user.
  • Kept behavior. Capitalized names are still colored as types in the languages that had that rule. Brackets in strings, comments and regular expressions do not take part in bracket matching. Go to definition and usages treat regular expressions as strings. Auto pairing before a closing quote and string prefixes for quote pairing work through the limn tokens.
  • Markup. Comment toggling uses the language under the cursor in embedded scripts, styles, SVG, WXML <wxs> blocks and Astro frontmatter.
  • Cleanup. rules.bin (128,900 bytes on dev), the dense and sparse table readers and the table compiler in cargo xtask syntax are removed. The .syntax parser moves from xtask into winc-syntax, and xtask uses it to generate the language metadata. The highlight snapshots and lexer tests of languages on limn are removed, since their colors now come from limn. Tests of the cache, checkpoint resume, embedded regions and the auto pairing features stay. The GDScript and Nushell definitions and snapshots the DFA produced are kept as runtime fixtures, and the runtime engine reproduces them exactly.

Visible differences

Decorators, tags, attributes, CSS selectors, interpolation delimiters and Rust lifetimes get the color limn assigns. Regular expressions in JavaScript, TypeScript and Ruby are colored by their parts instead of as one string. Variables and properties follow the kinds limn reports. Markdown ==highlight== is plain text, since limn has no token for it. Known limit: comment toggling treats a standalone --- as the end of Astro frontmatter even inside a comment or template string.

Performance

cargo xtask bench on macOS (Apple silicon) against dev 5fac00c, in two passes: dev, branch, branch, dev and then branch, dev, dev, branch. Each cell is the median of the four runs with the range in brackets.

Metric dev this PR
Startup, large.rs 176.9 ms (173.0 to 177.2) 179.6 ms (178.6 to 182.8)
Startup, huge.txt 123.8 ms (120.6 to 133.1) 131.7 ms (127.5 to 137.8)
Startup, huge.rs 139.5 ms (130.1 to 142.1) 137.8 ms (127.0 to 145.5)
Scroll p95, large.rs 0.4 ms 0.4 ms
Scroll p95, huge.txt 1.0 ms 1.1 ms
Scroll p95, huge.rs 0.65 ms 0.7 ms
Typing to frame p50 / p95, large.rs 0.53 / 0.75 ms 0.48 / 0.6 ms
Typing with preview p50, long.md 0.68 ms 0.68 ms
Preview scroll p95 0.7 ms 0.9 ms
Jump to the end, highlighting large.rs 31.3 ms 3.2 ms
Idle memory, large.rs 28 MB 28 MB
Release binary (macOS arm64) 16,862,336 B 16,881,696 B (+19,360 B, +0.11%)

Vim key to frame p95 is 16.4 ms in every run on both builds, over budget on dev as well on this machine.

Change type

  • Bug fix
  • Feature
  • Performance
  • Refactor
  • Documentation
  • Build / tooling

Verification

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo xtask test --all
  • Tested by hand on: macOS (Apple silicon)

Screenshots

Left is before, right is after.

Existing languages (TypeScript, Rust, Vue)

existing-light existing-dark

New languages (SystemVerilog, GDScript, Nushell, Device Tree)

new-light new-dark

Checklist

  • The change is focused and does not include unrelated refactoring or formatting.
  • Tests cover the fixed bug or the new behavior.
  • New interface text is added in both English and Simplified Chinese.
  • Startup time, memory use, and large files are not made slower (run cargo xtask bench when in doubt).
  • I have read and agree to the Contributor License Agreement.

@Niox1337
Niox1337 force-pushed the feat/limn-highlighting-899 branch from 7a011bb to a5e06f1 Compare December 4, 2026 06:05
@Niox1337
Niox1337 requested a review from chenyme December 4, 2026 06:14
0.5.0 splits the grammars into nine features. Enable the eight that
contain the grammars Winc maps to limn. Contextual keywords such as
Java record and when, Groovy trait and Scala given are now keywords
only where the grammar allows them, so the tests check them in
declarations instead of as bare words.
limn gives JSX child text and plain identifiers the same kind, so the
capitalized type pass colored words such as Hello in element text.
Track tags, children and brace expressions from the punctuation limn
emits and skip the pass inside child text.
limn takes Nix escapes as more than one character, so "\u{" leaks a
string into the following lines. It also interpolates $${ and lets a
path swallow a following indented string. The DFA rules handle all of
these, so the tests assert every original expectation again.
limn treats %{ and %} on their own lines as line comments, so the
lines between them are colored as code. The DFA rules color the whole
block. They need the compiler's if-value action again.
@Niox1337
Niox1337 force-pushed the feat/limn-highlighting-899 branch from a5e06f1 to c30716e Compare December 4, 2026 23:22

@CPU-JIA CPU-JIA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounded review of the incremental syntax cache at c30716e36bf4b986c4e3e4f469c9314278b38fed. Two minimal regressions and an incremental-vs-fresh differential probe fail on the original head. With temporary local changes to the two guards described inline, both minimal cases and the differential probe (Rust, TSX, HTML, Python, Ruby, YAML, C++ and Go; 48 edit batches each) pass; existing winc-syntax unit tests also pass: 85 passed / 2 ignored. Tested on Windows with Rust 1.99.1 and exact LF fixture bytes, without blessing snapshots. The temporary changes have been reverted; no commits or pushes were made to this PR. This does not claim full workspace, UI or performance validation.

Comment thread crates/winc-syntax/src/limn_cache.rs Resolved
Comment thread crates/winc-syntax/src/limn_cache.rs Resolved
@Niox1337
Niox1337 force-pushed the feat/limn-highlighting-899 branch from c30716e to 15c6e8b Compare December 5, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: 改善无 LSP 时的代码高亮体验

3 participants