nvim-treesitter icon indicating copy to clipboard operation
nvim-treesitter copied to clipboard

crash with indent on in python script

Open danpf opened this issue 2 years ago • 3 comments

Describe the bug

If I try and insert a : after deleting 2 lines, neovim crashes

To Reproduce

I can reproduce it from commandline via:

VIMRUNTIME=~/git/neovim/runtime ~/git/neovim/build/bin/nvim temp_script.py -c '/xyz123' -c 'normal $xxa:' -c 'wq'

Essentially: go to the line with xyz123, remove the last 2 characters, then type : it will crash instantly, or it will shift the line slightly back

Doesn't happen after TSDisable indent

Expected behavior

shouldn't crash

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation
- OK tree-sitter found 0.20.6 (ccd6bf554d922596ce905730d98a77af368bba5c) (parser generator, only needed for :TSInstallFromGrammar)
- OK node found v17.9.0 (only needed for :TSInstallFromGrammar)
- OK git executable found.
- OK cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "5.15.0-91-generic",
  sysname = "Linux",
  version = "#101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023"
}

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - cmake               ✓ . ✓ ✓ .
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓

  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}

Output of nvim --version

(Built from source)

NVIM v0.9.5
Build type: Debug
LuaJIT 2.1.1692716794
Compilation: /usr/bin/cc -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DNVIM_LOG_DEBUG -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/home/momma/git/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/build/src/nvim/auto -I/home/momma/git/neovim/build/include -I/home/momma/git/neovim/build/cmake.config -I/home/momma/git/neovim/src -I/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/.deps/usr/include -I/home/momma/git/neovim/.deps/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info
(aalpha-interview) ~/git/aalpha-interview

Additional context

minimal_example_file (rename to .py) minimal_crashing_script.py.txt

minimal init.lua config:

vim.g.mapleader = " "
vim.g.maplocalleader = " "

