Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions __tests__/cli-node-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/bin/codegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,10 @@ program
const args: Record<string, unknown> = {};
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) {
Expand Down