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
Incorrect textDocument/rename
response when multiple edits on same document.
#4901
Comments
I'm also able to recreate the issue with coc-rust-analyzer --
|
CC #4831. |
Hm, yup, that's definitely a bug, and I think even the design one. The fix is to change find_usages API to return references, groupped by the file: Ie, I'd imagine something like: struct FileReferences {
file_id: FIleId,
refs: Vec<FileReference> // stores only `TextRange`
} After this refactor, changing all the call-sites should should automagicaly fix all the issues (I belive we have a similar problem in the new extract enum variant assist). |
I don't think this is quite true anymore. |
Im not sure if I have a similar issue. I'm using neovim lsp and tried to rename a variable that has multiple occurences in the same file but getting an error like
I've changed many settings in my vim config but with the same results and as it works with other languages, this might seem an issue in the rust-analyzer. used:
|
|
It has been a while since the suggestion for how to fix this was given, do you still think that's the way to go here? |
@martskins yup, I still think that it makes sense to first refactor the reference search API to return results grouped per file. The relevatn entry point is |
Another thing which needs fixing after the underlying issue is resolved: https://github.com/rust-analyzer/rust-analyzer/pull/7032/files#diff-a7e1e771e911237bb893e1b0f5e0f2c2a856b54ca06f95ef0818a922f1a8b5ebR266 |
I just noticed that when issuing a
textDocument/rename
request on a file that has N occurrences of the symbol to be renamed, rust-analyzer replies with NTextDocumentEdit
s with a singleTextEdit
in it, whereas other servers reply with a singleTextDocumentEdit
with NTextEdit
s.This, according to the specification (above), seems incorrect to me, as applying a
TextDocumentEdit
effectively changes the version of the document, and any subsequent applies to the older version are potentially not valid anymore. More importantly it states that aTextDocumentEdit
describes all changes on a version.This is affecting LanguageClient-neovim right now, as filed in autozimu/LanguageClient-neovim#1055, when there are two occurrences of that symbol in the same line. If the leftmost edit is applied first, then the range for the rightmost edit is invalid, as the document has changed. When all the edits for a document are listed in a single
TextDocumentEdit
,LanguageClient-neovim
sorts those edits by character and applies them from right to left, but given the current response this is not possible, as there is a single edit for each text document (except all text documents are really the same).For what it's worth, we could potentially fix this in LanguageClient-neovim by grouping the
TextDocumentEdit
s by text document URI, but I feel like this is just a misinterpretation of the specification.The text was updated successfully, but these errors were encountered: