-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp: improve completion in append() calls
Add a special case for append() arguments so we infer the expected type from the append() context. For example: var foo []int foo = append(<>) We now infer the expected type at <> to be []int. We also support the variadicity of append(). Change-Id: Ie0ef0007907fcb7992f9697cb90970ce4d9a66b8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/205606 Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
- Loading branch information
1 parent
7d206e1
commit 97ad0ed
Showing
3 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package append | ||
|
||
func foo([]string) {} | ||
func bar(...string) {} | ||
|
||
func _() { | ||
var ( | ||
aInt []int //@item(appendInt, "aInt", "[]int", "var") | ||
aStrings []string //@item(appendStrings, "aStrings", "[]string", "var") | ||
aString string //@item(appendString, "aString", "string", "var") | ||
) | ||
|
||
foo(append()) //@rank("))", appendStrings, appendInt),rank("))", appendStrings, appendString) | ||
foo(append(nil, a)) //@rank("))", appendStrings, appendInt),rank("))", appendString, appendInt),snippet("))", appendStrings, "aStrings...", "aStrings...") | ||
foo(append(nil, "", a)) //@rank("))", appendString, appendInt),rank("))", appendString, appendStrings) | ||
|
||
// Don't add "..." to append() argument. | ||
bar(append()) //@snippet("))", appendStrings, "aStrings", "aStrings") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters