summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom/snippets
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/custom/snippets')
-rw-r--r--.config/nvim/lua/custom/snippets/go.lua28
1 files changed, 25 insertions, 3 deletions
diff --git a/.config/nvim/lua/custom/snippets/go.lua b/.config/nvim/lua/custom/snippets/go.lua
index bd0540b..d6b7114 100644
--- a/.config/nvim/lua/custom/snippets/go.lua
+++ b/.config/nvim/lua/custom/snippets/go.lua
@@ -1,11 +1,14 @@
require('luasnip.session.snippet_collection').clear_snippets('go')
local ls = require('luasnip')
+local s = ls.snippet
+local t = ls.text_node
local i = ls.insert_node
+local d = ls.dynamic_node
---@param abbr string
---@param expansion string
---@param args table
-local function s(abbr, expansion, args)
+local function snip(abbr, expansion, args)
return ls.snippet(abbr, require('luasnip.extras.fmt').fmt(expansion, args))
end
@@ -50,6 +53,25 @@ func {}(ctx context.Context, sess *session.Session, request packet{}) packet.Pay
]=]
ls.add_snippets('go', {
- s('tmod', tea_model, { i(0) }),
- s('sapi', server_api, { i(1), i(0) }),
+ snip('tmod', tea_model, { i(0) }),
+ snip('sapi', server_api, { i(1), i(0) }),
+
+ s('iferr', {
+ t({ 'if err != nil {', '' }),
+ i(1, ' return'),
+ t({ '', '}' }),
+ }),
+
+ s('fmterr', {
+ t('fmt.Errorf("'),
+ i(1, 'msg'),
+ t(': %w", err)'),
+ }),
+
+ s('dberr', {
+ t({ 'if err != nil {', '' }),
+ i(2, { ' log.Println("database error ', 'x', ':", err)', '' }),
+ i(2, ' return ', '&ErrInternalError'),
+ t({ '', '}' }),
+ }),
})