nvim-treesitter / nvim-treesitter-refactor

Refactor module for nvim-treesitter
Apache License 2.0
407 stars 25 forks source link

Error message when switching buffers #42

Open benjamineskola opened 1 year ago

benjamineskola commented 1 year ago

Describe the bug Occasionally when switching buffers I get the following error message:

Error detected while processing FileType Autocommands for "*":
Error executing lua callback: ...ter-refactor/lua/nvim-treesitter-refactor/navigation.lua:186: E31: No such mapping
stack traceback:
    [C]: in function 'nvim_buf_del_keymap'
    ...ter-refactor/lua/nvim-treesitter-refactor/navigation.lua:186: in function 'detach'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:518: in function 'detach_module'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:527: in function 'reattach_module'
    ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:131: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:130>

This doesn't seem to actually affect any functionality: I can still use smart-rename after the error occurs (which makes sense, perhaps, as it appears to be related to removing a mapping, but I don't know why that would be).

To Reproduce

This happens specifically when I'm switching from one buffer to another (e.g. with ]b), but not every time I do so. It doesn't seem to occur with the same buffer twice, so if I go A->B->A->B and it appears the first time I switch to B, it won't appear the second time I do.

Expected behavior No error message.

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check() ======================================================================== ## Installation - OK: `tree-sitter` found 0.20.7 (parser generator, only needed for :TSInstallFromGrammar) - OK: `node` found v16.18.0 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: Apple clang version 14.0.0 (clang-1400.0.29.202) - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. ## OS Info: { machine = "arm64", release = "22.2.0", sysname = "Darwin", version = "Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103" } ## Parser/Features H L F I J - meson ✓ . ✓ . ✓ - qmljs ✓ . ✓ . . - racket ✓ . ✓ . ✓ - scheme ✓ . ✓ . ✓ - rego ✓ . . . ✓ - markdown_inline ✓ . . . ✓ - embedded_template ✓ . . . ✓ - tlaplus ✓ ✓ ✓ . ✓ - v ✓ ✓ ✓ ✓ ✓ - commonlisp ✓ ✓ ✓ . . - svelte ✓ . ✓ ✓ ✓ - astro ✓ ✓ ✓ ✓ ✓ - cpp ✓ ✓ ✓ ✓ ✓ - pug ✓ . . . ✓ - glsl ✓ ✓ ✓ ✓ ✓ - hlsl ✓ ✓ ✓ ✓ ✓ - markdown ✓ . ✓ . ✓ - yang ✓ . ✓ ✓ ✓ - dot ✓ . . . ✓ - ninja ✓ . ✓ ✓ . - fusion ✓ ✓ ✓ ✓ . - help ✓ . . . ✓ - ledger ✓ . ✓ ✓ ✓ - rst ✓ ✓ . . ✓ - fennel ✓ ✓ . . ✓ - ql ✓ ✓ ✓ ✓ ✓ - graphql ✓ . . ✓ ✓ - pascal ✓ ✓ ✓ ✓ ✓ - jsonc ✓ ✓ ✓ ✓ ✓ - php ✓ ✓ ✓ ✓ ✓ - make ✓ . ✓ . ✓ - java ✓ ✓ . ✓ ✓ - kotlin ✓ ✓ ✓ . ✓ - comment ✓ . . . . - julia x ✓ ✓ ✓ ✓ - jsonnet ✓ . . . . - jsdoc ✓ . . . . - godot_resource ✓ ✓ ✓ . . - erlang ✓ . ✓ . . - sparql ✓ ✓ ✓ ✓ ✓ - ocaml ✓ ✓ ✓ . ✓ - turtle ✓ ✓ ✓ ✓ ✓ - devicetree ✓ ✓ ✓ ✓ ✓ - gdscript ✓ ✓ . ✓ ✓ - query ✓ ✓ ✓ ✓ ✓ - ocamllex ✓ . . . ✓ - menhir ✓ . . . ✓ - beancount ✓ . ✓ . . - org . . . . . - rnoweb ✓ . ✓ . ✓ - todotxt ✓ . . . . - bibtex ✓ . ✓ ✓ . - zig ✓ . ✓ ✓ ✓ - gomod ✓ . . . ✓ - fortran ✓ . ✓ ✓ . - cmake ✓ . ✓ . . - slint ✓ . . ✓ . - typescript ✓ ✓ ✓ ✓ ✓ - haskell ✓ . ✓ . ✓ - json5 ✓ . . . ✓ - pioasm ✓ . . . ✓ - hjson ✓ ✓ ✓ ✓ ✓ - hocon ✓ . . . ✓ - llvm ✓ . . . . - http ✓ . . . ✓ - prisma ✓ . . . . - rasi ✓ ✓ ✓ ✓ . - css ✓ . ✓ ✓ ✓ - scss ✓ . . ✓ . - hack ✓ . . . . - d ✓ . ✓ ✓ ✓ - python ✓ ✓ ✓ ✓ ✓ - rust ✓ ✓ ✓ ✓ ✓ - vala ✓ . ✓ . . - lalrpop ✓ ✓ . . ✓ - solidity ✓ . . . . - json ✓ ✓ ✓ ✓ . - proto ✓ . ✓ . . - elvish ✓ . . . ✓ - wgsl ✓ . ✓ ✓ . - javascript ✓ ✓ ✓ ✓ ✓ - m68k ✓ ✓ ✓ . ✓ - lua ✓ ✓ ✓ ✓ ✓ - yaml ✓ ✓ ✓ ✓ ✓ - tiger ✓ ✓ ✓ ✓ ✓ - t32 ✓ ✓ ✓ . ✓ - html ✓ ✓ ✓ ✓ ✓ - fish ✓ ✓ ✓ ✓ ✓ - gitignore ✓ . . . . - go ✓ ✓ ✓ ✓ ✓ - scala ✓ . ✓ . ✓ - gitattributes ✓ . . . ✓ - gowork ✓ . . . ✓ - supercollider ✓ ✓ ✓ ✓ ✓ - git_rebase ✓ . . . ✓ - elm ✓ . . . ✓ - ocaml_interface ✓ ✓ ✓ . ✓ - swift ✓ ✓ . . . - gitcommit ✓ . . . ✓ - diff ✓ . . . . - blueprint ✓ . . . . - twig ✓ . . . ✓ - nickel ✓ . . . . - perl ✓ . ✓ . ✓ - sxhkdrc ✓ . ✓ . ✓ - c ✓ ✓ ✓ ✓ ✓ - bash ✓ ✓ ✓ . ✓ - toml ✓ ✓ ✓ ✓ ✓ - tsx ✓ ✓ ✓ ✓ ✓ - awk ✓ . . . ✓ - hcl ✓ . ✓ ✓ ✓ - arduino ✓ ✓ ✓ ✓ ✓ - glimmer ✓ . . . . - jq ✓ . . . ✓ - verilog ✓ ✓ ✓ . ✓ - mermaid ✓ . . . . - latex ✓ . ✓ . ✓ - ebnf ✓ . . . . - cuda ✓ ✓ ✓ ✓ ✓ - foam ✓ ✓ ✓ ✓ ✓ - heex ✓ ✓ ✓ ✓ ✓ - eex ✓ . . . ✓ - dockerfile ✓ . . . ✓ - c_sharp ✓ ✓ ✓ . ✓ - ruby ✓ ✓ ✓ ✓ ✓ - vhs ✓ . . . . - regex ✓ . . . . - surface ✓ . ✓ ✓ ✓ - gleam ✓ ✓ ✓ ✓ ✓ - sql ✓ . . . ✓ - elixir ✓ ✓ ✓ ✓ ✓ - ada ✓ ✓ ✓ . . - r ✓ ✓ . ✓ ✓ - dart ✓ ✓ . ✓ ✓ - teal ✓ ✓ ✓ ✓ ✓ - vue ✓ . ✓ ✓ ✓ - nix ✓ ✓ ✓ . ✓ - vim ✓ ✓ ✓ . ✓ - agda ✓ . ✓ . . - norg . . . . . - clojure ✓ ✓ ✓ . ✓ - cooklang ✓ . . . . 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} ## The following errors have been detected: - ERROR: julia(highlights): ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 3592 for language julia julia(highlights) is concatenated from the following files: | [ERROR]:"/Users/ben/Library/nvim/lazy/nvim-treesitter/queries/julia/highlights.scm", failed to load: ...im/0.8.1/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 3592 for language julia

Output of nvim --version

NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.1/share/nvim"

Run :checkhealth for more info

Additional context Add any other context about the problem here.

asmodeus812 commented 1 year ago

I can also reproduce this when i try to jump to next / prev usage. Which it errors out and no jump is performed. Seems like a recent regression as it was working fine before

scienceplease commented 2 months ago

Also running into this stacktrace. Looking at the source (below) its assuming that if a mapping is present in the config.keymaps table that the mapping must still exist for the buffer. Any number of things could have taken place to invalidate this assumption before this detach function is called.

Trying to remove a mapping that no longer exists isn't really a error day-to-day users should care about. The call to nvim_buf_del_keymap could instead be wrapped in a pcall with the error written out to an appropriate log file or discarded entirely.

function M.detach(bufnr)
  local config = configs.get_module "refactor.navigation"

  for _, mapping in pairs(config.keymaps) do
    if mapping then
      api.nvim_buf_del_keymap(bufnr, "n", mapping)   -- <-- Wrap this in a `pcall`
    end
  end
end