feat: Promote "extends" to "implements" for class-to-interface relationships in edge creation

Addresses semantic accuracy in inheritance relationships where classes use "extends" syntax to implement interfaces. Adds target node inspection to detect interface/protocol targets and promotes the edge kind from "extends" to "implements" when the source is a concrete class or struct, ensuring proper representation of implementation vs inheritance relationships in the code graph.
This commit is contained in:
Colby McHenry
2026-04-07 00:02:47 -05:00
parent b712e4de63
commit 07d899b735
+26 -11
View File
@@ -422,17 +422,32 @@ export class ReferenceResolver {
* Create edges from resolved references
*/
createEdges(resolved: ResolvedRef[]): Edge[] {
return resolved.map((ref) => ({
source: ref.original.fromNodeId,
target: ref.targetNodeId,
kind: ref.original.referenceKind,
line: ref.original.line,
column: ref.original.column,
metadata: {
confidence: ref.confidence,
resolvedBy: ref.resolvedBy,
},
}));
return resolved.map((ref) => {
let kind = ref.original.referenceKind;
// Promote "extends" to "implements" when a class/struct targets an interface
if (kind === 'extends') {
const targetNode = this.queries.getNodeById(ref.targetNodeId);
if (targetNode && (targetNode.kind === 'interface' || targetNode.kind === 'protocol')) {
const sourceNode = this.queries.getNodeById(ref.original.fromNodeId);
if (sourceNode && sourceNode.kind !== 'interface' && sourceNode.kind !== 'protocol') {
kind = 'implements';
}
}
}
return {
source: ref.original.fromNodeId,
target: ref.targetNodeId,
kind,
line: ref.original.line,
column: ref.original.column,
metadata: {
confidence: ref.confidence,
resolvedBy: ref.resolvedBy,
},
};
});
}
/**