-
-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Introduction
Hi!
A bug report along with a proposed fix. I'm happy to discuss alternative approaches or make any adjustments based on your feedback. Please let me know if you need any additional information or clarification.
Then after reading the code I also found that it was documented with a FIXME comment.
It would be nice contributing to the codebase. Looking forward for feedback! 🙂
Description
When expanding the sql quasiquote snippet, neovim throws an error:
Error while evaluating dynamicNode@3 for snippet 'sql':
...lazy/haskell-snippets.nvim/lua/haskell-snippets/util.lua:50: bad argument #2 to 'rep' (number expected, got nil)
Root Cause
In lua/haskell-snippets/util.lua, the _indent_newline function uses pcall to safely call parent:get_buf_position(), but doesn't properly handle the failure case:
local _, pos = pcall(function()
return parent:get_buf_position()
end)
local indent_count = pos[2] -- crashes if pos is nilWhen pcall fails or returns nil, accessing pos[2] yields nil, and string.rep(' ', nil) throws the error.
Affected Snippets
Any snippet using util.indent_newline_text() or util.indent_newline_insert()
Proposed Fix
Check pcall success and pos validity before accessing pos[2], defaulting to 0 indent:
local ok, pos = pcall(function()
return parent:get_buf_position()
end)
local indent_count = (ok and pos and pos[2]) or 0Environment
- Neovim: v0.11.2
- LuaSnip: v2.4.1
- OS: Linux 6.12.47-1.qubes.fc37.x86_64