forked from KurokuLabs/margo
/
func-snippet.go
68 lines (63 loc) · 1.03 KB
/
func-snippet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package snippets
import (
"margo.sh/golang/cursor"
"margo.sh/mg"
)
func FuncSnippet(cx *cursor.CurCtx) []mg.Completion {
if cx.Scope == cursor.FileScope || cx.Scope.Is(cursor.FuncDeclScope) {
comp := mg.Completion{
Query: `func`,
Title: `name() {...}`,
Src: `
func ${1:name}($2)$3 {
$0
}
`,
}
if !cx.IsTestFile {
return []mg.Completion{comp}
}
return []mg.Completion{
{
Query: `func Test`,
Title: `Test() {...}`,
Src: `
func Test${1:name}(t *testing.T) {
$0
}
`,
},
{
Query: `func Benchmark`,
Title: `Benchmark() {...}`,
Src: `
func Benchmark${1:name}(b *testing.B) {
$0
}
`,
},
{
Query: `func Example`,
Title: `Example() {...}`,
Src: `
func Example${1:name}() {
$0
// Output:
}
`,
},
}
}
if cx.Scope.Is(cursor.BlockScope, cursor.VarScope) {
return []mg.Completion{{
Query: `func`,
Title: `func() {...}`,
Src: `
func($1)$2 {
$3
}$0
`,
}}
}
return nil
}