Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to `src-cli` are documented in this file.
### Changed

### Fixed
- `src search -stream` displayed the number of lines that contain matches instead of the number of matches.

### Removed

Expand Down
1 change: 1 addition & 0 deletions cmd/src/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func parseTemplate(text string) (*template.Template, error) {
"streamSearchHighlightCommit": streamSearchTemplateFuncs["streamSearchHighlightCommit"],
"streamSearchRenderCommitLabel": streamSearchTemplateFuncs["streamSearchRenderCommitLabel"],
"matchOrMatches": streamSearchTemplateFuncs["matchOrMatches"],
"countMatches": streamSearchTemplateFuncs["countMatches"],

// Alert rendering
"searchAlertRender": func(alert searchResultsAlert) string {
Expand Down
10 changes: 9 additions & 1 deletion cmd/src/search_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const streamingTemplate = `
{{- color "search-repository"}}{{.Repository}}{{color "nc" -}}
{{- " › " -}}
{{- color "search-filename"}}{{.Path}}{{color "nc" -}}
{{- color "success"}}{{matchOrMatches (len .LineMatches)}}{{color "nc" -}}
{{- color "success"}}{{matchOrMatches (countMatches .LineMatches)}}{{color "nc" -}}
{{- "\n" -}}
{{- color "search-border"}}{{"--------------------------------------------------------------------------------\n"}}{{color "nc"}}

Expand Down Expand Up @@ -375,6 +375,14 @@ var streamSearchTemplateFuncs = map[string]interface{}{
}
return fmt.Sprintf(" (%d matches)", i)
},

"countMatches": func(lineMatches []streaming.EventLineMatch) int {
count := 0
for _, l := range lineMatches {
count += len(l.OffsetAndLengths)
}
return count
},
}

func streamSearchHighlightDiffPreview(diffPreview string, highlights []highlight) string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/search_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ var event = []streaming.EventMatch{
Version: "",
LineMatches: []streaming.EventLineMatch{
{
Line: "foo bar",
Line: "foo bar foo",
LineNumber: 4,
OffsetAndLengths: [][2]int32{{4, 3}},
OffsetAndLengths: [][2]int32{{0, 3}, {8, 3}},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/src/testdata/streaming_search_want.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"type":"content","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 foo","lineNumber":4,"offsetAndLengths":[[0,3],[8,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]]}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/testdata/streaming_search_want.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org/repo › path/to/file (1 match)
org/repo › path/to/file (2 matches)
--------------------------------------------------------------------------------
  5 | foo bar
  5 | foo bar foo

sourcegraph/sourcegraph (http://127.0.0.1:55128/sourcegraph/sourcegraph) (1 match)
org/repo › path/to/file (2 matches)
Expand Down