Skip to content

fix(nvim): migrate nvim-treesitter master -> main for Neovim 0.12#27

Merged
jinyeow merged 4 commits into
mainfrom
feat/nvim-treesitter-main
Jul 20, 2026
Merged

fix(nvim): migrate nvim-treesitter master -> main for Neovim 0.12#27
jinyeow merged 4 commits into
mainfrom
feat/nvim-treesitter-main

Conversation

@jinyeow

@jinyeow jinyeow commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Problem

nvim-treesitter master is frozen for Neovim 0.11 and crashes on 0.12: its query_predicates.lua calls vim.treesitter's pre-0.12 get_node_text/get_range, throwing attempt to call method 'range' (a nil value) on any injection query — i.e. every markdown edit (render-markdown + the native highlighter both trigger it). checkhealth stayed green because parsers are fine; the break is in the query-predicate layer.

Fix — migrate to main (the 0.12+ rewrite)

  • plugins.lua: repin both plugins to version='main'.
  • nvim-pack-lock.json: pin the main revs. vim.pack.add checks out master on a fresh install even with version='main' (a default-branch quirk of the archived repo) — the locked rev is what lands a fresh install on main. An already-installed master checkout needs a one-time :lua vim.pack.update({'nvim-treesitter','nvim-treesitter-textobjects'}, { force = true }) (non-interactive; documented in CLAUDE.md).
  • treesitter.lua: rewritten for the main/native API — drop configs.setup{}; install() diffed against config.get_installed(); per-buffer vim.treesitter.start() + indentexpr in a FileType autocmd; textobjects via nvim-treesitter-textobjects.select/.move (same af/if/ac/ic, ]m [m ]] [[); incremental selection now native 0.12 (gnn/grn/grmvan/an/in; grc dropped). Explicit language.register() for ps1/cs/sh/javascriptreact.
  • nvim/zigcc.cmd + treesitter.lua CC: main compiles via the tree-sitter CLI, whose cc crate can't call zig cc directly (multi-word CC; forced msvc triple needs the Windows SDK). The shim rewrites the triple to x86_64-windows-gnu and forwards to zig cczig stays the sole compiler, no LLVM/MSVC. Adds tree-sitter.tree-sitter-cli to winget/packages.json.
  • Docs: CLAUDE.md treesitter + offline-install decisions; nvim/README prereqs.

Verification (isolated sandbox)

Lockfile → fresh vim.pack.add lands on main (install=function); parsers compile via the zig shim; and the original crash path — vim.treesitter.get_parser():parse(true) (injections) on a markdown buffer — returns ok, no error.

⚠️ Interactive confirmation still recommended after merge+pull (highlight, vaf/]m/gnn across lua/cs/ps1/markdown/org). The offline installer's parser step is master-specific and flagged as needing rework (out of scope).

jinyeow added 2 commits July 20, 2026 17:13
master is frozen for Neovim 0.11 and crashes on 0.12: its query_predicates
call vim.treesitter's pre-0.12 get_node_text/get_range, throwing
"attempt to call method 'range' (a nil value)" on any injection query
(every markdown edit). main is the 0.12+ rewrite and the fix.

- plugins.lua: repin both plugins to version='main'.
- nvim-pack-lock.json: pin the main revs. vim.pack.add checks out master on a
  fresh install even with version='main' (default-branch quirk of the archived
  repo); the locked rev is what makes a fresh install land on main. An already
  installed master checkout needs a one-time
  `:lua vim.pack.update({...}, { force = true })` (see CLAUDE.md).
- treesitter.lua: rewritten for the main/native API - drop configs.setup{};
  install() diffed against config.get_installed(); per-buffer
  vim.treesitter.start() + indentexpr in a FileType autocmd; textobjects via
  nvim-treesitter-textobjects.select/.move; incremental selection now native
  0.12 (gnn/grn/grm -> van/an/in; grc dropped). Explicit language.register()
  for ps1/cs/sh/javascriptreact (main drops master's ft->lang table).
- nvim/zigcc.cmd + treesitter.lua CC: main compiles via the tree-sitter CLI,
  whose cc crate can't call `zig cc` directly (multi-word CC; forced msvc
  triple needs the Windows SDK). The shim rewrites the triple to
  x86_64-windows-gnu and forwards to zig cc - zig stays the sole compiler, no
  LLVM/MSVC. Requires winget tree-sitter.tree-sitter-cli (added to packages.json).
- Docs: CLAUDE.md treesitter + offline-install decisions, nvim/README prereqs.

Verified end-to-end in an isolated sandbox: lockfile -> fresh install on main,
parsers compile via the zig shim, and markdown injection parse no longer crashes.
Addresses Codex review of the treesitter migration:
- nvim/README.md: Plugins table said the treesitter plugins are pinned to
  `master` (now `main`); the offline-install table referenced the removed
  `ensure_installed` API and described the master compile path — corrected,
  with a note that the offline parser/org steps need rework for `main`.
- treesitter.lua: apply stylua formatting (one parser/filetype per line) so
  the `stylua --check nvim/` CI gate passes.
@jinyeow

jinyeow commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Codex cross-model review (read-only, second opinion)

Verdict: no HIGH findings. Codex confirmed the pinned main APIs and argument shapes are correct — require('nvim-treesitter').install, config.get_installed('parsers'), vim.treesitter.start() in the FileType autocmd, indentexpr, and the textobjects select_textobject(query, group) / move.goto_*(query, group) calls (including that move accepts either a string or a list).

MEDIUM

  1. nvim/README.md — stale master reference (Plugins table still said the treesitter plugins are pinned to master). ✅ Fixedmain.
  2. nvim/README.md — stale ensure_installed (offline-install table referenced the removed API + the master compile path). ✅ Fixed → parser-list wording + a note that the offline parser/org steps need rework for main.
  3. treesitter.lua — silent pcall(vim.treesitter.start, …) hides permanent parser failures as if merely pending. Kept deliberately (rationale): the FileType autocmd fires per buffer, and on a fresh machine parsers are still compiling async — a vim.notify there would spam during the normal compile window. A permanent breakage still surfaces as missing highlight + :checkhealth nvim-treesitter. Open to revisiting if preferred.

LOW

  • nvim/zigcc.cmd%* reparsed via an env var, so unusual unquoted args with CMD metacharacters could be altered. Kept: tree-sitter build's real invocation passes quoted paths (verified end-to-end — parsers compile), so the known call site is safe. A structurally-argv-preserving wrapper would need a compiled exe; not worth it for the one caller.

Fixes pushed in c1be5fd. (Findings are Codex's; I applied/decided per the above.)

jinyeow and others added 2 commits July 20, 2026 17:43
The codex-skills (x2) and output-styles tests assert Windows junction paths
and were already failing the Ubuntu Pester job on main (pre-existing, not
introduced by this branch). Guard them -Skip:(-not $IsWindows), matching the
existing -Module all test, so #27's Ubuntu check is green independently of the
identical fix in #26. On Windows they run unchanged.
@jinyeow
jinyeow merged commit 7d8cf83 into main Jul 20, 2026
5 checks passed
@jinyeow
jinyeow deleted the feat/nvim-treesitter-main branch July 20, 2026 08:16
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.

1 participant