2019-05-29 17:58:27 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-10-02 12:45:55 -06:00
|
|
|
// Package debug exports debug information for gopls.
|
2019-05-29 17:58:27 -06:00
|
|
|
package debug
|
|
|
|
|
|
|
|
import (
|
2020-03-23 20:47:52 -06:00
|
|
|
"context"
|
2019-05-29 17:58:27 -06:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
2020-03-23 20:47:52 -06:00
|
|
|
|
|
|
|
"golang.org/x/tools/internal/gocommand"
|
2019-05-29 17:58:27 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type PrintMode int
|
|
|
|
|
|
|
|
const (
|
|
|
|
PlainText = PrintMode(iota)
|
|
|
|
Markdown
|
|
|
|
HTML
|
|
|
|
)
|
|
|
|
|
2019-06-07 13:55:45 -06:00
|
|
|
// Version is a manually-updated mechanism for tracking versions.
|
2019-11-04 10:37:03 -07:00
|
|
|
var Version = "master"
|
2019-06-07 13:55:45 -06:00
|
|
|
|
2020-02-06 06:27:27 -07:00
|
|
|
// PrintServerInfo writes HTML debug info to w for the Instance.
|
2020-03-23 20:47:52 -06:00
|
|
|
func (i *Instance) PrintServerInfo(ctx context.Context, w io.Writer) {
|
2020-01-14 16:58:59 -07:00
|
|
|
section(w, HTML, "Server Instance", func() {
|
2020-02-06 06:27:27 -07:00
|
|
|
fmt.Fprintf(w, "Start time: %v\n", i.StartTime)
|
|
|
|
fmt.Fprintf(w, "LogFile: %s\n", i.Logfile)
|
|
|
|
fmt.Fprintf(w, "Working directory: %s\n", i.Workdir)
|
|
|
|
fmt.Fprintf(w, "Address: %s\n", i.ServerAddress)
|
|
|
|
fmt.Fprintf(w, "Debug address: %s\n", i.DebugAddress)
|
2020-01-14 16:58:59 -07:00
|
|
|
})
|
2020-03-23 20:47:52 -06:00
|
|
|
PrintVersionInfo(ctx, w, true, HTML)
|
2020-01-14 16:58:59 -07:00
|
|
|
}
|
|
|
|
|
2020-03-23 20:47:52 -06:00
|
|
|
// PrintVersionInfo writes version information to w, using the output format
|
|
|
|
// specified by mode. verbose controls whether additional information is
|
|
|
|
// written, including section headers.
|
|
|
|
func PrintVersionInfo(ctx context.Context, w io.Writer, verbose bool, mode PrintMode) {
|
2019-05-29 17:58:27 -06:00
|
|
|
if !verbose {
|
|
|
|
printBuildInfo(w, false, mode)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
section(w, mode, "Build info", func() {
|
|
|
|
printBuildInfo(w, true, mode)
|
|
|
|
})
|
|
|
|
fmt.Fprint(w, "\n")
|
|
|
|
section(w, mode, "Go info", func() {
|
2020-03-23 20:47:52 -06:00
|
|
|
i := &gocommand.Invocation{
|
|
|
|
Verb: "version",
|
|
|
|
}
|
|
|
|
version, err := i.Run(ctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, version.String())
|
2019-05-29 17:58:27 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func section(w io.Writer, mode PrintMode, title string, body func()) {
|
|
|
|
switch mode {
|
|
|
|
case PlainText:
|
|
|
|
fmt.Fprintln(w, title)
|
|
|
|
fmt.Fprintln(w, strings.Repeat("-", len(title)))
|
|
|
|
body()
|
|
|
|
case Markdown:
|
|
|
|
fmt.Fprintf(w, "#### %s\n\n```\n", title)
|
|
|
|
body()
|
|
|
|
fmt.Fprintf(w, "```\n")
|
|
|
|
case HTML:
|
|
|
|
fmt.Fprintf(w, "<h3>%s</h3>\n<pre>\n", title)
|
|
|
|
body()
|
|
|
|
fmt.Fprint(w, "</pre>\n")
|
|
|
|
}
|
|
|
|
}
|