diff --git a/__tests__/cli-node-command.test.ts b/__tests__/cli-node-command.test.ts index 4d3485031..6e5166482 100644 --- a/__tests__/cli-node-command.test.ts +++ b/__tests__/cli-node-command.test.ts @@ -39,6 +39,7 @@ describe('codegraph node — argument handling (#1044)', () => { tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-node-cmd-')); fs.mkdirSync(path.join(tempDir, 'src')); fs.writeFileSync(path.join(tempDir, 'src/util.ts'), 'export function util(x: number){ return x + 1; }\n'); + fs.writeFileSync(path.join(tempDir, 'src/other.ts'), 'export function util(x: number){ return x - 1; }\n'); const cg = CodeGraph.initSync(tempDir); await cg.indexAll(); cg.close(); @@ -71,6 +72,14 @@ describe('codegraph node — argument handling (#1044)', () => { expect(stdout).toContain('Location:'); }); + it('a symbol pinned with -f includes the selected definition body (#1284)', () => { + const { stdout, code } = runNode(tempDir, ['util', '-f', 'src/util.ts']); + expect(code).toBe(0); + expect(stdout).toContain('src/util.ts'); + expect(stdout).toContain('return x + 1'); + expect(stdout).not.toContain('return x - 1'); + }); + it('neither symbol nor file gives a usage error, not commander\'s cryptic one', () => { const { stderr, code } = runNode(tempDir, []); expect(code).not.toBe(0); diff --git a/src/bin/codegraph.ts b/src/bin/codegraph.ts index 4d85e204f..251e3bf12 100644 --- a/src/bin/codegraph.ts +++ b/src/bin/codegraph.ts @@ -1376,7 +1376,10 @@ program const args: Record = {}; if (options.file) { args.file = options.file; - if (name && name !== options.file) args.symbol = name; + if (name && name !== options.file) { + args.symbol = name; + args.includeCode = true; + } } else if (name && (name.includes('/') || name.includes('\\'))) { args.file = name.replace(/\\/g, '/'); } else if (name) {