Skip to content

Commit ab51772

Browse files
authored
add EventPathMatch to the streaming API types (#568)
1 parent e47e47d commit ab51772

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

cmd/src/search_stream.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ func textDecoder(query string, t *template.Template, w io.Writer) streaming.Deco
146146
logError(fmt.Sprintf("error when executing template: %s\n", err))
147147
return
148148
}
149+
case *streaming.EventPathMatch:
150+
err := t.ExecuteTemplate(w, "path", struct {
151+
Query string
152+
*streaming.EventPathMatch
153+
}{
154+
Query: query,
155+
EventPathMatch: match,
156+
},
157+
)
158+
if err != nil {
159+
logError(fmt.Sprintf("error when executing template: %s\n", err))
160+
return
161+
}
149162
case *streaming.EventRepoMatch:
150163
err := t.ExecuteTemplate(w, "repo", struct {
151164
SourcegraphEndpoint string
@@ -201,6 +214,17 @@ func isLimitHit(progress *streaming.Progress) bool {
201214
}
202215

203216
const streamingTemplate = `
217+
{{define "path"}}
218+
{{- /* Repository and file name */ -}}
219+
{{- color "search-repository"}}{{.Repository}}{{color "nc" -}}
220+
{{- " › " -}}
221+
{{- color "search-filename"}}{{.Path}}{{color "nc" -}}
222+
{{- color "success"}}{{matchOrMatches 0}}{{color "nc" -}}
223+
{{- "\n" -}}
224+
{{- color "search-border"}}{{"--------------------------------------------------------------------------------\n"}}{{color "nc"}}
225+
{{- "\n" -}}
226+
{{- end -}}
227+
204228
{{define "file"}}
205229
{{- /* Repository and file name */ -}}
206230
{{- color "search-repository"}}{{.Repository}}{{color "nc" -}}

internal/streaming/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ func (r *eventMatchUnmarshaller) UnmarshalJSON(b []byte) error {
166166
r.EventMatch = &EventSymbolMatch{}
167167
case CommitMatchType:
168168
r.EventMatch = &EventCommitMatch{}
169+
case PathMatchType:
170+
r.EventMatch = &EventPathMatch{}
169171
default:
170172
return fmt.Errorf("unknown MatchType %v", typeU.Type)
171173
}

internal/streaming/events.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ type EventFileMatch struct {
2727

2828
func (e *EventFileMatch) eventMatch() {}
2929

30+
// EventPathMatch is a subset of zoekt.FileMatch for our Event API.
31+
type EventPathMatch struct {
32+
// Type is always PathMatchType. Included here for marshalling.
33+
Type MatchType `json:"type"`
34+
35+
Path string `json:"name"`
36+
Repository string `json:"repository"`
37+
Branches []string `json:"branches,omitempty"`
38+
Version string `json:"version,omitempty"`
39+
}
40+
41+
func (e *EventPathMatch) eventMatch() {}
42+
3043
// EventLineMatch is a subset of zoekt.LineMatch for our Event API.
3144
type EventLineMatch struct {
3245
Line string `json:"line"`
@@ -123,6 +136,7 @@ const (
123136
RepoMatchType
124137
SymbolMatchType
125138
CommitMatchType
139+
PathMatchType
126140
)
127141

128142
func (t MatchType) MarshalJSON() ([]byte, error) {
@@ -135,6 +149,8 @@ func (t MatchType) MarshalJSON() ([]byte, error) {
135149
return []byte(`"symbol"`), nil
136150
case CommitMatchType:
137151
return []byte(`"commit"`), nil
152+
case PathMatchType:
153+
return []byte(`"path"`), nil
138154
default:
139155
return nil, fmt.Errorf("unknown MatchType: %d", t)
140156
}
@@ -150,6 +166,8 @@ func (t *MatchType) UnmarshalJSON(b []byte) error {
150166
*t = SymbolMatchType
151167
} else if bytes.Equal(b, []byte(`"commit"`)) {
152168
*t = CommitMatchType
169+
} else if bytes.Equal(b, []byte(`"path"`)) {
170+
*t = PathMatchType
153171
} else {
154172
return fmt.Errorf("unknown MatchType: %s", b)
155173
}

0 commit comments

Comments
 (0)