ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Code actions for attribute accessor creation

Open ro-gun opened this issue 1 year ago • 1 comments

Motivation

Closes #2503

Implementation

Selecting the first valid instance variabe from the user's selection and generating an attribute accessor method just below the start of the corresponding class/module definition.

Automated Tests

Added

Manual Tests

Select a line which contains instance variables, click the light bulb and select desired attribute accessor.

Screencast from 20-10-24 06:18:44 PM IST.webm

ro-gun avatar Oct 20 '24 13:10 ro-gun

I'm unsure whether the calculation of target_range is appropriate.

ro-gun avatar Oct 20 '24 13:10 ro-gun

@vinistock I have made the changes, but the prism test cases are failing. The error happens because it can't find the position in the file. Could you guide me on how to resolve this? Also, Im not sure why the node build is failing

ro-gun avatar Jan 21 '25 05:01 ro-gun

The issue is that our default arguments for code action expectations (which is what is used on Prism fixtures) are assuming that line 1 character 1 exists, but the fixture only has a single line (lines are zero based).

We need to change this line to check if the document actually has two lines and, if not, set the end position of the range as line 0 character 1.

vinistock avatar Jan 23 '25 19:01 vinistock

Thank you for your detailed instructions. I followed the same approach for the expectations test.

Regarding the extension build failure, I believe the issue arises from here. However, I'm new to JavaScript, so any guidance would be greatly appreciated.

ro-gun avatar Jan 24 '25 15:01 ro-gun

Yes, you're correct. The range defined here doesn't actually exist in the document.

Switching that to { start: { line: 0, character: 0 }, end: { line: 1, character: 2 } } should do the trick, I believe.

vinistock avatar Jan 24 '25 20:01 vinistock

I didn't encounter any issues during manual testing on the client side. I'll set up the VSCode extensions and test again.

Ruby Tests are failed due to build failures.

ro-gun avatar Jan 30 '25 16:01 ro-gun

The test failure is due to the missing character position in the request. My bad, I overlooked it :facepalm:

ro-gun avatar Feb 04 '25 06:02 ro-gun