andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.

Home Page:https://www.vim.org/scripts/script.php?script_id=5624

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Highlights broken with latest treesitter

huwqchn opened this issue · comments

nvim-treesitter/nvim-treesitter#3092 (comment)

Get an error "query: invalid node type"

Did you already follow the steps listed in that comment? I did a :TSUpdate and it seems to work fine now.

I tried every steps, but still not wrok

I still can't reproduce it, can you share your .lua file?

I using lazy for plugins-loader now, there is my lua file

return {
  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    event = "BufReadPost",
    dependencies = {
      -- { -- too slow
      --   "nvim-treesitter/nvim-treesitter-textobjects",
      -- },
      -- { -- too slow
      --   "p00f/nvim-ts-rainbow",
      -- },
    },
    opts = {
      ensure_installed = {
        "bash",
        "c",
        "cmake",
        "cpp",
        "css",
        "diff",
        "fish",
        "gitignore",
        "go",
        "graphql",
        "help",
        "html",
        "http",
        "java",
        "javascript",
        "jsdoc",
        "jsonc",
        "latex",
        "lua",
        "markdown",
        "markdown_inline",
        "meson",
        "ninja",
        "nix",
        "norg",
        "org",
        "php",
        "python",
        "query",
        "regex",
        "rust",
        "scss",
        "sql",
        "svelte",
        "teal",
        "toml",
        "tsx",
        "typescript",
        "vhs",
        "vim",
        "vue",
        "wgsl",
        "yaml",
        "json",
      }, -- put the language you want in this array
      -- ensure_installed = "all", -- one of "all" or a list of languages
      ignore_install = {}, -- List of parsers to ignore installing
      sync_install = false, -- install languages synchronously (only applied to `ensure_installed`)

      -- Automatically install missing parsers when entering buffer
      auto_install = false,

      matchup = {
        enable = true, -- mandatory, false will disable the whole extension
        -- disable = { "c", "ruby" },  -- optional, list of language that will be disabled
      },
      highlight = {
        enable = true, -- false will disable the whole extension
        additional_vim_regex_highlighting = { "markdown" },
        disable = function(lang, buf)
          if vim.tbl_contains({ "latex" }, lang) then
            return true
          end

          local status_ok, big_file_detected = pcall(vim.api.nvim_buf_get_var, buf, "bigfile_disable_treesitter")
          return status_ok and big_file_detected
        end,
      },
      context_commentstring = {
        enable = true,
        enable_autocmd = false,
        config = {
          -- Languages that have a single comment style
          typescript = "// %s",
          css = "/* %s */",
          scss = "/* %s */",
          html = "<!-- %s -->",
          svelte = "<!-- %s -->",
          vue = "<!-- %s -->",
          json = "",
        },
      },
      incremental_selection = {
        enable = true,
        keymaps = {
          init_selection = "gnn",
          node_incremental = "grn",
          scope_incremental = "grc",
          node_decremental = "grm",
        },
      },
      query_linter = {
        enable = true,
        use_virtual_text = true,
        lint_events = { "BufWrite", "CursorHold" },
      },
      indent = { enable = true, disable = { "yaml", "python", "css", "c", "cpp" } },
      autotag = { enable = true },
      autopairs = { enable = true },
      textobjects = {
        swap = {
          enable = false,
        },
        select = {
          enable = false,
        },
        lsp_interop = {
          enable = false,
        },
      },
      textsubjects = {
        enable = false,
        keymaps = { ["."] = "textsubjects-smart", [";"] = "textsubjects-big" },
      },
      playground = {
        enable = true,
        disable = {},
        updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
        persist_queries = true, -- Whether the query persists across vim sessions
        keybindings = {
          toggle_query_editor = "o",
          toggle_hl_groups = "i",
          toggle_injected_languages = "t",
          toggle_anonymous_nodes = "a",
          toggle_language_display = "I",
          focus_language = "f",
          unfocus_language = "F",
          update = "R",
          goto_node = "<cr>",
          show_help = "?",
        },
      },
      rainbow = {
        enable = false,
        -- extended_mode = true, -- Highlight also non-parentheses delimiters, boolean or table: lang -> boolean
        -- max_file_lines = 1000, -- Do not enable for files with more than 1000 lines, int
        -- colors = {
        --   "DodgerBlue",
        --   "Orchid",
        --   "Gold",
        -- },
        -- disable = { "html" },
      },
    },
    config = function(_, opts)
      require("nvim-treesitter.configs").setup(opts)
    end,
  },

  {
    "nvim-treesitter/nvim-treesitter-context",
    event = "VeryLazy",
  },
  {
    "windwp/nvim-ts-autotag",
    event = "InsertEnter",
  },
  {
    "nvim-treesitter/playground",
    cmd = "TSPlaygroundToggle",
  },
  {
    "JoosepAlviste/nvim-ts-context-commentstring",
  },
  {
    "andymass/vim-matchup",
    event = "BufReadPost",
    config = function()
      vim.g.matchup_matchparen_offscreen = { method = nil }
      vim.g.matchup_matchpref = { html = { nolists = 1 } }
    end,
  },
}

