Skip to content

Commit

Permalink
Add FileEntityXRefRangeSpans to codemarkup
Browse files Browse the repository at this point in the history
Summary:
Right now the diff sketcher uses FileEntityXRefSpans to get ByteSpans
in favor of FileEntityXRefLocations; the latter yields
incomplete results on partial databases since it can't find a
definition site for many entitites.  This is a particular problem in
Hack, where even the production database is missing definition sites
for some entities.  But many languages (eg C++) use Ranges rather than
ByteSpans, and right now we're dropping those XRefs.  So this diff
introduced FileEntityXRefRangeSpans which does what we actually want.

Note that FileEntityXRefSpans was first introduced by simonmar in
D35141618 to support the sketcher.  So I believe this effectively
deprecates the one predicate in favor of the other.

An alternative is to pick Spans vs Locations by language, but
pepeiborra argues against that and in favor of the present solution
in v12 of D52309715.

Reviewed By: pepeiborra

Differential Revision: D52416817

fbshipit-source-id: 8e84588e234a5a5139d1112713c5c01080238eeb
  • Loading branch information
Jan-Willem Maessen authored and facebook-github-bot committed Dec 26, 2023
1 parent ba55172 commit 5693dd1
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions glean/schema/source/codemarkup.angle
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,16 @@ predicate FileEntityXRefLocations:
# Xrefs without the target location. This can be useful in cases
# where we don't have a target location, but we don't need it. This
# happens when indexing a subset of Hack files in a repo, for example.
predicate FileEntityXRefSpans:
predicate FileEntityXRefRangeSpans:
{
file: src.File,
span: src.ByteSpan,
location: codemarkup.types.RangeSpan,
entity: code.Entity,
}
{ File, Span, Entity } where
(codemarkup.hack.HackFileEntityXRefSpans { File, Span, E };
{ hack = E } = Entity) |
{ File, RangeSpan, Entity } where
( codemarkup.hack.HackFileEntityXRefSpans { File, Span, E };
{ hack = E } = Entity;
{ span = Span } = RangeSpan) |
(
(codemarkup.flow.FlowFileEntityXRefLocations { File, XRef, E };
{ flow = E } = Entity) |
Expand All @@ -265,9 +266,21 @@ predicate FileEntityXRefSpans:
{ kotlin = E } = Entity) |
(codemarkup.csharp.CSharpFileEntityXRefLocations { File, XRef, E };
{ csharp = E } = Entity);
{ source = { span = Span }} = XRef
{ source = RangeSpan} = XRef
)

# Like FileEntityXRefRangeSpans, but only returns spans and not ranges.
# Deprecated, use FileEntityXRefRangeSpans or language-specific
# predicates instead.
predicate FileEntityXRefSpans:
{
file: src.File,
span: src.ByteSpan,
entity: code.Entity,
}
{ File, Span, Entity } where
FileEntityXRefRangeSpans { File, { span = Span }, Entity }

# Finding xrefs. All references in a file, and their kinds
predicate FileEntityXRefKinds:
{
Expand Down

0 comments on commit 5693dd1

Please sign in to comment.