Show more files with capped per-file matches in code search output · Entire

Show more files with capped per-file matches in code search output

a38d68emain·

evisdren·4d ago·2 files·+72 added/-6 removed

Terminal output now favors breadth: up to 10 files with the first 3 matches each and a dim "+ N matches" overflow line, plus a blank line before the first result. Text display fetches a deeper page (100) so file variety can fill, unless --limit is passed; JSON is unchanged.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Changes

2

124 unmodified lines

125
126
127
128
129
130
131
244 unmodified lines

376
377
378
379
380
381
382
95 unmodified lines

478
479
480
481
482
483
484
485
486
487
488
489
490
491
2 unmodified lines

494
495
496
487
488
497
498
499
500
311 unmodified lines

812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
28 unmodified lines

855
856
857
858
859
841
842
860
861
862
863
864
845
865
866
867
868
869
870
871
1 unmodified line

873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
856
889
890
891

124 unmodified lines

query:         codeQuery,
            repoFilters:   codeRepos,
            limit:         limitFlag,
            limitExplicit: cmd.Flags().Changed("limit"),
            caseSensitive: caseSensitive,
            jsonOutput:    jsonOutput,
            insecureHTTP:  insecureHTTPAuth,
244 unmodified lines

repoFilters     []string
    resolvedRepoIDs []string // ULIDs resolved from repoFilters via repo index
    limit           int
    limitExplicit   bool // user passed --limit; don't override for text display
    caseSensitive   bool
    jsonOutput      bool
    insecureHTTP    bool
95 unmodified lines

}

w := cmd.OutOrStdout()
    textOutput := !opts.jsonOutput && interactive.IsTerminalWriter(w)

// Text output shows up to maxCodeSearchFiles files with a few matches
    // each, so fetch a deeper result set than the default --limit (which is
    // tuned for flat JSON output) unless the user asked for a specific limit.
    if textOutput && !opts.limitExplicit {
        opts.limit = codeSearchTextFetchLimit
    }

// Always fan out via searchAllCells — it fetches the repo index,
    // resolves slugs to ULIDs, and handles single- vs multi-jurisdiction.
2 unmodified lines

return err
}

isTerminal := interactive.IsTerminalWriter(w)
if opts.jsonOutput || !isTerminal {
if !textOutput {
return writeCodeSearchJSON(w, resp)
}

311 unmodified lines

// with an ellipsis so that JSONL/minified files don't blow up the terminal.
const maxContextLineLen = 200

// Text output display caps: show breadth (files) over depth (in-file matches).
// The fetch limit leaves headroom beyond files×matches so per-file overflow
// ("+ N matches") counts have data to count.
const (
maxCodeSearchFiles       = 10  // files shown in text output
maxCodeSearchFileMatches = 3   // matches shown per file
codeSearchTextFetchLimit = 100 // results fetched for text display
)

// writeCodeSearchText renders code search results grouped by file (ripgrep
// style): a colored "repo:path" header per file, indented line-numbered
// matches beneath it, and a dimmed stats footer. Colors are applied only when
28 unmodified lines

groups[i].results = append(groups[i].results, r)
}

shown := 0
for gi, g := range groups {
if gi > 0 {
fmt.Fprintln(w)
if gi == maxCodeSearchFiles {
break
}
fmt.Fprintln(w)
fmt.Fprintln(w, styles.render(styles.cyan, g.key))
for _, r := range g.results {
for mi, r := range g.results {
if mi == maxCodeSearchFileMatches {
break
}
line := r.ContextLine
runes := []rune(line)
if len(runes) > maxContextLineLen {
1 unmodified line

}
lineNo := styles.render(styles.dim, fmt.Sprintf("%d:", r.Line))
fmt.Fprintf(w, "  %s %s\n", lineNo, highlightCodeMatches(line, resp.Query, styles))
shown++
}
// ponytail: overflow counts only what this page fetched (peregrine
// has no per-file totals); a hot file shows "+ 97 matches" at most.
if extra := len(g.results) - maxCodeSearchFileMatches; extra > 0 {
label := "matches"
if extra == 1 {
label = "match"
}
fmt.Fprintln(w, styles.render(styles.dim, fmt.Sprintf("  + %d %s", extra, label)))
}
}

shown := len(resp.Results)
var summary string
if resp.Stats.TotalMatches > shown {
summary = fmt.Sprintf("Showing %d of %d matches across %d files in %d repos (%.0fms)",