Repository navigation
fix(editor): reindent pasted code without range formatting - #341
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
#334 enabled format-on-paste by default, but its implementation relied entirely on LSP range formatting. rust-analyzer supports whole-document formatting but explicitly does not support range formatting, so pasted Rust snippets kept their original indentation instead of aligning with their destination. Whole-file pastes beginning with a module documentation comment could also remain uniformly indented.
What changed
formatting.on_paste = false, work when LSP is disabled, and bound local processing for large pastes.//!comments, whole files, protected string contents, undo, and disabled formatting/LSP.How to Test
Open a Rust method with an indented body and paste:
Expect the first two lines and closing brace to align with the method body, the inner call to indent one additional level, and a single undo to remove the entire paste.
Paste a uniformly indented Rust module beginning with
//!into an empty.rsfile. Expect the module comment,usestatements, andimplblock to start at column zero while nested methods retain their relative indentation.Paste a multiline raw string and verify its contents remain unchanged. Repeat with
[formatting] on_paste = falseand verify the pasted whitespace remains untouched.Run
cargo test --test editing rust_,cargo test --lib paste, andcargo test --lib syntax_indent. The complete editing suite also passes 413 tests with--skip dot_repeats_linewise_paste_and_visual_block_insert; that existing 2 MiB stack-overflow test fails unchanged onmain. Strict all-target/all-feature Clippy passes.