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: ambiguous fillstruct commands returned by code action #40328

Closed
leitzler opened this issue Jul 21, 2020 · 1 comment
Closed

x/tools/gopls: ambiguous fillstruct commands returned by code action #40328

leitzler opened this issue Jul 21, 2020 · 1 comment
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@leitzler
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.14.6 darwin/amd64
$ go list -m golang.org/x/tools golang.org/x/tools/gopls
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a
golang.org/x/tools/gopls v0.0.0-20200721032237-77f530d86f9a

What did you do?

Called CodeAction() - refactor.rewrite with the following code:

package main

type foo struct {
    i int
}

func fn(a, b foo) {}

func main() {
    fn(foo{}, foo{}) // <- cursor on this line
}

What did you expect to see?

Two different commands returned so that the user (and gopls) can tell them apart.

What did you see instead?

The different command arguments includes the same range, and since the structs has the same name there is no way to tell them apart.

[]protocol.CodeAction{
    {
        Title:       "Fill foo with default values",
        Kind:        "refactor.rewrite",
        Diagnostics: nil,
        IsPreferred: false,
        Edit:        protocol.WorkspaceEdit{},
        Command:     &protocol.Command{
            Title:     "Fill foo with default values",
            Command:   "fill_struct",
            Arguments: {
                "{\"uri\":\"file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.YunKS0j1/main.go\",\"range\":{\"start\":{\"line\":9,\"character\":2},\"end\":{\"line\":9,\"character\":2}}}",
            },
        },
    },
    {
        Title:       "Fill foo with default values",
        Kind:        "refactor.rewrite",
        Diagnostics: nil,
        IsPreferred: false,
        Edit:        protocol.WorkspaceEdit{},
        Command:     &protocol.Command{
            Title:     "Fill foo with default values",
            Command:   "fill_struct",
            Arguments: {
                "{\"uri\":\"file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.YunKS0j1/main.go\",\"range\":{\"start\":{\"line\":9,\"character\":2},\"end\":{\"line\":9,\"character\":2}}}",
            },
        },
    },
}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 21, 2020
@gopherbot gopherbot added this to the Unreleased milestone Jul 21, 2020
@gopherbot
Copy link

Change https://golang.org/cl/243877 mentions this issue: internal/lsp: return the actual range from convenience code actions

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.4 Jul 21, 2020
@golang golang locked and limited conversation to collaborators Jul 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants