Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for range formatting with Syntax Tree #2657

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

vinistock
Copy link
Member

Motivation

Closes #203

A long time ago, I added the bits missing in Syntax Tree for partial formating. I always wanted to finish the work and offer range formatting, which is what this PR does.

As far as I know, there's no way to support this on RuboCop without some new API changes, but at least Syntax Tree users can benefit from it.

Implementation

The request is extremely similar to formatting. The only difference is that instead of formatting the entire document, we need to first locate the first node within the requested range and then calculate the indentation level for formatting (which is just the start column / 2).

Then we format only that node's slice and return a text edit to replace it.

Automated Tests

Added a test.

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Oct 2, 2024
@vinistock vinistock self-assigned this Oct 2, 2024
@vinistock vinistock requested a review from a team as a code owner October 2, 2024 22:11
@vinistock vinistock requested review from andyw8 and st0012 October 2, 2024 22:11
@vinistock vinistock force-pushed the vs-add-range-formatting branch from af91b22 to 67c25e5 Compare October 2, 2024 22:31
Copy link
Contributor

@andyw8 andyw8 left a comment

Choose a reason for hiding this comment

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

(did not 🎩 )

lib/ruby_lsp/requests/range_formatting.rb Show resolved Hide resolved
@vinistock vinistock merged commit 33aaf30 into main Oct 3, 2024
36 checks passed
@vinistock vinistock deleted the vs-add-range-formatting branch October 3, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add range formatting to the ruby-lsp
2 participants