summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/custom/snippets/go.lua
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-11-06 22:27:41 +0200
committerKyren223 <Kyren223@proton.me>2024-11-06 22:27:41 +0200
commitd732fb2bc20de00b7bd6aaf58c715a42f499f6dd (patch)
treeacf3a0ca1182c5ad974e7726bd1e5adfc446be6d /.config/nvim/lua/custom/snippets/go.lua
parent44223b77ee093c29c0845801aee7a508348f1b00 (diff)
Added go snippet to help with bubbletea boilerplate
Diffstat (limited to '.config/nvim/lua/custom/snippets/go.lua')
-rw-r--r--.config/nvim/lua/custom/snippets/go.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/.config/nvim/lua/custom/snippets/go.lua b/.config/nvim/lua/custom/snippets/go.lua
new file mode 100644
index 0000000..c6ddd09
--- /dev/null
+++ b/.config/nvim/lua/custom/snippets/go.lua
@@ -0,0 +1,49 @@
+require('luasnip.session.snippet_collection').clear_snippets('go')
+local ls = require('luasnip')
+local i = ls.insert_node
+
+---@param abbr string
+---@param expansion string
+---@param args table
+local function s(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) (Model, tea.Cmd) {{
+ switch msg := msg.(type) {{
+ default:
+ return m, nil
+ }}
+}}
+]=]
+
+ls.add_snippets('go', {
+ s('tmod', tea_model, { i(0) }),
+})