Repository navigation
feat(editor): format pasted text by default - #334
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.
Pasting code currently preserves the clipboard text exactly, even when the active language server can safely format only the affected range. This adds opt-out format-on-paste behavior so pasted snippets adopt the surrounding document style without triggering an unrelated whole-document rewrite.
The editor now requests
textDocument/rangeFormattingfor the changed character range after terminal, normal/visual, block, and multi-cursor paste operations. Requests are only sent to language servers that advertise range-formatting support, are skipped for external whole-document formatters, and are guarded by the buffer revision so stale responses cannot overwrite newer edits.Format on paste defaults to enabled and can be disabled with:
How to Test
let value=1;. Confirm only the pasted range is formatted and the surrounding document remains unchanged.formatting.on_paste = false, repeat the paste, and confirm the clipboard text remains unchanged.cargo test pasteand thepasted_text_is_formatted_by_a_range_capable_language_servertest to cover normal, visual, block, multi-cursor, stale-response, and end-to-end LSP behavior.cargo clippy --all-targets --all-features -- -D warnings.