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

Rename on multiple files failing with latest stable #6654

Closed
E-ricus opened this issue Nov 27, 2020 · 7 comments · Fixed by gluon-lang/lsp-types#191 or #6690
Closed

Rename on multiple files failing with latest stable #6654

E-ricus opened this issue Nov 27, 2020 · 7 comments · Fixed by gluon-lang/lsp-types#191 or #6690

Comments

@E-ricus
Copy link

E-ricus commented Nov 27, 2020

With 2020-11-23 rust analyzer stable release, the rename of an element with references on multiple files is failing
I have to open the files of all references before calling the rename
I though it was a client error on coc-rust-analyzer: fannheyward/coc-rust-analyzer#482
But testing it on vscode I receive a similar error

Unknown workspace edit change received: { "edits": [ { "newText": "CompanyServicea", "range": { "end": { "character": 49, "line": 3 }, "start": { "character": 35, "line": 3 } } } ], "textDocument": { "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/lib.rs" } }

Steps to reproduce:

  • Have an element (function, struct, etc...) that has references on different un open files
  • Call rename on the element

Opening each file manually, then the rename works

Tested on:
Os: macOS Catalina and manjaro-linux
Clients: vscode with rust-analyzer plugin, neovim with coc-rust-anlyzer

@jhpratt
Copy link
Member

jhpratt commented Nov 28, 2020

Confirming on Ubuntu 20.10 with VS Code (stable).

@Veykril
Copy link
Member

Veykril commented Nov 28, 2020

Also happens on current nightly, can also confirm that the previous stable release doesn't trigger this problem(VsCode). It instead properly opens all edited files with the edits applied.
So the problem got introduced somewhere in the last week.

#6566 touched the lsp protocol stuff last week, especially the SnippetTextDocumentEdit and has some renaming things in it. I wonder if this causes the problems somehow?

There was also a follow-up PR this week #6619 but that did not fix this as it is still reproducible for me on nightly though this also doesn't seem to touch anything relevant anyways.

@Veykril
Copy link
Member

Veykril commented Nov 28, 2020

Okay, the problem is indeed the commit c7c4e91 introduced in #6566. The server built on that commit gives the same error, but the commit d4128be which is the one before the PR still works fine.

@kjeremy Do you perhaps know what might have happened here?

@kjeremy
Copy link
Contributor

kjeremy commented Nov 28, 2020

I will take a look this weekend when I have some time. It's most likely something in gluon-lang/lsp-types#186. Can someone grab a trace during a rename so we can see the params and response?

@E-ricus
Copy link
Author

E-ricus commented Nov 28, 2020

I will take a look this weekend when I have some time. It's most likely something in gluon-lang/lsp-types#186. Can someone grab a trace during a rename so we can see the params and response?

[Trace - 9:21:30 PM] Sending request 'textDocument/prepareRename - (41)'.
Params: {
    "textDocument": {
        "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/services/company_service.rs"
    },
    "position": {
        "line": 4,
        "character": 19
    }
}


[Trace - 9:21:30 PM] Received response 'textDocument/prepareRename - (41)' in 3ms.
Result: {
    "end": {
        "character": 25,
        "line": 4
    },
    "start": {
        "character": 11,
        "line": 4
    }
}


[Trace - 9:21:36 PM] Sending request 'textDocument/rename - (42)'.
Params: {
    "textDocument": {
        "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/services/company_service.rs"
    },
    "position": {
        "line": 4,
        "character": 19
    },
    "newName": "CompanyServicee"
}


[Trace - 9:21:36 PM] Received response 'textDocument/rename - (42)' in 4ms.
Result: {
    "documentChanges": [
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 25,
                            "line": 4
                        },
                        "start": {
                            "character": 11,
                            "line": 4
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/services/company_service.rs",
                "version": 1
            }
        },
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 34,
                            "line": 4
                        },
                        "start": {
                            "character": 20,
                            "line": 4
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/src/main.rs"
            }
        },
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 57,
                            "line": 17
                        },
                        "start": {
                            "character": 43,
                            "line": 17
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/src/main.rs"
            }
        },
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 49,
                            "line": 3
                        },
                        "start": {
                            "character": 35,
                            "line": 3
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/lib.rs"
            }
        },
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 22,
                            "line": 11
                        },
                        "start": {
                            "character": 8,
                            "line": 11
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/services/company_service.rs",
                "version": 1
            }
        },
        {
            "edits": [
                {
                    "newText": "CompanyServicee",
                    "range": {
                        "end": {
                            "character": 41,
                            "line": 20
                        },
                        "start": {
                            "character": 27,
                            "line": 20
                        }
                    }
                }
            ],
            "textDocument": {
                "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/services/company_service.rs",
                "version": 1
            }
        }
    ]
}

There you go!
here I'm changing CompanyService to CompanyServicee

And the error for that rename

Unknown workspace edit change received: { "edits": [ { "newText": "CompanyServicee", "range": { "end": { "character": 49, "line": 3 }, "start": { "character": 35, "line": 3 } } } ], "textDocument": { "uri": "file:///home/ericus/Documents/rust-projects/adci/web/src/lib.rs" } }

@kjeremy
Copy link
Contributor

kjeremy commented Nov 30, 2020

FYI I can reproduce this.

@kjeremy
Copy link
Contributor

kjeremy commented Nov 30, 2020

The new OptionalVersionedTextDocumentIdentifier requires that the version field be either a version # or null. Most other places in the protocol allow us to elide the value if it's null and so we typically don't send it down at all. This is why it worked when the file was open: version was always filled since the server has ownership at that point (my bad!). I will pull in the new lsp-types crate in as soon as it is published.

bors bot added a commit that referenced this issue Dec 1, 2020
6690: lsp-types 0.85: Fixes OptionalVersionedTextDocumentIdentifier specification r=kjeremy a=kjeremy

Fixes #6654

Co-authored-by: kjeremy <kjeremy@gmail.com>
@bors bors bot closed this as completed in e4ffd70 Dec 1, 2020
Matthias-Fauconneau pushed a commit to Matthias-Fauconneau/rust-analyzer that referenced this issue Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants