Handle the `find-related` subcommand.
(
path: str, file_path: str, line: int, top_k: int, content: list[ContentType], max_snippet_lines: int | None
)
| 115 | |
| 116 | |
| 117 | def _run_find_related( |
| 118 | path: str, file_path: str, line: int, top_k: int, content: list[ContentType], max_snippet_lines: int | None |
| 119 | ) -> None: |
| 120 | """Handle the `find-related` subcommand.""" |
| 121 | index = _load_index(path, content) |
| 122 | chunk = resolve_chunk(index.chunks, file_path, line) |
| 123 | if chunk is None: |
| 124 | print(f"No chunk found at {file_path}:{line}.", file=sys.stderr) |
| 125 | sys.exit(1) |
| 126 | results = index.find_related(chunk, top_k=top_k, max_snippet_lines=max_snippet_lines) |
| 127 | label = f"Chunks related to {file_path}:{line}" |
| 128 | out = ( |
| 129 | format_results(label, results, max_snippet_lines) |
| 130 | if results |
| 131 | else {"error": f"No related chunks found for {file_path}:{line}."} |
| 132 | ) |
| 133 | print(json.dumps(out)) |
| 134 | _maybe_save_index(index, path) |
| 135 | |
| 136 | |
| 137 | def _run_clear(clear_type: _CLEAR_CHOICE) -> None: |
no test coverage detected