Skip to content

Commit da02d19

Browse files
greynewellclaude
andauthored
Fix find: show original search query in count summary instead of first result name (#74)
The summary line showed matches[0].Name instead of the original symbol query. For a search like "handler", the output said: 3 match(es) for "handleRequest" instead of: 3 match(es) for "handler" Also adds a test to prevent regression. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 75318ca commit da02d19

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

internal/find/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func Run(ctx context.Context, cfg *config.Config, dir, symbol string, opts Optio
4343
fmt.Fprintf(os.Stderr, "No matches for %q\n", symbol)
4444
return nil
4545
}
46-
return printMatches(os.Stdout, matches, ui.ParseFormat(opts.Output))
46+
return printMatches(os.Stdout, matches, symbol, ui.ParseFormat(opts.Output))
4747
}
4848

4949
func search(g *api.Graph, symbol, kind string) []Match {
@@ -113,7 +113,7 @@ func search(g *api.Graph, symbol, kind string) []Match {
113113
return matches
114114
}
115115

116-
func printMatches(w io.Writer, matches []Match, fmt_ ui.Format) error {
116+
func printMatches(w io.Writer, matches []Match, query string, fmt_ ui.Format) error {
117117
if fmt_ == ui.FormatJSON {
118118
return ui.JSON(w, matches)
119119
}
@@ -131,7 +131,7 @@ func printMatches(w io.Writer, matches []Match, fmt_ ui.Format) error {
131131
fmt.Fprintf(w, " calls: %s\n", strings.Join(m.Callees, ", "))
132132
}
133133
}
134-
fmt.Fprintf(w, "\n%d match(es) for %q\n", len(matches), matches[0].Name)
134+
fmt.Fprintf(w, "\n%d match(es) for %q\n", len(matches), query)
135135
return nil
136136
}
137137

internal/find/handler_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestPrintMatches_JSON(t *testing.T) {
130130
{ID: "n2", Kind: "File", Name: "main.go", File: "main.go"},
131131
}
132132
var buf bytes.Buffer
133-
if err := printMatches(&buf, matches, ui.FormatJSON); err != nil {
133+
if err := printMatches(&buf, matches, "handle", ui.FormatJSON); err != nil {
134134
t.Fatalf("printMatches JSON: %v", err)
135135
}
136136
var decoded []map[string]any
@@ -147,7 +147,7 @@ func TestPrintMatches_Human(t *testing.T) {
147147
{ID: "n1", Kind: "Function", Name: "handleAuth", File: "auth/handler.go", Callers: []string{"main"}},
148148
}
149149
var buf bytes.Buffer
150-
if err := printMatches(&buf, matches, ui.FormatHuman); err != nil {
150+
if err := printMatches(&buf, matches, "handle", ui.FormatHuman); err != nil {
151151
t.Fatalf("printMatches human: %v", err)
152152
}
153153
out := buf.String()
@@ -163,7 +163,7 @@ func TestPrintMatches_HumanNoFile(t *testing.T) {
163163
{ID: "n1", Kind: "Function", Name: "doThing"},
164164
}
165165
var buf bytes.Buffer
166-
if err := printMatches(&buf, matches, ui.FormatHuman); err != nil {
166+
if err := printMatches(&buf, matches, "doThing", ui.FormatHuman); err != nil {
167167
t.Fatalf("printMatches: %v", err)
168168
}
169169
out := buf.String()
@@ -177,13 +177,17 @@ func TestPrintMatches_HumanShowsMatchCount(t *testing.T) {
177177
{ID: "n1", Kind: "Function", Name: "foo"},
178178
}
179179
var buf bytes.Buffer
180-
if err := printMatches(&buf, matches, ui.FormatHuman); err != nil {
180+
if err := printMatches(&buf, matches, "fo", ui.FormatHuman); err != nil {
181181
t.Fatal(err)
182182
}
183183
out := buf.String()
184184
if !strings.Contains(out, "1 match") {
185185
t.Errorf("should show match count:\n%s", out)
186186
}
187+
// Verify the query (not the first match name) is shown in the summary.
188+
if !strings.Contains(out, `"fo"`) {
189+
t.Errorf("should show original query 'fo' in summary, not match name:\n%s", out)
190+
}
187191
}
188192

189193
// ── helpers ───────────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)