1
0
mirror of https://github.com/golang/go synced 2024-10-01 16:08:33 -06:00
go/internal/lsp/testdata/channel/channel.go
Muir Manders 3721262b3e internal/lsp: support taking address for completion candidates
We now support taking the address of objects to make better completion
candidates. For example:

i := 123
var p *int = <> // now you get a candidate for "&i"

This required that we track addressability better, particularly when
searching for deep candidates. Now each candidate knows if it is
addressable, and the deep search propagates addressability to child
candidates appropriately.

The basic propagation logic is:

- In-scope *types.Var candidates are addressable. This handles your
  basic "foo" variable whose address if "&foo".

- Surrounding selector is addressable based on type checker info. This
  knows "foo.bar.<>" is addressable but "foo.bar().<>" isn't

- When evaluating deep completions, fields after a function call lose
  addressability, but fields after a pointer regain addressability. For
  example, "foo.bar()" isn't addressable, but "foo.bar().baz" is
  addressable if "bar()" returns a pointer.

Fixes golang/go#36132.

Change-Id: I6a8659eb8c203262aedf86844ac39a2d1e81ecc4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212399
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-23 23:54:10 +00:00

26 lines
581 B
Go

package channel
func _() {
var (
aa = "123" //@item(channelAA, "aa", "string", "var")
ab = 123 //@item(channelAB, "ab", "int", "var")
)
{
type myChan chan int
var mc myChan
mc <- a //@complete(" //", channelAB, channelAA)
}
{
var ac chan int //@item(channelAC, "ac", "chan int", "var")
a <- a //@complete(" <-", channelAC, channelAA, channelAB)
}
{
var foo chan int //@item(channelFoo, "foo", "chan int", "var")
wantsInt := func(int) {} //@item(channelWantsInt, "wantsInt", "func(int)", "var")
wantsInt(<-) //@rank(")", channelFoo, channelAB)
}
}