Add dodder.nvim: tree-sitter grammars and neovim plugin#364
Add dodder.nvim: tree-sitter grammars and neovim plugin#364friedenberg wants to merge 6 commits into
Conversation
Scaffold the zz-nvim tree-sitter plugin with the first two grammars that replace zz-vim's regex syntax highlighting: - hyphence: the object edit format (--- fenced metadata + injectable body). Shared rule modules (common/markl.js, common/metadata.js) parse markl-ids and metadata lines; the (body) node is left opaque for per-type language injection. highlights.scm preserves zz-vim's semantic contract; injections.scm delegates body-language resolution to a custom lua directive. - doddish: the query language (predicate[sigil][genre], groups, negation). Both grammars have committed generated parsers and passing tree-sitter corpus tests (7 hyphence, 11 doddish). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUwx95KwKfaw5HdjkWsCgR
- Add the dodder_organize grammar (hyphence header + # headings + -/% box object lines), reusing common/metadata.js and new common/box.js. Passing corpus tests and a highlights.scm covering box interiors and headings. - Refactor metadata so it ends exactly at the closing "---": the fence newline, blank line, and body belong to the consumer. Fixes a newline shift/reduce conflict in organize and keeps hyphence body injection clean (body now requires \n\n so a metadata-only file yields no body node). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUwx95KwKfaw5HdjkWsCgR
- filetype.lua: vim.filetype.add for object/workspace filetypes (replaces ftdetect) - injection.lua: custom #dodder-injection-language! directive + async resolver (dodder show -format type.vim-syntax-type) with a static fallback table; degrades to markdown when dodder is off PATH; nvim<0.10 jobstart fallback. - init.lua: setup() wiring language.register + FileType/BufWritePost autocmds. - ftplugin.lua: ports equalprg, gf zettel navigation, action/copy/preview menus (vim.ui.select), organize # folding, and commentstrings from zz-vim. - health.lua: :checkhealth dodder. plugin/dodder.lua: auto-setup. Verified end-to-end in neovim: metadata highlighting, per-type body injection (nested grammar), doddish/organize highlighting, ftplugin options, and health. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUwx95KwKfaw5HdjkWsCgR
Add the dodder-nvim flake package parallel to dodder-vim: compile each grammar with pkgs.tree-sitter.buildGrammar from its committed parser.c (generate = false), then stage the plugin via buildVimPlugin with the parsers copied into $out/parser/<lang>.so so neovim's built-in vim.treesitter auto-loads them off the runtimepath (no nvim-treesitter dependency). Surfaced through the flake's forwarded packages set and the non-flake import path. dodder-vim is retained for legacy Vim users. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUwx95KwKfaw5HdjkWsCgR
Simplify pass: - Dedup the bin() resolution logic (was reimplemented separately in ftplugin.lua, health.lua, injection.lua) into a single dodder.bin() exported from init.lua. - Extract the sepBy1 grammar helper (duplicated verbatim in doddish and organize grammar.js) into grammars/common/util.js. - Drop injection.lua's type_to_lang table -- every entry mapped to 'markdown', which is already the function's default fallback. - Dedup the qlmanage/tacky "requires external tool" guard in ftplugin.lua into a single require_executable() helper. - Derive go/default.nix's dodder-nvim postInstall cp lines from the dodder-nvim-grammars attrset instead of hardcoding three copies of the same three names. - Add nodejs + tree-sitter to the devShell so `tree-sitter generate`/ `test` actually work for the zz-nvim grammars (was silently broken: tree-sitter-cli shells out to node to evaluate grammar.js). Review pass (found via live testing, not just static reading): - health.lua called `dodder -version` (a flag) instead of the real `version` subcommand, dumping a full usage/stack-trace instead of a version string. - injection.lua's async resolve callback checked only nvim_buf_is_valid(bufnr), not that the buffer still names the same file -- a slow `dodder show` completing after :bwipeout + buffer number reuse could apply a stale language resolution to an unrelated buffer. Now also compares the captured file name. - ftplugin.lua's setup_organize applied window-local fold options to vim.api.nvim_get_current_win(), which isn't necessarily the window showing the organize buffer (FileType events carry no window). Now applies to every window actually displaying the buffer via win_findbuf, falling back to current only if none do yet. - ftplugin.lua's gf_zettel discarded the checkout command's exit status, silently opening an empty buffer on a failed checkout instead of surfacing the error. - README.md's grammar table used GFM pipe-table syntax, which this repo's pandoc-on-save formatting doesn't preserve (CLAUDE.md Formatting section) -- converted to a plain list. New: six `explore-nvim-*` justfile recipes (root justfile, matching the existing explore-haustoria-*/explore-live convention) that spin up a throwaway dodder repo with real example zettels and walk through every grammar/feature in Neovim: hyphence highlighting + live body injection, forced-toml injection on .dodder-workspace, organize-text, doddish query highlighting, and :checkhealth. Backed by a new zz-nvim/examples/example.doddish fixture (verified parse-clean against the real doddish grammar) and a README pointer. All six were exercised end-to-end against the real nix-built dodder-nvim package and dodder CLI, not just parsed. :clown: Generated with [Clown](https://github.com/amarbel-llc/clown) (build 0.3.22+fa0406f, amarbel-llc/clown@fa0406f) Co-Authored-By: Clown <[email protected]>
45aed79 to
5fe0ac2
Compare
|
Took ownership of this PR: rebased onto Simplify — deduped the Review — an 8-angle pass (3 correctness + reuse/simplification/efficiency/altitude/CLAUDE.md-conventions) surfaced 4 real bugs, all found and fixed via live testing (headless nvim + a real throwaway dodder repo), not just static reading:
New: six Tests: Filed a followup for wiring :clown: Reviewed and cleaned up by Clown (build 0.3.22+fa0406f, amarbel-llc/clown@fa0406f) |
Introduces
zz-nvim, a complete Neovim plugin replacingzz-vim's regex-based syntax highlighting with tree-sitter grammars and adding per-object-type body-language injection.Summary
This adds three new tree-sitter grammars for dodder's domain-specific languages:
The plugin provides:
Key Changes
Grammar definitions (
zz-nvim/grammars/*/grammar.js):Generated parser code (
zz-nvim/grammars/*/src/parser.c,node-types.json,grammar.json):Lua plugin (
zz-nvim/lua/dodder/):init.lua: main entry point with setup/teardownftplugin.lua: buffer-local options, gf navigation, object/organize menusinjection.lua: async body-language resolution from object type metadatafiletype.lua: filetype detection for dodder objectshealth.lua::checkhealth dodderverificationHighlighting and injection queries (
zz-nvim/queries/*/):Nix integration (
go/default.nix):dodder-nvimpackage building the three grammars viatree-sitter.buildGrammar.soparsers included in the plugin distributionTest corpus (
zz-nvim/grammars/*/test/corpus/):The plugin is designed to coexist with zz-vim; users choose one per their editor preference.
https://claude.ai/code/session_01KUwx95KwKfaw5HdjkWsCgR