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 code action to add attribute for instance variable #2503

Open
vinistock opened this issue Aug 28, 2024 · 5 comments · May be fixed by #2739
Open

Add code action to add attribute for instance variable #2503

vinistock opened this issue Aug 28, 2024 · 5 comments · May be fixed by #2739
Assignees
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes

Comments

@vinistock
Copy link
Member

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 #2372.

@vinistock vinistock added enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes labels Aug 28, 2024
@rogancodes
Copy link
Contributor

rogancodes commented Oct 16, 2024

Hi Team, I am looking at this issue.

What should be the code action kind for this?

@andyw8
Copy link
Contributor

andyw8 commented Oct 16, 2024

@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).

@vinistock
Copy link
Member Author

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.

@rogancodes
Copy link
Contributor

@vinistock, whenever only block node is selected for toggling block style. It gives InvalidTargetRange error.

Screencast.from.19-10-24.08.41.01.PM.IST.webm

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?

@rogancodes
Copy link
Contributor

My bad, didnt realized that filtered node is call node, not the block node.

@rogancodes rogancodes linked a pull request Oct 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help-wanted Extra attention is needed pinned This issue or pull request is pinned and won't be marked as stale server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants