mirror of
https://github.com/tomru/vim.git
synced 2026-03-03 22:47:25 +01:00
143 lines
2.8 KiB
Lua
143 lines
2.8 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)
|
|
),
|
|
},
|
|
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 = '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' })
|