RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.19k stars 50 forks source link

Treesitter provider for GDScript doesn't work #133

Closed cptchuckles closed 2 years ago

cptchuckles commented 2 years ago

Describe the bug The Treesitter provider for GDScript does not work. Note: the LSP servers for gdscript don't provide textDocument/documentHighlight, which leaves regex the only option, but regex sux.

To Reproduce Steps to reproduce the behavior (include minimal init.vim or .vimrc):

  1. Save the below config to /tmp/illuminate-min.lua
  2. run $ nvim -nu /tmp/illuminate-min.lua 2a. Close and reopen neovim
  3. Open a gdscript .gd file (one is provided below)
  4. Observe no illuminating

Minimal config (/tmp/illuminate-min.lua):

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/illuminate-min/site]]
local package_root = "/tmp/illuminate-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      {
        "nvim-treesitter/nvim-treesitter",
        run = function()
          require('nvim-treesitter.install').update({ with_sync = true })
        end,
      },
      "RRethy/vim-illuminate",
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true
_G.setup = function()
  local tspath = "/tmp/illuminate-min/treesitter"
  vim.opt.runtimepath:append(tspath)
  require("nvim-treesitter.configs").setup {
    parser_install_dir = tspath,
    ensure_installed = { 'gdscript', 'lua' },
    highlight = {
      enable = true,
      additional_vim_regex_highlighting = false,
    },
  }
  require("illuminate").configure {
    providers = { 'treesitter' },
    under_cursor = true,
  }
end

Minimal .gd source file:

extends Node

var thing_a = "hello world"

func _ready():
    var thing_b = "goodbye world"
    print(thing_a)
    print(thing_b)

Here is the TSPlayground output for the above gdscript file:

extends_statement [0, 0] - [0, 12]
  dotted_type [0, 8] - [0, 12]
    type [0, 8] - [0, 12]
variable_statement [2, 0] - [2, 27]
  name [2, 4] - [2, 11]
  string [2, 14] - [2, 27]
function_definition [4, 0] - [7, 15]
  name [4, 5] - [4, 11]
  parameters [4, 11] - [4, 13]
  return_type [4, 14] - [4, 21]
    type [4, 17] - [4, 21]
  body [4, 22] - [7, 15]
    variable_statement [5, 1] - [5, 30]
      name [5, 5] - [5, 12]
      string [5, 15] - [5, 30]
    expression_statement [6, 1] - [6, 15]
      call [6, 1] - [6, 15]
        identifier [6, 1] - [6, 6]
        argument_list [6, 6] - [6, 15]
          identifier [6, 7] - [6, 14]
    expression_statement [7, 1] - [7, 15]
      call [7, 1] - [7, 15]
        identifier [7, 1] - [7, 6]
        argument_list [7, 6] - [7, 15]
          identifier [7, 7] - [7, 14]

Output from :IlluminateDebug

buf_should_illuminate 1 true
config {
  delay = 100,
  filetype_overrides = {},
  filetypes_allowlist = {},
  filetypes_denylist = { "dirbuf", "dirvish", "fugitive" },
  modes_allowlist = {},
  modes_denylist = {},
  providers = { "treesitter" },
  providers_regex_syntax_allowlist = {},
  providers_regex_syntax_denylist = {},
  under_cursor = true
}
started true
provider table: 0x7fe7c936cc90 treesitter

Expected behavior With the above provided .gd source file, you should be able to hover thing_a or thing_b and get highlighting on all occurrences, and use <a-n> and <a-p> to hop between references. Nothing happens.

RRethy commented 2 years ago

This is a limitation in nvim-treesitter, you can see the locals query for gdscript here. You can try modifying the gdscript locals query yourself to highlight variable usages and make a PR into nvim-treesitter which is what vim-illuminate is using under the hood. That being said, there's nothing that can be done on vim-illuminate's side.