feat: Add Swift inheritance extraction for class, struct, enum, and protocol relationships
Addresses Swift's inheritance_specifier syntax where type relationships are specified after colons (e.g. `class UploadRequest: DataRequest, Sendable`). Extracts user_type > type_identifier children from inheritance_specifier nodes as 'extends' references to properly model Swift's inheritance, protocol conformance, and struct conformance patterns in the code graph.
This commit is contained in:
@@ -583,6 +583,9 @@ export class TreeSitterExtractor {
|
||||
});
|
||||
if (!structNode) return;
|
||||
|
||||
// Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable)
|
||||
this.extractInheritance(node, structNode.id);
|
||||
|
||||
// Push to stack for field extraction
|
||||
this.nodeStack.push(structNode.id);
|
||||
const body = getChildByField(node, this.extractor.bodyField) || node;
|
||||
@@ -1309,6 +1312,23 @@ export class TreeSitterExtractor {
|
||||
}
|
||||
}
|
||||
|
||||
// Swift: inheritance_specifier > user_type > type_identifier
|
||||
// Used for class inheritance, protocol conformance, and protocol inheritance
|
||||
if (child.type === 'inheritance_specifier') {
|
||||
const userType = child.namedChildren.find((c: SyntaxNode) => c.type === 'user_type');
|
||||
const typeId = userType?.namedChildren.find((c: SyntaxNode) => c.type === 'type_identifier');
|
||||
if (typeId) {
|
||||
const name = getNodeText(typeId, this.source);
|
||||
this.unresolvedReferences.push({
|
||||
fromNodeId: classId,
|
||||
referenceName: name,
|
||||
referenceKind: 'extends',
|
||||
line: typeId.startPosition.row + 1,
|
||||
column: typeId.startPosition.column,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Recurse into container nodes (e.g. field_declaration_list in Go structs)
|
||||
if (child.type === 'field_declaration_list') {
|
||||
this.extractInheritance(child, classId);
|
||||
|
||||
Reference in New Issue
Block a user