-- Plugin Manager Setup {{{
-- https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
        vim.fn.system({
                "git",
                "clone",
                "--filter=blob:none",
                "https://github.com/folke/lazy.nvim.git",
                "--branch=stable", -- latest stable release
                lazypath,
        })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
        {
                "nvim-treesitter/nvim-treesitter",
                dependencies = {
                        "nvim-treesitter/nvim-treesitter-textobjects",
                },
                build = ":TSUpdate",
                config = function()
                        require("nvim-treesitter.configs").setup({
                                -- Add languages to be installed here that you want installed for treesitter
                                ensure_installed = {
                                        "python",
                                },
                                -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
                                auto_install = false,

                                indent = { enable = true }})
                end,
        },
})

coredump

Core was generated by `/home/me/git/neovim/build/bin/nvim --embed'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  ts_query_cursor_next_capture (self=0x5555561ddbf0, match=0x7fffffffb610, capture_index=0x7fffffffb5f0) at /home/me/git/neovim/.deps/build/src/treesitter/lib/src/./query.c:4061
4061            self->states.contents[first_unfinished_state_index].capture_list_id
[Current thread is 1 (Thread 0x7ffff7c64b80 (LWP 193738))]
(gdb) bt
#0  ts_query_cursor_next_capture (self=0x5555561ddbf0, match=0x7fffffffb610, capture_index=0x7fffffffb5f0) at /home/me/git/neovim/.deps/build/src/treesitter/lib/src/./query.c:4061
#1  0x0000555555792382 in query_next_capture (L=0x7ffff76d1380) at /home/me/git/neovim/src/nvim/lua/treesitter.c:1308
#2  0x00005555559e7946 in lj_BC_FUNCC ()
#3  0x00005555559d3c2c in lua_pcall (L=0x7ffff76d1380, nargs=<optimized out>, nresults=1, errfunc=<optimized out>) at lj_api.c:1116
#4  0x000055555578679b in nlua_pcall (lstate=0x7ffff76d1380, nargs=1, nresults=1) at /home/me/git/neovim/src/nvim/lua/executor.c:159
#5  0x0000555555789ea8 in nlua_typval_exec (lcmd=0x555555b92da0 <IObuff> "local _A=select(1,...) return (require\"nvim-treesitter.indent\".get_indent(74))c%dpf_aalpha_interview%pose_align.py.swp\"", lcmd_len=78,
    name=0x555555aaab90 "luaeval()", args=0x7fffffffbb00, argcount=1, special=true, ret_tv=0x7fffffffc120) at /home/me/git/neovim/src/nvim/lua/executor.c:1445
#6  0x0000555555789b9d in nlua_typval_eval (str=..., arg=0x7fffffffbb00, ret_tv=0x7fffffffc120) at /home/me/git/neovim/src/nvim/lua/executor.c:1374
#7  0x00005555556d64da in f_luaeval (argvars=0x7fffffffbaf0, rettv=0x7fffffffc120, fptr=...) at /home/me/git/neovim/src/nvim/eval/funcs.c:4569
#8  0x00005555556caf8c in call_internal_func (fname=0x555556130620 "luaeval", argcount=1, argvars=0x7fffffffbaf0, rettv=0x7fffffffc120) at /home/me/git/neovim/src/nvim/eval/funcs.c:242
#9  0x00005555556f0fde in call_func (funcname=0x555556130600 "luaeval", len=7, rettv=0x7fffffffc120, argcount_in=1, argvars_in=0x7fffffffbaf0, funcexe=0x7fffffffbcb0)
    at /home/me/git/neovim/src/nvim/eval/userfunc.c:1622
#10 0x00005555556ee2c1 in get_func_tv (name=0x555556130600 "luaeval", len=7, rettv=0x7fffffffc120, arg=0x7fffffffc0d0, funcexe=0x7fffffffbcb0) at /home/me/git/neovim/src/nvim/eval/userfunc.c:495
#11 0x00005555556a6765 in eval_func (arg=0x7fffffffc0d0, name=0x555555f2a6b8 "luaeval(printf('require\"nvim-treesitter.indent\".get_indent(%d)', v:lnum))", name_len=7, rettv=0x7fffffffc120, evaluate=true,
    basetv=0x0) at /home/me/git/neovim/src/nvim/eval.c:2193
#12 0x00005555556a8061 in eval7 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1, want_string=0) at /home/me/git/neovim/src/nvim/eval.c:3000
#13 0x00005555556a792d in eval6 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1, want_string=0) at /home/me/git/neovim/src/nvim/eval.c:2742
#14 0x00005555556a73a9 in eval5 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2597
#15 0x00005555556a6eb4 in eval4 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2467
#16 0x00005555556a6d14 in eval3 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2399
#17 0x00005555556a6b74 in eval2 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2342
#18 0x00005555556a6986 in eval1 (arg=0x7fffffffc0d0, rettv=0x7fffffffc120, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2280
#19 0x00005555556a6858 in eval0 (arg=0x555555f2a6b8 "luaeval(printf('require\"nvim-treesitter.indent\".get_indent(%d)', v:lnum))", rettv=0x7fffffffc120, nextcmd=0x7fffffffc240, evaluate=1)
    at /home/me/git/neovim/src/nvim/eval.c:2236
#20 0x00005555556f51e5 in ex_return (eap=0x7fffffffc220) at /home/me/git/neovim/src/nvim/eval/userfunc.c:2962
#21 0x000055555571473f in execute_cmd0 (retv=0x7fffffffc1d8, eap=0x7fffffffc220, errormsg=0x7fffffffc1f0, preview=false) at /home/me/git/neovim/src/nvim/ex_docmd.c:1620
#22 0x0000555555716673 in do_one_cmd (cmdlinep=0x7fffffffc440, flags=7, cstack=0x7fffffffc550, fgetline=0x5555556f5a0c <get_func_line>, cookie=0x55555613d220) at /home/me/git/neovim/src/nvim/ex_docmd.c:2282
#23 0x000055555571211f in do_cmdline (cmdline=0x0, fgetline=0x5555556f5a0c <get_func_line>, cookie=0x55555613d220, flags=7) at /home/me/git/neovim/src/nvim/ex_docmd.c:578
#24 0x00005555556efc87 in call_user_func (fp=0x55555613ba10, argcount=0, argvars=0x7fffffffd180, rettv=0x7fffffffd750, firstline=74, lastline=74, selfdict=0x0)
    at /home/me/git/neovim/src/nvim/eval/userfunc.c:1122
#25 0x00005555556f0397 in call_user_func_check (fp=0x55555613ba10, argcount=0, argvars=0x7fffffffd180, rettv=0x7fffffffd750, funcexe=0x7fffffffd340, selfdict=0x0)
    at /home/me/git/neovim/src/nvim/eval/userfunc.c:1259
#26 0x00005555556f0f6a in call_func (funcname=0x55555613b9d0 "nvim_treesitter#indent", len=22, rettv=0x7fffffffd750, argcount_in=0, argvars_in=0x7fffffffd180, funcexe=0x7fffffffd340)
    at /home/me/git/neovim/src/nvim/eval/userfunc.c:1613
#27 0x00005555556ee2c1 in get_func_tv (name=0x55555613b9d0 "nvim_treesitter#indent", len=22, rettv=0x7fffffffd750, arg=0x7fffffffd740, funcexe=0x7fffffffd340)
    at /home/me/git/neovim/src/nvim/eval/userfunc.c:495
#28 0x00005555556a6765 in eval_func (arg=0x7fffffffd740, name=0x555556120380 "nvim_treesitter#indent()", name_len=22, rettv=0x7fffffffd750, evaluate=true, basetv=0x0)
    at /home/me/git/neovim/src/nvim/eval.c:2193
#29 0x00005555556a8061 in eval7 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1, want_string=0) at /home/me/git/neovim/src/nvim/eval.c:3000
#30 0x00005555556a792d in eval6 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1, want_string=0) at /home/me/git/neovim/src/nvim/eval.c:2742
#31 0x00005555556a73a9 in eval5 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2597
#32 0x00005555556a6eb4 in eval4 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2467
#33 0x00005555556a6d14 in eval3 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2399
#34 0x00005555556a6b74 in eval2 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2342
#35 0x00005555556a6986 in eval1 (arg=0x7fffffffd740, rettv=0x7fffffffd750, evaluate=1) at /home/me/git/neovim/src/nvim/eval.c:2280
#36 0x00005555556a3245 in eval_to_number (expr=0x555556120380 "nvim_treesitter#indent()") at /home/me/git/neovim/src/nvim/eval.c:932
#37 0x000055555576a6f1 in get_expr_indent () at /home/me/git/neovim/src/nvim/indent.c:1141
#38 0x000055555576b0ba in fixthisline (get_the_indent=0x55555576a62b <get_expr_indent>) at /home/me/git/neovim/src/nvim/indent.c:1395
#39 0x000055555577277e in do_c_expr_indent () at /home/me/git/neovim/src/nvim/indent_c.c:3699
#40 0x000055555569a085 in insert_do_cindent (s=0x7fffffffd920) at /home/me/git/neovim/src/nvim/edit.c:1212
#41 0x0000555555698690 in insert_check (state=0x7fffffffd920) at /home/me/git/neovim/src/nvim/edit.c:379
--Type <RET> for more, q to quit, c to continue without paging--bt
#42 0x00005555558cb582 in state_enter (s=0x7fffffffd920) at /home/me/git/neovim/src/nvim/state.c:40
#43 0x0000555555698581 in insert_enter (s=0x7fffffffd920) at /home/me/git/neovim/src/nvim/edit.c:336
#44 0x000055555569a1e7 in edit (cmdchar=65, startln=false, count=1) at /home/me/git/neovim/src/nvim/edit.c:1275
#45 0x00005555557f9fe3 in invoke_edit (cap=0x7fffffffdb10, repl=0, cmd=65, startln=0) at /home/me/git/neovim/src/nvim/normal.c:6288
#46 0x00005555557f9f75 in nv_edit (cap=0x7fffffffdb10) at /home/me/git/neovim/src/nvim/normal.c:6265
#47 0x00005555557eeb70 in normal_execute (state=0x7fffffffda90, key=65) at /home/me/git/neovim/src/nvim/normal.c:1210
#48 0x00005555558cb706 in state_enter (s=0x7fffffffda90) at /home/me/git/neovim/src/nvim/state.c:99
#49 0x00005555557ecd0f in normal_enter (cmdwin=false, noexmode=false) at /home/me/git/neovim/src/nvim/normal.c:500
#50 0x00005555555e29aa in main (argc=2, argv=0x7fffffffdeb8) at /home/me/git/neovim/src/nvim/main.c:642
(gdb)
(gdb) bt

danpf avatar Jan 18 '24 00:01 danpf

Thanks for the detailed reproduction step (a nitpicking is that lazy.nvim should not be used for the minimal repro: https://github.com/neovim/neovim/wiki/Minimal-reproduction-template).

I can reproduce this with neovim HEAD 0.10-nightly as well. It looks like this is an upstream treesitter issue (or neovim core maybe). Ideally a simpler reproduction should be possible without nvim-treesitter & lazy, only using the problematic (relevant) query. Will have another closer look.

wookayin avatar Jan 18 '24 18:01 wookayin

I have recently updated tree-sitter; if you can bisect Neovim, that would be helpful.

clason avatar Jan 18 '24 18:01 clason

lazy.nvim should not be used for the minimal repro: https://github.com/neovim/neovim/wiki/Minimal-reproduction-template).

That link does not work. it redirects to https://github.com/neovim/neovim/wiki/ and says: ` You do not have permission to update this wiki.

I have recently updated tree-sitter; if you can bisect Neovim, that would be helpful.

updating nvim-treesitter to 5037721 does not solve the problem.

FWIW, looking at this again, I'm convinced that the problem is related to the list[tuple[str, int] type annotation missing a closing bracket on the 8th line. but i even wrote a script to iteratively remove lines and I could not get it any smaller so maybe there is more than 1 thing at play here.

danpf avatar Jan 18 '24 20:01 danpf