From 7342f9734a7d34afdb2645e0ef18eca666acfc4e Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 9 Jul 2020 19:16:55 -0400 Subject: [PATCH] internal/lsp/cmd: add a -vv flag for higher verbosity Add a higher log level for the command-line. This uses the verboseOutput setting. Updates golang/go#40139 Change-Id: I9b7edcda12b0431058c9cfe1413b7c5fc016c026 Reviewed-on: https://go-review.googlesource.com/c/tools/+/241857 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Robert Findley --- internal/lsp/cmd/cmd.go | 23 +++++++++++++++++------ internal/lsp/cmd/info.go | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index 28d69159f8..15a4363ce5 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -57,12 +57,15 @@ type Application struct { // The environment variables to use. env []string - // Support for remote lsp server + // Support for remote LSP server. Remote string `flag:"remote" help:"forward all commands to a remote lsp specified by this flag. With no special prefix, this is assumed to be a TCP address. If prefixed by 'unix;', the subsequent address is assumed to be a unix domain socket. If 'auto', or prefixed by 'auto;', the remote address is automatically resolved based on the executing environment."` - // Enable verbose logging + // Verbose enables verbose logging. Verbose bool `flag:"v" help:"verbose output"` + // VeryVerbose enables a higher level of verbosity in logging output. + VeryVerbose bool `flag:"vv" help:"very verbose output"` + // Control ocagent export of telemetry OCAgent string `flag:"ocagent" help:"the address of the ocagent (e.g. http://localhost:55678), or off"` @@ -71,6 +74,10 @@ type Application struct { PrepareOptions func(*source.Options) } +func (a *Application) verbose() bool { + return a.Verbose || a.VeryVerbose +} + // New returns a new Application ready to run. func New(name, wd string, env []string, options func(*source.Options)) *Application { if wd == "" { @@ -339,15 +346,15 @@ func (c *cmdClient) LogMessage(ctx context.Context, p *protocol.LogMessageParams case protocol.Warning: log.Print("Warning:", p.Message) case protocol.Info: - if c.app.Verbose { + if c.app.verbose() { log.Print("Info:", p.Message) } case protocol.Log: - if c.app.Verbose { + if c.app.verbose() { log.Print("Log:", p.Message) } default: - if c.app.Verbose { + if c.app.verbose() { log.Print(p.Message) } } @@ -382,7 +389,7 @@ func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ParamConfigur } env[l[0]] = l[1] } - results[i] = map[string]interface{}{ + m := map[string]interface{}{ "env": env, "analyses": map[string]bool{ "fillreturns": true, @@ -391,6 +398,10 @@ func (c *cmdClient) Configuration(ctx context.Context, p *protocol.ParamConfigur "undeclaredname": true, }, } + if c.app.VeryVerbose { + m["verboseOutput"] = true + } + results[i] = m } return results, nil } diff --git a/internal/lsp/cmd/info.go b/internal/lsp/cmd/info.go index 995640c712..8c013dec93 100644 --- a/internal/lsp/cmd/info.go +++ b/internal/lsp/cmd/info.go @@ -32,7 +32,7 @@ func (v *version) DetailedHelp(f *flag.FlagSet) { // Run prints version information to stdout. func (v *version) Run(ctx context.Context, args ...string) error { - debug.PrintVersionInfo(ctx, os.Stdout, v.app.Verbose, debug.PlainText) + debug.PrintVersionInfo(ctx, os.Stdout, v.app.verbose(), debug.PlainText) return nil }