diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-04-24 11:36:39 +0300 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-04-24 11:36:39 +0300 |
| commit | 6bef8f32b19778fdfe52f0eb39719425508dcc7b (patch) | |
| tree | f293141ed7e8676b76bb06c07a0fa9472b10e2ac /.config/nvim/lua/snippets/go.lua | |
| parent | dbd9a6fdd0c44e26b200fb706aacd120a2e09c47 (diff) | |
Refactored nvim config to make it easier and less insanely nested
Diffstat (limited to '.config/nvim/lua/snippets/go.lua')
| -rw-r--r-- | .config/nvim/lua/snippets/go.lua | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.config/nvim/lua/snippets/go.lua b/.config/nvim/lua/snippets/go.lua new file mode 100644 index 0000000..d6b7114 --- /dev/null +++ b/.config/nvim/lua/snippets/go.lua @@ -0,0 +1,77 @@ +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 snip(abbr, expansion, args) + return ls.snippet(abbr, require('luasnip.extras.fmt').fmt(expansion, args)) +end + +local tea_model = [=[ +import ( + "fmt" + + tea "github.com/charmbracelet/bubbletea" +) + +type Model struct{{ + {} +}} + +func New() Model {{ + return Model{{ + }} +}} + +func (m Model) Init() tea.Cmd {{ + return nil +}} + +func (m Model) View() string {{ + return fmt.Sprintf( + "%s", + "", + ) +}} + +func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {{ + switch msg := msg.(type) {{ + default: + return m, nil + }} +}} +]=] + +local server_api = [=[ +func {}(ctx context.Context, sess *session.Session, request packet{}) packet.Payload {{ +}} +]=] + +ls.add_snippets('go', { + 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({ '', '}' }), + }), +}) |
