MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / matchReference

Function matchReference

src/resolution/name-matcher.ts:9392–9432  ·  view source on GitHub ↗
(
  ref: UnresolvedRef,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

9390}
9391
9392export function matchReference(
9393 ref: UnresolvedRef,
9394 context: ResolutionContext
9395): ResolvedRef | null {
9396 const result = gateLanguageMatch(matchReferenceInner(ref, context), ref, context);
9397 // `this.container.classList.toggle()` inside `toggle()`, `window.$events
9398 // .listen()` inside `listen()`, Scala's `requestToArmeria(request).execute()`
9399 // inside `execute()`: a member of what the receiver is, which is the calling
9400 // method only through a TS/JS field of the caller's own type.
9401 if (result && result.targetNodeId === ref.fromNodeId && isCollapsedNonRecursion(ref, context)) return null;
9402 // A name the calling JS/TS function binds itself shadows the file's own:
9403 // lodash's `mixin(object, …)` calling `object(this.__wrapped__)` is its
9404 // parameter, whichever strategy (fuzzy included) found a `function object`.
9405 if (result && JS_LOCAL_REF_KINDS.has(ref.referenceKind)) {
9406 const target = context.getNodeById?.(result.targetNodeId);
9407 // (A target of another name is what the local was followed to: `const
9408 // selected = useStore(s => s.reset); selected()` is the store's `reset`.)
9409 if (target && target.name === ref.referenceName && isOutsideJsLocal(target, ref, context)) return null;
9410 }
9411 // R looks a call's name up among FUNCTIONS only, skipping other bindings:
9412 // ggplot2's tests' `c <- data_frame(b = 3)` is never what `c(1, 2)` calls —
9413 // base R's `c` is. (A project binding made by a function factory, ggplot2's
9414 // `geom_point <- make_constructor(…)`, is a function, and stays.)
9415 if (result && ref.language === 'r' && ref.referenceKind === 'calls' && R_BASE_FUNCTIONS.has(ref.referenceName)) {
9416 const target = context.getNodeById?.(result.targetNodeId);
9417 if (target && (target.kind === 'variable' || target.kind === 'constant') && !isRFunctionValue(target, context)) return null;
9418 }
9419 // C has no methods, and C code cannot call a C++ one: hiredis' function
9420 // pointer `c->funcs->read(c, buf, …)` is no Qt adapter's `read`.
9421 if (result && ref.language === 'c' && ref.referenceKind === 'calls' &&
9422 context.getNodeById?.(result.targetNodeId)?.kind === 'method') return null;
9423 // A type never inherits from itself: cats' `trait BigDecimalInstances extends
9424 // cats.kernel.instances.BigDecimalInstances` and `trait AllOps … with
9425 // Bifoldable.AllOps` name another type of their own name.
9426 if (result && result.targetNodeId === ref.fromNodeId && isInheritanceRef(ref)) return otherSupertypeNamed(ref, context);
9427 // Nor does a value's initializer call the value: sttp's `val response =
9428 // basicRequest.get(…).response(asStringAlways)` is a request's `response`.
9429 if (result && result.targetNodeId === ref.fromNodeId && ref.referenceKind === 'calls' &&
9430 VALUE_KINDS.has(context.getNodeById?.(ref.fromNodeId)?.kind ?? '')) return null;
9431 return result ? retargetSelfOverload(result, ref, context) : result;
9432}
9433
9434/**
9435 * The supertype an inheritance ref names when the name is the declaring

Callers 3

resolveOneInnerMethod · 0.90
resolution.test.tsFile · 0.90

Calls 10

isInheritanceRefFunction · 0.90
gateLanguageMatchFunction · 0.85
matchReferenceInnerFunction · 0.85
isCollapsedNonRecursionFunction · 0.85
isOutsideJsLocalFunction · 0.85
isRFunctionValueFunction · 0.85
otherSupertypeNamedFunction · 0.85
retargetSelfOverloadFunction · 0.85
hasMethod · 0.80
getNodeByIdMethod · 0.65

Tested by

no test coverage detected