Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: downrank slice as second "append()" param #40535

Closed
muirdm opened this issue Aug 2, 2020 · 1 comment
Closed

x/tools/gopls: downrank slice as second "append()" param #40535

muirdm opened this issue Aug 2, 2020 · 1 comment

Comments

@muirdm
Copy link

@muirdm muirdm commented Aug 2, 2020

type foo struct { i int }
var bar []foo
bar = append(bar, <>)

Currently in the above example gopls prefers "bar" at "<>", but it's rare that you append a slice to itself. I think we should adjust scoring so that the literal candidate "foo{}" is ranked above "bar".

We could add a special case to downrank the first append param as the second append param, but I'm not sure the best way to do it. If we just check types.Object equality, we will incorrectly dowrank in the following case:

type foo struct { i []int }
var a, b foo
a.i = append(a.i, <>)

At "<>" we would downrank "b.i" in addition to "a.i". To avoid this we would need to use objectpath or AST/text equality check.

@gopherbot gopherbot added this to the Unreleased milestone Aug 2, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Aug 4, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 8, 2020

Change https://golang.org/cl/247519 mentions this issue: internal/lsp/source: improve completion in append()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.