sublimelsp / LSP-rust-analyzer

Convenience package for rust-analyzer
MIT License
69 stars 11 forks source link

feat: implement custom join lines command/keybinding #110

Closed rchl closed 8 months ago

rchl commented 8 months ago

Just for fun I've implemented handling for one more custom request for joining lines.

It's bound to default join lines key binding but it will fall back to the native one if server is not active or returns an error for some reason.

The placement of the command differs from already implemented commands but I would rather use that approach and convert existing commands to use the same way in the future for more clarity.

Fixes #29

predragnikolic commented 8 months ago

Hello Rafal, I noticed two issues.

Undo issue

it messes the undo history. Lets say I have 4 lines.

fn main() {
    println!("Hello, world!"); | // cursor is here
    println!("Hello, world!");
    println!("Hello, world!");
    println!("Hello, world!");
}

If i trigger the rust_analyzer_join_lines command 24x. I would expect that only 3 edits occur, so I would need to undo 3 times. Instead, I need to undo 24x to undo the change...

output

Interestingly, the native join lines command only requires one undo to undo the 3 join lines.

output

Lost text issue

If you quickly trigger the rust_analyzer_join_lines command, text can get lost:

output

rchl commented 8 months ago

That looks like it needs changes purged before triggering the request.

rchl commented 8 months ago

Latest update should address undo but I still see it sometimes breaking the code when triggering command very quickly. I might have to add some manual change_count check as server doesn't specify document version in the edit it returns so it's not possible to know whether the edit is outdated.

rchl commented 8 months ago

Wrong edits should be also fixed.