internal/lsp/source/completion: use c.matcher for comments

This change adds calls to c.matcher.score for commment completion so
comments match the prefix (or fuzzy match depending on user settings)
and don't end up giving the user too many irrelevant suggestions.

Change-Id: Ie660f82c491c17d52e68e781a812bf8053e501f8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258322
Trust: Danish Dua <danishdua@google.com>
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/lsp/source/completion/completion.go b/internal/lsp/source/completion/completion.go
index bd157e6..7140374 100644
--- a/internal/lsp/source/completion/completion.go
+++ b/internal/lsp/source/completion/completion.go
@@ -859,6 +859,9 @@
 							continue
 						}
 						obj := c.pkg.GetTypesInfo().ObjectOf(name)
+						if matchScore := c.matcher.Score(name.String()); matchScore <= 0 {
+							continue
+						}
 						c.deepState.enqueue(candidate{obj: obj, score: stdScore})
 					}
 				case *ast.TypeSpec:
@@ -878,6 +881,9 @@
 					}
 
 					obj := c.pkg.GetTypesInfo().ObjectOf(spec.Name)
+					if matchScore := c.matcher.Score(obj.Name()); matchScore <= 0 {
+						continue
+					}
 					// Type name should get a higher score than fields but not highScore by default
 					// since field near a comment cursor gets a highScore
 					score := stdScore * 1.1
@@ -924,6 +930,9 @@
 							// use c.item here to ensure scoring order is
 							// maintained. deepSearch manipulates the score so
 							// we can't enqueue the items directly.
+							if matchScore := c.matcher.Score(field.Name()); matchScore <= 0 {
+								continue
+							}
 							item, err := c.item(ctx, candidate{obj: field, name: field.Name(), score: lowScore})
 							if err != nil {
 								continue
@@ -943,6 +952,9 @@
 				continue
 			}
 
+			if matchScore := c.matcher.Score(obj.Name()); matchScore <= 0 {
+				continue
+			}
 			// We don't want to expandFuncCall inside comments. deepSearch
 			// doesn't respect this setting so we don't enqueue the item here.
 			item, err := c.item(ctx, candidate{
@@ -1016,6 +1028,10 @@
 				continue
 			}
 
+			if matchScore := c.matcher.Score(obj.Name()); matchScore <= 0 {
+				continue
+			}
+
 			// if we're in a field comment/doc, score that field as more relevant
 			score := stdScore
 			if field.Comment != nil && field.Comment.Pos() <= cursor && cursor <= field.Comment.End() {