はじめに
Neovimでtree-sitterを利用するプラグインとして、nvim-treesitterというプラグインが有名だったのですが、
最近nvim-treesitterはパブリックアーカイブされてしまいました。
事情については以下の記事を参照ください。
現時点ではパブリックアーカイブのため、インストールをすること自体は可能ですが、アーカイブされているという特性上、今後も使い続けられるとは限りません。
この記事では、nvim-treesitterからtree-sitter-manager.nvimに移行した話をまとめます。
tree-sitterとは
tree-sitterとは、シンタックスハイライトの解析に特化したパーサーです。
tree-sitterを用いることで、正規表現だけでは表現が難しいようなシンタックスハイライトも実現しやすく、
より正確で詳細なコード解析が可能になります。
nvim-treesitterとは
nvim-treesitterは、tree-sitterをNeovimで使えるようにしたプラグインです。
詳細については以下をご覧ください。
元々はtree-sitterを用いたNeovim内での挙動処理などもプラグインとして担っていたのですが、
Neovim 0.12からはtree-sitterとのインテグレーションがNeovim自体に組み込まれており、
現状のmainブランチのnvim-tree-sitterはパーサーとクエリの管理に機能を絞ったものになっています。(このように機能を絞ったタイミングでリポジトリはパブリックアーカイブされています)
詳しくは以下の記事をご覧ください。
neovim-treesitterがパブリックアーカイブされた経緯
neovim-treesitterはNeovimでtree-sitterを使う際の第一選択のプラグインでしたが、多くの利用者がいた中急遽パブリックアーカイブされました。
アーカイブされた経緯については多くの方がまとめていますが、この記事では、delphinusさんのGistを紹介します。
tree-sitter-manager.nvimとは
tree-sitter-manager.nvimはneovim-treesitterがアーカイブされたのを受け公開された、パーサー、クエリの管理の機能に特化した、ライトなプラグインになっています。
READMEでは以下のように説明されています。
Although Neovim 0.12 integrated Tree-sitter into the core, it still lacks a built-in parser installer. With nvim-treesitter/nvim-treesitter now archived, this plugin provides a lightweight, actively maintained alternative that makes installing parsers and adding new languages effortless.
tree-sitter-manager.nvim provides a minimal alternative for:
- Installing and removing Tree-sitter parsers
- Automatically copying queries for syntax highlighting
- Managing parsers through a clean TUI interface
移行方法
移行方法はとてもシンプルで、READMEに書いてある通りに進めるだけで完了します。
僕はプラグインマネージャーとしてlazy.nvimを使用しているため、以下のように設定しています。
{
"romus204/tree-sitter-manager.nvim",
dependencies = {}, -- tree-sitter CLI must be installed system-wide
config = function()
require("tree-sitter-manager").setup({
ensure_installed = "all",
})
end
}
plugins.luaの全体は以下のとおりです。
ensure_installed = "all"を設定することで、プラグインインストール後、最初のセットアップで全てのパーサーをインストールするようにしました。