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

Method gateTargetKind

src/resolution/index.ts:4335–4418  ·  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

4333 * supertype that lives outside the repo — silent beats wrong.
4334 */
4335 private gateTargetKind(result: ResolvedRef | null, ref: UnresolvedRef): ResolvedRef | null {
4336 if (!result) return result;
4337
4338 // A Go name called or passed bare that the function around it binds
4339 // itself — a parameter, a `:=`, a `var` — is that binding, never a
4340 // declaration of the package: client-go's `init := func(…)` then
4341 // `init(t)` calls no `func init()`.
4342 if (ref.language === 'go' && (ref.referenceKind === 'calls' || ref.referenceKind === 'function_ref') &&
4343 isGoBareName(ref, this.context) && isGoLocallyBound(ref, this.context)) return null;
4344
4345 // A `#define` is a value, never a callee (#1838): a macro defined only in
4346 // an unrelated file is not what `NAME(x)` here expands to either.
4347 if (ref.referenceKind === 'calls') {
4348 const target = this.nodeById(result.targetNodeId);
4349 if (target?.kind === 'constant' && CPP_DEFINE_SIGNATURE.test(target.signature ?? '')) return null;
4350 // A Go call made through an expression — `h.Validate().Error()`, a
4351 // `.Metrics()` chained onto the line above — calls a method of whatever
4352 // the expression is. A type is called only bare (`T(x)`, `(*T)(x)`) or
4353 // through its package; as a struct here it read as an instantiation.
4354 if (target && ref.language === 'go' && GO_TYPE_KINDS.has(target.kind) &&
4355 !ref.referenceName.includes('.') && !isGoBareName(ref, this.context)) return null;
4356 }
4357
4358 // A TypeScript interface or type alias is no value: nothing calls one or
4359 // makes an instance of it. A strategy that found one by name meant the
4360 // value its file declares beside it (`interface Ok` and `function Ok` in a
4361 // result module); with none there, the name is a value from elsewhere
4362 // that the project only types (`new Response()`, `new Worker()`), and
4363 // links nothing.
4364 if ((ref.referenceKind === 'calls' || ref.referenceKind === 'instantiates') && ESM_IMPORT_LANGUAGES.has(ref.language)) {
4365 const target = this.nodeById(result.targetNodeId);
4366 if (target && (target.kind === 'interface' || target.kind === 'type_alias')) {
4367 const value = this.sameNamedValueOfType(target);
4368 if (!value) return null;
4369 result = { ...result, targetNodeId: value.id };
4370 }
4371 }
4372
4373 // An `imports` reference names something importable — never a member that
4374 // only exists inside a type, nor its own import statement. A module path
4375 // that names no file (`./missing`, `stdio.h`, `pkg.mod`, a C# `using` of
4376 // an outside namespace) reaches the statement by its qualified name; as an
4377 // edge to itself it is never retried, while a failed ref is retried by the
4378 // sync that adds the file it names.
4379 if (ref.referenceKind === 'imports') {
4380 const target = this.nodeById(result.targetNodeId);
4381 if (target?.kind === 'import' && target.filePath === ref.filePath) return null;
4382 return target && !isImportableKind(target.kind) ? null : result;
4383 }
4384
4385 // A Go type declaration — an alias, a defined type, a struct's fields —
4386 // names its types as an embedding does (below): written through a package
4387 // that is none of the file's imports as indexed, the type found by its
4388 // bare name is another package's namesake, or the declaration itself
4389 // (`op clientv3.Op` beside the file's own `Op`).
4390 if (ref.language === 'go' && ref.referenceKind === 'references' &&
4391 GO_TYPE_KINDS.has(this.nodeById(ref.fromNodeId)?.kind ?? '') && isGoUnknownQualified(ref, this.context)) return null;
4392

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