Skip to content

Commit 9a0e49d

Browse files
committed
feat(lua): add autosnippet "#i"
1 parent bc2191d commit 9a0e49d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lua/luasnip-snippets/snippets/lua/default.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local i = require("luasnip-snippets.nodes").insert_node
44
local ls = require("luasnip")
55
local f = ls.function_node
66
local tsp = require("luasnip.extras.treesitter_postfix")
7+
local rep = require("luasnip.extras").rep
78

89
local function last_lua_module_section(args)
910
local text = args[1][1] or ""
@@ -62,6 +63,37 @@ return {
6263
}),
6364
},
6465

66+
snippet {
67+
'#i',
68+
name = "require(...)",
69+
dscr = "Expands to require statement with type annotation",
70+
mode = "bwA",
71+
nodes = fmt(
72+
[[
73+
---@type {}
74+
local {} = require("{}")
75+
]],
76+
{
77+
rep(1),
78+
f(function(args)
79+
local module_name = args[1][1]
80+
local parts = vim.split(module_name, ".", {
81+
plain = true,
82+
trimempty = true,
83+
})
84+
module_name = parts[#parts]
85+
parts = vim.split(module_name, "/", {
86+
plain = true,
87+
trimempty = true,
88+
})
89+
module_name = parts[#parts]
90+
return module_name:gsub("^%l", string.upper)
91+
end, { 1 }),
92+
i(1, "module"),
93+
}
94+
),
95+
},
96+
6597
tsp.treesitter_postfix(
6698
{
6799
trig = ".ipairs",

0 commit comments

Comments
 (0)