Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

client: Centralize ref panel logic for Location grouping & uniquing #58183

Merged
merged 14 commits into from
Nov 15, 2023

Conversation

varungandhi-src
Copy link
Contributor

The current ref panel code scatters calls for grouping and uniquing in a bunch of different places.
This makes the code hard to understand (which invariants hold and why?) and makes it harder
to propagate information easily at per-file or per-repo granularity.

In the future, we want to attach one SCIP Document per file for https://github.com/sourcegraph/sourcegraph/issues/58182

So I've attempted to centralize the grouping and uniquing logic here, and made
liberal use of assertions and comments to make it clear which invariants hold.

My coding style + naming is probably somewhat unidiomatic, open to suggestions for improvements.

Test plan

TODO, not sure what kinds of tests I should add. Unit tests for the new LocationGroup class?

Is there any easy way to add fuzz tests to make sure that no assertions are hit?

@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented Nov 8, 2023

📖 Storybook live preview

},
references: {
endCursor: lsif.references.pageInfo.endCursor,
nodes: dedupeLocations(lsif.references.nodes).map(buildPreciseLocation),
nodes: new LocationsGroup(lsif.references.nodes.map(buildPreciseLocation)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, this is a bit suboptimal because we're mapping before de-duping, but it should be fine in most cases as we generally have < 50 references, and we have a pagination limit which prevents this from growing quickly. Thoughts on if I should change it so that the mapping happens after filtering regardless?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it will have any measurable impact.

Copy link
Contributor

@fkling fkling left a comment

Choose a reason for hiding this comment

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

Left some suggestions, otherwise lgtm!

},
references: {
endCursor: lsif.references.pageInfo.endCursor,
nodes: dedupeLocations(lsif.references.nodes).map(buildPreciseLocation),
nodes: new LocationsGroup(lsif.references.nodes.map(buildPreciseLocation)),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it will have any measurable impact.

@varungandhi-src varungandhi-src enabled auto-merge (squash) November 15, 2023 03:39
@varungandhi-src varungandhi-src merged commit 725f9aa into main Nov 15, 2023
@varungandhi-src varungandhi-src deleted the vg/refpanel-centralize branch November 15, 2023 05:22
vovakulikov pushed a commit that referenced this pull request Dec 12, 2023
…58183)

This way, we can document invariants and add assertions in a central
places.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants