Add lua snippets file.

main
Joshua Potter 2024-01-05 09:58:57 -07:00
parent 60a48b8186
commit 41579e25a0
4 changed files with 58 additions and 6 deletions

View File

@ -8,5 +8,9 @@
nvim-lspconfig = ''
require('lua.init').nvim_lspconfig()
'';
nvim-snippets = ''
require('luasnip').add_snippets('lua', require('lua.snippets'))
'';
};
}

View File

@ -0,0 +1,48 @@
local fmt = require('luasnip.extras.fmt').fmt
local ls = require('luasnip')
local ul = require('utils.luasnip')
local c = ls.choice_node
local i = ls.insert_node
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
return {
s(
{ name = 'for', trig = 'for' },
fmt([[
for {} do
{}
end]],
{
c(1, {
sn(nil, {
i(1, 'i'),
t('='),
i(2, 'm'),
t(','),
i(3, 'n'),
}),
sn(nil, {
i(1, 'k'),
t(', '),
i(2, 'v'),
t(' in pairs('),
i(3, 'tbl'),
t(')'),
}),
sn(nil, {
i(1, 'i'),
t(', '),
i(2, 'v'),
t(' in ipairs('),
i(3, 'seq'),
t(')'),
}),
}),
ul.visual_isn(2),
}
)
),
}

View File

@ -18,10 +18,10 @@ for {} in {}:
{}]],
{
c(1, {
i(nil, '_1'),
i(nil, '_2'),
i(nil, '_3'),
{ i(1, '_4'), t(', '), i(2, '_5') },
i(nil, 'i'),
i(nil, 'k'),
i(nil, 'v'),
{ i(1, 'k'), t(', '), i(2, 'v') },
}),
d(2, function(_, parent)
local index = ul.choice_index(parent.nodes[2])
@ -47,7 +47,7 @@ for {} in {}:
})[index])
)
end, { 1 }),
ul.visual_dynamic_node(3),
ul.visual_isn(3),
}
)
),

View File

@ -3,7 +3,7 @@ local M = {}
local luasnip = require('luasnip')
local types = require('luasnip.util.types')
function M.visual_dynamic_node(pos)
function M.visual_isn(pos)
local f = luasnip.function_node
local isn = luasnip.indent_snippet_node