Support instance variables for definition, hover, completion and workspace symbols
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:
- Start indexing all possible ways to declare an instance variable
- Definition support
- Hover support
- Completion support
- Workspace symbol support
Automated Tests
Added tests.
Manual Tests
- Start the LSP on this branch
- Verify you can jump to the declaration of an instance variable
- Verify you see documentation for an instance variable on hover
- Verify you get completion when typing
@ - Verify you can find instance variable declarations when searching using workspace symbol (CMD + T)
Not a blocker, but would we want to also support instance_variable_set and instance_variable_get?
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. 🤔
Are there some docs we should update as part of this?
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.
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.