Add func snippet for go
This commit is contained in:
parent
aba1664d09
commit
b0cfb31645
59
snippets/go.lua
Normal file
59
snippets/go.lua
Normal file
@ -0,0 +1,59 @@
|
||||
# Go LuaSnip Snippets
|
||||
|
||||
local luasnip = require('luasnip')
|
||||
local snip = luasnip.snippet
|
||||
local text = luasnip.text_node
|
||||
local ins = luasnip.insert_node
|
||||
local func = luasnip.function_node
|
||||
local node = luasnip.snippet_node
|
||||
local key = require("luasnip.nodes.key_indexer").new_key
|
||||
|
||||
local function short_name(name)
|
||||
local short = string.lower(string.sub(name, 1, 1))
|
||||
for i = 2, #name do
|
||||
local char = string.sub(name, i, i)
|
||||
if char == string.upper(char) then
|
||||
short = short .. char
|
||||
end
|
||||
end
|
||||
return string.lower(short)
|
||||
end
|
||||
|
||||
local snippets = {
|
||||
|
||||
snip('func', {
|
||||
text('func '),
|
||||
node(1, {
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return '(' .. short_name(args[1][1]) .. ' *'
|
||||
end
|
||||
return ''
|
||||
end, key('type')),
|
||||
ins(1, '', { key = 'type' }),
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return ') '
|
||||
end
|
||||
return ''
|
||||
end, key('type')),
|
||||
}),
|
||||
ins(2, 'name'),
|
||||
text('('),
|
||||
ins(3, ''),
|
||||
text(') '),
|
||||
ins(4, '', { key = 'return' }),
|
||||
func(function(args)
|
||||
if string.len(args[1][1]) > 0 then
|
||||
return ' '
|
||||
end
|
||||
return ''
|
||||
end, key('return')),
|
||||
text({ '{', '\t' }),
|
||||
ins(0, ''),
|
||||
text({ '', '}' }),
|
||||
}),
|
||||
|
||||
}
|
||||
|
||||
return snippets
|
Loading…
x
Reference in New Issue
Block a user