gopls/internal/lsp: add min/max builtin

For golang/go#59488

Change-Id: I43d9a5b644a9c3ce647a11f9e2b647093b070c9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/498515
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
diff --git a/gopls/internal/lsp/completion_test.go b/gopls/internal/lsp/completion_test.go
index 1fc7304..bef5e11 100644
--- a/gopls/internal/lsp/completion_test.go
+++ b/gopls/internal/lsp/completion_test.go
@@ -25,8 +25,8 @@
 		opts.LiteralCompletions = strings.Contains(string(src.URI()), "literal")
 		opts.ExperimentalPostfixCompletions = strings.Contains(string(src.URI()), "postfix")
 	})
-	got = tests.FilterBuiltins(src, got)
-	want := expected(t, test, items)
+	got = filterSkipCompletionItems(tests.FilterBuiltins(src, got))
+	want := filterSkipCompletionItems(expected(t, test, items))
 	if diff := tests.DiffCompletionItems(want, got); diff != "" {
 		t.Errorf("mismatching completion items (-want +got):\n%s", diff)
 	}
@@ -175,3 +175,16 @@
 	}
 	return list.Items
 }
+
+func filterSkipCompletionItems(items []protocol.CompletionItem) []protocol.CompletionItem {
+	n := 0
+	for _, item := range items {
+		// TODO(cuonglm): remove once https://go-review.googlesource.com/c/go/+/498495 land.
+		if item.Label == "max" || item.Label == "min" {
+			continue
+		}
+		items[n] = item
+		n++
+	}
+	return items[:n]
+}
diff --git a/gopls/internal/lsp/testdata/builtins/builtin_go121.go b/gopls/internal/lsp/testdata/builtins/builtin_go121.go
index cb8e8fa..a52d168 100644
--- a/gopls/internal/lsp/testdata/builtins/builtin_go121.go
+++ b/gopls/internal/lsp/testdata/builtins/builtin_go121.go
@@ -4,5 +4,5 @@
 package builtins
 
 func _() {
-	//@complete("", any, append, bool, byte, cap, clear, close, comparable, complex, complex128, complex64, copy, delete, error, _false, float32, float64, imag, int, int16, int32, int64, int8, len, make, new, panic, print, println, real, recover, rune, string, _true, uint, uint16, uint32, uint64, uint8, uintptr, _nil)
+	//@complete("", any, append, bool, byte, cap, clear, close, comparable, complex, complex128, complex64, copy, delete, error, _false, float32, float64, imag, int, int16, int32, int64, int8, len, make, max, min, new, panic, print, println, real, recover, rune, string, _true, uint, uint16, uint32, uint64, uint8, uintptr, _nil)
 }
diff --git a/gopls/internal/lsp/testdata/builtins/builtins.go b/gopls/internal/lsp/testdata/builtins/builtins.go
index 75c6e41..47fa682 100644
--- a/gopls/internal/lsp/testdata/builtins/builtins.go
+++ b/gopls/internal/lsp/testdata/builtins/builtins.go
@@ -28,6 +28,8 @@
 /* int8 */ //@item(int8, "int8", "", "type")
 /* iota */ //@item(iota, "iota", "", "const")
 /* len(v Type) int */ //@item(len, "len", "func(v Type) int", "func")
+/* max(x Type, y ...Type) Type */ //@item(max, "max", "func(x Type, y ...Type) Type", "func")
+/* min(y Type, y ...Type) Type */ //@item(min, "min", "func(y Type, y ...Type) Type", "func")
 /* make(t Type, size ...int) Type */ //@item(make, "make", "func(t Type, size ...int) Type", "func")
 /* new(Type) *Type */ //@item(new, "new", "func(Type) *Type", "func")
 /* nil */ //@item(_nil, "nil", "", "var")
diff --git a/gopls/internal/lsp/tests/util_go121.go b/gopls/internal/lsp/tests/util_go121.go
index 9306586..c5b2278 100644
--- a/gopls/internal/lsp/tests/util_go121.go
+++ b/gopls/internal/lsp/tests/util_go121.go
@@ -9,4 +9,6 @@
 
 func init() {
 	builtins["clear"] = true
+	builtins["max"] = true
+	builtins["min"] = true
 }