Added a bunch of go snippets
This commit is contained in:
@@ -34,8 +34,10 @@ end
|
||||
|
||||
cmp.setup({
|
||||
enabled = is_enabled,
|
||||
preselect = cmp.PreselectMode.None,
|
||||
completion = { completeopt = 'menu,menuone,noinsert' },
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'luasnip' }, -- for snippets
|
||||
{
|
||||
name = 'nvim_lsp',
|
||||
option = {
|
||||
@@ -44,7 +46,6 @@ cmp.setup({
|
||||
},
|
||||
},
|
||||
}, -- for lsp
|
||||
{ name = 'luasnip' }, -- for snippets
|
||||
{ name = 'lazydev', group_index = 0 }, -- for lazydev.nvim
|
||||
{ name = 'path' }, -- for filesystem
|
||||
}, {}),
|
||||
|
||||
@@ -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({ '', '}' }),
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user