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.

clew/query/externcalls.py:197

Show on the map →

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 found

1 more lines, not shown

Activity · 13 steps
lines 224–224sites = _harvest_file(Path(repo_root), file)lines 225–225◇ if not siteslines 226–226return []lines 227–227within = [s for s in sites if start <= int(s[1]) <= end]lines 228–228lang = _ts_language_for(file)lines 229–229reportable = _reportable(within, is_python=lang is not None and "python" in lang.__name__)lines 230–230found: list[ExternalCallee] = []lines 231–231◇ for name, lines in _by_name(reportable).items()lines 232–232◇ if len(found) >= MAX_EXTERNAL_CALLEESlines 233–233breaklines 234–234◇ if _unindexed(conn, name)lines 235–235found.append(ExternalCallee(name=name, call_lines=tuple(lines)))lines 236–236return found

Requirements

REQ-DDB-QUERY-001