-
Notifications
You must be signed in to change notification settings - Fork 4
luasnip-again #70
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
luasnip-again #70
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||||||||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
- 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| 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"), }) | ||||||||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Undefined identifiers
-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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
There was a problem hiding this comment.
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 indirectlydebug.getinfo(2, 'S')resolves to the caller ofscript_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.📝 Committable suggestion
🤖 Prompt for AI Agents