tree-sitter / tree-sitter-go

Go grammar for tree-sitter
MIT License
317 stars 63 forks source link

Failure at initialization of go-ts-mode with recent Emacs #141

Closed dunric closed 6 months ago

dunric commented 6 months ago

I've successfully installed libtree-sitter-go.so lib from current master branch.

Attempt to start go-ts-mode fails with

Error during redisplay: (jit-lock-function 202) signaled (treesit-query-error "Node type error at" 150 "(function_declaration name: (identifier) @font-lock-function-name-face) (method_declaration name: (field_identifier) @font-lock-function-name-face) (method_spec name: (field_identifier) @font-lock-function-name-face) (field_declaration name: (field_identifier) @font-lock-property-name-face) (parameter_declaration name: (identifier) @font-lock-variable-name-face) (short_var_declaration left: (expression_list (identifier) @font-lock-variable-name-face (\",\" (identifier) @font-lock-variable-name-face) )) (var_spec name: (identifier) @font-lock-variable-name-face (\",\" name: (identifier) @font-lock-variable-name-face) )"

GNU Emacs 29.3 on x86_64 Linux go-mode.el version 1.6.0 tree-sitter-go current tree-sitter-gomod current

ObserverOfTime commented 6 months ago

"Node type error at" means that go-ts-mode needs to be updated.

MacMcIrish commented 6 months ago

Adding some flavour, go-ts-mode is packaged with emacs and the latest release of emacs (29.3 at time of writing) is not compatible with the latest release of tree-sitter-go, and treesit-install-language-grammar doesn't allow for specifying specific version.

Rolling back to v0.20.0 fixed the issue for me.

Copying the quick fix for others that installed via treesit-install-language-grammar like myself on fresh installs of emacs:

git clone https://github.com/tree-sitter/tree-sitter-go && cd tree-sitter-go
git checkout v0.20.0
tree-sitter generate
tree-sitter build
# mac specific instructions
rm ~/.emacs.d/tree-sitter/libtree-sitter-go.dylib
cp go.dylib ~/.emacs.d/tree-sitter/libtree-sitter-go.dylib

And restart emacs.

dunric commented 6 months ago

@MacMcIrish Good find, stock go-ts-mode is out of sync with current parser lib and it causes such issues.

However you don't need retire to manual compilation of older version. Just pass to treesit-install-language-grammar function desired tag/branch in interactive mode. In this case v0.20.0 and it will rebuild it automatically.

Syntax highlighting of current go-ts-mode with tree-sitter-go parser seems to lack some features available in normal go-mode like distinguished rendering of method/function names and module identifiers.