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 5package cmd 6 7import ( 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) 19 20// version implements the version command. 21type version struct { 22 app *Application 23} 24 25func (v *version) Name() string { return "version" } 26func (v *version) Usage() string { return "" } 27func (v *version) ShortHelp() string { return "print the gopls version information" } 28func (v *version) DetailedHelp(f *flag.FlagSet) { 29 fmt.Fprint(f.Output(), ``) 30 f.PrintDefaults() 31} 32 33// Run prints version information to stdout. 34func (v *version) Run(ctx context.Context, args ...string) error { 35 debug.PrintVersionInfo(os.Stdout, v.app.Verbose, debug.PlainText) 36 return nil 37} 38 39// bug implements the bug command. 40type bug struct{} 41 42func (b *bug) Name() string { return "bug" } 43func (b *bug) Usage() string { return "" } 44func (b *bug) ShortHelp() string { return "report a bug in gopls" } 45func (b *bug) DetailedHelp(f *flag.FlagSet) { 46 fmt.Fprint(f.Output(), ``) 47 f.PrintDefaults() 48} 49 50const goplsBugPrefix = "x/tools/gopls: " 51const goplsBugHeader = `Please answer these questions before submitting your issue. Thanks! 52 53#### What did you do? 54If possible, provide a recipe for reproducing the error. 55A complete runnable program is good. 56A link on play.golang.org is better. 57A failing unit test is the best. 58 59#### What did you expect to see? 60 61 62#### What did you see instead? 63 64 65` 66 67// Run collects some basic information and then prepares an issue ready to 68// be reported. 69func (b *bug) Run(ctx context.Context, args ...string) error { 70 buf := &bytes.Buffer{} 71 fmt.Fprint(buf, goplsBugHeader) 72 debug.PrintVersionInfo(buf, true, debug.Markdown) 73 body := buf.String() 74 title := strings.Join(args, " ") 75 if !strings.HasPrefix(title, goplsBugPrefix) { 76 title = goplsBugPrefix + title 77 } 78 if !browser.Open("https://github.com/golang/go/issues/new?title=" + url.QueryEscape(title) + "&body=" + url.QueryEscape(body)) { 79 fmt.Print("Please file a new issue at golang.org/issue/new using this template:\n\n") 80 fmt.Print(body) 81 } 82 return nil 83} 84