From ea203083f5768a3d06cd6a3886ae25da58785b50 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Sun, 3 Nov 2019 18:09:58 -0800 Subject: [PATCH] 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 Reviewed-by: Rebecca Stambler Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cache/view.go | 6 ++++-- internal/lsp/source/options.go | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index ae3c9a5e29..1488a368bb 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -128,7 +128,9 @@ func (v *view) Config(ctx context.Context) *packages.Config { 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 @@ func (v *view) buildProcessEnv(ctx context.Context) (*imports.ProcessEnv, error) 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 b69d9faf68..c45d034b79 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -108,6 +108,8 @@ type Options struct { // LocalPrefix is used to specify goimports's -local behavior. LocalPrefix string + + VerboseOutput bool } type CompletionOptions struct { @@ -289,6 +291,9 @@ func (o *Options) set(name string, value interface{}) OptionResult { } o.LocalPrefix = localPrefix + case "verboseOutput": + result.setBool(&o.VerboseOutput) + // Deprecated settings. case "wantSuggestedFixes": result.State = OptionDeprecated