nvim-treesitterで `Failed to source` エラーになる場合の解決方法
neovim のバイナリを新しくしたところ、下記のエラーメッセージが出て treesitter が動かなくなりました。
Failed to source`/home/hoge/.local/share/nvim/lazy/nvim-treesitter/plugin/nvim-treesitter.lua`
これは neovim 付属の parser が treesitter と互換性がないことが原因らしいです。
まず、neovim を立ち上げて以下のコマンドを実行します。
:echo nvim_get_runtime_file('parser', v:true)
すると以下のように parser が 2 つ見つかるはずなので、後者のディレクトリを削除します。
['/home/yourname/.local/share/nvim/lazy/nvim-treesitter/parser','/home/yourname/bin/nvim-macos/lib/nvim/parser']
nvim を再起動して、:checkhealth nvim-treesitter
を実行し、Parser 一覧で x
がついているものを :TSInstall hoge
でインストールし直すと治りました。
参考: https://github.com/nvim-treesitter/nvim-treesitter/issues/3970#issuecomment-1353836834