Skip to content

Commit 9131e54

Browse files
authored
rename File events to Content events (#569)
This commit renames references to file events to content events in order to match the changes made in the stream API.
1 parent ab51772 commit 9131e54

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

cmd/src/search_stream.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ func textDecoder(query string, t *template.Template, w io.Writer) streaming.Deco
133133
OnMatches: func(matches []streaming.EventMatch) {
134134
for _, match := range matches {
135135
switch match := match.(type) {
136-
case *streaming.EventFileMatch:
137-
err := t.ExecuteTemplate(w, "file", struct {
136+
case *streaming.EventContentMatch:
137+
err := t.ExecuteTemplate(w, "content", struct {
138138
Query string
139-
*streaming.EventFileMatch
139+
*streaming.EventContentMatch
140140
}{
141-
Query: query,
142-
EventFileMatch: match,
141+
Query: query,
142+
EventContentMatch: match,
143143
},
144144
)
145145
if err != nil {
@@ -225,7 +225,7 @@ const streamingTemplate = `
225225
{{- "\n" -}}
226226
{{- end -}}
227227
228-
{{define "file"}}
228+
{{define "content"}}
229229
{{- /* Repository and file name */ -}}
230230
{{- color "search-repository"}}{{.Repository}}{{color "nc" -}}
231231
{{- " › " -}}

cmd/src/search_stream_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func testServer(t *testing.T, handler http.Handler) *httptest.Server {
3737
}
3838

3939
var event = []streaming.EventMatch{
40-
&streaming.EventFileMatch{
41-
Type: streaming.FileMatchType,
40+
&streaming.EventContentMatch{
41+
Type: streaming.ContentMatchType,
4242
Path: "path/to/file",
4343
Repository: "org/repo",
4444
Branches: nil,

cmd/src/testdata/streaming_search_want.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"type":"file","name":"path/to/file","repository":"org/repo","lineMatches":[{"line":"foo bar","lineNumber":4,"offsetAndLengths":[[4,3]]}]}
1+
{"type":"content","name":"path/to/file","repository":"org/repo","lineMatches":[{"line":"foo bar","lineNumber":4,"offsetAndLengths":[[4,3]]}]}
22
{"type":"repo","repository":"sourcegraph/sourcegraph"}
33
{"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"}]}
44
{"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]]}

internal/streaming/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func (r *eventMatchUnmarshaller) UnmarshalJSON(b []byte) error {
158158
}
159159

160160
switch typeU.Type {
161-
case FileMatchType:
162-
r.EventMatch = &EventFileMatch{}
161+
case ContentMatchType:
162+
r.EventMatch = &EventContentMatch{}
163163
case RepoMatchType:
164164
r.EventMatch = &EventRepoMatch{}
165165
case SymbolMatchType:

internal/streaming/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ func TestDecoder(t *testing.T) {
2727
}, {
2828
Name: "matches",
2929
Value: []EventMatch{
30-
&EventFileMatch{
31-
Type: FileMatchType,
30+
&EventContentMatch{
31+
Type: ContentMatchType,
3232
Path: "test",
3333
},
3434
&EventRepoMatch{

internal/streaming/events.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ type EventMatch interface {
1212
eventMatch()
1313
}
1414

15-
// EventFileMatch is a subset of zoekt.FileMatch for our Event API.
16-
type EventFileMatch struct {
17-
// Type is always FileMatchType. Included here for marshalling.
15+
// EventContentMatch is a subset of zoekt.FileMatch for our Event API.
16+
type EventContentMatch struct {
17+
// Type is always ContentMatchType. Included here for marshalling.
1818
Type MatchType `json:"type"`
1919

2020
Path string `json:"name"`
@@ -25,7 +25,7 @@ type EventFileMatch struct {
2525
LineMatches []EventLineMatch `json:"lineMatches"`
2626
}
2727

28-
func (e *EventFileMatch) eventMatch() {}
28+
func (e *EventContentMatch) eventMatch() {}
2929

3030
// EventPathMatch is a subset of zoekt.FileMatch for our Event API.
3131
type EventPathMatch struct {
@@ -132,7 +132,7 @@ type EventError struct {
132132
type MatchType int
133133

134134
const (
135-
FileMatchType MatchType = iota
135+
ContentMatchType MatchType = iota
136136
RepoMatchType
137137
SymbolMatchType
138138
CommitMatchType
@@ -141,8 +141,8 @@ const (
141141

142142
func (t MatchType) MarshalJSON() ([]byte, error) {
143143
switch t {
144-
case FileMatchType:
145-
return []byte(`"file"`), nil
144+
case ContentMatchType:
145+
return []byte(`"content"`), nil
146146
case RepoMatchType:
147147
return []byte(`"repo"`), nil
148148
case SymbolMatchType:
@@ -158,8 +158,8 @@ func (t MatchType) MarshalJSON() ([]byte, error) {
158158
}
159159

160160
func (t *MatchType) UnmarshalJSON(b []byte) error {
161-
if bytes.Equal(b, []byte(`"file"`)) {
162-
*t = FileMatchType
161+
if bytes.Equal(b, []byte(`"content"`)) {
162+
*t = ContentMatchType
163163
} else if bytes.Equal(b, []byte(`"repo"`)) {
164164
*t = RepoMatchType
165165
} else if bytes.Equal(b, []byte(`"symbol"`)) {

0 commit comments

Comments
 (0)