internal/lsp: add config flag to hide debugging output

Add a new "verboseOutput" config flag (defaults to "false") to enable
verbose go/packages and imports output. Previously this output was
always present.

The go/packages output would dump out the entire (humongous) "go list"
JSON response which would lock up my editor for a second whenever
something triggered a go/packages call.

The imports output would produce a bunch of "gopathwalk" debug
messages that aren't useful in general and in particular add noisy
output to tests.

Change-Id: Ie4693d074cb84f1397e0e51d7346dc9391bd1278
Reviewed-on: https://go-review.googlesource.com/c/tools/+/205138
Reviewed-by: Koichi Shiraishi <zchee.io@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go
index ae3c9a5..1488a36 100644
--- a/internal/lsp/cache/view.go
+++ b/internal/lsp/cache/view.go
@@ -128,7 +128,9 @@
 			panic("go/packages must not be used to parse files")
 		},
 		Logf: func(format string, args ...interface{}) {
-			log.Print(ctx, fmt.Sprintf(format, args...))
+			if v.options.VerboseOutput {
+				log.Print(ctx, fmt.Sprintf(format, args...))
+			}
 		},
 		Tests: true,
 	}
@@ -186,7 +188,7 @@
 			log.Print(ctx, fmt.Sprintf(format, args...))
 		},
 		LocalPrefix: v.options.LocalPrefix,
-		Debug:       true,
+		Debug:       v.options.VerboseOutput,
 	}
 	for _, kv := range cfg.Env {
 		split := strings.Split(kv, "=")
diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go
index b69d9fa..c45d034 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -108,6 +108,8 @@
 
 	// LocalPrefix is used to specify goimports's -local behavior.
 	LocalPrefix string
+
+	VerboseOutput bool
 }
 
 type CompletionOptions struct {
@@ -289,6 +291,9 @@
 		}
 		o.LocalPrefix = localPrefix
 
+	case "verboseOutput":
+		result.setBool(&o.VerboseOutput)
+
 	// Deprecated settings.
 	case "wantSuggestedFixes":
 		result.State = OptionDeprecated