From c39ce2148d8ec966a8dff2790a54aa704dd38457 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 16 Dec 2019 19:35:09 -0500 Subject: [PATCH] internal/lsp: expose option to disable timeouts for completion This is useful for integration testing. Fixes golang/go#36142 Change-Id: I175510df19f384a0a027267337925ebae15ef827 Reviewed-on: https://go-review.googlesource.com/c/tools/+/211584 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- internal/lsp/source/options.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index 1c378ead69..1a1bbe5390 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -250,6 +250,10 @@ func (o *Options) set(name string, value interface{}) OptionResult { result.setBool(&o.Completion.CaseSensitive) case "completeUnimported": result.setBool(&o.Completion.Unimported) + case "completionTimeout": + if v, ok := result.asInt(); ok { + o.Completion.Budget = time.Duration(v) * time.Second + } case "hoverKind": hoverKind, ok := value.(string) @@ -347,6 +351,15 @@ func (r *OptionResult) asBool() (bool, bool) { return b, true } +func (r *OptionResult) asInt() (int, bool) { + b, ok := r.Value.(int) + if !ok { + r.errorf("Invalid type %T for int option %q", r.Value, r.Name) + return 0, false + } + return b, true +} + func (r *OptionResult) setBool(b *bool) { if v, ok := r.asBool(); ok { *b = v