-
-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting Errors : Invalid 'col': out of range #1224
Comments
Hi :) |
(also, what version of luasnip are you on? These line-numbers don't match current master at least) |
Appreciate the quick response! :) I had this in my lazy - is it not latest? HEAD detached at v2.3.0
nothing to commit, working tree clean
It is hard to give a MWE because it happens randomly - it happens when deleting I believe This is my WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet gobin: Detected deletion of snippet `gobin`, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Leaving snippet-root due to invalid extmarks.
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN | main: Removing snippet : Error while setting adjacent snippet as current node: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:136: Invalid 'col': out of range
WARN | main: Removing snippet : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:33: attempt to perform arithmetic on a nil value |
Just changed it to |
Ah, okay 👍 |
Yeah I shared the ls.setup but there is also ls.config.setup where I have it. Need to understand what the difference is between those two setups. This is my entire setup - I checked and ls.setup() is only called here - but I'll check again My entire config (sorry haha) local function setup_luasnip_new()
local types = require('luasnip.util.types')
local ls = require('luasnip')
ls.setup({
keep_roots = true,
link_roots = true,
link_children = true,
update_events = 'TextChanged,TextChangedI',
delete_check_events = 'TextChanged,InsertLeave',
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { 'choiceNode', 'Comment' } },
},
},
},
ext_base_prio = 300,
ext_prio_increase = 1,
enable_autosnippets = false,
store_selection_keys = '<Tab>',
})
end
local function config_setup()
require('luasnip').config.setup({
region_check_events = 'InsertEnter,CursorMoved', -- "CursorMoved", "CursorHold", "InsertEnter"
delete_check_events = 'TextChanged,CursorMoved',
-- extend ft snippets to load
load_ft_func = require('luasnip.extras.filetype_functions').extend_load_ft({
c = { 'cpp' },
markdown = { 'lua', 'json', 'html' },
html = { 'css', 'javascript' },
typescript = { 'javascript' },
all = { '_' },
}),
on_snippet_expanded = function() vim.api.nvim_exec_autocmds('User', { pattern = 'LuasnipSnippetExpanded' }) end,
})
end
local function extend_snip_filetypes()
local filetype_extensions = {
typescript = { 'tsdoc' },
javascript = { 'jsdoc' },
lua = { 'luadoc' },
python = { 'pydoc' },
rust = { 'rustdoc' },
cs = { 'csharpdoc' },
java = { 'javadoc' },
c = { 'cdoc' },
cpp = { 'cppdoc' },
php = { 'phpdoc' },
kotlin = { 'kdoc' },
ruby = { 'rdoc' },
sh = { 'shelldoc' },
}
local function choice_node_callback()
if require('luasnip').choice_active() then
require('luasnip.extras.select_choice')()
return nil
else
return '<C-n>'
end
end
local function create_choice_autocmds()
vim.api.nvim_create_autocmd('User', {
pattern = 'LuasnipChoiceNodeEnter',
callback = function()
set_choice_keymaps()
choice_node_callback()
end,
})
vim.api.nvim_create_autocmd('User', {
pattern = 'LuasnipChoiceNodeLeave',
callback = function() unset_choice_keymaps() end,
})
end
local function setup_keymaps()
local luasnip = require('luasnip')
local next_snip =
{ desc = 'Luasnip Prev Snip', callback = function() luasnip.jump(-1) end, noremap = true, silent = true }
local prev_snip =
{ desc = 'Luasnip Prev Snip', callback = function() luasnip.jump(-1) end, noremap = true, silent = true }
vim.api.nvim_set_keymap('i', '<C-k>', '', next_snip)
vim.api.nvim_set_keymap('s', '<C-k>', '', next_snip)
vim.api.nvim_set_keymap('i', '<C-j>', '', prev_snip)
vim.api.nvim_set_keymap('s', '<C-j>', '', prev_snip)
end
-- Extend snippets for each filetype
for filetype, extensions in pairs(filetype_extensions) do
require('luasnip').filetype_extend(filetype, extensions)
end
end
local function load_snippets()
local dir = KSNIPS
if not dir then return end
local files = require('utils.fs.dir').scan_directory(KSNIPS)
for _, filename in ipairs(files) do
load_if_valid(filename)
end
load_default_snippets()
end
local function set_snips_filetype_json()
vim.cmd([[
augroup CodeSnippetsJSON
autocmd!
autocmd BufNewFile,BufRead *.code-snippets set filetype=json
augroup END
]])
end
local function setup_luasnip()
setup_luasnip_new()
config_setup()
extend_snip_filetypes()
setup_keymaps()
create_choice_autocmds()
load_snippets()
set_snips_filetype_json()
end
|
Ah, |
Ah I see yeah I cleaned up my config to just ls.setup - I've been trying but it seems to be happening randomly pretty much I can't tell much from the logs too - but the errors are fairly frequent
|
I tried a bunch of stuff this is as much info as I could get as an update - I found the main issue is in this function in
function Mark:pos_begin_end_raw()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = true })
return { mark_info[1], mark_info[2] }, {
mark_info[3].end_row,
mark_info[3].end_col,
}
end It frequently returns mark_info with nil values that causes a lot of failures - elsewhere as it is called from a bunch of places For e.g -- change all opts except rgravs.
function Mark:update_opts(opts)
local opts_cp = vim.deepcopy(opts)
opts_cp.right_gravity = self.opts.right_gravity
opts_cp.end_right_gravity = self.opts.end_right_gravity
-- gets called by Node:set_ext_opts(name) causing the crash
self:set_opts(opts_cp)
end
function Mark:set_opts(opts)
local pos_begin, pos_end = self:pos_begin_end_raw()
vim.api.nvim_buf_del_extmark(0, session.ns_id, self.id)
self.opts = opts
-- set new extmark, current behaviour for updating seems inconsistent,
-- eg. gravs are reset, deco is kept.
self.id = vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
vim.tbl_extend(
"force",
opts,
{ end_line = pos_end[1], end_col = pos_end[2] }
)
)
end
I used debuginfo to get some trace info LUASNIP ERROR in Mark:pos_begin_end_raw:
Caller Info 1x: {
currentline = 332,
func = <function 1>,
lastlinedefined = 338,
linedefined = 281,
short_src = "....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua",
what = "Lua"
} Caller Info 2x: {
currentline = 403,
func = <function 1>,
lastlinedefined = 404,
linedefined = 397,
short_src = "....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua",
what = "Lua"
} Caller Info 3x: {
currentline = 307,
func = <function 1>,
lastlinedefined = 309,
linedefined = 301,
short_src = "...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/node.lua",
what = "Lua"
} Status: true
Error/mark_info: {}
self.id: 169
session.ns_id: 2
Current buffer: 9
Current line: 151
Filetype: lua
LUASNIP DEBUG Mark:set_opts:
Caller Info 1x: {
currentline = 403,
func = <function 1>,
lastlinedefined = 404,
linedefined = 397,
short_src = "....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua",
what = "Lua"
} Caller Info 2x: {
currentline = 307,
func = <function 1>,
lastlinedefined = 309,
linedefined = 301,
short_src = "...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/node.lua",
what = "Lua"
} Passed Opts: {
end_right_gravity = false,
right_gravity = true
} Status: false
Result: "....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:300: Invalid 'end_col': out of range"
self.id: 169
session.ns_id: 2
pos_begin,pos_end raw: nil
opts: {
end_right_gravity = false,
right_gravity = true
}
self.opts: {
end_right_gravity = false,
right_gravity = true
}====================================
LUASNIP ERROR in Mark:pos_begin_end_raw:
Caller Info 1x: {
currentline = 332,
....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/util.lua:211: Keyboard interrupt
LUASNIP ERROR in Mark:pos_begin_end_raw:
Caller Info 1x: {
currentline = 388,
func = <function 1>,
lastlinedefined = 394,
linedefined = 386,
short_src = "....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua",
what = "Lua"
} Caller Info 2x: {
currentline = 739,
func = <function 1>,
lastlinedefined = 765,
linedefined = 727,
short_src = "...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/util.lua",
what = "Lua"
} Caller Info 3x: {
currentline = 1251,
func = <function 1>,
lastlinedefined = 1259,
linedefined = 1250,
short_src = "...al/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/snippet.lua",
what = "Lua"
} Status: true
Error/mark_info: {}
self.id: 169
session.ns_id: 2
Current buffer: 9
Current line: 151
Filetype: lua Here is the modified code which just adds a bunch of logging to trace the issue local session = require('luasnip.session')
local Mark = {}
function Mark:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
-- opts just like in nvim_buf_set_extmark.
local function mark(pos_begin, pos_end, opts)
return Mark:new({
id = vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
-- override end_* in opts.
vim.tbl_extend('force', opts, { end_row = pos_end[1], end_col = pos_end[2] })
),
-- store opts here, can't be queried using nvim_buf_get_extmark_by_id.
opts = opts,
})
end
local function bytecol_to_utfcol(pos)
local status, result = pcall(function()
local lines = vim.api.nvim_buf_get_lines(0, pos[1], pos[1] + 1, false)
if not lines or #lines == 0 then error('No line content found') end
local line = lines[1]
local utf16_indx, _ = vim.str_utfindex(line, pos[2])
return { pos[1], utf16_indx }
end)
if status then return result end
local error_info = {
error_message = tostring(result),
position = string.format('Line: %d, Col: %d', pos[1], pos[2]),
line_content = vim.inspect(vim.api.nvim_buf_get_lines(0, pos[1], pos[1] + 1, false)),
buffer_name = vim.api.nvim_buf_get_name(0),
filetype = vim.bo.filetype,
}
-- Create a formatted error message
local error_msg = string.format(
'Error in bytecol_to_utfcol:\n'
.. ' Message: %s\n'
.. ' Position: %s\n'
.. ' Line content: %s\n'
.. ' Buffer: %s\n'
.. ' Filetype: %s',
error_info.error_message,
error_info.position,
error_info.line_content,
error_info.buffer_name,
error_info.filetype
)
print('LUASNIP ERROR: ' .. error_msg)
return pos
end
local function bytecol_to_utfcol_old(pos)
local line = vim.api.nvim_buf_get_lines(0, pos[1], pos[1] + 1, false)
-- line[1]: get_lines returns table.
-- use utf16-index.
local utf16_indx, _ = vim.str_utfindex(line[1] or '', pos[2])
return { pos[1], utf16_indx }
end
function Mark:pos_begin_end()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = true })
return bytecol_to_utfcol({ mark_info[1], mark_info[2] }),
bytecol_to_utfcol({ mark_info[3].end_row, mark_info[3].end_col })
end
function Mark:pos_begin()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = false })
return bytecol_to_utfcol({ mark_info[1], mark_info[2] })
end
function Mark:pos_end()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = true })
return bytecol_to_utfcol({ mark_info[3].end_row, mark_info[3].end_col })
end
function Mark:pos_begin_end_raw()
local status, mark_info = pcall(vim.api.nvim_buf_get_extmark_by_id, 0, session.ns_id, self.id, { details = true })
if not status or not mark_info or #mark_info < 3 then
local info = debug.getinfo(2, 'Slf')
local info_r = debug.getinfo(3, 'Slf')
local info_d = debug.getinfo(4, 'Slf')
local error_msg = string.format(
'LUASNIP ERROR in Mark:pos_begin_end_raw:\n'
.. ' Caller Info 1x: %s'
.. ' Caller Info 2x: %s'
.. ' Caller Info 3x: %s'
.. ' Status: %s\n'
.. ' Error/mark_info: %s\n'
.. ' self.id: %s\n'
.. ' session.ns_id: %s\n'
.. ' Current buffer: %s\n'
.. ' Current line: %s\n'
.. ' Filetype: %s',
vim.inspect(info),
vim.inspect(info_r),
vim.inspect(info_d),
tostring(status),
vim.inspect(mark_info),
vim.inspect(self.id),
vim.inspect(session.ns_id),
vim.api.nvim_get_current_buf(),
vim.api.nvim_win_get_cursor(0)[1],
vim.bo.filetype
)
print(error_msg)
return nil, nil
end
if mark_info then return { mark_info[1], mark_info[2] }, {
mark_info[3].end_row,
mark_info[3].end_col,
} end
end
function Mark:pos_begin_end_raw_old()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = true })
return { mark_info[1], mark_info[2] }, {
mark_info[3].end_row,
mark_info[3].end_col,
}
end
function Mark:pos_begin_raw()
local mark_info = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, self.id, { details = false })
return { mark_info[1], mark_info[2] }
end
function Mark:copy_pos_gravs_old(opts)
local pos_beg, pos_end = self:pos_begin_end_raw()
opts.right_gravity = self.opts.right_gravity
opts.end_right_gravity = self.opts.end_right_gravity
return mark(pos_beg, pos_end, opts)
end
function Mark:copy_pos_gravs(opts)
local status, result = pcall(function()
local pos_beg, pos_end = self:pos_begin_end_raw()
if not pos_beg or not pos_end then error('pos_begin_end_raw returned nil values') end
opts.right_gravity = self.opts.right_gravity
opts.end_right_gravity = self.opts.end_right_gravity
return mark(pos_beg, pos_end, opts)
end)
if not status then
local error_msg = string.format(
'LUASNIP ERROR in Mark:copy_pos_gravs:\n'
.. ' Error: %s\n'
.. ' self.id: %s\n'
.. ' session.ns_id: %s\n'
.. ' Current buffer: %s\n'
.. ' Current line: %s\n'
.. ' Filetype: %s\n'
.. ' self.opts: %s\n'
.. ' Input opts: %s\n'
.. ' Extmarks in namespace: %s',
tostring(result),
vim.inspect(self.id),
vim.inspect(session.ns_id),
vim.api.nvim_get_current_buf(),
vim.api.nvim_win_get_cursor(0)[1],
vim.bo.filetype,
vim.inspect(self.opts),
vim.inspect(opts),
vim.inspect(vim.api.nvim_buf_get_extmarks(0, session.ns_id, 0, -1, { details = true }))
)
print(error_msg)
return nil
end
return result
end
-- opts just like in nvim_buf_set_extmark.
-- opts as first arg bcs. pos are pretty likely to stay the same.
function Mark:update_old(opts, pos_begin, pos_end)
-- if one is changed, the other is likely as well.
if not pos_begin then
pos_begin = old_pos_begin
if not pos_end then pos_end = old_pos_end end
end
-- override with new.
self.opts = vim.tbl_extend('force', self.opts, opts)
vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
vim.tbl_extend('force', self.opts, { id = self.id, end_row = pos_end[1], end_col = pos_end[2] })
)
end
-- opts just like in nvim_buf_set_extmark.
-- opts as first arg bcs. pos are pretty likely to stay the same.
function Mark:update(opts, pos_begin, pos_end)
local status, result = pcall(function()
-- if one is changed, the other is likely as well.
if not pos_begin or not pos_end then
local current_begin, current_end = self:pos_begin_end_raw()
pos_begin, pos_end = pos_begin or current_begin, pos_end or current_end
end
self.opts = vim.tbl_extend('force', self.opts, opts)
return vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
vim.tbl_extend('force', self.opts, { id = self.id, end_row = pos_end[1], end_col = pos_end[2] })
)
end)
if not status then
local error_msg = string.format(
'LUASNIP ERROR in Mark:update:\n'
.. ' Error: %s\n'
.. ' self.id: %s\n'
.. ' session.ns_id: %s\n'
.. ' Current buffer: %s\n'
.. ' Current line: %s\n'
.. ' Filetype: %s\n'
.. ' self.opts: %s\n'
.. ' Input opts: %s\n'
.. ' pos_begin: %s\n'
.. ' pos_end: %s\n'
.. ' Extmarks in namespace: %s',
tostring(result),
vim.inspect(self.id),
vim.inspect(session.ns_id),
vim.api.nvim_get_current_buf(),
vim.api.nvim_win_get_cursor(0)[1],
vim.bo.filetype,
vim.inspect(self.opts),
vim.inspect(opts),
vim.inspect(pos_begin),
vim.inspect(pos_end),
vim.inspect(vim.api.nvim_buf_get_extmarks(0, session.ns_id, 0, -1, { details = true }))
)
print(error_msg)
return nil
end
return result
end
function Mark:set_opts(opts)
local status, result = pcall(function()
local pos_begin, pos_end = self:pos_begin_end_raw()
vim.api.nvim_buf_del_extmark(0, session.ns_id, self.id)
self.opts = opts
--- return early here
if not pos_begin or not pos_end then
-- print('ERROR:Mark:set_opts returned NIL pos_begin, pos_end')
-- if init_present then print('Initially pos_begin, pos_end is not nil') end
return
end
-- Frequently, here pos_begin[1] and pos_begin[2] is invalid - causing a crash
self.id = vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
vim.tbl_extend('force', opts, { end_row = pos_end[1], end_col = pos_end[2] })
)
end)
if not status then
local info = debug.getinfo(2, 'Slf')
local info_r = debug.getinfo(3, 'Slf')
local log_msg = string.format(
'LUASNIP DEBUG Mark:set_opts:\n'
.. ' Caller Info 1x: %s'
.. ' Caller Info 2x: %s'
.. ' Passed Opts: %s'
.. ' Status: %s\n'
.. ' Result: %s\n'
.. ' self.id: %s\n'
.. ' session.ns_id: %s\n'
.. ' pos_begin,pos_end raw: %s\n'
.. ' opts: %s\n'
.. ' self.opts: %s'
.. '====================================',
vim.inspect(info),
vim.inspect(info_r),
vim.inspect(opts),
tostring(status),
vim.inspect(result),
tostring(self.id),
tostring(session.ns_id),
vim.inspect(self:pos_begin_end_raw()),
vim.inspect(opts),
vim.inspect(self.opts)
)
print(log_msg)
end
end
function Mark:set_opts_old(opts)
local pos_begin, pos_end = self:pos_begin_end_raw()
vim.api.nvim_buf_del_extmark(0, session.ns_id, self.id)
self.opts = opts
-- set new extmark, current behaviour for updating seems inconsistent,
-- eg. gravs are reset, deco is kept.
-- over here frequently pos_begin[1] and pos_begin[2] is invalid - causing a crash
self.id = vim.api.nvim_buf_set_extmark(
0,
session.ns_id,
pos_begin[1],
pos_begin[2],
vim.tbl_extend('force', opts, { end_row = pos_end[1], end_col = pos_end[2] })
)
end
function Mark:set_rgravs(rgrav_left, rgrav_right)
-- don't update if nothing would change.
if self.opts.right_gravity ~= rgrav_left or self.opts.end_right_gravity ~= rgrav_right then
self.opts.right_gravity = rgrav_left
self.opts.end_right_gravity = rgrav_right
self:set_opts(self.opts)
end
end
function Mark:get_rgrav(which)
if which == -1 then
return self.opts.right_gravity
else
return self.opts.end_right_gravity
end
end
function Mark:set_rgrav(which, rgrav)
if which == -1 then
if self.opts.right_gravity == rgrav then return end
self.opts.right_gravity = rgrav
else
if self.opts.end_right_gravity == rgrav then return end
self.opts.end_right_gravity = rgrav
end
self:set_opts(self.opts)
end
function Mark:get_endpoint(which)
-- simpler for now, look into perf here later.
local l, r = self:pos_begin_end_raw()
if which == -1 then
return l
else
return r
end
end
-- change all opts except rgravs.
function Mark:update_opts(opts)
local opts_cp = vim.deepcopy(opts)
opts_cp.right_gravity = self.opts.right_gravity
opts_cp.end_right_gravity = self.opts.end_right_gravity
-- gets called by Node:set_ext_opts(name) causing the crash
self:set_opts(opts_cp)
end
function Mark:clear() vim.api.nvim_buf_del_extmark(0, session.ns_id, self.id) end
return {
mark = mark,
} Also miscellaneous but the arg for Let me know if you need anything else! |
Hello sir - that was a lot of info so maybe you could look here - I'm wondering why there aren't null checks/ return early here in local function focus_node(self, lrgrav, rrgrav)
-- find nodes on path from self to root.
local nodes_path = node_util.root_path(self)
-- direction is the direction away from this node, towards the outside of
-- the tree-representation of the snippet.
-- This is dubbed "direction" because it is the direction we will search in
-- to find nodes on one endpoint of self.
for _, direction in ipairs({ -1, 1 }) do
local self_direction_endpoint = self.mark:get_endpoint(direction)
local direction_rgrav = util.ternary(direction == -1, lrgrav, rrgrav)
local effective_direction_rgrav = direction_rgrav
-- adjust left rgrav of all nodes on path upwards to root/snippet:
-- (i st. self and the snippet are both handled)
for i = 1, #nodes_path do
local node = nodes_path[i]
local node_direction_endpoint = node.mark:get_endpoint(direction)
if
not util.pos_equal(
node_direction_endpoint,
self_direction_endpoint
)
then
-- stop adjusting rgravs once self no longer is on the boundary of
-- its parents, or if the rgrav is already set correctly.
break
end
node.mark:set_rgrav(direction, effective_direction_rgrav)
-- Once self's snippet is reached on the root-path, we will only
-- adjust nodes self should be completely contained inside.
-- Since the rgravs, however, may be set up otherwise (for example
-- when focusing on an $0 that is the last node of the snippet), we
-- have to adjust them now.
if node.snippet == node then
effective_direction_rgrav = direction == 1
end
-- can't use node.parent, since that might skip nodes (in the case of
-- dynamicNode, for example, the generated snippets parent is not the
-- dynamicNode, but its parent).
-- also: don't need to check for nil, because the
local node_above = nodes_path[i + 1]
if node_above then
node_above:set_sibling_rgravs(
node,
self_direction_endpoint,
direction,
effective_direction_rgrav
)
end
end
self:subtree_set_pos_rgrav(
self_direction_endpoint,
-direction,
direction_rgrav
)
end
end For example - when |
IIRC this can happen when the text the extmark is on is deleted, which happens often. So the error in itself is not a problem, we just have to catch it somewhere and perform appropriate actions (usually remove the faulty snippet)
There are checks, they are just outside of this code! In your case exit_out_of_region does these checks by running If you want to do some further debugging, you could check which nodes' extmarks cause the crash, and then somehow check out whether |
I also frequently get the following error:
With me having a very rudimentary config: local luasnip = require("luasnip")
local loader = require("luasnip.loaders.from_lua")
local snippet_folder = vim.fn.stdpath("config") .. "/luasnip"
local function load_snippets()
loader.load({ paths = snippet_folder })
end
load_snippets()
vim.keymap.set({ "i" }, "<C-j>", function()
local snip = require("luasnip")
if snip.expand_or_jumpable(1) then
snip.expand_or_jump()
end
end)
vim.keymap.set({ "i" }, "<C-k>", function()
local snip = require("luasnip")
if snip.jumpable(-1) then
snip.jump(-1)
end
end)
vim.keymap.set({ "i" }, "<C-l>", function()
local snip = require("luasnip")
if snip.choice_active() then
snip.change_choice(1)
end
end)
vim.keymap.set({ "n" }, "\\s", load_snippets)
luasnip.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI",
enable_autosnippets = true
} Not sure if the issue is related but any help would be appreciated |
Seems to be a similar issue, indeed.. it also fails because an extmark we "validated" is suddenly invalid. PS: use |
Hey, would love to keep providing info on the issue, any tips on easiest ways to disable all plugins besides commenting out everything in my packer config file? |
No good idea, sorry :/ |
Similar issue as #239
These errors have been happning frequently for me - any recommendation for settings to update?
Does it happen because
Config
The text was updated successfully, but these errors were encountered: