-
Notifications
You must be signed in to change notification settings - Fork 3
/
proto.snippets
120 lines (98 loc) · 2.35 KB
/
proto.snippets
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
global !p
from snippets import *
from snippets.go import *
import px
for full_name, name in px.libs().items():
exec("import " + full_name)
endglobal
global !p
def is_inside_message(snip):
return px.whitespaces.match_higher_indent(
snip.buffer,
snip.cursor,
'message\s+'
)
def is_inside_service(snip):
return px.whitespaces.match_higher_indent(
snip.buffer,
snip.cursor,
'service\s+'
)
def is_inside_rpc(snip):
return px.whitespaces.match_higher_indent(
snip.buffer,
snip.cursor,
'rpc\s+'
)
def is_inside_rpc_option(snip):
return px.whitespaces.match_higher_indent(
snip.buffer,
snip.cursor,
'option\s+'
)
def is_surrounded_by(snip, before, after):
return px.cursor.is_between(
snip.buffer[snip.cursor[0]],
snip.cursor,
before,
after
)
endglobal
snippet "^m" "message" bAr
message $1 {
$0
}
endsnippet
context "is_inside_service(snip)"
snippet "r" "rpc" bAr
rpc $1(${2:`!p snip.rv=t[1] + "Request"`}) returns (${3:`!p snip.rv=t[1] + "Response"`}) {
$4
}
endsnippet
context "is_inside_rpc(snip)"
snippet "o" "rpc option http annotation" bAr
option (google.api.http) = {
$1
};
endsnippet
context "is_inside_rpc_option(snip)"
snippet "g" "http annotation get" bAr
get: "/v1/$1"
endsnippet
context "is_inside_rpc_option(snip)"
snippet "b" "http annotation body" bAr
body: "${1:*}"
endsnippet
context "is_inside_message(snip)"
snippet s "string field message" bA
string $1 ${2:`!p snip.rv = "[ (gogoproto.customname) = \"ID\" ]" if re.match(r'^id\W', t[1]) else ""`};
endsnippet
context "is_inside_message(snip)"
snippet r "repeated field message" bA
repeated $1
endsnippet
context "is_inside_message(snip)"
snippet ts "string field message" bA
google.protobuf.Timestamp $1 [ (gogoproto.stdtime) = true ];
endsnippet
context "is_inside_message(snip)"
snippet [ "field annotation" w
[ $1 ]
endsnippet
context "is_surrounded_by(snip, '\[', '\]')"
snippet e "required message" w
(validator.field) = {msg_exists : true}
endsnippet
context "is_surrounded_by(snip, '\[', '\]')"
snippet n "custom name" w
(gogoproto.customname) = "$1"
endsnippet
context "is_surrounded_by(snip, '\[', '\]')"
snippet t "gogoproto stdtime" w
(gogoproto.stdtime) = true
endsnippet
snippet "^s" "service" br
service $1 {
$0
}
endsnippet