Skip to content

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

@muirdm

Description

@muirdm
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions