Skip to content
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

Open
kuro337 opened this issue Aug 19, 2024 · 15 comments
Open

Getting Errors : Invalid 'col': out of range #1224

kuro337 opened this issue Aug 19, 2024 · 15 comments

Comments

@kuro337
Copy link

kuro337 commented Aug 19, 2024

Similar issue as #239

These errors have been happning frequently for me - any recommendation for settings to update?

Does it happen because

....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:136: Invalid 'col': out of range

Error detected while processing CursorMoved Autocommands for "*":
Error executing lua callback: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:136: Invalid 'end_col': out of range
stack traceback:
        [C]: in function 'nvim_buf_set_extmark'
        ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:136: in function 'set_opts'
        ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:199: in function 'update_opts'
        ...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/node.lua:178: in function 'input_leave'
        ...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/util.lua:109: in function 'leave_nodes_between'
        ...local/share/nvim/lazy/LuaSnip/lua/luasnip/nodes/util.lua:565: in function 'refocus'
        ...kuro/.local/share/nvim/lazy/LuaSnip/lua/luasnip/init.lua:675: in function 'exit_out_of_region'
        ...ro/.local/share/nvim/lazy/LuaSnip/lua/luasnip/config.lua:103: in function <...ro/.local/share/nvim/lazy/LuaSnip/lua/luasnip/config.lua:102>
 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

