phase 7: semantic tokens for syntax highlighting
CI / cargo fmt --check (push) Successful in 30s
CI / cargo clippy (push) Successful in 1m16s
CI / cargo test (push) Successful in 1m20s

`textDocument/semanticTokens/full` + `/range` per SPEC §6.9. Token
type scheme settled in P7: custom `vimwiki*` types
(`vimwikiHeading`, `vimwikiBold`, `vimwikiCodeBlock`, `vimwikiKeyword`,
`vimwikiWikilink`, `vimwikiTransclusion`, …) plus `level1`..`level6`
and `centered` modifiers. Default highlight groups for these arrive
in Phase 9.

Pipeline (`semantic_tokens.rs`):

- `legend()` builds the `SemanticTokensLegend` advertised in
  `initialize` capabilities.
- `LineIndex` precomputes byte offsets per line so multi-line span
  splitting and UTF-16 conversion stay linear.
- `collect_tokens` walks the AST. Blocks that are visually distinct
  (heading, preformatted, math-block, comment) emit one token over
  their span; multi-line ones get split per line because the LSP wire
  format can't represent a token that crosses a newline. Container
  blocks (paragraph, list item, table cell, blockquote) recurse into
  inlines instead of wrapping them, so we end up with a non-overlapping
  tile of inline tokens. Headings shadow nested inlines (one heading
  token covers the line, no Bold-inside-Heading).
- `encode` produces the LSP delta-quintuple stream
  `(deltaLine, deltaStart, length, type, mods)`. UTF-16 mode converts
  byte offsets/lengths to code-unit counts on the fly (BMP + surrogate
  pairs).
- `build_data` is the entry point used by both handlers; the `range`
  variant filters tokens by overlap in the same encoding the client
  requested.

Capability declared as `SemanticTokensOptions { full = true,
range = true, legend = … }`. Both handlers reuse the document store.

P7 resolved in SPEC §11 — custom vimwiki types with rationale and a
note that Phase 9 will ship default highlight-group definitions in
`syntax/nuwiki.vim` and the Lua glue.

Tests (21 new): legend integrity, per-construct emission for every
inline + block kind, heading shadowing of inner inlines, multi-line
code/math block splitting, sort order, delta encoding (same line and
crossing lines), UTF-16 length conversion for é, range filter,
empty-doc edge case, end-to-end `build_data` parity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-10 21:14:01 +00:00
parent c44db37bab
commit 6efe154f1a
5 changed files with 767 additions and 9 deletions
+6 -5
View File
@@ -3,9 +3,10 @@
A Vim/Neovim plugin providing full vimwiki syntax support, implemented as a
Rust-based language server (LSP).
> **Status:** Phase 6 (LSP foundation) complete. `nuwiki-ls` speaks LSP over
> stdio: didOpen/didChange/didClose, parse diagnostics, nested document
> outline. Editor glue, semantic tokens, and navigation still pending.
> **Status:** Phase 7 (semantic tokens) complete. The server now serves
> `semanticTokens/full` + `/range` with custom `vimwiki*` token types and
> `level1`..`level6` + `centered` modifiers. Navigation features and
> editor glue still pending.
See [`SPEC.md`](./SPEC.md) for the full project specification.
@@ -20,8 +21,8 @@ See [`SPEC.md`](./SPEC.md) for the full project specification.
| 4 | Vimwiki Parser | ✅ done |
| 5 | Renderer | ✅ done |
| 6 | LSP Foundation | ✅ done |
| 7 | Semantic Tokens | ⏳ next |
| 8 | Navigation | ⏳ |
| 7 | Semantic Tokens | ✅ done |
| 8 | Navigation | ⏳ next |
| 9 | Editor Glue | ⏳ |
| 10 | CI/CD release pipeline | ⏳ |