Skip to content

Split textDocument/formatting response TextEdit to avoid cursor jumping #7044

@Jesse-Bakker

Description

@Jesse-Bakker

At the moment, rust-analyzer wraps the entire file returned from rustfmt in a single TextEdit in the response to a textDocument/formatting request. This may cause the client cursor to end up far from its original position after formatting. It should not be that difficult to apply a diffing algorithm to the original file contents and rustfmt output to send many smaller TextEdits instead.

The difference in behaviour would be small in VSCode, as that editor does diffing on the client side to split the edits, but in other editors (like neovim, which I use), this can mean not losing all marks or having to find the place one is working again after formatting.

You could consider this as being fixed/blocked by #1665, but I think it may be nice to just do some simple diffing first

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )E-hardS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions