Generate call table row scaffolding for a section's nodes. The Caller/Callee columns make a claim about the whole graph ("External entry / no inbound edge"), so they must be computed from the whole graph. Built from ``section_edges`` alone they only see edges whose *both* endpoints
(
nodes: list,
section_edges: list,
lang: str,
all_edges: list | None = None,
all_nodes: list | None = None,
)
| 1230 | |
| 1231 | |
| 1232 | def generate_call_table_rows( |
| 1233 | nodes: list, |
| 1234 | section_edges: list, |
| 1235 | lang: str, |
| 1236 | all_edges: list | None = None, |
| 1237 | all_nodes: list | None = None, |
| 1238 | ) -> str: |
| 1239 | """Generate call table row scaffolding for a section's nodes. |
| 1240 | |
| 1241 | The Caller/Callee columns make a claim about the whole graph ("External |
| 1242 | entry / no inbound edge"), so they must be computed from the whole graph. |
| 1243 | Built from ``section_edges`` alone they only see edges whose *both* |
| 1244 | endpoints sit in this section, so a node called from anywhere else is |
| 1245 | mislabelled an entry point. Section coverage makes that the common case |
| 1246 | rather than a corner case: only ``max_sections`` communities are rendered, |
| 1247 | so most callers are not in any rendered section at all. |
| 1248 | |
| 1249 | ``all_edges``/``all_nodes`` are the full graph; ``all_nodes`` also lets |
| 1250 | out-of-section callers render as labels instead of raw node ids. Both |
| 1251 | default to None, preserving the previous behaviour for other callers. |
| 1252 | """ |
| 1253 | if not nodes: |
| 1254 | return "" |
| 1255 | |
| 1256 | # Build source/target lookup from edges |
| 1257 | node_by_id = {n.get("id"): n for n in (all_nodes or nodes)} |
| 1258 | callers = defaultdict(set) |
| 1259 | callees = defaultdict(set) |
| 1260 | for e in (all_edges if all_edges is not None else section_edges): |
| 1261 | src = e.get("source", "") |
| 1262 | tgt = e.get("target", "") |
| 1263 | if e.get("relation") in ("calls", "imports", "imports_from", "uses", "method", "indirect_call"): |
| 1264 | callers[tgt].add(src) |
| 1265 | callees[src].add(tgt) |
| 1266 | |
| 1267 | rows = [] |
| 1268 | for i, n in enumerate(nodes[:30], 1): # cap at 30 rows |
| 1269 | nid = n.get("id", "") |
| 1270 | label = n.get("label", nid) |
| 1271 | source_file = safe_file_path(n.get("source_file", "")) |
| 1272 | file_type = n.get("file_type", "code") |
| 1273 | |
| 1274 | # Suggest a tag type based on file_type and label heuristics |
| 1275 | tag = _suggest_tag(label, file_type, lang, node_kind(n)) |
| 1276 | |
| 1277 | caller_text = format_node_refs( |
| 1278 | callers.get(nid, set()), |
| 1279 | node_by_id, |
| 1280 | lang, |
| 1281 | pick_text(lang, "外部入口 / 无直接入边", "External entry / no inbound edge"), |
| 1282 | ) |
| 1283 | callee_text = format_node_refs( |
| 1284 | callees.get(nid, set()), |
| 1285 | node_by_id, |
| 1286 | lang, |
| 1287 | pick_text(lang, "无直接出边", "No direct outbound edge"), |
| 1288 | ) |
| 1289 |