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 switch block refactor #2372

Merged
merged 3 commits into from
Aug 8, 2024
Merged

Add switch block refactor #2372

merged 3 commits into from
Aug 8, 2024

Conversation

vinistock
Copy link
Member

Motivation

This PR adds a new refactor code action to switch the style of a block. If the block uses do..end, it becomes a one liner brace block and vice-versa.

Implementation

The first commit adds a new method to locate the first node matching a given list of types within the selected range. This is important for refactors, because users will select the code they want to apply some refactor on and we need to ignore the surrounding extra selection if it doesn't match the expected node.

The second commit adds the code action.

Automated Tests

Added tests.

Manual Tests

Select a block, click the light bulb (CMD + .) and select switch block style.

block_style_demo.mov

@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Jul 26, 2024
@vinistock vinistock self-assigned this Jul 26, 2024
@vinistock vinistock requested a review from a team as a code owner July 26, 2024 13:50
@vinistock vinistock requested review from andyw8 and st0012 July 26, 2024 13:50
@andyw8
Copy link
Contributor

andyw8 commented Jul 26, 2024

Nice. I used to use https://github.com/jgdavey/vim-blockle for this.

@vinistock vinistock force-pushed the vs-add-switch-block-refactor branch from 8f4ed00 to 1ca9bc0 Compare July 26, 2024 15:54
@vinistock vinistock force-pushed the vs-add-switch-block-refactor branch from 1ca9bc0 to 5e15210 Compare August 7, 2024 17:50
Copy link

@amomchilov amomchilov left a comment

Choose a reason for hiding this comment

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

Great feature!

lib/ruby_lsp/document.rb Outdated Show resolved Hide resolved
lib/ruby_lsp/requests/code_action_resolve.rb Show resolved Hide resolved
@vinistock vinistock force-pushed the vs-add-switch-block-refactor branch 2 times, most recently from 31215f1 to 435639b Compare August 8, 2024 14:27
@vinistock vinistock requested a review from st0012 August 8, 2024 14:28
lib/ruby_lsp/requests/code_action_resolve.rb Outdated Show resolved Hide resolved
@vinistock vinistock force-pushed the vs-add-switch-block-refactor branch from 435639b to c273e3c Compare August 8, 2024 17:15
@vinistock vinistock enabled auto-merge (squash) August 8, 2024 17:15
@vinistock vinistock merged commit b7f033e into main Aug 8, 2024
35 checks passed
@vinistock vinistock deleted the vs-add-switch-block-refactor branch August 8, 2024 17:31
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.

4 participants