Noir::GoCalleeExtractor
Tree-sitter-backed Go 1-hop callee extractor. Parallels
Noir::PythonCalleeExtractor but works at the AST level — Go can't
share the Python convention of "give me a body string", because
tree-sitter Go needs a complete source_file and a bare function body
isn't one.
The extractor receives a full Go file plus the set of route call expression rows the analyzer cares about. For each match it locates the handler argument and walks the appropriate body:
func_literal(inline closure handler) — walk the closure's body in place;path/lineon emitted callees point at the original file.identifier(named handler) — look the name up in the file's top-levelfunction_declarations first, then inexternal_functions(sibling files in the same Go package). The external map is built once per directory byGoEngine#collect_package_function_bodiesso cross-file lookups are cheap.selector_expression— resolve unambiguous same-package method values (handler.Get) throughexternal_methods, and imported top-level function handlers (pkg.Foo) when the analyzer supplies a go.mod-backed import-path function index.
Builtins (len, make, append, …) and Go's primitive type
constructors (int, string, byte, …) are filtered to keep the
per-endpoint list focused on signal that's actually useful to an AI
reviewer.
Constants
Go builtins and primitive type-conversions that carry no useful
signal. Anything framework-specific (c.JSON, c.Query,
gin.H{...}, etc.) is kept on purpose — those tell a reviewer how
the endpoint shapes input/output.
Instance methods
For each call_expression at a row in route_rows, find the handler
argument, walk its body, and return the 1-hop callees keyed by row.
Each entry is a tuple {name, callee_file_path, file_line_1_based}.
external_methods maps a (package-unqualified) method name to the
bodies that define it, so a method-value handler (as.Campaigns,
s.handleOIDCRedirect — the dominant shape in gorilla/mux and chi
apps) resolves to its method body when the name is unambiguous.
Like callees_for_routes, but returns an empty map immediately when
enabled is false. Lets analyzers skip the tree-sitter walk on
default scans where callees won't be observed.
Public entry for walking a captured function/method body and
returning its 1-hop callees. Used by analyzers (Beego controller
routing) that resolve a handler to a FunctionBody outside the
standard route-row flow.
Returns top-level function declarations in source, keyed by name.
file_path is recorded on each FunctionBody so callees emitted by
later re-parsing can report a useful path.
Callers treat the result as read-only (they copy entries into their own per-directory maps), which is what lets it be shared.
Collects top-level method_declaration bodies keyed by method name.
The value is a list because a name can be defined on several receiver
types in one package; callers that need an unambiguous resolution
should require size == 1. Used to attach callees to controller-style
routes whose handler is referenced by method name only.
{alias => import path} for every import in source. Public so the
chi analyzer can turn apiv1.Routes() in a .Mount(...) call into
the package directory that declares Routes.
Per-directory tables for callers that only look them up per directory
(see LazyPackageBodies): no gate for functions, func ( for methods.