(args: z.infer<typeof ListSymArgs>, ctx: ToolContext)
| 114 | argsSchema = ListSymArgs; |
| 115 | |
| 116 | async execute(args: z.infer<typeof ListSymArgs>, ctx: ToolContext): Promise<ToolResult> { |
| 117 | const db = requireDB(); |
| 118 | if ('error' in db) return { content: db.error, isError: true }; |
| 119 | |
| 120 | const abs = path.isAbsolute(args.path) ? args.path : path.resolve(ctx.cwd, args.path); |
| 121 | const rows = db.listSymbolsInFile(abs); |
| 122 | if (rows.length === 0) { |
| 123 | return { |
| 124 | content: `[NO_SYMBOLS] No indexed symbols in ${args.path}. The file may not be indexed (run /index) or may not be a supported language.`, |
| 125 | isError: false, |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | // Compute indentation by parent depth — easier to read |
| 130 | const byId = new Map(rows.map(r => [r.id, r])); |
| 131 | const depthOf = (r: typeof rows[number]): number => { |
| 132 | let d = 0; |
| 133 | let cur = r.parent_symbol_id; |
| 134 | while (cur !== null && byId.has(cur) && d < 10) { |
| 135 | d++; |
| 136 | cur = byId.get(cur)!.parent_symbol_id; |
| 137 | } |
| 138 | return d; |
| 139 | }; |
| 140 | |
| 141 | const lines = rows.map(r => { |
| 142 | const indent = ' '.repeat(depthOf(r)); |
| 143 | return `${indent}${String(r.start_line).padStart(4)} ${r.kind} ${r.name}`; |
| 144 | }); |
| 145 | return { |
| 146 | content: `${args.path} — ${rows.length} symbol${rows.length > 1 ? 's' : ''}:\n${lines.join('\n')}`, |
| 147 | metadata: { count: rows.length }, |
| 148 | }; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // ---------------- find_callers ---------------- |
nothing calls this directly
no test coverage detected