nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.9k stars 907 forks source link

Crash when entering specific text #7316

Closed yuhui-liu closed 3 weeks ago

yuhui-liu commented 3 weeks ago

Describe the bug

Neovim crashes when editing cpp files and entering specific text.

To Reproduce

crash-min.cpp:

#include <vector>
class ANYTHING {
 public:
 private:
  std::vector<int> a;
};

and here's init.lua:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  spec={
    "nvim-treesitter/nvim-treesitter",
    config = function()
      require('nvim-treesitter.configs').setup({
      highlight = { enable = true },
      ensure_installed = {
        'c', 'cpp','css', 'html', 'javascript', 'typescript', 'tsx', 'lua', 'vim', 'vimdoc',
      },
    })
    end
  }
})

To reproduce: nvim -u init.lua crash-min.cpp After it launches:jjoconst

Expected behavior

It crashes and exits. When open again with nvim -u init.lua crash-min.cpp, there's message like E325: ATTENTION Found a swap file by the name "~/.local/state/nvim/swap/%home%username%projects%crash%crash-min.cpp.swp" ......

Output of :checkhealth nvim-treesitter

Installation ~

OS Info: { machine = "x86_64", release = "6.8.0-47-generic", sysname = "Linux", version = "#47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct 2 16:16:55 UTC 2" } ~

Parser/Features H L F I J

Output of nvim --version

NVIM v0.11.0-dev Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Run "nvim -V1 -v" for more info

Additional context

There are other words can trigger this but i forget to record. All happens when deal with cpp and hpp files.

clason commented 3 weeks ago

Please report this at the tree-sitter-cpp repo (and include a backtrace). Crashes cannot be handled in this plugin.