Config

  local types = require('luasnip.util.types')
  local ls = require('luasnip')

  ls.setup({
    keep_roots = true,
    link_roots = true,
    link_children = true,

    -- Update more often, :h events for more info.
    update_events = 'TextChanged,TextChangedI',

    -- Snippets aren't automatically removed if their text is deleted.
    -- `delete_check_events` determines on which events (:h events) a check for
    -- deleted snippets is performed.
    -- This can be especially useful when `history` is enabled.

    -- delete_check_events = 'TextChanged,InsertLeave',

    ext_opts = {
      [types.choiceNode] = {
        active = {
          virt_text = { { 'choiceNode', 'Comment' } },
        },
      },
    },
    -- Controls highlight priority - set to avoid conflicts
    -- treesitter-hl has 100, use something higher (default is 200).
    ext_base_prio = 300,
    -- minimal increase in priority.
    ext_prio_increase = 1,

    --- for now disable autosnippets (expand on their own)
    enable_autosnippets = false,

    --- @TM_SELECTED_TEXT` not set by default - key to trigger
    --- In Visual mode pressing <TAB> will store the text - then when
    --- TM_SELECTED_TEXT used - it uses that data
    store_selection_keys = '<Tab>',

    -- ft func used to get the current active filetype
    --ft_func = function()
    --  return vim.split(vim.bo.filetype, '.', true) --- @diagnostic disable-line
    --end,
  })
@L3MON4D3
Copy link
Owner

Hi :)
Those luasnip-settings seem fine, could you try to find a MWE? I haven't encountered those errors in a long time

@L3MON4D3
Copy link
Owner

(also, what version of luasnip are you on? These line-numbers don't match current master at least)

@kuro337
Copy link
Author

kuro337 commented Aug 20, 2024

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
  {
    'L3MON4D3/LuaSnip',
    event = 'InsertEnter',
    dependencies = { 'rafamadriz/friendly-snippets' },
    version = 'v2.*',
    build = 'make install_jsregexp',
    config = require('plugins.lsp.luasnip').setup_luasnip,
  },

It is hard to give a MWE because it happens randomly - it happens when deleting I believe

This is my luasnip.log

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

@kuro337
Copy link
Author

kuro337 commented Aug 20, 2024

Just changed it to 2.3 explicitly,

@L3MON4D3
Copy link
Owner

Ah, okay 👍
What does confuse me a bit is that the error originates from the region_check_events-setting, but it should not be enabled based on your config.. could you double-check that you don't have some other package manager/anything active which is also calling ls.setup?

@kuro337
Copy link
Author

kuro337 commented Aug 20, 2024

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


@L3MON4D3
Copy link
Owner

Ah, ls.config.setup is the same as ls.setup, but I'd suggest you only use ls.setup, that's more well-known :)
Alright, this explains where that call came from :D
I'll look into it soon-ish, but if you can find a reliable MWE, that would really help :)

@kuro337
Copy link
Author

kuro337 commented Aug 20, 2024

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

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
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 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
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 : Error while getting extmark-position: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:36: index out of range
WARN  | main: Removing snippet get_file_nameonly: Detected deletion of snippet `get_file_nameonly`, 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 : 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 get_path: Leaving snippet-root due to invalid extmarks.
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 lenstr: 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 vardef: Detected deletion of snippet `vardef`, removing it
WARN  | main: Removing snippet vardef: Leaving snippet-root due to invalid extmarks.
WARN  | main: Removing snippet vardef: Leaving snippet-root due to invalid extmarks.
WARN  | main: Removing snippet vardef: Detected deletion of snippet `vardef`, removing it
WARN  | main: Removing snippet vardef: Detected deletion of snippet `vardef`, removing it
WARN  | main: Removing snippet vardef: Detected deletion of snippet `vardef`, 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 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 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
WARN  | main: Removing snippet : Error while setting adjacent snippet as current node: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
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
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 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 : 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 : 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 : 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 : 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 : 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 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 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 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 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 : 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:82: attempt to index a nil value
WARN  | main: Removing snippet : Error while setting adjacent snippet as current node: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
WARN  | main: Removing snippet : Error while setting adjacent snippet as current node: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
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:82: attempt to index a nil value
WARN  | main: Removing snippet : Error while setting adjacent snippet as current node: ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
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:82: attempt to index a nil value
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 vardef: Detected deletion of snippet `vardef`, removing it
WARN  | main: Removing snippet : Removing snippet `` due to error ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:136: Invalid 'end_row': out of range
WARN  | main: Removing snippet : Removing snippet `` due to error ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
WARN  | main: Removing snippet : Removing snippet `` due to error ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
WARN  | main: Removing snippet : Removing snippet `` due to error ....local/share/nvim/lazy/LuaSnip/lua/luasnip/util/mark.lua:82: attempt to index a nil value
WARN  | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN  | main: Removing snippet : Leaving snippet-root due to invalid extmarks.
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 : 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 vardef: Detected deletion of snippet `vardef`, 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 vardef: Detected deletion of snippet `vardef`, removing it
WARN  | main: Removing snippet : Detected deletion of snippet ``, removing it
WARN  | main: Removing snippet : Detected deletion of snippet ``, removing it
W

@kuro337
Copy link
Author

kuro337 commented Aug 27, 2024

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 mark.lua -

function Mark:pos_begin_end_raw()

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

set_opts calls it a lot and accesses pos_begin[2] directly which causes crashes

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 nvim_buf_set_extmark opt seems to be end_row instead of end_line, although updating it everywhere seems to have no effect

Let me know if you need anything else!

@kuro337
Copy link
Author

kuro337 commented Aug 30, 2024

@L3MON4D3

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 node.lua

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 vim.api.nvim_buf_get_extmark_by_id fails or returns invalid - shouldn't there be checks? It seems like almost all the crashes are happening because there's no nil checks for the results of vim.api.nvim_buf_get_extmark_by_id, sorry don't mean to be annoying, would be glad to help if anything.

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Aug 31, 2024

It frequently returns mark_info with nil values that causes a lot of failures - elsewhere as it is called from a bunch of places

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)

Also miscellaneous but the arg for nvim_buf_set_extmark opt seems to be end_row instead of end_line, although updating it everywhere seems to have no effect

end_row used to be the correct key to set, I guess they changed it in a backwards compatible way? I'll keep an eye on it, if it gets deprecated we'll have to ensure that we update the key, thank's for letting me know :)

For example - when vim.api.nvim_buf_get_extmark_by_id fails or returns invalid - shouldn't there be checks?

There are checks, they are just outside of this code! In your case exit_out_of_region does these checks by running extmarks_valid on all snippets that could be accessed in refocus, and only after all were validated, it will run refocus.
This means a relatively recent call to pos_begin_end_raw succeeded, but yet, it fails shortly after during refocus, which seems very weird :/

If you want to do some further debugging, you could check which nodes' extmarks cause the crash, and then somehow check out whether extmarks_valid was called on it, or if something changed inbetween these two calls

@Philogy
Copy link

Philogy commented Sep 3, 2024

I also frequently get the following error:

E5108: Error executing lua: ...site/pack/packer/start/LuaSnip/lua/luasnip/util/mark.lua:136: Invalid 'col': out of range
stack traceback:
        [C]: in function 'nvim_buf_set_extmark'
        ...site/pack/packer/start/LuaSnip/lua/luasnip/util/mark.lua:136: in function 'set_opts'
        ...site/pack/packer/start/LuaSnip/lua/luasnip/util/mark.lua:181: in function 'set_rgrav'
        ...ite/pack/packer/start/LuaSnip/lua/luasnip/nodes/node.lua:548: in function 'focus_node'
        ...ite/pack/packer/start/LuaSnip/lua/luasnip/nodes/node.lua:590: in function 'focus'
        .../pack/packer/start/LuaSnip/lua/luasnip/nodes/snippet.lua:652: in function 'trigger_expand'
        ...nvim/site/pack/packer/start/LuaSnip/lua/luasnip/init.lua:282: in function 'snip_expand'
        ...nvim/site/pack/packer/start/LuaSnip/lua/luasnip/init.lua:351: in function 'expand'
        ...nvim/site/pack/packer/start/LuaSnip/lua/luasnip/init.lua:394: in function 'expand_or_jump'
        /Users/philogy/.config/nvim/after/plugin/luasnip.lua:14: in function </Users/philogy/.config/nvim/after/plugin/luasnip.lua:11>

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

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 3, 2024

Seems to be a similar issue, indeed.. it also fails because an extmark we "validated" is suddenly invalid.
Does it always trigger on expand for you? Does it happen if you have all/most other plugins disabled? I'd love to get to the bottom of this, but without some way to reproduce this, I can't do much :/

PS: use lazy_load instead of load if you don't explicitly need load ;)

@Philogy
Copy link

Philogy commented Sep 16, 2024

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?

@L3MON4D3
Copy link
Owner

No good idea, sorry :/
I'd mostly suspect plugins that somehow modify the buffer, maybe try disabling those first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants