forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.ts
819 lines (814 loc) · 20.9 KB
/
go.ts
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
const buildModeSuggestions: Fig.Suggestion[] = [
{
name: "archive",
description: "Build the listed non-main packages into .a files",
},
{
name: "c-archive",
description:
"Build the listed main package, plus all packages it imports, into a C archive file",
},
{
name: "c-shared",
description:
"Build the listed main package, plus all packages it imports, into a C shared library",
},
{
name: "default",
description:
"Listed main packages are built into executables and listed non-main packages are built into .a files",
},
{
name: "shared",
description:
"Combine all the listed non-main packages into a single shared library that will be used when building with the -linkshared option",
},
{
name: "exe",
description:
"Build the listed main packages and everything they import into executables",
},
{
name: "pie",
description:
"Build the listed main packages and everything they import into position independent executables (PIE)",
},
{
name: "plugin",
description:
"Build the listed main packages, plus all packages that they import, into a Go plugin",
},
];
const resolutionAndExecutionOptions: Fig.Option[] = [
{
name: "-n",
description: "print the commands but do not run them.",
},
{
name: "-v",
description: "print the names of packages as they are compiled.",
},
{
name: "-x",
description: "print the commands.",
},
{
name: "-tags",
description:
"a comma-separated list of build tags to consider satisfied during the build.",
args: {
name: "tags",
},
},
{
name: "-toolexec",
insertValue: "-toolexec '{cursor}'",
description:
"a program to use to invoke toolchain programs like vet and asm.",
args: {
name: "cmd",
},
},
];
const globalOptions: Fig.Option[] = [
...resolutionAndExecutionOptions,
{
name: "-a",
description: "force rebuilding of packages that are already up-to-date.",
},
{
name: "-p",
description: "the number of programs, such as build commands or",
args: {
name: "programs",
},
},
{
name: "-race",
description: `enable data race detection.
Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64,
linux/ppc64le and linux/arm64 (only for 48-bit VMA).`,
},
{
name: "-msan",
description: `enable interoperation with memory sanitizer.
Supported only on linux/amd64, linux/arm64
and only with Clang/LLVM as the host C compiler.
On linux/arm64, pie build mode will be used.`,
},
{
name: "-work",
description: `print the name of the temporary work directory and
do not delete it when exiting.`,
},
{
name: "-asmflags",
insertValue: "-asmflags='{cursor}'",
description: "arguments to pass on each go tool asm invocation.",
args: {
name: "flag",
variadic: true,
},
},
{
name: "-buildmode",
description: "build mode to use. See 'go help buildmode' for more.",
args: {
name: "mode",
suggestions: buildModeSuggestions,
},
},
{
name: "-compiler",
description:
"name of compiler to use, as in runtime.Compiler (gccgo or gc).",
args: {
name: "name",
},
},
{
name: "-gccgoflags",
insertValue: "--gccgoflags='{cursor}'",
description: "arguments to pass on each gccgo compiler/linker invocation.",
args: {
name: "flag",
variadic: true,
},
},
{
name: "-gcflags",
insertValue: "-gcflags='{cursor}'",
description: "arguments to pass on each go tool compile invocation.",
args: {
name: "flag",
variadic: true,
},
},
{
name: "-installsuffix",
description:
"a suffix to use in the name of the package installation directory,",
args: {
name: "suffix",
},
},
{
name: "-ldflags",
insertValue: "-ldflags='{cursor}'",
description: "arguments to pass on each go tool link invocation..",
args: {
name: "flag",
variadic: true,
},
},
{
name: "-linkshared",
description:
"build code that will be linked against shared libraries previously",
},
{
name: "-mod",
description: "module download mode to use: readonly, vendor, or mod.",
args: {
name: "mode",
suggestions: [
{
name: "readonly",
},
{
name: "vendor",
},
{
name: "mod",
},
],
},
},
{
name: "-modcacherw",
description:
"leave newly-created directories in the module cache read-write",
},
{
name: "-modfile",
description:
"in module aware mode, read (and possibly write) an alternate go.mod file instead of the one in the module root directory.",
args: {
name: "file",
},
},
{
name: "-overlay",
description:
"read a JSON config file that provides an overlay for build operations.",
args: {
name: "file",
},
},
{
name: "-pkgdir",
description:
"install and load all packages from dir instead of the usual locations.",
args: {
name: "dir",
},
},
{
name: "-trimpath",
description: "remove all file system paths from the resulting executable.",
},
];
const packagesArg: Fig.Arg = {
name: "packages",
variadic: true,
isOptional: true,
};
export const completionSpec: Fig.Spec = {
name: "go",
description: "Go is a tool for managing Go source code.",
posixNoncompliantFlags: true,
subcommands: [
{
name: "bug",
description: "start a bug report",
},
{
name: "build",
description: "compile packages and dependencies",
options: [
...globalOptions,
{
name: "-o",
description:
"write the resulting executable or object to the named output file or directory",
args: {
template: ["filepaths", "folders"],
},
},
{
name: "-i",
description:
"install the packages that are dependencies of the target",
},
],
args: packagesArg,
},
{
name: "clean",
description: "remove object files and cached files",
options: [
...globalOptions,
{
name: "-i",
description: "remove the corresponding installed archive or binary",
},
{
name: "-r",
description:
"apply recursively to all the dependencies of the packages named by the import paths.",
},
{
name: "-cache",
description: "remove the entire go build cache",
},
{
name: "-testcache",
description: "expire all test results in the go build cache.",
},
{
name: "-modcache",
description:
"remove the entire module download cache, including unpacked source code of versioned dependencies.",
},
],
},
{
name: "doc",
description: "show documentation for package or symbol",
options: [
{
name: "-all",
description: "Show all the documentation for the package.",
},
{
name: "-c",
description: "Respect case when matching symbols.",
},
{
name: "-cmd",
description:
"Treat a command (package main) like a regular package. Otherwise package main's exported symbols are hidden when showing the package's top-level documentation.",
},
{
name: "-short",
description: "One-line representation for each symbol.",
},
{
name: "-src",
description: "Show the full source code for the symbol.",
},
{
name: "-u",
description:
"Show documentation for unexported as well as exported symbols, methods, and fields.",
},
],
args: {
name: "package",
},
},
{
name: "env",
description: "print Go environment information",
options: [
{
name: "-json",
description:
"prints the environment in JSON format instead of as a shell script.",
},
{
name: "-u",
description:
"unset the default setting for the named environment variables",
args: {
variadic: true,
},
},
{
name: "-w",
description:
"change the default settings of the named environment variables to the given values.",
args: {
variadic: true,
},
},
],
},
{
name: "fix",
description: "update packages to use new APIs",
args: packagesArg,
},
{
name: "fmt",
description: "gofmt (reformat) package sources",
options: [
{
name: "-n",
description: "print the commands that would be executed",
},
{
name: "-x",
description: "print the commands as they are exectued",
},
{
name: "-mod",
description: "which module download mode to use",
args: {
name: "mode",
suggestions: [
{
name: "readonly",
},
{
name: "vendor",
},
],
},
},
],
args: packagesArg,
},
{
name: "generate",
description: "generate Go files by processing source",
options: [
...globalOptions,
{
name: "-run",
insertValue: '-run "{cursor}"',
description:
"specifies a regular expression to select directives whose full original source text matches the expression.",
},
],
},
{
name: "get",
description: "add dependencies to current module and install them",
options: [
...globalOptions,
{
name: "-t",
description:
"modules needed to build tests of packages specified on the command line.",
},
{
name: "-u",
description: "update to newer minor or patch releases when available",
args: {
isOptional: true,
suggestions: [
{
name: "patch",
description: "update to newer patch releases",
},
],
},
},
{
name: "-insecure",
description: "permit fetching from insecure origins",
},
{
name: "-d",
description:
"only update go.mod and download source code needed to build packages.",
},
],
args: {
name: "url",
isOptional: true,
},
},
{
name: "install",
description: "compile and install packages and dependencies",
options: [...globalOptions],
args: {
name: "packages",
variadic: true,
},
},
{
name: "list",
description: "list packages or modules",
options: [
...globalOptions,
{
name: "-compiled",
description: "set CompiledGoFiles to the Go source files",
},
{
name: "-deps",
description:
"terate over not just the named packages but also all their dependencies",
},
{
name: "-f",
insertValue: "-f '{cursor}'",
description: "specify an alternate format for the list",
args: {
name: "format",
},
},
{
name: "-e",
description:
"processes the erroneous packages with the usual printing",
},
{
name: "-export",
description:
"set the Export field to the name of a file containing up-to-date export information for the given package.",
},
{
name: "-find",
description:
"identify the named packages but not resolve their dependencies",
},
{
name: "-test",
description: "report test binaries",
},
{
name: "-m",
description: "list modules instead of packages",
},
{
name: "-u",
description: "add information about available upgrades",
},
{
name: "-versions",
description:
"set the Module's Versions field to a list of all known versions of that module",
},
{
name: "-retracted",
description: "eport information about retracted module versions",
},
],
args: {
isOptional: true,
},
},
{
name: "mod",
description: "module maintenance",
subcommands: [
{
name: "download",
description: "download the named modules into the module cache",
options: [
{
name: "-json",
description:
"print a sequence of JSON objects to standard output, describing each downloaded module (or failure)",
},
{
name: "-x",
description:
" print the commands download executes to standard error.",
},
],
args: {
name: "modules",
variadic: true,
},
},
{
name: "edit",
description: "edit and format go.mod files",
options: [
{
name: "-module",
description: "change the module's path",
},
{
name: "-go",
insertValue: "-go=",
description: "set the expected Go language version",
args: {
name: "version",
},
},
{
name: "-require",
insertValue: "-require=",
description: "add a requirement on the given module",
args: {
name: "path",
},
},
{
name: "-droprequire",
insertValue: "-droprequire=",
description: "drop a requirement on the given module",
args: {
name: "path",
},
},
{
name: "-exclude",
insertValue: "-exclude=",
description: "add an exclusion on the given module",
args: {
name: "path",
},
},
{
name: "-dropexclude",
insertValue: "-dropexclude=",
description: "drop an exclusion on the given module",
args: {
name: "path",
},
},
{
name: "-replace",
insertValue: "-replace=",
description:
"add a replacement of the given module path and version pair",
args: {
name: "path",
},
},
{
name: "-dropreplace",
insertValue: "-dropreplace=",
description:
"drops a replacement of the given module path and version pair",
args: {
name: "path",
},
},
{
name: "-retract",
insertValue: "-retract=",
description: "add a retraction for the given version",
args: {
name: "version",
},
},
{
name: "-dropretract",
insertValue: "-dropretract=",
description: "drop a retraction for the given version",
args: {
name: "version",
},
},
{
name: "-fmt",
description:
"format the go.mod file without making other changes",
},
{
name: "-print",
description:
"print the final go.mod in its text format instead of writing it back to disk",
},
{
name: "-json",
description:
" print the final go.mod in JSON format instead of writing it back to disk in text forma",
},
],
},
{
name: "graph",
description: "print the module requirement graph",
},
{
name: "init",
description:
"initialize and write a new go.mod file in the current directory",
args: {
name: "module path",
isOptional: true,
},
},
{
name: "tidy",
description:
"ensure that the go.mod file matches the source code in the module",
options: [
{
name: "-e",
description:
"attempt to proceed despite errors encountered while loading packages",
},
{
name: "-v",
description: "print information about removed modules",
},
],
},
{
name: "vendor",
description:
"construct a directory named vendor in the main module's root directory",
options: [
{
name: "-e",
description:
"attempt to proceed despite errors encountered while loading packages",
},
{
name: "-v",
description: "print information about removed modules",
},
],
},
{
name: "verify",
description:
"check that dependencies of the main module stored in the module cache have not been modified since they were downloaded",
},
{
name: "why",
description:
"show a shortest path in the import graph from the main module to each of the listed packages",
options: [
{
name: "-m",
description: "treat its arguments as a list of modules",
},
{
name: "-vendor",
description:
"ignore imports in tests of packages outside the main module ",
},
],
args: {
name: "packages",
variadic: true,
},
},
],
},
{
name: "run",
description: "compile and run Go program",
options: [
...globalOptions,
{
name: "-exec",
description: "invoke the binary using xprog",
args: {},
},
],
args: {
name: "package",
isScript: true,
},
},
{
name: "test",
description: "test packages",
options: [
...globalOptions,
{
name: "-args",
description:
"pass the remainder of the command line to the test binary",
args: {
variadic: true,
},
},
{
name: "-c",
description: "compile the test binary to pkg.test but do not run it",
},
{
name: "-exec",
description: "invoke the binary using xprog",
args: {},
},
{
name: "-i",
description: "install packages that are dependencies of the test.",
},
{
name: "-json",
description: "convert test output to JSON suitable",
},
{
name: "-o",
description: " Compile the test binary to the named file",
args: {
name: "file",
template: "filepaths",
},
},
],
},
{
name: "tool",
description: "run specified go tool",
options: [
{
name: "-n",
description:
"print the command that would be executed but not execute it",
},
],
args: {
name: "tool",
generators: {
script: "go tool",
splitOn: "\n",
},
},
},
{
name: "version",
description: "print Go version",
options: [
{
name: "-m",
description:
"print each executable's embedded module version information",
},
{
name: "-v",
description: "report unrecognized files",
},
],
args: {
name: "file",
isOptional: true,
},
},
{
name: "vet",
description: "report likely mistakes in packages",
options: [
...resolutionAndExecutionOptions,
{
name: "-vettool",
insertValue: "-vettool=",
description:
"select a different analysis tool with alternative or additional checks",
args: {
name: "tool",
},
},
],
args: {
name: "package",
isOptional: true,
},
},
],
};