Skip to content

fix(highlight): resolve fenced info-string aliases so sh / js highlight#20

Merged
delphinus merged 1 commit into
mainfrom
fix/treesitter-lang-alias
May 28, 2026
Merged

fix(highlight): resolve fenced info-string aliases so sh / js highlight#20
delphinus merged 1 commit into
mainfrom
fix/treesitter-lang-alias

Conversation

@delphinus
Copy link
Copy Markdown
Owner

Summary

  • ```sh / ```js / ```py などの短縮形を treesitter にそのまま渡していたため、対応するパーサが見つからず pcall がコケて、goto continue でハイライト適用が黙ってスキップされていました。Neovim core も nvim-treesitter "main" branch もこれらを alias として登録しないため、ユーザがハイライト崩れに気付きにくい状態でした。
  • display_utils.apply_treesitter_highlights で info string を treesitter パーサ名に解決する resolve_lang() を導入。vim.treesitter.language.get_lang() を先に試し (ユーザが vim.treesitter.language.register() で登録した alias を尊重)、未登録の場合だけプラグイン同梱の小さな alias 表 (sh/zsh/shellbashjs/jsxjavascripttstypescriptpypythonrbrubyrsrustymlyamlmdmarkdownps1powershell) にフォールバックします。
  • 解決済みの名前をパーサロード・highlights query 取得・@capture.<lang> の hl_group すべてに使うよう統一。

Test plan

  • make test — 新規 tests/display_utils_test.lua 20 件含む全テスト pass
  • 実環境で ```sh フェンスドブロックを開き、bash の treesitter ハイライトが適用されることを確認
  • 既存の ```bash / ```lua 等のハイライトが従来通り動くことを確認

Fenced code blocks tagged with ```sh / ```js / ```py and similar short
forms were silently losing treesitter highlighting because the info
string was passed straight to vim.treesitter.get_string_parser, which
looks up parsers by their literal name. Neither Neovim core nor
nvim-treesitter's "main" branch registers these as aliases by default,
so loading the parser/query failed and the goto-continue path swallowed
the error.

Resolve via vim.treesitter.language.get_lang() first (so user-registered
aliases keep working) and fall back to a small built-in alias table for
the most common cases. Use the resolved name for the parser, the
highlights query, and the @capture.<lang> hl_group so all three stay in
sync.
@delphinus delphinus merged commit 4af5c3e into main May 28, 2026
4 checks passed
@delphinus delphinus deleted the fix/treesitter-lang-alias branch May 28, 2026 07:25
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