Skip to content

Commit 33c741d

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]>
1 parent 933c7cc commit 33c741d

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

gopls/internal/lsp/completion_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
2525
opts.LiteralCompletions = strings.Contains(string(src.URI()), "literal")
2626
opts.ExperimentalPostfixCompletions = strings.Contains(string(src.URI()), "postfix")
2727
})
28-
got = tests.FilterBuiltins(src, got)
29-
want := expected(t, test, items)
28+
got = filterSkipCompletionItems(tests.FilterBuiltins(src, got))
29+
want := filterSkipCompletionItems(expected(t, test, items))
3030
if diff := tests.DiffCompletionItems(want, got); diff != "" {
3131
t.Errorf("mismatching completion items (-want +got):\n%s", diff)
3232
}
@@ -175,3 +175,16 @@ func (r *runner) callCompletion(t *testing.T, src span.Span, options func(*sourc
175175
}
176176
return list.Items
177177
}
178+
179+
func filterSkipCompletionItems(items []protocol.CompletionItem) []protocol.CompletionItem {
180+
n := 0
181+
for _, item := range items {
182+
// TODO(cuonglm): remove once https://go-review.googlesource.com/c/go/+/498495 land.
183+
if item.Label == "max" || item.Label == "min" {
184+
continue
185+
}
186+
items[n] = item
187+
n++
188+
}
189+
return items[:n]
190+
}

gopls/internal/lsp/testdata/builtins/builtin_go121.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
package builtins
55

66
func _() {
7-
//@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)
7+
//@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)
88
}

gopls/internal/lsp/testdata/builtins/builtins.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ package builtins
2828
/* int8 */ //@item(int8, "int8", "", "type")
2929
/* iota */ //@item(iota, "iota", "", "const")
3030
/* len(v Type) int */ //@item(len, "len", "func(v Type) int", "func")
31+
/* max(x Type, y ...Type) Type */ //@item(max, "max", "func(x Type, y ...Type) Type", "func")
32+
/* min(y Type, y ...Type) Type */ //@item(min, "min", "func(y Type, y ...Type) Type", "func")
3133
/* make(t Type, size ...int) Type */ //@item(make, "make", "func(t Type, size ...int) Type", "func")
3234
/* new(Type) *Type */ //@item(new, "new", "func(Type) *Type", "func")
3335
/* nil */ //@item(_nil, "nil", "", "var")

gopls/internal/lsp/tests/util_go121.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ package tests
99

1010
func init() {
1111
builtins["clear"] = true
12+
builtins["max"] = true
13+
builtins["min"] = true
1214
}

0 commit comments

Comments
 (0)