* codegraph_explore for a query that names one symbol (#3407; see * `explore-one-symbol.ts`). Null hands the query to the general path: no * single name, a name with no definition or more than three, or a definition * whose file changed on disk since it was indexed (the general path owns
(
cg: CodeGraph,
matchQuery: string,
query: string,
projectRoot: string,
budget: ExploreOutputBudget,
maxFiles: number,
indexedFileCount: number,
)
| 8435 | * drifted files). `CODEGRAPH_EXPLORE_ONE_SYMBOL=0` turns it off, for A/B runs. |
| 8436 | */ |
| 8437 | private exploreOneSymbol( |
| 8438 | cg: CodeGraph, |
| 8439 | matchQuery: string, |
| 8440 | query: string, |
| 8441 | projectRoot: string, |
| 8442 | budget: ExploreOutputBudget, |
| 8443 | maxFiles: number, |
| 8444 | indexedFileCount: number, |
| 8445 | ): ToolResult | null { |
| 8446 | if (process.env.CODEGRAPH_EXPLORE_ONE_SYMBOL === '0') return null; |
| 8447 | const name = oneSymbolQueryName(matchQuery); |
| 8448 | if (!name) return null; |
| 8449 | let defs: Node[] | null; |
| 8450 | try { |
| 8451 | defs = oneSymbolDefinitions(cg, name); |
| 8452 | } catch { |
| 8453 | return null; |
| 8454 | } |
| 8455 | if (!defs) return null; |
| 8456 | |
| 8457 | // Each file read once, and only trusted when it still matches the index: |
| 8458 | // a changed file's indexed line numbers can point at other code (#1474). |
| 8459 | const read = new Map<string, { content: string; lines: string[] } | null>(); |
| 8460 | const readFile = (filePath: string) => { |
| 8461 | const held = read.get(filePath); |
| 8462 | if (held !== undefined) return held; |
| 8463 | let entry: { content: string; lines: string[] } | null = null; |
| 8464 | try { |
| 8465 | const abs = validatePathWithinRoot(projectRoot, filePath); |
| 8466 | if (abs && existsSync(abs)) { |
| 8467 | const content = readFileSync(abs, 'utf-8'); |
| 8468 | if (!this.isFileStaleOnDisk(cg, filePath, content)) entry = { content, lines: content.split(/\r?\n/) }; |
| 8469 | } |
| 8470 | } catch { |
| 8471 | entry = null; |
| 8472 | } |
| 8473 | read.set(filePath, entry); |
| 8474 | return entry; |
| 8475 | }; |
| 8476 | |
| 8477 | const isTest = this.testCodeReading(cg); |
| 8478 | const rel = (p: string) => p.replace(/\\/g, '/'); |
| 8479 | let answer: OneSymbolAnswer | null; |
| 8480 | try { |
| 8481 | answer = renderOneSymbolAnswer({ |
| 8482 | cg, |
| 8483 | maxChars: budget.maxOutputChars, |
| 8484 | // A definition is the answer, so it may take half the tier's ceiling, |
| 8485 | // never less than the per-file cap the general path gives a file. |
| 8486 | bodyChars: Math.max(budget.maxCharsPerFile, Math.floor(budget.maxOutputChars / 2)), |
| 8487 | readLines: (filePath) => readFile(filePath)?.lines ?? null, |
| 8488 | isTest, |
| 8489 | synthNote: (edge) => this.synthEdgeNote(edge), |
| 8490 | elidedNote: elidedBodyNote, |
| 8491 | testsThroughCallers: (dependents) => this.indirectTestNote(cg, dependents, rel, isTest).replace(/^;\s*/, ''), |
| 8492 | nodeServed: this.isToolServed('node'), |
| 8493 | }, name, defs); |
| 8494 | } catch { |
no test coverage detected