Skip to content

Commit cf0532b

Browse files
fix: print signature in codemap snippet terminal output (#119)
Match codemap show: location, indented signature, then source body.
1 parent 665c19a commit cf0532b

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stainless-code/codemap": patch
3+
---
4+
5+
Print symbol signature in `codemap snippet` terminal output, matching `codemap show` and the documented contract.

src/cli/cmd-snippet.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createTables } from "../db";
88
import type { CodemapDatabase } from "../db";
99
import { hashContent } from "../hash";
1010
import { openCodemapDatabase } from "../sqlite-db";
11-
import { parseSnippetRest } from "./cmd-snippet";
11+
import { parseSnippetRest, renderSnippetTerminal } from "./cmd-snippet";
1212

1313
describe("parseSnippetRest", () => {
1414
it("returns help on --help / -h", () => {
@@ -69,6 +69,43 @@ describe("parseSnippetRest", () => {
6969
});
7070
});
7171

72+
describe("renderSnippetTerminal", () => {
73+
it("prints signature between location and source", () => {
74+
const lines: string[] = [];
75+
const origLog = console.log;
76+
console.log = (...args: unknown[]) => {
77+
lines.push(
78+
args.map((a) => (typeof a === "string" ? a : String(a))).join(" "),
79+
);
80+
};
81+
try {
82+
renderSnippetTerminal({
83+
matches: [
84+
{
85+
name: "foo",
86+
kind: "function",
87+
file_path: "src/a.ts",
88+
line_start: 1,
89+
line_end: 2,
90+
signature: "function foo(): void",
91+
is_exported: 1,
92+
parent_name: null,
93+
visibility: null,
94+
source: "line1\nline2",
95+
stale: false,
96+
missing: false,
97+
},
98+
],
99+
});
100+
} finally {
101+
console.log = origLog;
102+
}
103+
expect(lines[0]).toBe("src/a.ts:1-2");
104+
expect(lines[1]).toBe(" function foo(): void");
105+
expect(lines[2]).toBe("line1\nline2");
106+
});
107+
});
108+
72109
describe("buildSnippetResult — source enrichment + envelope", () => {
73110
let projectRoot: string;
74111
let db: CodemapDatabase;

src/cli/cmd-snippet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export async function runSnippetCmd(opts: SnippetOpts): Promise<void> {
180180
console.log(JSON.stringify(result));
181181
return;
182182
}
183-
renderTerminal(result);
183+
renderSnippetTerminal(result);
184184
} catch (err) {
185185
const msg = err instanceof Error ? err.message : String(err);
186186
emitErrorMaybeJson(msg, opts.json);
@@ -197,7 +197,7 @@ function describeFilter(
197197
return parts.length === 0 ? "" : ` (filters: ${parts.join(", ")})`;
198198
}
199199

200-
function renderTerminal(result: SnippetResult): void {
200+
export function renderSnippetTerminal(result: SnippetResult): void {
201201
let anyStale = false;
202202
for (let i = 0; i < result.matches.length; i++) {
203203
const m = result.matches[i]!;
@@ -207,6 +207,7 @@ function renderTerminal(result: SnippetResult): void {
207207
console.log(
208208
`${m.file_path}:${m.line_start}-${m.line_end}${stalePrefix}${missingPrefix}`,
209209
);
210+
console.log(` ${m.signature}`);
210211
if (m.source !== undefined) console.log(m.source);
211212
if (m.stale) anyStale = true;
212213
}

0 commit comments

Comments
 (0)