Add code action to add attribute for instance variable
Add new code actions to add a new attr_reader, attr_writer or attr_accessor for the given instance variable.
# BEFORE
class Foo
def initialize
@name = "Bar"
end
end
# AFTER
class Foo
attr_reader :name
def initialize
@name = "Bar"
end
end
Here's an example PR adding a refactor end to end https://github.com/Shopify/ruby-lsp/pull/2372.
Hi Team, I am looking at this issue.
What should be the code action kind for this?
@rogancodes for now, just use your judgement to pick a name, we can easily change it before merging.
(I would argue that it shouldn't use the term 'refactor', since we are changing the external interface of the class).
The kind is only used to sort the actions in the editor's dropdown. I agree that this isn't exactly a refactor, so maybe we can go with empty? I think those appear at the bottom of the list.
@vinistock, whenever only block node is selected for toggling block style. It gives InvalidTargetRange error.
https://github.com/user-attachments/assets/2bfc57c4-b7da-41e3-952c-0f7c914e6580
When I debugged it, I found that the locate_first_within_range method in RubyDocument doesn't capture the desired node if the start character of the selected region is the desired node itself.
I'm relying on this method to capture the first occurrence of the instance variable node. Is this behavior intentional, or should I address it?
My bad, didnt realized that filtered node is call node, not the block node.