Enable "toggle block style" refactor when there's no selection #3818
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.
Motivation
The "toggle block style" refactor action currently only works if there is a selection in the editor which covers a call node and its associated block. When there's no selection but the cursor is inside a block, it would be nice to be able to toggle the style of the block that the cursor is inside.
Implementation
CodeActionsrequest: add a quick check using@document.locate_nodeto conditionally offer the "toggle block style" action if the cursor is inside aBlockNodeCodeActionResolverequest: add a similar call to find the current block node when there's no selection. The actual rewrite also needs theCallNodeassociated with the block, and I couldn't figure out a good way to do this without adding a secondRubyDocument.locatecall. (When you calllocate_nodeto get the BlockNode, you don't get any reference to theCallNodethat theBlockNodeis attached to. You also can't just look for aCallNodecovering the cursor - that could return aCallNodethat's actually inside the block that you want to toggle.)Automated Tests
Added some expectation tests:
Manual Tests