aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/debug
diff options
context:
space:
mode:
authorRebecca Stambler <rstambler@golang.org>2020-03-23 22:47:52 -0400
committerRebecca Stambler <rstambler@golang.org>2020-03-24 20:15:47 +0000
commit6fc5d0bc36fc9f0458937704b7b40bbcf4ea46bc (patch)
treeadfb109cbbdf41afcdcb885d89e06f9142734280 /internal/lsp/debug
parenta5e5fedfe7429586fde86c123b10f1bc23d21a25 (diff)
downloadgolang-x-tools-6fc5d0bc36fc9f0458937704b7b40bbcf4ea46bc.tar.gz
internal/lsp: print view-specific environment
For debugging purposes, we print the output of `go env` on start. Now, we print a view-specific `go env`, which will helps us when debugging multi-project workspaces. Additional information included: the folder of the view, if the view has a valid build configuration, and the build flags for the view. Updates golang/go#37978 Change-Id: Iadffd46f8ac5410971558a304b8bbcb2f9bdbcc3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/225137 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
Diffstat (limited to 'internal/lsp/debug')
-rw-r--r--internal/lsp/debug/info.go31
-rw-r--r--internal/lsp/debug/serve.go2
2 files changed, 18 insertions, 15 deletions
diff --git a/internal/lsp/debug/info.go b/internal/lsp/debug/info.go
index 5890396c9..8baf1d932 100644
--- a/internal/lsp/debug/info.go
+++ b/internal/lsp/debug/info.go
@@ -6,10 +6,12 @@
package debug
import (
+ "context"
"fmt"
"io"
- "os/exec"
"strings"
+
+ "golang.org/x/tools/internal/gocommand"
)
type PrintMode int
@@ -24,7 +26,7 @@ const (
var Version = "master"
// PrintServerInfo writes HTML debug info to w for the Instance.
-func (i *Instance) PrintServerInfo(w io.Writer) {
+func (i *Instance) PrintServerInfo(ctx context.Context, w io.Writer) {
section(w, HTML, "Server Instance", func() {
fmt.Fprintf(w, "Start time: %v\n", i.StartTime)
fmt.Fprintf(w, "LogFile: %s\n", i.Logfile)
@@ -32,13 +34,13 @@ func (i *Instance) PrintServerInfo(w io.Writer) {
fmt.Fprintf(w, "Address: %s\n", i.ServerAddress)
fmt.Fprintf(w, "Debug address: %s\n", i.DebugAddress)
})
- PrintVersionInfo(w, true, HTML)
+ PrintVersionInfo(ctx, w, true, HTML)
}
-// PrintVersionInfo writes version and environment information to w, using the
-// output format specified by mode. verbose controls whether additional
-// information is written, including section headers.
-func PrintVersionInfo(w io.Writer, verbose bool, mode PrintMode) {
+// 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) {
if !verbose {
printBuildInfo(w, false, mode)
return
@@ -48,13 +50,14 @@ func PrintVersionInfo(w io.Writer, verbose bool, mode PrintMode) {
})
fmt.Fprint(w, "\n")
section(w, mode, "Go info", func() {
- cmd := exec.Command("go", "version")
- cmd.Stdout = w
- cmd.Run()
- fmt.Fprint(w, "\n")
- cmd = exec.Command("go", "env")
- cmd.Stdout = w
- cmd.Run()
+ i := &gocommand.Invocation{
+ Verb: "version",
+ }
+ version, err := i.Run(ctx)
+ if err != nil {
+ panic(err)
+ }
+ fmt.Fprintln(w, version.String())
})
}
diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go
index ab08e1479..783574046 100644
--- a/internal/lsp/debug/serve.go
+++ b/internal/lsp/debug/serve.go
@@ -376,7 +376,7 @@ func (i *Instance) getFile(r *http.Request) interface{} {
func (i *Instance) getInfo(r *http.Request) interface{} {
buf := &bytes.Buffer{}
- i.PrintServerInfo(buf)
+ i.PrintServerInfo(r.Context(), buf)
return template.HTML(buf.String())
}