問題
久しぶりにNeoVim開いてinit.lua
開いたら大変なことになっていることに気がつきました
この場合はtreesitterの色がついている(白文字はほとんどない)けれど、ほぼ全部白文字+真っ赤エラーの時もありました
環境
macOS 13.0
nvim, treesitterはbrew経由
> nvim --version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.local
Features: +acl +iconv +tui
See ":help feature-compile"
システム vimrc: "$VIM/sysinit.vim"
省略時の $VIM: "/opt/homebrew/Cellar/neovim/0.8.1/share/nvim"
Run :checkhealth for more info
> tree-sitter --version
tree-sitter 0.20.7
:checkhealth nvim-treesitter
nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
- OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
- OK: `node` found v14.17.0 (only needed for :TSInstallFromGrammar)
- OK: `git` executable found.
- OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: Apple clang version 14.0.0 (clang-1400.0.29.202)
- OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
## OS Info:
{
machine = "arm64",
release = "22.1.0",
sysname = "Darwin",
version = "Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103"
}
## Parser/Features H L F I J
- vim x ✓ ✓ . ✓
- help x . . . x
- lua ✓ ✓ ✓ ✓ ✓
- c ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
## The following errors have been detected:
- ERROR: vim(highlights): ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 2765 for language vim
vim(highlights) is concatenated from the following files:
| [ERROR]:"/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/highlights.scm", failed to load: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 2765 for language vim
- ERROR: help(highlights): ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 100 for language help
help(highlights) is concatenated from the following files:
| [ERROR]:"/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/help/highlights.scm", failed to load: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 100 for language help
- ERROR: help(injections): ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 14 for language help
help(injections) is concatenated from the following files:
| [ERROR]:"/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/help/injections.scm", failed to load: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 14 for language help
さっきのエラーが出てますね
結論
エラーでググるとこんなのが出てきます
内容はこんな感じ
:TSInstall! <lang>
を実行しろ
- で治らなければ以下のコマンドを実行し、
:echo nvim_get_runtime_file('*/<lang>.so', v:true) :echo nvim_get_runtime_file('queries/<lang>/*.scm', v:true)
nvim-treesitter以下でないフォルダが出てこればそれを削除しろ
やってみます
コマンドのの部分は自分がエラー出てるやつにしてください
僕はとりあえず"vim"を指定してやります
1. :TSInstall! vim
ハイライトはちょっと回復した、けどエラーは出るし起動し直したりしてるとハイライトも消える ダメそう
2. コマンド→ファイル削除
:echo nvim_get_runtime_file('*/vim.so', v:true)
['/opt/homebrew/Cellar/neovim/0.8.1/lib/nvim/parser/vim.so']
これnvim-treesitter以下じゃなさそうだな...
:echo nvim_get_runtime_file('queries/vim/*.scm', v:true)
['/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/folds.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/highlights.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/injections.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/locals.scm',
'/opt/homebrew/Cellar/neovim/0.8.1/share/nvim/runtime/queries/vim/highlights.scm',
'/opt/homebrew/Cellar/neovim/0.8.1/share/nvim/runtime/queries/vim/injections.scm']
最後の2つ、nvim-treesitter外っぽい
→/opt/homebrew/Cellar/neovim/0.8.1/lib/nvim/parser
と/opt/homebrew/Cellar/neovim/0.8.1/share/nvim/runtime/queries
消せば解決するのでは?
やってみる
削除後
:echo nvim_get_runtime_file('*/vim.so', v:true)
[]
:echo nvim_get_runtime_file('queries/vim/*.scm', v:true)
['/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/folds.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/highlights.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/injections.scm',
'/Users/zoi/.local/share/nvim/site/pack/jetpack/opt/nvim-treesitter/queries/vim/locals.scm']
うん、綺麗
:checkhealth nvim-treesitter
nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
- OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar)
- OK: `node` found v14.17.0 (only needed for :TSInstallFromGrammar)
- OK: `git` executable found.
- OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: Apple clang version 14.0.0 (clang-1400.0.29.202)
- OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
## OS Info:
{
machine = "arm64",
release = "22.1.0",
sysname = "Darwin",
version = "Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103"
}
## Parser/Features H L F I J
- lua ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang}
やった! エラー消えた!
というわけで、無事にエラー消えました
nvimのインストールフォルダ内にあったのも空ファイルではないんですが、おそらく古いファイルが残っていて、:TSUpdate
でnvim-treesitter内のファイルは更新されたんだろうけど、別ファイルを参照するようになってたんじゃないかと思います。PATHの優先順みたいな感じ?
NeoVimを気分で触ってるにわかですが、やっぱり公式のGitHubのissueが一番信用できますね
それではみなさん、良いNeoVimライフを!