-
Notifications
You must be signed in to change notification settings - Fork 1.3k
client: Centralize ref panel logic for Location grouping & uniquing #58183
Conversation
5b9e6cb
to
1a15900
Compare
}, | ||
references: { | ||
endCursor: lsif.references.pageInfo.endCursor, | ||
nodes: dedupeLocations(lsif.references.nodes).map(buildPreciseLocation), | ||
nodes: new LocationsGroup(lsif.references.nodes.map(buildPreciseLocation)), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
- Fixed some local variable names - Added more assertions - Added more comments
Otherwise, the call-sites read weirdly due to property syntax a.getX.b
53c4290
to
5325035
Compare
There was a problem hiding this 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)), |
There was a problem hiding this comment.
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.
d10743b
to
a0c03cf
Compare
…58183) This way, we can document invariants and add assertions in a central places.
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?