externcalls.py¶
clew/query/externcalls.py
The callees a function has that the index holds no function for.
external_callees
list[ExternalCallee] clew.query.externcalls.external_callees(sqlite3.Connection conn, Path|str repo_root, str file, int start, int end)
The unresolvable callee names a function's own body calls.
Called by _body_and_external
Calls _by_name, _harvest_file, _reportable, _ts_language_for, _unindexed
Source · 40 lines
def external_callees(
conn: sqlite3.Connection,
repo_root: Path | str,
file: str,
start: int,
end: int,
) -> list[ExternalCallee]:
"""Answer "this function calls out of the index, to these names" for the body
extent `file:start..end`.
The extent comes from the resolved identity's own `memberdef` row, so the caller
has already decided WHICH same-named function is being described (gh#26) and this
cannot attribute one identity's calls to another. Sites are filtered by line, which
includes calls inside lambdas and nested blocks — correctly: those are calls this
function's text makes.
An empty list means one of two things and does not distinguish them: every callee
resolved, or the body could not be parsed. That is acceptable here and only here,
because the field is ADDITIVE — a consumer that gets nothing is exactly as informed
as it was before this existed — and because the alternative, an "unknown" sentinel
in a one-shot payload, spends bytes on every function to describe a condition the
payload cannot act on.
@brief List a function body's unresolvable callee names.
@return Capped ExternalCallee rows, in source order.
@version 2
"""
sites = _harvest_file(Path(repo_root), file)
if not sites:
return []
within = [s for s in sites if start <= int(s[1]) <= end]
lang = _ts_language_for(file)
reportable = _reportable(within, is_python=lang is not None and "python" in lang.__name__)
found: list[ExternalCallee] = []
for name, lines in _by_name(reportable).items():
if len(found) >= MAX_EXTERNAL_CALLEES:
break
if _unindexed(conn, name):
found.append(ExternalCallee(name=name, call_lines=tuple(lines)))
return found1 more lines, not shown