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

Crash on empty first line when number line is on (markdown)

Open ivomac opened this issue 1 year ago • 3 comments

Description

With vim.opt.number = true, while editing a markdown file where the first line is empty, the plugin will crash when you have scrolled far down enough for the context line to trigger.

Neovim version

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1713773202 system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim"

Expected behavior

Single empty context line on top

Actual behavior

Error detected while processing CursorMoved Autocommands for "*":                                                               
Error executing lua callback: /tmp/nvim/site/ts_context/lua/treesitter-context/render.lua:106: Could not apply exmtark to { -1, 0 }: Invalid 'line': out of range
stack traceback:
        [C]: in function 'error'
        /tmp/nvim/site/ts_context/lua/treesitter-context/render.lua:106: in function 'add_extmark'
        /tmp/nvim/site/ts_context/lua/treesitter-context/render.lua:235: in function 'highlight_bottom'
        /tmp/nvim/site/ts_context/lua/treesitter-context/render.lua:303: in function 'render_lno'
        /tmp/nvim/site/ts_context/lua/treesitter-context/render.lua:353: in function 'open'
        /tmp/nvim/site/ts_context/lua/treesitter-context.lua:50: in function 'open'
        /tmp/nvim/site/ts_context/lua/treesitter-context.lua:111: in function 'f'
        /tmp/nvim/site/ts_context/lua/treesitter-context.lua:27: in function </tmp/nvim/site/ts_context/lua/treesitter-context.lua:21>

Minimal config

local plugins = {
  ts         = 'https://github.com/nvim-treesitter/nvim-treesitter',
  ts_context = 'https://github.com/nvim-treesitter/nvim-treesitter-context',
}

for name, url in pairs(plugins) do
  local install_path = '/tmp/nvim/site/'..name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.o.runtimepath = install_path..','..vim.o.runtimepath
end

vim.opt.number = true

Steps to reproduce

example.md

  1. nvim --clean -u minimal.lua example.md
  2. :TSInstall markdown
  3. G (go to bottom)

ivomac avatar May 15 '24 10:05 ivomac

I can confirm this bug, and in my cases, I am using nvim 0.10 release

the first several lines of markdown looks like this:

---
title: tech problems summary
---


milanglacier avatar May 16 '24 22:05 milanglacier

I tried to fix it so that the error does not occur.

https://github.com/nvim-treesitter/nvim-treesitter-context/pull/448

Anyone who has reproduced it, please try it if you like.

If there is a better way, please let me know!

yanskun avatar May 23 '24 03:05 yanskun

@yanskun, your fix worked for me in the several files where I had the error.

kbro237 avatar May 23 '24 13:05 kbro237