Return the chunk containing *line* in *file_path*, or None. Reconstructs a Chunk from its JSON-primitive MCP tool arguments (file_path + line) before calling into the library.
(chunks: list[Chunk], file_path: str, line: int)
| 17 | |
| 18 | |
| 19 | def resolve_chunk(chunks: list[Chunk], file_path: str, line: int) -> Chunk | None: |
| 20 | """Return the chunk containing *line* in *file_path*, or None. |
| 21 | |
| 22 | Reconstructs a Chunk from its JSON-primitive MCP tool arguments (file_path + line) |
| 23 | before calling into the library. |
| 24 | """ |
| 25 | fallback = None |
| 26 | for chunk in chunks: |
| 27 | if chunk.file_path == file_path and chunk.start_line <= line <= chunk.end_line: |
| 28 | if line < chunk.end_line: |
| 29 | return chunk |
| 30 | if fallback is None: # line == end_line: boundary; keep as fallback for end-of-file chunks |
| 31 | fallback = chunk |
| 32 | return fallback |
| 33 | |
| 34 | |
| 35 | def format_results(query: str, results: list[SearchResult], max_snippet_lines: int | None = None) -> dict[str, Any]: |
no outgoing calls