From e5d82edf65b964d07b1df8dd6ec81f315522b66d Mon Sep 17 00:00:00 2001 From: Camden Cheek Date: Tue, 20 Jul 2021 10:07:32 -0600 Subject: [PATCH] rename File events to Content events This commit renames references to file events to content events in order to match the changes made in the stream API. --- cmd/src/search_stream.go | 12 ++++++------ cmd/src/search_stream_test.go | 4 ++-- cmd/src/testdata/streaming_search_want.json | 2 +- internal/streaming/client.go | 4 ++-- internal/streaming/client_test.go | 4 ++-- internal/streaming/events.go | 18 +++++++++--------- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/src/search_stream.go b/cmd/src/search_stream.go index 83362b0898..1a06b46372 100644 --- a/cmd/src/search_stream.go +++ b/cmd/src/search_stream.go @@ -133,13 +133,13 @@ func textDecoder(query string, t *template.Template, w io.Writer) streaming.Deco OnMatches: func(matches []streaming.EventMatch) { for _, match := range matches { switch match := match.(type) { - case *streaming.EventFileMatch: - err := t.ExecuteTemplate(w, "file", struct { + case *streaming.EventContentMatch: + err := t.ExecuteTemplate(w, "content", struct { Query string - *streaming.EventFileMatch + *streaming.EventContentMatch }{ - Query: query, - EventFileMatch: match, + Query: query, + EventContentMatch: match, }, ) if err != nil { @@ -225,7 +225,7 @@ const streamingTemplate = ` {{- "\n" -}} {{- end -}} -{{define "file"}} +{{define "content"}} {{- /* Repository and file name */ -}} {{- color "search-repository"}}{{.Repository}}{{color "nc" -}} {{- " › " -}} diff --git a/cmd/src/search_stream_test.go b/cmd/src/search_stream_test.go index 2f7fa23936..be1887d5c8 100644 --- a/cmd/src/search_stream_test.go +++ b/cmd/src/search_stream_test.go @@ -37,8 +37,8 @@ func testServer(t *testing.T, handler http.Handler) *httptest.Server { } var event = []streaming.EventMatch{ - &streaming.EventFileMatch{ - Type: streaming.FileMatchType, + &streaming.EventContentMatch{ + Type: streaming.ContentMatchType, Path: "path/to/file", Repository: "org/repo", Branches: nil, diff --git a/cmd/src/testdata/streaming_search_want.json b/cmd/src/testdata/streaming_search_want.json index 702b4d7693..8404bb99b8 100755 --- a/cmd/src/testdata/streaming_search_want.json +++ b/cmd/src/testdata/streaming_search_want.json @@ -1,4 +1,4 @@ -{"type":"file","name":"path/to/file","repository":"org/repo","lineMatches":[{"line":"foo bar","lineNumber":4,"offsetAndLengths":[[4,3]]}]} +{"type":"content","name":"path/to/file","repository":"org/repo","lineMatches":[{"line":"foo bar","lineNumber":4,"offsetAndLengths":[[4,3]]}]} {"type":"repo","repository":"sourcegraph/sourcegraph"} {"type":"symbol","name":"path/to/file","repository":"org/repo","symbols":[{"url":"github.com/sourcegraph/sourcegraph/-/blob/cmd/frontend/graphqlbackend/search_results.go#L1591:26-1591:35","name":"doResults","containerName":"","kind":"FUNCTION"},{"url":"github.com/sourcegraph/sourcegraph/-/blob/cmd/frontend/graphqlbackend/search_results.go#L1591:26-1591:35","name":"Results","containerName":"SearchResultsResolver","kind":"FIELD"}]} {"type":"commit","icon":"","label":"[sourcegraph/sourcegraph-atom](/github.com/sourcegraph/sourcegraph-atom) › [Stephen Gutekanst](/github.com/sourcegraph/sourcegraph-atom/-/commit/5b098d7fed963d88e23057ed99d73d3c7a33ad89): [all: release v1.0.5](/github.com/sourcegraph/sourcegraph-atom/-/commit/5b098d7fed963d88e23057ed99d73d3c7a33ad89)^","url":"","detail":"","content":"```COMMIT_EDITMSG\nfoo bar\n```","ranges":[[1,3,3]]} diff --git a/internal/streaming/client.go b/internal/streaming/client.go index e927bd1721..79ee92efaf 100644 --- a/internal/streaming/client.go +++ b/internal/streaming/client.go @@ -158,8 +158,8 @@ func (r *eventMatchUnmarshaller) UnmarshalJSON(b []byte) error { } switch typeU.Type { - case FileMatchType: - r.EventMatch = &EventFileMatch{} + case ContentMatchType: + r.EventMatch = &EventContentMatch{} case RepoMatchType: r.EventMatch = &EventRepoMatch{} case SymbolMatchType: diff --git a/internal/streaming/client_test.go b/internal/streaming/client_test.go index 522e429326..2af482acbb 100644 --- a/internal/streaming/client_test.go +++ b/internal/streaming/client_test.go @@ -27,8 +27,8 @@ func TestDecoder(t *testing.T) { }, { Name: "matches", Value: []EventMatch{ - &EventFileMatch{ - Type: FileMatchType, + &EventContentMatch{ + Type: ContentMatchType, Path: "test", }, &EventRepoMatch{ diff --git a/internal/streaming/events.go b/internal/streaming/events.go index 57485911ca..c30eac40c5 100644 --- a/internal/streaming/events.go +++ b/internal/streaming/events.go @@ -12,9 +12,9 @@ type EventMatch interface { eventMatch() } -// EventFileMatch is a subset of zoekt.FileMatch for our Event API. -type EventFileMatch struct { - // Type is always FileMatchType. Included here for marshalling. +// EventContentMatch is a subset of zoekt.FileMatch for our Event API. +type EventContentMatch struct { + // Type is always ContentMatchType. Included here for marshalling. Type MatchType `json:"type"` Path string `json:"name"` @@ -25,7 +25,7 @@ type EventFileMatch struct { LineMatches []EventLineMatch `json:"lineMatches"` } -func (e *EventFileMatch) eventMatch() {} +func (e *EventContentMatch) eventMatch() {} // EventPathMatch is a subset of zoekt.FileMatch for our Event API. type EventPathMatch struct { @@ -132,7 +132,7 @@ type EventError struct { type MatchType int const ( - FileMatchType MatchType = iota + ContentMatchType MatchType = iota RepoMatchType SymbolMatchType CommitMatchType @@ -141,8 +141,8 @@ const ( func (t MatchType) MarshalJSON() ([]byte, error) { switch t { - case FileMatchType: - return []byte(`"file"`), nil + case ContentMatchType: + return []byte(`"content"`), nil case RepoMatchType: return []byte(`"repo"`), nil case SymbolMatchType: @@ -158,8 +158,8 @@ func (t MatchType) MarshalJSON() ([]byte, error) { } func (t *MatchType) UnmarshalJSON(b []byte) error { - if bytes.Equal(b, []byte(`"file"`)) { - *t = FileMatchType + if bytes.Equal(b, []byte(`"content"`)) { + *t = ContentMatchType } else if bytes.Equal(b, []byte(`"repo"`)) { *t = RepoMatchType } else if bytes.Equal(b, []byte(`"symbol"`)) {