diff --git a/.changeset/fix-snippet-terminal-signature.md b/.changeset/fix-snippet-terminal-signature.md new file mode 100644 index 0000000..fea585a --- /dev/null +++ b/.changeset/fix-snippet-terminal-signature.md @@ -0,0 +1,5 @@ +--- +"@stainless-code/codemap": patch +--- + +Print symbol signature in `codemap snippet` terminal output, matching `codemap show` and the documented contract. diff --git a/src/cli/cmd-snippet.test.ts b/src/cli/cmd-snippet.test.ts index d69d2bf..e6da52a 100644 --- a/src/cli/cmd-snippet.test.ts +++ b/src/cli/cmd-snippet.test.ts @@ -8,7 +8,7 @@ import { createTables } from "../db"; import type { CodemapDatabase } from "../db"; import { hashContent } from "../hash"; import { openCodemapDatabase } from "../sqlite-db"; -import { parseSnippetRest } from "./cmd-snippet"; +import { parseSnippetRest, renderSnippetTerminal } from "./cmd-snippet"; describe("parseSnippetRest", () => { it("returns help on --help / -h", () => { @@ -69,6 +69,43 @@ describe("parseSnippetRest", () => { }); }); +describe("renderSnippetTerminal", () => { + it("prints signature between location and source", () => { + const lines: string[] = []; + const origLog = console.log; + console.log = (...args: unknown[]) => { + lines.push( + args.map((a) => (typeof a === "string" ? a : String(a))).join(" "), + ); + }; + try { + renderSnippetTerminal({ + matches: [ + { + name: "foo", + kind: "function", + file_path: "src/a.ts", + line_start: 1, + line_end: 2, + signature: "function foo(): void", + is_exported: 1, + parent_name: null, + visibility: null, + source: "line1\nline2", + stale: false, + missing: false, + }, + ], + }); + } finally { + console.log = origLog; + } + expect(lines[0]).toBe("src/a.ts:1-2"); + expect(lines[1]).toBe(" function foo(): void"); + expect(lines[2]).toBe("line1\nline2"); + }); +}); + describe("buildSnippetResult — source enrichment + envelope", () => { let projectRoot: string; let db: CodemapDatabase; diff --git a/src/cli/cmd-snippet.ts b/src/cli/cmd-snippet.ts index 19172a9..442831e 100644 --- a/src/cli/cmd-snippet.ts +++ b/src/cli/cmd-snippet.ts @@ -180,7 +180,7 @@ export async function runSnippetCmd(opts: SnippetOpts): Promise { console.log(JSON.stringify(result)); return; } - renderTerminal(result); + renderSnippetTerminal(result); } catch (err) { const msg = err instanceof Error ? err.message : String(err); emitErrorMaybeJson(msg, opts.json); @@ -197,7 +197,7 @@ function describeFilter( return parts.length === 0 ? "" : ` (filters: ${parts.join(", ")})`; } -function renderTerminal(result: SnippetResult): void { +export function renderSnippetTerminal(result: SnippetResult): void { let anyStale = false; for (let i = 0; i < result.matches.length; i++) { const m = result.matches[i]!; @@ -207,6 +207,7 @@ function renderTerminal(result: SnippetResult): void { console.log( `${m.file_path}:${m.line_start}-${m.line_end}${stalePrefix}${missingPrefix}`, ); + console.log(` ${m.signature}`); if (m.source !== undefined) console.log(m.source); if (m.stale) anyStale = true; }