Created
January 16, 2022 08:30
-
-
Save lotusirous/361f494193e0295cb70a0809ae782fee to your computer and use it in GitHub Desktop.
Some go snippets for luasnip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ls = require "luasnip" | |
local s = ls.snippet | |
local i = ls.insert_node | |
local t = ls.text_node | |
local f = ls.function_node | |
local function copyname(args) | |
return args[1] | |
end | |
local snips = { | |
go = { | |
s( | |
"ef", | |
{ | |
i(1, {"val"}), | |
t ", err := ", | |
i(2, {"f"}), | |
t "(", | |
i(3), | |
t ")", | |
i(0) | |
} | |
), | |
s( | |
"pf", | |
{ | |
-- Simple static text. | |
t("// "), | |
-- function, first parameter is the function, second the Placeholders | |
-- whose text it gets as input. | |
f(copyname, 1), | |
i(4, {" ... "}), -- paste function name | |
t({"", "func "}), | |
-- Placeholder/Insert. | |
i(1), | |
t("("), | |
-- Placeholder with initial text. | |
i(2, ""), | |
t(")"), | |
i(3, {" error "}), | |
-- Linebreak | |
t({"{", "\t"}), | |
-- Last Placeholder, exit Point of the snippet. EVERY 'outer' SNIPPET NEEDS Placeholder 0. | |
i(0), | |
t({"", "}"}) | |
} | |
) | |
} | |
} | |
return snips |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment