-
Notifications
You must be signed in to change notification settings - Fork 324
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
Edits are applied twice #752
Comments
This is actually expected. Otherwise another extension / server can never participate in a file rename. This is also the reason why these events are in the workspace realm (they trigger if something to the workspace happens). I will clarify that in the spec. There is currently no way in the spec to prevent them. What we could think about is to add an indication to the event who triggered it. In the VS Code client libs you could do of course filter them in the middleware. |
@Veykril can you give me an example were this behavior causes problems. |
Can you please explain the flow to me since I am not familiar with what happens in Rust on a mod rename. |
Assuming we have two files here: mod foobar; foobar.rs A rename on the So the result we get from this is mod foo foo.rs which is incorrect as we lost a semicolon we shouldnt lose Similarly if we rename |
I can see how this is intentional so that other extensions can observe this, but the question is if it makes sense to send the WillRenameRequest to the server that caused the rename. Maybe a simple solution on the rust-analyzer side would be to only send the file edits in a rename response if the client supports |
@Veykril OK. Understood. Filtering the events without knowing exactly who has caused them by which operation is very difficult in an async environment. It could lead to drop an event although the server was not the source. So the only fix for this would be that we can tag an workspace edit with an ID which is the repeated in an event to ensure correct interpretation. Requires work in VS Code side and the libraries. So I like your simple solution
|
Hm, while we are working-around this on our side, there's still behavior that surprises me -- vscode applies two conficing edits. Here's a log when I rename
Note that the server sends two identical edits for document version 1. I would expect the client to either error out because the edits are conflicting, or to notice that they are identical and apply only one (that is, to figure out that they OT-merge to a single edit). Instead, the client sends two didChange events:
So, it applies edit with version 1 to a document with version 2. |
7958: Avoid double text edits when renaming mod declaration r=matklad a=Veykril Closes #7916 See microsoft/vscode-languageserver-node#752 for context Co-authored-by: Lukas Wirth <[email protected]>
@matklad thanks for reporting this! |
This popped up in Rust-Analyzer and we are unsure whether its a bug in the client or us implementing it wrong rust-lang/rust-analyzer#7916
Basically when the user renames a module in the source via the rename action rust-analyzer replies with a
WorkspaceEdit
that renames all locations as well as file names that are affected. This in turn seems to cause vscode to trigger one or moreWillRenameFiles
requests for which we reply with the sameWorkspaceEdit
as this is basically the same rename request in this case. This causes two renames to be applied per reference causing incorrect text edits.We assume that VSCode should not react with a
WillRenameFiles
request when the file renames are caused by the server, is this assumption wrong? If yes what should be done by the server to prevent this as the documentation doesn't make this clear to us https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#workspace_willRenameFilesThe text was updated successfully, but these errors were encountered: