internal/lsp/source/completion: use a minimum budget of 10ms for shallow completions

Type-checking can be very expensive for large packages and leave no
budget for shallow completions. This change adds a minimum budget of
10ms so we show the user at least some shallow suggestions.

Updates golang/go#41434

Change-Id: If2ef59c3fbdcfa2ebaabb21256cf606a4f9c14d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262347
Trust: Danish Dua <danishdua@google.com>
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/internal/lsp/source/completion/completion.go b/internal/lsp/source/completion/completion.go
index 8cee897..417b287 100644
--- a/internal/lsp/source/completion/completion.go
+++ b/internal/lsp/source/completion/completion.go
@@ -527,7 +527,13 @@
 	if c.opts.budget == 0 {
 		ctx, cancel = context.WithCancel(ctx)
 	} else {
-		ctx, cancel = context.WithDeadline(ctx, c.startTime.Add(c.opts.budget))
+		// timeoutDuration is the completion budget remaining. If less than
+		// 10ms, set to 10ms
+		timeoutDuration := time.Until(c.startTime.Add(c.opts.budget))
+		if timeoutDuration < 10*time.Millisecond {
+			timeoutDuration = 10 * time.Millisecond
+		}
+		ctx, cancel = context.WithTimeout(ctx, timeoutDuration)
 	}
 	defer cancel()