mitranim / sublime-rust-fmt

Sublime Text plugin that formats Rust code with rustfmt
30 stars 3 forks source link

RustFmt moves cursor incorrectly in some cases #10

Closed Lucretiel closed 4 years ago

Lucretiel commented 4 years ago

If I have the following code:

fn example_function() {
    █
    ^ Cursor location
    }

After formatting the file during a save, my cursor is moved to outside of the function body:

fn exam█ple_function() {}
       ^ Cursor location

If possible, it would be nice if the location of the cursor could be preserved after a rustfmt.

mitranim commented 4 years ago

Apologies for the late response.

This can be fixed by basically reverting 002cef221c2a92a304c5a2763cb15db41b43c991. The change was made for simplicity and speed, but I just checked the plugin's performance on the longest file I could find in the Rust source (src/libcore/slice/mod.rs at the time of writing) and didn't observe any difference between the two methods. My apologies to everyone whose cursor position was being moved all these months, I should have kept that method.

I'm gonna test the change locally to find any potential gotchas. Just a heads up for now. Thanks for letting me know!

mitranim commented 4 years ago

Just published 0.1.10 which once again uses the diffing method, minimizing cursor jumping. Let me know if this solves the issue or creates any new ones.

mitranim commented 4 years ago

Should work, so I'm closing the issue for now. Please enjoy. 🙂