I have the same problem with treesitter enabled for matchup. I have tried neovim 0.8.2, nightly, TSUpdate, and using lazy.nvim too.

That's interesting, Its looks work well when using packer.nvim

I have slightly the same problem but it only occurs on the nightly build (master branch), when I switch to the v0.8.2 build (stable branch), it works fine.
It only occurs when my cursor hits these (){}[] characters. 🤔

image

So it works with packer but not lazy.nvim? That's very strange.

@AnoRebel this code path in the backtrace shouldn't be possible at all with nightly. I am not sure what's going on.

I guess lazy.nvim lazy load some thing...

lunarvim using lazy now, and matchup works with lvim.

@AnoRebel this code path in the backtrace shouldn't be possible at all with nightly. I am not sure what's going on.

@andymass I'm on v0.9.0-dev-701+g34b973b1d and thats the output, followed by more errors, if my cursor touches any of those characters.

The problem is not in lazy.nvim package manager, but in LazyVim config. It uses version = "*" by default and the last release of this plugin is too old.

Use something like this { "andymass/vim-matchup", branch = "master", event = "BufReadPost" }, in your lazy.nvim config, or turn off version = * in your lazy.vim config.

@lkhphuc thank you for solving that issue! I will cut a new release soon, my expectation was that anyone using neovim would use HEAD.

@AnoRebel I just pushed a quick change to the repo, can you try that?

@AnoRebel I just pushed a quick change to the repo, can you try that?

@andymass Running without the branch="master" I get this:
image

But I used @lkhphuc method(adding branch="master") and the error goes away now. Thanks for the fix.

Looks like everyone's issue is solved, resolving.

Unfortunately, I'm still getting this error, specifically for Julia.

  • I have run :TSUpdate and :TSInstall! julia
  • :checkhealth shows nothing wrong
  • I am using lazy.nvim currently, but adding branch=master and completely reinstalling vim-matchup seems to have had no effect
  • I'm on NVIM v0.9.0-dev-918+gb8ad1bfe8b on Linux
  • My trace is almost identical to those shared before, but differs in some line numbers:
    matchup-error
    (I suspect these differences reflect that I'm using HEAD of vim-matchup and have updated nvim-treesitter)

I'm happy to move this to a new issue if you'd prefer, @andymass, as it seems like this may have to do with Julia specifically (I cannot reproduce the error for any other language - have tried Lua, C++, Python).

@wbthomason I also get this issue on Julia. I think it's separate from the issue here and think it would be wise to open a new issue regarding the Julia support :) I love this plugin and would love to see the Julia compatibility get fixed as well

Thanks @mehalter and @wbthomason, I think I see the issue. 9c95910
I guess at some point the Julia grammar changed compound_expression to compound_statement (or perhaps, it never worked..)

Thanks for the quick fix (and, as always, excellent plugin), @andymass!