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

Function resolveImportedInstanceMember

src/resolution/import-resolver.ts:4467–4502  ·  view source on GitHub ↗

* Resolve a CALL through an imported value to the method on the value's own * type: `reproStore.notifyJoinGuildStatus()` where `reproStore` is * `export const reproStore = new ReproStore()` in the imported file (#1292). * The same-file form of this call already resolves via local-variable * rece

(
  value: Node,
  ref: UnresolvedRef,
  localName: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

4465 * caller keeps its existing constant-edge behavior.
4466 */
4467function resolveImportedInstanceMember(
4468 value: Node,
4469 ref: UnresolvedRef,
4470 localName: string,
4471 context: ResolutionContext
4472): ResolvedRef | null {
4473 if (ref.referenceKind !== 'calls') return null;
4474 if (value.kind !== 'constant' && value.kind !== 'variable') return null;
4475 // The method called on the value itself: `app.jinja_env.filters.keys()`
4476 // calls `keys`, no method of the app's type — never `jinja_env`.
4477 const member = ref.referenceName.slice(localName.length + 1);
4478 if (!member || member.includes('.')) return null;
4479
4480 const source = context.readFile(value.filePath);
4481 if (!source) return null;
4482 // Only the value's own declaration lines — never the whole file, so a
4483 // same-named identifier elsewhere can't donate a type.
4484 const lines = source.split('\n');
4485 const declSlice = lines.slice(Math.max(0, value.startLine - 1), value.endLine).join('\n');
4486
4487 const receiver = value.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
4488 for (const pattern of localReceiverTypePatterns(value.language as Language, receiver)) {
4489 const m = declSlice.match(pattern);
4490 if (!m || !m[1]) continue;
4491 const typeName = normalizeInferredTypeName(m[1]);
4492 if (!typeName) continue;
4493 // Several classes may share the name. The value's file says which one:
4494 // the class it imports under that name, or else the one it declares.
4495 const declaring = ESM_IMPORT_LANGUAGES.has(value.language)
4496 ? tsImportedTypeFile(m[1], { ...ref, filePath: value.filePath, language: value.language }, context) ?? value.filePath
4497 : undefined;
4498 const resolved = resolveMethodOnType(typeName, member, ref, context, 0.85, 'instance-method', declaring);
4499 if (resolved) return resolved;
4500 }
4501 return null;
4502}
4503
4504function resolveStaticMember(
4505 container: Node,

Callers 1

resolveViaImportFunction · 0.85

Calls 3

readFileMethod · 0.80
hasMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected