Skip to content

Add find references support for constants - #2632

Merged
vinistock merged 1 commit into
mainfrom
vs-add-references-support
Oct 2, 2024
Merged

Add find references support for constants#2632
vinistock merged 1 commit into
mainfrom
vs-add-references-support

Conversation

@vinistock

Copy link
Copy Markdown
Member

Motivation

Closes#202

With the same infrastructure added in #2626, we can easily support finding constant references. Instead of building an array of text edits, we just return an array of locations.

Implementation

The idea is to use the same reference finder implementation and then return all of the hits back as locations.

I also had to fix a small duplication issue to be able to respect the LSP spec's includeDeclaration parameter.

Automated Tests

Added tests.

@vinistockvinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Sep 30, 2024
@vinistockvinistock self-assigned this Sep 30, 2024
@vinistock
vinistock requested a review from a team as a code ownerSeptember 30, 2024 14:12
@andyw8

Copy link
Copy Markdown
Contributor

Do we need any safeguards for someone running Find References on a large codebase for some constant with a high number of occurrences?

@andyw8andyw8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very exciting to have this.

Comment threadjekyll/index.markdown Outdated
Comment threadjekyll/index.markdown Outdated
Comment threadlib/ruby_lsp/requests/references.rb Outdated
Comment threadlib/ruby_lsp/internal.rb Outdated
Comment threadlib/ruby_indexer/lib/ruby_indexer/reference_finder.rb Outdated
@vinistock
vinistockforce-pushed the vs-add-references-support branch from 8d1136c to 6b96c8cCompareOctober 1, 2024 12:58
@vinistock
vinistock requested a review from andyw8October 1, 2024 13:00
@andyw8

andyw8 commented Oct 1, 2024

Copy link
Copy Markdown
Contributor

I found one issue:

Create a new file, but don't save it:

classWidget2defbarendendWidget2

Right-click on Widget2 in the first line then Find All References

The LSP will error with:

Ruby LSP error NoMethodError: undefined method `full_name' for an instance of Prism::ProgramNode /Users/andyw8/src/github.com/Shopify/ruby-lsp/lib/ruby_lsp/requests/support/common.rb:152:in `constant_name'

@vinistock

Copy link
Copy Markdown
MemberAuthor

The issue was related to not finding a target. I fixed it in the latest push.

@vinistock
vinistockforce-pushed the vs-add-rename-support branch 5 times, most recently from 21f56af to 377e988CompareOctober 2, 2024 20:18
Base automatically changed from vs-add-rename-support to mainOctober 2, 2024 20:39
@vinistock
vinistockforce-pushed the vs-add-references-support branch from 933a025 to 4274afdCompareOctober 2, 2024 22:04
@vinistock
vinistock enabled auto-merge (squash) October 2, 2024 22:05
@vinistock
vinistock merged commit 970b466 into mainOct 2, 2024
@vinistock
vinistock deleted the vs-add-references-support branch October 2, 2024 22:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or requestserverThis pull request should be included in the server gem's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vinistock@andyw8