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

Avoid showing duplicate completions #2215

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

vinistock
Copy link
Member

Motivation

While testing #2214, I noticed we were showing duplicate completion entries. The issue is that we were not deduping methods with the same name that appear multiple times in the same hierarchy chain.

We always want to show only the first entry we find in the hierarchy chain, since that's the one that is actually getting invoked.

Implementation

Since the prefix search returns all possible methods with no ordering guarantees, I started using a hash to remember the entries we found and the index in the ancestor chain where we found it.

Then we only override the entries if we find one earlier in the chain.

The code has a little bit of duplication, but it's hard to avoid because the completion path triggered on the dot character (@entries.values.flatten) returns any type of entries included classes. We can either duplicate the entry class checks or the ancestor index checks, but I don't think we can fully remove all of the duplication.

Automated Tests

Added a test that prevents regression.

@vinistock vinistock added bugfix This PR will fix an existing bug server This pull request should be included in the server gem's release notes labels Jun 20, 2024
@vinistock vinistock self-assigned this Jun 20, 2024
@vinistock vinistock requested a review from a team as a code owner June 20, 2024 20:45
@vinistock vinistock requested review from andyw8 and st0012 June 20, 2024 20:45
@vinistock vinistock changed the title Vs/avoid showing duplicate completions Avoid showing duplicate completions Jun 20, 2024
lib/ruby_indexer/lib/ruby_indexer/index.rb Outdated Show resolved Hide resolved
lib/ruby_indexer/lib/ruby_indexer/index.rb Outdated Show resolved Hide resolved
@vinistock vinistock force-pushed the vs/avoid_showing_duplicate_completions branch from 691e113 to 6bc29fc Compare June 21, 2024 13:47
@vinistock vinistock requested a review from st0012 June 21, 2024 13:47
@vinistock vinistock force-pushed the vs/avoid_showing_duplicate_completions branch from 6bc29fc to 7c7823f Compare June 21, 2024 15:16
@vinistock vinistock force-pushed the vs/avoid_showing_duplicate_completions branch from 7c7823f to 6185828 Compare June 21, 2024 16:42
@vinistock vinistock merged commit a554660 into main Jun 21, 2024
33 checks passed
@vinistock vinistock deleted the vs/avoid_showing_duplicate_completions branch June 21, 2024 17:31
def owner
@target.owner
end
# sig { returns(T.nilable(Entry::Namespace)) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this change intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, forgot to remove the commented out code. I removed it directly on main 3aa0430.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR will fix an existing bug server This 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.

3 participants