Skip to content

Conversation

@siketyan
Copy link
Member

Summary

Fixes #2260

The LSP implementation of textDocument/rangeFormatting and textDocument/onTypeFormatting compares entire code of the source and the formatted snippet returned by Workspace::format_range. Return value of format_range only contains code within the range, so the compared diff deletes most of the code incorrectly.

This pull request fixes the behaviour by limiting the source to the formatted range specified in Printed::range, before comparing it.

Test Plan

Added a test to server.tests.rs.

@siketyan siketyan requested review from a team May 14, 2025 07:03
@siketyan siketyan self-assigned this May 14, 2025
@github-actions github-actions bot added the A-LSP Area: language server protocol label May 14, 2025
@siketyan siketyan force-pushed the fix/lsp-range-formatting branch from cb7b420 to 860a2a0 Compare May 14, 2025 07:04
@siketyan siketyan force-pushed the fix/lsp-range-formatting branch from 860a2a0 to 7da5311 Compare May 14, 2025 07:04
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ematipico
Copy link
Member

Remember the changeset :)

@ematipico ematipico merged commit f70dee5 into biomejs:main May 14, 2025
11 checks passed
@siketyan siketyan deleted the fix/lsp-range-formatting branch May 14, 2025 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LSP Area: language server protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Format on Paste" & "Format on Save Mode: Modification" Deletes Lines Incorrectly

2 participants