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
Milestone

Comments

@leitzler
Copy link
Contributor

@leitzler leitzler commented Jul 21, 2020

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 this to the Unreleased milestone Jul 21, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 21, 2020

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

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.