Skip to content

x/tools/gopls: consider disambiguating same-score completion candidates using candidate length #40262

Open
@muirdm

Description

@muirdm

Currently completion candidates are sorted by score, and then secondarily sorted lexicographically to provide a predictable order. I propose we instead do a secondary sort by candidate length, preferring shorter candidates. My intuition is that shorter names are used more frequently than longer names, so it is a somewhat better heuristic to put shorter items first, all else being equal.

Edit: Note that this proposal only comes in to play when candidates have identical scores. Currently the tie-break sorting is alphabetical; I'm proposing we switch to a potentially better heuristic. This will have a very small impact in general.

Contrived example:

package main

type myStr struct {
	s string
}

func (m myStr) Get() string {
	return m.s
}

type foo struct {
	ID         myStr
	AardvarkID myStr
}

func main() {
	var f foo
	var _ string = f      // want "f.ID.s" but got "f.AardvarkID.s"
	var _ string = fidget // want "f.ID.Get()" but got "f.AardvarkID.Get()"
}

/cc @heschik because you had an opinion in slack

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis 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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions