fix(highlight): resolve fenced info-string aliases so sh / js highlight#20
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/shell→bash、js/jsx→javascript、ts→typescript、py→python、rb→ruby、rs→rust、yml→yaml、md→markdown、ps1→powershell) にフォールバックします。highlightsquery 取得・@capture.<lang>の hl_group すべてに使うよう統一。Test plan
make test— 新規tests/display_utils_test.lua20 件含む全テスト pass```shフェンスドブロックを開き、bashの treesitter ハイライトが適用されることを確認```bash/```lua等のハイライトが従来通り動くことを確認