Skip to content

Commit

Permalink
feat(api): add DecorationsRequest filter for build config (#3449)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Feb 6, 2019
1 parent a9bfcfa commit 2480a93
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 154 deletions.
7 changes: 7 additions & 0 deletions kythe/go/serving/xrefs/xrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (t *Table) Decorations(ctx context.Context, req *xpb.DecorationsRequest) (*

if req.References {
patterns := xrefs.ConvertFilters(req.Filter)
buildConfigs := stringset.New(req.BuildConfig...)

reply.Reference = make([]*xpb.DecorationsReply_Reference, 0, len(decor.Decoration))
reply.Nodes = make(map[string]*cpb.NodeInfo, len(decor.Target))
Expand Down Expand Up @@ -292,6 +293,11 @@ func (t *Table) Decorations(ctx context.Context, req *xpb.DecorationsRequest) (*
bindings := stringset.New()

for _, d := range decor.Decoration {
// Filter decorations by requested build configs.
if len(buildConfigs) != 0 && !buildConfigs.Contains(d.Anchor.BuildConfiguration) {
continue
}

start, end, exists := patcher.Patch(d.Anchor.StartOffset, d.Anchor.EndOffset)
// Filter non-existent anchor. Anchors can no longer exist if we were
// given a dirty buffer and the anchor was inside a changed region.
Expand Down Expand Up @@ -394,6 +400,7 @@ func decorationToReference(norm *span.Normalizer, d *srvpb.FileDecorations_Decor
Kind: d.Kind,
Span: span,
TargetDefinition: d.TargetDefinition,
BuildConfig: d.Anchor.BuildConfiguration,
}
}

Expand Down
21 changes: 21 additions & 0 deletions kythe/go/serving/xrefs/xrefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var (
Ticket: "kythe://c?lang=otpl?path=/a/path#6-9",
StartOffset: 6,
EndOffset: 9,

BuildConfiguration: "test-build-config",
},
Kind: "/kythe/defines/binding",
Target: "kythe://c?lang=otpl?path=/a/path#map",
Expand Down Expand Up @@ -501,6 +503,23 @@ func TestDecorationsRefs(t *testing.T) {
}
}

func TestDecorationsBuildConfig(t *testing.T) {
d := tbl.Decorations[1]

st := tbl.Construct(t)
reply, err := st.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{Ticket: d.File.Ticket},
References: true,
BuildConfig: []string{"test-build-config"},
})
testutil.FatalOnErrT(t, "DecorationsRequest error: %v", err)

expected := refs(span.NewNormalizer(d.File.Text), d.Decoration[:1])
if err := testutil.DeepEqual(expected, reply.Reference); err != nil {
t.Fatal(err)
}
}

func TestDecorationsDirtyBuffer(t *testing.T) {
d := tbl.Decorations[1]

Expand Down Expand Up @@ -544,6 +563,8 @@ func TestDecorationsDirtyBuffer(t *testing.T) {
ColumnOffset: 9,
},
},

BuildConfig: "test-build-config",
},
// Skipped anchor for "empty?" (inside edit region)
{
Expand Down
9 changes: 9 additions & 0 deletions kythe/proto/xref.proto
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ message DecorationsRequest {

// What kind of snippets to return (or none).
SnippetsKind snippets = 9;

// Set of build configurations with which to filter decorations. If empty,
// no filtering based on build configs will be done; all decorations for the
// file will be returned.
repeated string build_config = 11;
}

message DecorationsReply {
Expand All @@ -179,6 +184,9 @@ message DecorationsReply {
// The reference's span within the source file.
common.Span span = 5;

// The build config of the file containing this reference.
string build_config = 6;

reserved 1, 10, 11;
}

Expand Down Expand Up @@ -216,6 +224,7 @@ message DecorationsReply {

// If requested, a list of diagnostics applying to the requested file
// location.
// TODO(schroederc): filter spanning diagnostics by build configuration
repeated common.Diagnostic diagnostic = 5;

// This field will contain one entry, keyed by ticket, for each distinct node
Expand Down
Loading

0 comments on commit 2480a93

Please sign in to comment.