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 <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go
index 28d6915..15a4363 100644
--- a/internal/lsp/cmd/cmd.go
+++ b/internal/lsp/cmd/cmd.go
@@ -57,12 +57,15 @@
 	// 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 @@
 	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 @@
 	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 @@
 			}
 			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 @@
 				"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 995640c..8c013de 100644
--- a/internal/lsp/cmd/info.go
+++ b/internal/lsp/cmd/info.go
@@ -32,7 +32,7 @@
 
 // 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
 }