-
Notifications
You must be signed in to change notification settings - Fork 3
/
go.snippets
1192 lines (938 loc) · 24.1 KB
/
go.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################################################################
# GLOBALS
###############################################################################
global !p
from snippets import *
from snippets.go import *
def pum_visible():
return vim.eval('pumvisible()') == '1'
def pre_expand_():
px.common.get_active_completer().reset()
def is_inside_brackets(snip):
line = snip.buffer[snip.line]
before = line[:snip.column]
if px.cursor.is_between(line, snip.cursor, r'\[', r'\]'):
return True
if re.match(r'.*\[[^]]*$', before):
return True
return False
def before_equal_sign(snip):
line = snip.buffer[snip.line]
if len(line) <= snip.column+1:
return False
return line[snip.column+1] == '='
def is_inside_inline_struct_instance(snip):
part = snip.buffer[snip.cursor[0]][:snip.cursor[1]]
return '{' in part
def is_inside_if_err(snip):
return px.whitespaces.match_higher_indent(
snip.buffer, snip.cursor, r'if err\s+'
)
def is_inside_struct_instance(snip):
if is_inside_anon_struct(snip):
return True
if is_inside_inline_struct_instance(snip):
return True
return px.whitespaces.match_higher_indent(
snip.buffer, snip.cursor, r'[\w.]+{$|[^{]} {$'
)
def is_inside_anon_struct(snip):
return px.whitespaces.match_higher_indent(
snip.buffer, snip.cursor, r'}\s*{'
)
def is_inside_map(snip):
return px.whitespaces.match_higher_indent(
snip.buffer, snip.cursor, r'map\S+{$'
)
def is_inside_case_condition(snip):
line = snip.buffer[snip.line]
return re.match(r'^\s+case ', line)
def is_viable_for_equal_statement(snip):
return not is_string() and not is_comment() and \
not is_inside_brackets(snip) and \
not before_equal_sign(snip) and \
not is_inside_struct_instance(snip) and \
not is_inside_inline_struct_instance(snip) and \
not is_inside_anon_struct(snip) and \
not is_inside_map(snip) and \
not is_inside_case_condition(snip)
def insert_space(snip, space=" "):
line = snip.buffer[snip.line]
if snip.buffer[snip.line] != snip.context:
line = snip.context
snip.buffer[snip.line] = \
line[:snip.column] + \
space + \
line[snip.column:]
snip.cursor.set(
snip.line,
snip.column + len(space),
)
def is_manually_triggered():
return vim.eval('get(g:, "_expand_snippet", "0")') == '1'
def get_program_name_from_usage(snip):
prev_line = snip.buffer[snip.snippet_start[0] - 1]
return prev_line.strip().split(' ', 1)[0]
def guess_binary_name_from_path():
return os.path.basename(os.path.realpath('.'))
def add_usage(snip):
px.langs.go.goto_const();
snip.expand_anon(r"""var version = "${2:[manual build]}"
var usage = \`{PROGRAM} - $1
$3
Usage:
{PROGRAM} -h | --help
$4
Options:
-h --help Show this help.
$0
`
""".replace('{PROGRAM}', snip.tabstops[1].current_text), options='m')
def fix_matchem(char):
pass
def get_indent_levels(snip, base_line):
if snip.context is None:
snip.context = {}
if len(snip.buffer) <= base_line+1:
return
snip.context['upper_indent'] = px.whitespaces.get_indentation(
snip.buffer[base_line]
)[1]
snip.context['inner_indent'] = px.whitespaces.get_indentation(
snip.buffer[base_line+1]
)[1]
return snip.context
def get_padded_equal_sign(selection=None):
if not selection:
cursor = px.cursor.get()
selection = px.buffer.get()[cursor[0]][:cursor[1]]
if not selection:
return "=", ""
if re.match(r'\w', selection[-1]):
return " = ", selection
else:
return "= ", selection
endglobal
###############################################################################
priority -1
###############################################################################
context "px.snippets.make_context(snip)"
pre_expand "pre_expand_()"
post_jump "jump_to_if_body_on_err_not_nil(snip)"
snippet i "if" bw
if ${1:`!p
try:
once
except:
once = True
snip.rv = get_value_for_if(snip.c, snip.context)
`} {
$0
}
endsnippet
context "not is_string() and not is_comment() and (is_type_decl(snip) or is_func_decl(snip))"
snippet "(.*)(\w| )([si6fyeb])" "type string int int64 float64 byte error bool" er
`!p
trigger = match.group(3)
typedef = {
's': 'string',
'i': 'int',
'6': 'int64',
'f': 'float64',
'y': '[]byte',
'e': 'error',
'b': 'bool',
}[trigger]
snip.rv = match.group(1) + (match.group(2).strip() + ' ') + typedef`
endsnippet
context "not is_string() and not is_comment()"
snippet "t" "anon struct" ew
struct {
$1
}
endsnippet
snippet de "defer" b
defer $1($2)
endsnippet
context "not is_string() and not is_comment() and is_type_decl(snip)"
snippet m "" bwe
$1 map[${2:string}]${3:interface{}}
endsnippet
context "not is_string() and not is_comment() and is_func_decl(snip)"
snippet m "" we
$1 map[${2:string}]${3:interface{}}${4/.+/(?0:, )/}$4
endsnippet
snippet ii "if <VISUAL>" bwA
if ${VISUAL} {
$1
}
endsnippet
snippet fe "fmt.Errorf($1 or VISUAL)" w
fmt.Errorf(${1:${VISUAL}})
endsnippet
snippet fef "fmt.Errorf with message" w
fmt.Errorf("$1: %s", ${2:${VISUAL:err}})
endsnippet
snippet ff "fmt.Errorf only message" w
fmt.Errorf("$1")
endsnippet
snippet r "return" bw
return $0
endsnippet
snippet "return nil" "return nil, err" bw
return nil, err
endsnippet
snippet ,e ", err" iA
, err$0
endsnippet
context "px.langs.go.is_if_bracket(snip.buffer, snip.line, snip.column-1)"
snippet "}([\w])" "else before closing bracket" bwrA
} else {
`!p snip.rv=match.group(1)`$1
}
endsnippet
###############################################################################
priority 0
###############################################################################
context "is_if_condition(snip)"
snippet e "" w
${1:${VISUAL}} == "$2"
endsnippet
context "is_if_condition(snip)"
snippet en "" w
${1:${VISUAL}} != "$2"
endsnippet
context "is_if_condition(snip)"
snippet l "" w
len(${1:${VISUAL}}) == ${2:0}
endsnippet
context "is_if_condition(snip)"
snippet ln "" w
len(${1:${VISUAL}}) != ${2:0}
endsnippet
###############################################################################
priority 1
###############################################################################
snippet / "visual not nil" "get_selected_placeholder(snip)" iAe
`!p snip.rv = snip.context` != nil
endsnippet
context "is_inside_if_err(snip)"
snippet pa "panic" b
panic(err)
endsnippet
context "not pum_visible() and not is_string() and not is_comment() and is_viable_for_equal_statement(snip)"
snippet : "colon equals auto" iAe
:=`!p snip.rv = ' '`
endsnippet
context "not pum_visible() and not is_string() and not is_comment() and is_inside_struct_instance(snip)"
snippet : "colon space auto" iAe
:`!p snip.rv = ' '`
endsnippet
snippet = "" "not is_string() and not is_comment() and {'selection': None}" iAe
`!p snip.rv, snip.context['selection'] = get_padded_equal_sign(snip.context['selection'])`
endsnippet
###############################################################################
priority 2
###############################################################################
snippet e "" wb
err := ``
endsnippet
context "not is_string() and not is_comment()""
snippet = "" wbA
${1:err} := ``
endsnippet
context "is_first_line(snip)"
snippet "package m" "" bwrAe
package main
endsnippet
context "snip.line == 0 and snip.column == 0"
snippet m "" eA
package main
func main() {
$0
}
endsnippet
context "px.langs.go.is_if_bracket(snip.buffer, snip.line, snip.column-1)"
snippet "}\s" "else before closing bracket" bwrA
} else {
$1
}
endsnippet
context "not is_string() and not is_comment() and is_before_first_func(snip)"
snippet "^c$" "" bwreA
const (
$0
)
endsnippet
snippet ass "anon struct with fields" w
struct {
$1
}{
$2
}
endsnippet
snippet "((\w+)\s*(\*?[\w\[\].\{\}*]+)(\s+`[^`]+`)?)\s+(to|js|bs|sc|ya|bi|do|xo|db)$" "annotation" "not px.syntax.is_string(snip.cursor)" bre
`!p
line = match.group(1)
prefixes = {
"to": "toml",
"js": "json",
"bs": "bson",
"sc": "schema",
"ya": "yaml",
"bi": "binding",
"do": "docopt",
"xo": "xorm",
"db": "db",
}
prefix = prefixes[match.group(5)]
if line.endswith('\`'):
quote = ' '
line = line[:-1]
else:
quote = ' \`'
snip.rv = line + quote + prefix
def get_placeholder(prefix, name):
if prefix == "docopt":
return get_docopt_placeholder(name)
else:
return px.util.convert_camelcase_to_snakecase(name)
def get_docopt_placeholder(name):
matches = re.match(r'(Mode|Arg|Value|Flag)(.*)', name)
if matches is None:
return "--" + px.util.convert_camelcase_to_kebabcase(name)
else:
identifier = px.util.convert_camelcase_to_kebabcase(matches.group(2))
if matches.group(1) == "Mode":
return identifier
if matches.group(1) == "Arg":
return "<" + identifier + ">"
if matches.group(1) == "Value" or matches.group(1) == "Flag":
return ("-" if len(identifier) == 1 else "--") + identifier
return identifier
surround = ""
if prefix == "xorm":
surround = "'"
`:"`!p snip.rv=surround`${1:`!p snip.rv=get_placeholder(prefix, match.group(2))`}`!p snip.rv=surround`"\`
endsnippet
snippet ,o "" i
,omitempty
endsnippet
snippet msi "map[string]interface" w
map[string]interface{}
endsnippet
snippet mss "map[string]string" w
map[string]string
endsnippet
snippet s "switch" bw
switch ${1:name} {
case ${2:true}:
$3
$4
}
endsnippet
snippet w "switch true" bw
switch {
case ${1}:
$2
$3
}
endsnippet
snippet se "select" bw
select {
case ${1}:
$2
$3
}
endsnippet
context "px.snippets.make_context(snip)"
pre_expand "px.common.get_active_completer().reset()"
snippet p "fmt printf xxx debug" bwe
`!p
try:
once
except:
once = True
cursor = px.cursor.get()
filename = os.path.basename(px.buffer.get().name)
func = 'Fprintln'
left = '"'
right = ')'
if t[1] != '':
func = 'Fprintf'
left = ' ' + t[1] + ': %#v\\n", '
right = ')'
if t[1] == 'err':
left = ' ' + t[1] + ': %s\\n", '
if " " in t[1]:
func = 'Fprintf'
left = ' '
right = '\\n")'
left = " " + filename + ":" + str(cursor[0]) + left
`fmt.`!p snip.rv = func`(os.Stderr, "XXXXXX`!p snip.rv=left`${1}`!p snip.rv=right`
endsnippet
context "px.snippets.make_context(snip)"
pre_expand "px.common.get_active_completer().reset()"
snippet lr "fmt printf xxx debug" bwe
`!p
try:
once
except:
once = True
cursor = px.cursor.get()
filename = os.path.basename(px.buffer.get().name)
func = 'Println'
left = '"'
right = ')'
if t[1] != '':
func = 'Printf'
left = ' ' + t[1] + ': %#v\\n", '
right = ')'
if t[1] == 'err':
left = ' ' + t[1] + ': %s\\n", '
if " " in t[1]:
func = 'Println'
left = ' '
right = '\\n")'
left = " " + filename + ":" + str(cursor[0]) + left
`log.`!p snip.rv = func`("XXXXXX`!p snip.rv=left`${1}`!p snip.rv=right`
endsnippet
snippet main "func main" bw
func main() {
$0
}
endsnippet
context "snip.buffer[snip.cursor[0]] == 'v'"
post_jump "px.snippets.expand(snip)"
snippet "^v" "var" bwrA
vr$1
endsnippet
snippet "v" "var" bwr
var $1
endsnippet
snippet "vr" "var" bwr
`!p
vis = ""
if snip.v.text != "":
vis = snip.v.text
vis = re.sub(r' := ', ' = ', vis)
vis = re.sub(r'var ', '', vis)
vis = re.sub(r'^', '\t', vis, flags=re.M)
vis = vis.strip()
`var (
${1:`!p snip.rv=vis`}
)
endsnippet
snippet rn "return nil" bw
return nil
endsnippet
snippet ap "append" bw
${1:slice} = append($1, $2)
endsnippet
snippet ms "make slice" w
make([]$1, ${2:0})
endsnippet
snippet mc "make chan" w
make(chan $1, ${2:0})
endsnippet
snippet mm "make map" w
make(map[${1:string}]${2:interface\{\}})
endsnippet
snippet if "interface" w
interface{}
endsnippet
snippet ts "type switch" bw
switch ${1:newVar} := ${2:checkVar}.(type) {
case ${3:Type}:
$4
}
endsnippet
snippet "= =" "" "is_if_condition(snip)" Aie
== $0
endsnippet
snippet "= =" "" "not is_if_condition(snip)" Aie
:= $0
endsnippet
snippet "fa?" "false" wr
false
endsnippet
snippet "tr?" "true" bwr
true
endsnippet
###############################################################################
priority 3
###############################################################################
context "not pum_visible() and not is_string() and not is_manually_triggered() and snip.buffer[snip.line]"
post_jump "insert_space(snip)"
snippet , "comma auto" eAi
,X
endsnippet
snippet an "func anonymous" w
func ($1) $2${2/.+/ /}{
$3
}
endsnippet
snippet "^n" "" "not is_string() and not is_comment()" bweAr
func $1($2) $3`!p snip.rv = (" {" if t[3] != "" else "{") `
$4
}
endsnippet
snippet "== =" "" Ai
!= $0
endsnippet
snippet "!= =" "" Ai
== $0
endsnippet
snippet ":= =" "" Ai
= $0
endsnippet
snippet "= n" "" "is_if_condition(snip)" Aie
= nil$0
endsnippet
###############################################################################
priority 4
###############################################################################
snippet "== nil[=n]" "" "is_if_condition(snip)" Aier
!= nil$0
endsnippet
snippet "!= nil[=n]" "" "is_if_condition(snip)" Aier
== nil$0
endsnippet
post_jump "if snip.tabstop == 0: add_usage(snip)"
snippet do "docopt" b
args, err := docopt.ParseArgs(usage, nil, "${1:`!p snip.rv = guess_binary_name_from_path()`} " + version)
if err != nil {
panic(err)
}
endsnippet
snippet - "docopt command declaration" "is_inside_docopt_section(snip, 'usage') and not is_inside_docopt_section(snip, 'options')" beA
`!p snip.rv = get_program_name_from_usage(snip)` -$0
endsnippet
post_jump "if snip.tabstop == 2: docopt_format_options(snip)"
snippet "\s*-" "docopt option declaration" "is_inside_docopt_section(snip, 'options')" beAr
-$1`!p snip.rv=get_options_indentation(snip)``!p snip.rv=split_long_docopt_line(t, snip)`$2
endsnippet
snippet [ "docopt option default with matchem" "is_inside_docopt_section(snip, 'options')" eA
`!p snip.rv="["`default: $1]
endsnippet
post_expand "fix_matchem('[')"
snippet args[ "args[blah]" wi
args[`!p
if t[1].startswith('-'):
if len(t[1]) > 2 and not t[1].startswith('--'):
snip.rv = '"-'
else:
snip.rv = '"'
else:
snip.rv = '"<'
`$1`!p
if t[1].startswith('-'):
snip.rv = '"'
else:
snip.rv = '>"'
`].(${2:string})$0
endsnippet
# Snippet to call log.Debugf with function args.
# Should be expanded on line before actual function call.
# Function call should be formatted like following pattern:
#
# foo := bar(
# arg1,
# arg2,
# arg3,
# )
#
# or like this pattern:
#
# bar(
# arg1,
# arg2,
# arg3,
# )
#
snippet x "log.Debugf args of function on next line"
`!p
def is_next_line_contains_function_call_only(buffer, line):
return re.match(r'.*\($', buffer[line + 1])
def get_function_name_from_line(buffer, line):
matches = re.match(r'^(\t*|.*=\s)([\w\.]*)\($', buffer[line + 1])
if matches:
return matches.group(2)
def get_function_args_count(buffer, line, line_first_arg):
while line <= len(buffer):
line += 1
matches = re.match(r'.*\)$', buffer[line])
if matches:
return line - line_first_arg
def run(buffer, line):
if not is_next_line_contains_function_call_only(buffer, line):
return
function_name = get_function_name_from_line(buffer, line)
line_current_arg = line + 2
args_count = get_function_args_count(buffer, line, line_current_arg)
if args_count == 0:
return
buffer.append(
snip.mkline(
formatLogInfoFunction % (
os.path.basename(px.buffer.get().name),
line_current_arg + args_count + 1,
function_name
),
),
line
)
line += 1
line_current_arg += 1
line_last_arg = line_current_arg + args_count
while line_current_arg < line_last_arg:
arg = buffer[line_current_arg].strip()[:-1] # [:-1] to remove ','
buffer.append(
snip.mkline(formatLogInfo % (arg.replace('"', r'\"'), arg)),
line
)
line_current_arg += 2
line += 1
line_last_arg += 1
buffer = px.buffer.get()
line, _ = px.cursor.get()
formatLogInfo = 'log.Debugf("\\t%%s: %%#v", "%s", %s); '
formatLogInfoFunction = 'log.Debugf("%s:%s: %%s", "%s()"); '
run(buffer, line)
`
endsnippet
context "snip.buffer[snip.line-1].endswith('[') and snip.buffer[snip.line].strip().startswith(']')"
snippet "" "[\n]" brA
$0
endsnippet
snippet lu "" w
${1}.Lock()
defer `!p snip.rv=t[1]`.Unlock()
endsnippet
snippet ru "" w
${1}.RLock()
defer `!p snip.rv=t[1]`.RUnlock()
endsnippet
snippet ":\s+" "" wr
$1: $1,
endsnippet
snippet ctx "ctx context.Context" w
ctx context.Context
endsnippet
###############################################################################
priority 5
###############################################################################
context "not is_string() and not is_comment() and not is_func_decl(snip)"
snippet ", e" "err, " ie
, err``
endsnippet
context "is_func_decl(snip)"
snippet ", e" "err, " ie
, error``
endsnippet
context "not is_string() and not is_comment()"
snippet ", n" ", nil" ie
, nil``
endsnippet
context "not is_string() and not is_comment()"
snippet ", " "err, " ie
, err``
endsnippet
context "not is_string() and not is_comment()"
snippet n, "nil, " Ae
nil, ``
endsnippet
context "not is_string() and not is_comment()"
snippet e, "err, " Ae
err, ``
endsnippet
snippet "return e" "return err" bw
return err
endsnippet
context "get_indent_levels(snip, snip.line)"
post_expand "get_indent_levels(snip, snip.snippet_start[0])"
snippet "return(.*)fm" "return fmt.Errorf" bwr
`!p
quote = '"'
if '"' in t[1]:
quote = '\`'
`return`!p snip.rv = match.group(1)`fmt.Errorf(
"$1: %s"`!p
snip.rv = (",\n" + snip.context['inner_indent'] if t[2] else ",")
`$2`!p
snip.rv = ("," if t[2] else "") + " err,\n" + snip.context['upper_indent'] + ")"
`
endsnippet
context "get_indent_levels(snip, snip.line)"
post_expand "get_indent_levels(snip, snip.snippet_start[0])"
snippet "(return)?(.*\W)([kc])" "return karma/context" bwr
`!p
quote = '"'
if '"' in t[1]:
quote = '\`'
subject = "karma"
if match.group(3) == "c":
subject = "context"
prefix=match.group(2)
if match.group(1):
prefix=match.group(1) + prefix
snip.rv=prefix
``!p snip.rv=subject`.Format(
`!p snip.rv=snip.context['upper_indent']` err,
`!p snip.rv=snip.context['upper_indent']` `!p snip.rv = quote`$0`!p snip.rv = quote``!p
snip.rv = (",\n" + snip.context['inner_indent'] if t[2] else ",")
``!p
snip.rv = ("," if t[2] else "") + "\n" + snip.context['upper_indent'] + ")"
`
endsnippet
snippet kd "" w
karma.Describe("$1", $2)$0
endsnippet
snippet "(karma\.)$" "describe context" r
`!p snip.rv=match.group(1)`
Describe("$1", $2).
$0
endsnippet
snippet "(Describe\(.*\)\.)$" "more describe context" r
`!p snip.rv=match.group(1)`
Describe("$1", $2).$0
endsnippet
snippet "return n" "return nil" bw
return nil
endsnippet
snippet "r (.)" "return auto" bwrA
return `!p snip.rv=match.group(1)`
endsnippet
snippet fr "for true forever" bw
for {
$1
}
endsnippet
snippet qt "t.fatal" bw
if err != nil {
t.Fatal(err)
}
endsnippet
snippet tf "t.fatalf" bw
t.Fatalf("$1")
endsnippet
snippet qf "log fatal" bw
if err != nil {
log.Fatal(err)
}
endsnippet
snippet qff "log fatalf" bw
if err != nil {
log.Fatalf(\`$1: %s\`, $2, err)
}
endsnippet
snippet rt "return true" bw
return true
endsnippet
snippet rf "return false" bw
return false
endsnippet
context "not is_string() and not is_comment() and px.langs.go.extract_prev_method_binding(snip.buffer, snip.cursor) and {'line': snip.line}"
snippet "^d$" "" bweAr
`!p
try:
once
except:
once = True
prev_binding = px.langs.go.extract_prev_method_binding(
px.buffer.get(), px.cursor.get()
)
if not prev_binding:
binding = ''
else:
name, binding_type = prev_binding
binding = name + ' *' + str(binding_type)
`
func (`!p snip.rv=binding`) $1($2) $3 {
$4
}
endsnippet
snippet re "return errors.New" bw
return errors.New($1)
endsnippet
snippet en "" w
errors.New("$0")
endsnippet
snippet "(func\s.*\)\s+)([\w\d_\s\{\}\[\]\*\.]+),\s?([\w\d_\s\{\}\[\]\*\.]+)" "add commas around multple return variables" rA
`!p snip.rv=match.group(1)`(`!p snip.rv=match.group(2)`, `!p snip.rv=match.group(3)`$0)
endsnippet
snippet "^\)\s+?([\w\d_\s\{\}\[\]\*\.]+),\s+?([\w\d_\s\{\}\[\]\*\.]+)" "return multipleadd commas around multple return variables" rA
) (`!p snip.rv=match.group(1)`, `!p snip.rv=match.group(2)`$0)
endsnippet
snippet jp "print json" bw
{
marshaledXXX, _ := json.MarshalIndent($1, "", " ")
fmt.Printf("`!p snip.rv=t[1]`: %s\n", string(marshaledXXX))
}
endsnippet
snippet "^e" "func Test" wrA
func Test$1(t *testing.T) {
test := assert.New(t)
$2
}
endsnippet
snippet "^b" "func Bench" wrA
func Benchmark$1(b *testing.B) {
for i := 0; i < b.N; i++ {