Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions plugins/nobbz/lua/nobbz/blink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ blink.setup({
["<C-Space>"] = { "show", "show_documentation", "hide_documentation", },
["<C-e>"] = { "hide", "fallback", },
["<CR>"] = { "accept", "fallback", },
["<Tab>"] = { "select_next", "fallback", },
["<S-Tab>"] = { "select_prev", "fallback", },
["<Up>"] = { "snippet_forward", "fallback", },
["<Down>"] = { "snippet_backward", "fallback", },
["<C-p>"] = { "select_prev", "fallback", },
["<C-n>"] = { "select_next", "fallback", },
["<C-b>"] = { "scroll_documentation_up", "fallback", },
["<C-f>"] = { "scroll_documentation_down", "fallback", },
["<C-l>"] = { "select_next", "fallback", },
["<C-Down>"] = { "select_next", "fallback", },
["<C-h>"] = { "select_prev", "fallback", },
["<C-Up>"] = { "select_prev", "fallback", },
["<Tab>"] = { "snippet_forward", "fallback", },
["<S-Tab>"] = { "snippet_backward", "fallback", },
["<C-k>"] = { "scroll_documentation_up", "fallback", },
["<C-j>"] = { "scroll_documentation_down", "fallback", },
},
})
46 changes: 22 additions & 24 deletions plugins/nobbz/lua/nobbz/luasnip.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
local luasnip = require("luasnip")
local lualoader = require("luasnip.loaders.from_lua")

---returns a function that steps a choice if available by `step`
---@param step integer
---@return function
local function choice(step)
return function()
if luasnip.choice_active() then luasnip.change_choice(step) end
end
luasnip.config.setup({
enable_autosnippets = true,
})

WK.add({
{ "<C-k>", luasnip.expand, desc = "expand snippet", },
})

local function script_path(suffix)
local path = debug.getinfo(2, "S").source:sub(2):match("(.*/)")
if suffix then return path .. suffix end
return path
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

script_path() uses the wrong stack-level and breaks when invoked indirectly

debug.getinfo(2, 'S') resolves to the caller of script_path, which is fine for the one internal call in this file, but it fails if the helper is reused from another module (it will then resolve the foreign caller’s path).
Using level 1 (the current function) is safer and matches the usual pattern.

-local function script_path(suffix)
-  local path = debug.getinfo(2, "S").source:sub(2):match("(.*/)")
+local function script_path(suffix)
+  local path = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
local function script_path(suffix)
local path = debug.getinfo(2, "S").source:sub(2):match("(.*/)")
if suffix then return path .. suffix end
return path
local function script_path(suffix)
local path = debug.getinfo(1, "S").source:sub(2):match("(.*/)")
if suffix then return path .. suffix end
return path
🤖 Prompt for AI Agents
In plugins/nobbz/lua/nobbz/luasnip.lua around lines 12 to 15, the script_path
function uses debug.getinfo with stack level 2, which points to the caller of
script_path and causes incorrect path resolution when called indirectly. Change
the stack level argument from 2 to 1 in debug.getinfo to refer to the current
function itself, ensuring the path is always correctly resolved regardless of
the caller.

end

---returns a function that steps through template gaps by `step_size`
---@param step_size integer
---@return function
local function stepper(step_size)
return function()
if luasnip.jumpable(step_size) then
luasnip.jump(step_size)
else
return step_size > 0 and "<Tab>" or "<S-Tab>"
end
local function list_snips()
local ft_list = luasnip.available()[vim.o.filetype]
local ft_snips = {}
for _, item in pairs(ft_list) do
ft_snips[item.trigger] = item.desc
end
vim.print(ft_snips)
Comment on lines +18 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

list_snips() crashes when no snippets exist for the current filetype

luasnip.available()[vim.o.filetype] can be nil; calling pairs() on nil raises an error.

-  local ft_list = luasnip.available()[vim.o.filetype]
+  local ft_list = luasnip.available()[vim.o.filetype] or {}

Add a short guard to keep the command safe in empty buffers.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
local function list_snips()
local ft_list = luasnip.available()[vim.o.filetype]
local ft_snips = {}
for _, item in pairs(ft_list) do
ft_snips[item.trigger] = item.desc
end
vim.print(ft_snips)
local function list_snips()
local ft_list = luasnip.available()[vim.o.filetype] or {}
local ft_snips = {}
for _, item in pairs(ft_list) do
ft_snips[item.trigger] = item.desc
end
vim.print(ft_snips)
🤖 Prompt for AI Agents
In plugins/nobbz/lua/nobbz/luasnip.lua around lines 18 to 24, the function
list_snips() crashes because it calls pairs() on nil when no snippets exist for
the current filetype. To fix this, add a guard clause that checks if ft_list is
nil before the for loop, and if so, return early or set ft_list to an empty
table to prevent the error.

end

WK.add({
{ "<Tab>", stepper(1), desc = "next snippet gap", mode = { "s", "i", }, expr = true, },
{ "<S-Tab>", stepper(-1), desc = "previous snippet gap", mode = { "s", "i", }, expr = true, },
{ "<C-a>", choice(1), desc = "next choice", mode = { "s", "i", }, },
{ "<C-s>", choice(-1), desc = "previous choice", mode = { "s", "i", }, },
{ "<C-e>", luasnip.expand, desc = "expand snippet", mode = "s", },
})
vim.api.nvim_create_user_command("SnipList", list_snips, {})

lualoader.load({ paths = script_path("luasnip"), })
6 changes: 6 additions & 0 deletions plugins/nobbz/lua/nobbz/luasnip/gitcommit.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vim.print("luasnip loading")

return {
s({ trig = "sc", desc = "short-cut ticket", },
{ t("[SC-"), i(1), t("]"), i(2), }),
}
Comment on lines +3 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined identifiers s, t, i – snippet file will error at load time

luasnip does not expose these globals by default.
Declare them locally:

-return {
-  s({ trig = "sc", desc = "short-cut ticket", },
-    { t("[SC-"), i(1), t("]"), i(2), }),
-}
+local ls = require("luasnip")
+local s, t, i = ls.snippet, ls.text_node, ls.insert_node
+
+return {
+  s({ trig = "sc", desc = "short-cut ticket" }, {
+    t("[SC-"), i(1), t("] "), i(2),
+  }),
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return {
s({ trig = "sc", desc = "short-cut ticket", },
{ t("[SC-"), i(1), t("]"), i(2), }),
}
local ls = require("luasnip")
local s, t, i = ls.snippet, ls.text_node, ls.insert_node
return {
s({ trig = "sc", desc = "short-cut ticket" }, {
t("[SC-"), i(1), t("] "), i(2),
}),
}
🤖 Prompt for AI Agents
In plugins/nobbz/lua/nobbz/luasnip/gitcommit.lua around lines 3 to 6, the
identifiers s, t, and i are used without being declared, causing errors at load
time. Fix this by locally requiring or importing these functions from the
luasnip module at the top of the file before their usage, ensuring they are
properly defined and available in the snippet file.