Files
vim/after/plugin/snips.lua
2023-05-16 08:14:44 +02:00

175 lines
3.4 KiB
Lua

local has_luasnip, luasnip = pcall(require, 'luasnip')
if not has_luasnip then
return
end
local ls = luasnip
local s = ls.snippet
-- local sn = ls.snippet_node
-- local isn = ls.indent_snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
-- local d = ls.dynamic_node
-- local r = ls.restore_node
-- local events = require("luasnip.util.events")
-- local ai = require("luasnip.nodes.absolute_indexer")
local extras = require 'luasnip.extras'
-- local l = extras.lambda
local rep = extras.rep
-- local p = extras.partial
-- local m = extras.match
-- local n = extras.nonempty
-- local dl = extras.dynamic_lambda
local fmt = require('luasnip.extras.fmt').fmt
-- local fmta = require("luasnip.extras.fmt").fmta
-- local conds = require("luasnip.extras.expand_conditions")
-- local postfix = require("luasnip.extras.postfix").postfix
-- local types = require("luasnip.util.types")
-- local parse = require("luasnip.util.parser").parse_snippet
--
--
ls.config.set_config {
history = true,
updateevents = 'TextChanged,TextChangedI',
}
local snippets = {
all = {
s(
'timestamp',
f(function()
return os.date '%Y-%m-%d %H:%M'
end)
),
},
gitcommit = {
s(
{ trig = 'cc', name = 'conventional commit' },
fmt(
[[
{}({}): {} {}
{}
]],
{ i(1, 'type'), i(2, 'scope'), i(3, 'ticket'), i(4, 'message'), i(0) }
)
),
},
lua = {
s('hey', c(1, { t 'hey ho', t 'hoi' })),
s(
{ trig = 'prequire', name = 'pcall require' },
fmt(
[[
local has_{}, {} = pcall(require, '{}')
if not has_{} then
return
end
{}
]],
{ rep(1), rep(1), i(1), rep(1), i(0) }
)
),
},
javascript = {
s(
{ trig = 'rfc', name = 'React Fuctional Component' },
fmt(
[[
import PropTypes from 'prop-types';
const {} = function({}) {{
return {};
}};
{}.propTypes = {{
{}
}};
export default {};
]],
{ i(1, 'ComponentName'), i(2, '{}'), i(0), rep(1), i(3), rep(1) }
)
),
s(
{ trig = 'des', name = 'describe' },
fmt(
[[
describe("{}", () => {{
{}
}});
]],
{ i(1), i(0) }
)
),
s(
{ trig = 'it', name = 'it' },
fmt(
[[
it("{}", () => {{
{}
}});
]],
{ i(1), i(0) }
)
),
s(
{ trig = 'bfe', name = 'beforeEach' },
fmt(
[[
beforeEach(() => {{
{}
}});
]],
{ i(0) }
)
),
s(
{ trig = 'bf', name = 'beforeX' },
fmt(
[[
before{}(() => {{
{}
}});
]],
{ c(1, { t 'Each', t 'All' }), i(0) }
)
),
s(
{ trig = 'afe', name = 'afterEach' },
fmt(
[[
afterEach(() => {{
{}
}});
]],
{ i(0) }
)
),
s(
{ trig = 'egbr', name = 'expect getByRole' },
fmt(
[[
expect(screen.getByRole('{}', {{ name: /{}/i}})).{}
]],
{ i(1, 'heading'), i(2), i(0) }
)
),
s(
{ trig = 'tbid', name = 'toBeInDocument()' },
fmt(
[[
toBeInDocument();
{}
]],
{ i(0) }
)
),
},
}
ls.add_snippets(nil, snippets, { key = 'my-snips' })