Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201028153306-37f0764111ff / internal / lsp / cmd / info.go
1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package cmd
6
7 import (
8         "bytes"
9         "context"
10         "flag"
11         "fmt"
12         "net/url"
13         "os"
14         "strings"
15
16         "golang.org/x/tools/internal/lsp/browser"
17         "golang.org/x/tools/internal/lsp/debug"
18         "golang.org/x/tools/internal/lsp/source"
19 )
20
21 // version implements the version command.
22 type version struct {
23         app *Application
24 }
25
26 func (v *version) Name() string      { return "version" }
27 func (v *version) Usage() string     { return "" }
28 func (v *version) ShortHelp() string { return "print the gopls version information" }
29 func (v *version) DetailedHelp(f *flag.FlagSet) {
30         fmt.Fprint(f.Output(), ``)
31         f.PrintDefaults()
32 }
33
34 // Run prints version information to stdout.
35 func (v *version) Run(ctx context.Context, args ...string) error {
36         debug.PrintVersionInfo(ctx, os.Stdout, v.app.verbose(), debug.PlainText)
37         return nil
38 }
39
40 // bug implements the bug command.
41 type bug struct{}
42
43 func (b *bug) Name() string      { return "bug" }
44 func (b *bug) Usage() string     { return "" }
45 func (b *bug) ShortHelp() string { return "report a bug in gopls" }
46 func (b *bug) DetailedHelp(f *flag.FlagSet) {
47         fmt.Fprint(f.Output(), ``)
48         f.PrintDefaults()
49 }
50
51 const goplsBugPrefix = "x/tools/gopls: <DESCRIBE THE PROBLEM>"
52 const goplsBugHeader = `ATTENTION: Please answer these questions BEFORE submitting your issue. Thanks!
53
54 #### What did you do?
55 If possible, provide a recipe for reproducing the error.
56 A complete runnable program is good.
57 A link on play.golang.org is better.
58 A failing unit test is the best.
59
60 #### What did you expect to see?
61
62
63 #### What did you see instead?
64
65
66 `
67
68 // Run collects some basic information and then prepares an issue ready to
69 // be reported.
70 func (b *bug) Run(ctx context.Context, args ...string) error {
71         buf := &bytes.Buffer{}
72         fmt.Fprint(buf, goplsBugHeader)
73         debug.PrintVersionInfo(ctx, buf, true, debug.Markdown)
74         body := buf.String()
75         title := strings.Join(args, " ")
76         if !strings.HasPrefix(title, goplsBugPrefix) {
77                 title = goplsBugPrefix + title
78         }
79         if !browser.Open("https://github.com/golang/go/issues/new?title=" + url.QueryEscape(title) + "&body=" + url.QueryEscape(body)) {
80                 fmt.Print("Please file a new issue at golang.org/issue/new using this template:\n\n")
81                 fmt.Print(body)
82         }
83         return nil
84 }
85
86 type apiJSON struct{}
87
88 func (sj *apiJSON) Name() string      { return "api-json" }
89 func (sj *apiJSON) Usage() string     { return "" }
90 func (sj *apiJSON) ShortHelp() string { return "print json describing gopls API" }
91 func (sj *apiJSON) DetailedHelp(f *flag.FlagSet) {
92         fmt.Fprint(f.Output(), ``)
93         f.PrintDefaults()
94 }
95
96 func (sj *apiJSON) Run(ctx context.Context, args ...string) error {
97         fmt.Fprintf(os.Stdout, source.GeneratedAPIJSON)
98         return nil
99 }