nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.03k stars 181 forks source link

Nim parser fails at compiling and installs incorrectly #542

Closed koaledu closed 6 months ago

koaledu commented 6 months ago

Describe the bug

Apparently the parser for the Nim programming language fails to compile, and produces unexpected behavior like an error message when opening a .nim file and unreliable syntax highlighting; sometimes it works and sometimes it doesn't, but the error message is always there.

I'm not sure if it's a problem with the Neovim distro I'm using (AstroNvim) but I don't think it is, I installed other parsers and they installed perfectly and work flawlessly.

To Reproduce

  1. Execute Neovim typing nvim on the terminal

  2. Create or open a file with the .nim extension

  3. Type :TSInstall nim

  4. Get an error message

[nvim-treesitter] [0/1] Compiling...                                                                                                                          
Failed to execute the following command:                                                                                                                      
{                                                                                                                                                             
  cmd = <function 1>                                                                                                                                          
}                                                                                                                                                             
"/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 9840 for language nim" 

Screenshot from 2023-12-22 22-12-08

  1. Exit Neovim pressing :q!

  2. Reopen the .nim file. The file sometimes has syntax highlighting, sometimes not

  3. Get an error message

Error detected while processing User Autocommands for "AstroMasonLspSetup"..FileType Autocommands for "*":                                                    
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 9840 for language nim            
stack traceback:                                                                                                                                              
        [C]: in function '_ts_parse_query'                                                                                                                    
        /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'get_query'                                                                     
        ...r-textobjects/lua/nvim-treesitter/textobjects/shared.lua:99: in function 'available_textobjects'                                                   
        ...r-textobjects/lua/nvim-treesitter/textobjects/select.lua:172: in function 'attach'                                                                 
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:509: in function 'attach_module'                                                          
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:532: in function 'reattach_module'                                                        
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:133: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:132>        
        [C]: in function 'nvim_exec_autocmds'                                                                                                                 
        ...e/mduardo/.config/nvim/lua/plugins/configs/lspconfig.lua:43: in function <...e/mduardo/.config/nvim/lua/plugins/configs/lspconfig.lua:41>          
        [C]: in function 'nvim_exec_autocmds'                                                                                                                 
        /home/mduardo/.config/nvim/lua/astronvim/utils/init.lua:145: in function </home/mduardo/.config/nvim/lua/astronvim/utils/init.lua:145>

Screenshot from 2023-12-22 22-12-37

Expected behavior

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `node` found v21.4.0 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (GCC) 13.2.1 20230801
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "6.6.7-arch1-1",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Thu, 14 Dec 2023 03:45:42 +0000"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - java                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - kotlin              ✓ ✓ ✓ . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - nim                 ✓ ✓ ✓ . ✓
  - odin                ✓ ✓ ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - sql                 ✓ . . ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - zig                 ✓ . ✓ ✓ ✓

  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} ~

Output of nvim --version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1702233742

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Additional context

My Neovim setup is AstroNvim.

This bug report was originally reported over here.

kiyoon commented 6 months ago

Does this happen after updating the plugin?

koaledu commented 6 months ago

I updated the plugin as you said, and still get the second error message but after skipping it the syntax highlighting works fine.

Screenshot from 2023-12-24 12-12-24

theHamsta commented 6 months ago

The error message means that the parser was installed successfully, but that there are incompatible textobjects. Could you open https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a/queries/nim/textobjects.scm#L481 locally and let Neovim query linter show you what query in considers invalid.

:echo nvim_get_runtime_file('queries/nim/textobjects.scm', v:true)

and

:echo nvim_get_runtime_file('parser/nim.so', v:true)

might help you to see where the nim parser and the nim textobject queries are installed.

alaviss commented 6 months ago

This appears to be an AstroNvim problem. I spun up a fresh copy of nvim with AstroNvim and noticed that the nvim-treesitter-textobjects used was ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a, which does not have the updated nim queries.

koaledu commented 6 months ago

The error message means that the parser was installed successfully, but that there are incompatible textobjects. Could you open

https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a/queries/nim/textobjects.scm#L481 locally and let Neovim query linter show you what query in considers invalid.

:echo nvim_get_runtime_file('queries/nim/textobjects.scm', v:true)

and

:echo nvim_get_runtime_file('parser/nim.so', v:true)

might help you to see where the nim parser and the nim textobject queries are installed.

I got this

['/home/mduardo/.local/share/nvim/lazy/nvim-treesitter-textobjects/queries/nim/textobjects.scm'] and ['/home/mduardo/.local/share/nvim/lazy/nvim-treesitter/parser/nim.so']

alaviss commented 6 months ago

AstroNvim has finally updated their textobjects commit which should solve this problem, please test again.

koaledu commented 6 months ago

Works flawlessly Thank y'all!

image