Skip to content

Commit

Permalink
gopls/internal/lsp: add min/max builtin
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cuonglm authored and gopherbot committed May 30, 2023
1 parent 933c7cc commit 33c741d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions gopls/internal/lsp/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (r *runner) Completion(t *testing.T, src span.Span, test tests.Completion,
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)
}
Expand Down Expand Up @@ -175,3 +175,16 @@ func (r *runner) callCompletion(t *testing.T, src span.Span, options func(*sourc
}
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]
}
2 changes: 1 addition & 1 deletion gopls/internal/lsp/testdata/builtins/builtin_go121.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions gopls/internal/lsp/testdata/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ package builtins
/* 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")
Expand Down
2 changes: 2 additions & 0 deletions gopls/internal/lsp/tests/util_go121.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ package tests

func init() {
builtins["clear"] = true
builtins["max"] = true
builtins["min"] = true
}

0 comments on commit 33c741d

Please sign in to comment.