Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / internal / lsp / debug / 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 debug exports debug information for gopls.
6 package debug
7
8 import (
9         "context"
10         "fmt"
11         "io"
12         "strings"
13 )
14
15 type PrintMode int
16
17 const (
18         PlainText = PrintMode(iota)
19         Markdown
20         HTML
21 )
22
23 // Version is a manually-updated mechanism for tracking versions.
24 var Version = "master"
25
26 // PrintServerInfo writes HTML debug info to w for the Instance.
27 func (i *Instance) PrintServerInfo(ctx context.Context, w io.Writer) {
28         section(w, HTML, "Server Instance", func() {
29                 fmt.Fprintf(w, "Start time: %v\n", i.StartTime)
30                 fmt.Fprintf(w, "LogFile: %s\n", i.Logfile)
31                 fmt.Fprintf(w, "Working directory: %s\n", i.Workdir)
32                 fmt.Fprintf(w, "Address: %s\n", i.ServerAddress)
33                 fmt.Fprintf(w, "Debug address: %s\n", i.DebugAddress)
34         })
35         PrintVersionInfo(ctx, w, true, HTML)
36 }
37
38 // PrintVersionInfo writes version information to w, using the output format
39 // specified by mode. verbose controls whether additional information is
40 // written, including section headers.
41 func PrintVersionInfo(ctx context.Context, w io.Writer, verbose bool, mode PrintMode) {
42         if !verbose {
43                 printBuildInfo(w, false, mode)
44                 return
45         }
46         section(w, mode, "Build info", func() {
47                 printBuildInfo(w, true, mode)
48         })
49 }
50
51 func section(w io.Writer, mode PrintMode, title string, body func()) {
52         switch mode {
53         case PlainText:
54                 fmt.Fprintln(w, title)
55                 fmt.Fprintln(w, strings.Repeat("-", len(title)))
56                 body()
57         case Markdown:
58                 fmt.Fprintf(w, "#### %s\n\n```\n", title)
59                 body()
60                 fmt.Fprintf(w, "```\n")
61         case HTML:
62                 fmt.Fprintf(w, "<h3>%s</h3>\n<pre>\n", title)
63                 body()
64                 fmt.Fprint(w, "</pre>\n")
65         }
66 }