Skip to content

Commit

Permalink
chore: add some snippets for Go files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarmos-san committed Nov 24, 2024
1 parent 757f5a5 commit 1dfe6f8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions dotfiles/.config/nvim/luasnippets/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local luasnip = require("luasnip")
local snippet = luasnip.snippet
local insert_node = luasnip.insert_node
local fmt = require("luasnip.extras.fmt").fmt

return {
-- Snippet for defining a function
snippet(
{ trig = "func", desc = "Create a function definition" },
fmt(
[[
func {1}({2} {3}) ({4}) {{
return {5}
}}
]],
{
insert_node(1, "FunctionName"),
insert_node(2, "Argument"),
insert_node(3, "ArgumentType"),
insert_node(4, "ReturnType"),
insert_node(5, ""),
}
)
),

-- Snippet to create a Go struct
snippet(
{ trig = "struct", desc = "Create a Go struct" },
fmt(
[[
type {1} struct {{
{2}
}}
]],
{ insert_node(1, "StructName"), insert_node(2, "") }
)
),

-- Snippet to create struct method
snippet(
{ trig = "method", desc = "Create a struct method" },
fmt(
[[
func ({1}) {2}({3}) {4} {{
return {5}
}}
]],
{
insert_node(1, "Struct"),
insert_node(2, "Method"),
insert_node(3, "Args"),
insert_node(4, "ReturnType"),
insert_node(5, ""),
}
)
),
}

0 comments on commit 1dfe6f8

Please sign in to comment.