From 6f9e13bbec44ce9d95b8776df8ef7466fc76bcb0 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Tue, 17 Dec 2019 19:12:17 -0800 Subject: [PATCH] internal/lsp/debug: print the debug port Print the debug port to stderr when the debug server listens on a dynamic port so that clients can determine which port to use when launching a browser to the debug view. Change-Id: I92f5e334df5cefdf54f7242ac2328b026852c70e Reviewed-on: https://go-review.googlesource.com/c/tools/+/211798 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/debug/serve.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/lsp/debug/serve.go b/internal/lsp/debug/serve.go index c62a5256ce..9644569385 100644 --- a/internal/lsp/debug/serve.go +++ b/internal/lsp/debug/serve.go @@ -9,6 +9,7 @@ import ( "context" "go/token" "html/template" + stdlog "log" "net" "net/http" "net/http/pprof" @@ -16,6 +17,7 @@ import ( "path" "runtime" "strconv" + "strings" "sync" "golang.org/x/tools/internal/span" @@ -214,7 +216,12 @@ func Serve(ctx context.Context, addr string) error { if err != nil { return err } - log.Print(ctx, "Debug serving", tag.Of("Port", listener.Addr().(*net.TCPAddr).Port)) + + port := listener.Addr().(*net.TCPAddr).Port + if strings.HasSuffix(addr, ":0") { + stdlog.Printf("debug server listening on port %d", port) + } + log.Print(ctx, "Debug serving", tag.Of("Port", port)) prometheus := prometheus.New() rpcs := &rpcs{} traces := &traces{}