tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
95 stars 20 forks source link

terraform.so: undefined symbol: tree_sitter_terraform #14

Closed cova-fe closed 2 years ago

cova-fe commented 2 years ago

Describe the bug Hi, I'm trying to install this parser, using https://github.com/nvim-treesitter/nvim-treesitter#adding-parsers directions. The installation seems to be ok, but I get this error when opening a terraform file:

Error detected while processing CursorHold Autocommands for "<buffer=1>":
E5108: Error executing lua Failed to load parser: uv_dlsym: /home/cova/.local/share/lunarvim/site/pack/packer/start/nvim-treesitter/parser/terraform.so: undefined symbol: tree_sitter_terraform
stack traceback:
        [C]: in function '_ts_add_language'
        /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:33: in function 'require_language'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:38: in function '_create_parser'
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:93: in function 'get_parser'
        ...ext-commentstring/lua/ts_context_commentstring/utils.lua:124: in function 'get_node_at_cursor_start_of_line'
        ...-commentstring/lua/ts_context_commentstring/internal.lua:116: in function 'calculate_commentstring'
        ...-commentstring/lua/ts_context_commentstring/internal.lua:145: in function 'update_commentstring'
        [string ":lua"]:1: in main chunk

To Reproduce I just followed the directions described above. My configuration for this plugin:

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.terraform = {
  install_info = {
    url = "/home/cova/repos/github/utils/tree-sitter-hcl/", -- local path or git repo
    files = {
      "src/parser.c",
      "src/scanner.cc",
    }
  },
    filetype = "terraform", -- if filetype does not agrees with parser name
}

Then I just ran TSInstall terraform (also tried from grammar)

I'm pretty sure that I'm doing something wrong, but can't see what :) I'm running lunarvim (master) with neovim 0.6.1

Any suggestions where to look?

Thanks!

MichaHoffmann commented 2 years ago

Hey @cova-fe,

This parser should already be installed as "hcl": https://github.com/nvim-treesitter/nvim-treesitter/blob/fa2a6b68aaa6df0187b5bbebe6cbadc120d4a65a/lua/nvim-treesitter/parsers.lua#L435. The used_by: "terraform" should make it work with terraform and there are also a few autocommands to set the filetype of .tf and .tfvars to "terraform" so that the parser is chosen for files with that ending: https://github.com/nvim-treesitter/nvim-treesitter/blob/fa2a6b68aaa6df0187b5bbebe6cbadc120d4a65a/ftdetect/hcl.vim#L2

In principle it should work out of the box with just TSInstall hcl i think! Does this help you?

ps.: i think the error comes from the fact that this parser exports the symbol tree_sitter_hcl instead of tree_sitter_terraform ( https://github.com/MichaHoffmann/tree-sitter-hcl/blob/3cb7fc28247efbcb2973b97e71c78838ad98a583/src/parser.c#L31372 )

cova-fe commented 2 years ago

Yep, indeed! I was tricked because I was searching for "terraform" in the list of supported files :) sorry for the noise and thanks for the quick answer!

MichaHoffmann commented 2 years ago

Hey @cova-fe,

no worries, the setup is a little confusing with hcl vs terraform, actually i think one could probably write a terraform parser ( adding the missing keywords ) using this as a base and make highlighting and everything a little more comfortable in nvim-treesitter. Maybe in a future version!