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

Support instance variables for definition, hover, completion and workspace symbols

Open vinistock opened this issue 1 year ago • 3 comments

Motivation

This PR starts indexing instance variables, so that we can provide definition, hover, completion and workspace symbol in the LSP. Eventually, it will also allow us to provide rename and find references.

Implementation

I split the work by commit to make it easier to review:

  1. Start indexing all possible ways to declare an instance variable
  2. Definition support
  3. Hover support
  4. Completion support
  5. Workspace symbol support

Automated Tests

Added tests.

Manual Tests

  1. Start the LSP on this branch
  2. Verify you can jump to the declaration of an instance variable
  3. Verify you see documentation for an instance variable on hover
  4. Verify you get completion when typing @
  5. Verify you can find instance variable declarations when searching using workspace symbol (CMD + T)

vinistock avatar May 13 '24 05:05 vinistock

Not a blocker, but would we want to also support instance_variable_set and instance_variable_get?

andyw8 avatar May 13 '24 15:05 andyw8

I notice that for Document Symbol, the @ is included as part of the name. I know that's how Ruby represents it internally, but I'm wondering if that should be exposed. 🤔

andyw8 avatar May 13 '24 15:05 andyw8

Are there some docs we should update as part of this?

andyw8 avatar May 13 '24 16:05 andyw8

Not a blocker, but would we want to also support instance_variable_set and instance_variable_get?

My gut feeling is that it's probably not worth it. The only times when you'd use those is if you want to set variables in an unknown target, which we wouldn't be able to understand statically anyway. For example:

def foo(a)
  # Where do we put this?
  # Similarly for instance_variable_get, how do we know where to find the ivar?
  a.instance_variable_set(:@bar, [])
end

I notice that for Document Symbol, the @ is included as part of the name. I know that's how Ruby represents it internally, but I'm wondering if that should be exposed. 🤔

Does it cause any issues? I tested it and if you type the name of the variable without the @ the filtering works fine.

Are there some docs we should update as part of this?

Updated completion and definition docs.

vinistock avatar May 27 '24 19:05 vinistock

I notice that for Document Symbol, the @ is included as part of the name. I know that's how Ruby represents it internally, but I'm wondering if that should be exposed.

I don't think it's introduced by this PR anyway tho? Document symbol for ivars has been around for a while as it doesn't need the index to work.

st0012 avatar May 28 '24 20:05 st0012