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

Method gateTargetKind

src/resolution/index.ts:4556–4643  ·  view source on GitHub ↗

* Drop a resolution whose target cannot be what the reference names. * Applied at the `resolveOne` seam so it covers every strategy uniformly — * framework, import, name-match, chain, CFML component path. * * For `imports`: the target must be importable. A member that only exists * in

(result: ResolvedRef | null, ref: UnresolvedRef)

Source from the content-addressed store, hash-verified

4554 * supertype that lives outside the repo — silent beats wrong.
4555 */
4556 private gateTargetKind(result: ResolvedRef | null, ref: UnresolvedRef): ResolvedRef | null {
4557 if (!result) return result;
4558
4559 // A Go name called or passed bare that the function around it binds
4560 // itself — a parameter, a `:=`, a `var` — is that binding, never a
4561 // declaration of the package: client-go's `init := func(…)` then
4562 // `init(t)` calls no `func init()`.
4563 if (ref.language === 'go' && (ref.referenceKind === 'calls' || ref.referenceKind === 'function_ref') &&
4564 isGoBareName(ref, this.context) && isGoLocallyBound(ref, this.context)) return null;
4565
4566 // A `#define` is a value, never a callee (#1838): a macro defined only in
4567 // an unrelated file is not what `NAME(x)` here expands to either.
4568 if (ref.referenceKind === 'calls') {
4569 const target = this.nodeById(result.targetNodeId);
4570 if (target?.kind === 'constant' && CPP_DEFINE_SIGNATURE.test(target.signature ?? '')) return null;
4571 // A Go call made through an expression — `h.Validate().Error()`, a
4572 // `.Metrics()` chained onto the line above — calls a method of whatever
4573 // the expression is. A type is called only bare (`T(x)`, `(*T)(x)`) or
4574 // through its package; as a struct here it read as an instantiation.
4575 if (target && ref.language === 'go' && GO_TYPE_KINDS.has(target.kind) &&
4576 !ref.referenceName.includes('.') && !isGoBareName(ref, this.context)) return null;
4577 // A JS/TS call written on `this` reads a property of the object: a
4578 // `const`/`let`/`var` or a `function` declaration is a lexical binding,
4579 // never what `this.cast()` names (see isLexicalBindingOfJsThisCall).
4580 if (target && isLexicalBindingOfJsThisCall(target, ref, this.context)) return null;
4581 }
4582
4583 // A TypeScript interface or type alias is no value: nothing calls one or
4584 // makes an instance of it. A strategy that found one by name meant the
4585 // value its file declares beside it (`interface Ok` and `function Ok` in a
4586 // result module); with none there, the name is a value from elsewhere
4587 // that the project only types (`new Response()`, `new Worker()`), and
4588 // links nothing.
4589 if ((ref.referenceKind === 'calls' || ref.referenceKind === 'instantiates') && ESM_IMPORT_LANGUAGES.has(ref.language)) {
4590 const target = this.nodeById(result.targetNodeId);
4591 if (target && (target.kind === 'interface' || target.kind === 'type_alias')) {
4592 const value = this.sameNamedValueOfType(target);
4593 if (!value) return null;
4594 result = { ...result, targetNodeId: value.id };
4595 }
4596 }
4597
4598 // An `imports` reference names something importable — never a member that
4599 // only exists inside a type, nor its own import statement. A module path
4600 // that names no file (`./missing`, `stdio.h`, `pkg.mod`, a C# `using` of
4601 // an outside namespace) reaches the statement by its qualified name; as an
4602 // edge to itself it is never retried, while a failed ref is retried by the
4603 // sync that adds the file it names.
4604 if (ref.referenceKind === 'imports') {
4605 const target = this.nodeById(result.targetNodeId);
4606 if (target?.kind === 'import' && target.filePath === ref.filePath) return null;
4607 return target && !isImportableKind(target.kind) ? null : result;
4608 }
4609
4610 // A Go type declaration — an alias, a defined type, a struct's fields —
4611 // names its types as an embedding does (below): written through a package
4612 // that is none of the file's imports as indexed, the type found by its
4613 // bare name is another package's namesake, or the declaration itself

Callers 1

resolveOneInMethod · 0.95

Calls 8

nodeByIdMethod · 0.95
sameNamedValueOfTypeMethod · 0.95
sameNamedTypeOfValueMethod · 0.95
isImportableKindFunction · 0.90
isInheritanceRefFunction · 0.90
isSupertypeTargetFunction · 0.90
isBoundToOutOfRepoImportFunction · 0.90
hasMethod · 0.80

Tested by

no test coverage detected