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: edits from "extract variable" isn't ordered #47486

Closed
leitzler opened this issue Jul 31, 2021 · 1 comment
Closed

x/tools/gopls: edits from "extract variable" isn't ordered #47486

leitzler opened this issue Jul 31, 2021 · 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 devel go1.17-912f075047 Fri Jul 2 21:06:08 2021 +0000 darwin/amd64
$ go list -m golang.org/x/tools golang.org/x/tools/gopls
golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2
golang.org/x/tools/gopls v0.0.0-20210726203631-07bc1bf47fb2

What did you do?

With the following main.go and the char 1 selected I called "Extract variable":

package main

func main() {
        _ = 1 + 2
        _ = 3 + 4
}

What did you expect to see?

I expected to see the edits returned in order, so that they can be applied in reverse to maintain the offset (just like gopls does itself)

What did you see instead?

The ApplyEdit I receive when executing the command provides edits that isn't ordered:

ApplyEdit: &protocol.ApplyWorkspaceEditParams{
    Label: "",
    Edit:  protocol.WorkspaceEdit{
        Changes:         {},
        DocumentChanges: {
            {
                TextDocument: protocol.OptionalVersionedTextDocumentIdentifier{
                    Version:                1,
                    TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.WMGcjYlM/main.go"},
                },
                Edits: {
                    {
                        Range: protocol.Range{
                            Start: protocol.Position{Line:0x3, Character:0x5},
                            End:   protocol.Position{Line:0x3, Character:0x6},
                        },
                        NewText: "x",
                    },
                },
            },
            {
                TextDocument: protocol.OptionalVersionedTextDocumentIdentifier{
                    Version:                1,
                    TextDocumentIdentifier: protocol.TextDocumentIdentifier{URI:"file:///private/var/folders/j4/l2j99h6d5qd6knjlllql0bb80000gn/T/tmp.WMGcjYlM/main.go"},
                },
                Edits: {
                    {
                        Range: protocol.Range{
                            Start: protocol.Position{Line:0x3, Character:0x1},
                            End:   protocol.Position{Line:0x3, Character:0x1},
                        },
                        NewText: "x := 1\n\t",
                    },
                },
            },
        },
        ChangeAnnotations: {},
    },
}

When a client receives the edits out of order it introduce unnecessary ambiguity.

@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 31, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jul 31, 2021
@gopherbot
Copy link

Change https://golang.org/cl/338869 mentions this issue: internal/lsp: send "extract variable" edits ordered

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.7.2 Aug 2, 2021
@golang golang locked and limited conversation to collaborators Aug 2, 2022
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