feat: Add complete PHP language support with trait handling and property extraction

Addresses PHP traits extracted as classes, missing class properties, skipped constants, and invisible trait usage. Adds classifyClassNode to distinguish traits from classes, fixes property extraction for PHP's property_element AST structure (added 4,366 field nodes), and adds visitNode hook for class constants and trait use declarations (increased trait edges from 636 to 1,514). Also improves Liquid schema name handling and file path reference resolution. Verified against Laravel codebase.
This commit is contained in:
Colby McHenry
2026-04-07 13:44:14 -05:00
parent 1b279dcf94
commit f402ab8363
8 changed files with 151 additions and 5 deletions
+34 -2
View File
@@ -266,6 +266,8 @@ export class TreeSitterExtractor {
this.extractEnum(node);
} else if (classification === 'interface') {
this.extractInterface(node);
} else if (classification === 'trait') {
this.extractClass(node, 'trait');
} else {
this.extractClass(node);
}
@@ -542,7 +544,7 @@ export class TreeSitterExtractor {
/**
* Extract a class
*/
private extractClass(node: SyntaxNode): void {
private extractClass(node: SyntaxNode, kind: NodeKind = 'class'): void {
if (!this.extractor) return;
const name = extractName(node, this.source, this.extractor);
@@ -550,7 +552,7 @@ export class TreeSitterExtractor {
const visibility = this.extractor.getVisibility?.(node);
const isExported = this.extractor.isExported?.(node, this.source);
const classNode = this.createNode('class', name, node, {
const classNode = this.createNode(kind, name, node, {
docstring,
visibility,
isExported,
@@ -864,6 +866,35 @@ export class TreeSitterExtractor {
}
}
// PHP property_declaration: property_element → variable_name → name
if (declarators.length === 0) {
const propElements = node.namedChildren.filter(c => c.type === 'property_element');
if (propElements.length > 0) {
// Get type annotation if present (e.g. "string", "int", "?Foo")
const typeNode = node.namedChildren.find(
c => c.type !== 'visibility_modifier' && c.type !== 'static_modifier'
&& c.type !== 'readonly_modifier' && c.type !== 'property_element'
&& c.type !== 'var_modifier'
);
const typeText = typeNode ? getNodeText(typeNode, this.source) : undefined;
for (const elem of propElements) {
const varName = elem.namedChildren.find(c => c.type === 'variable_name');
const nameNode = varName?.namedChildren.find(c => c.type === 'name');
if (!nameNode) continue;
const name = getNodeText(nameNode, this.source);
const signature = typeText ? `${typeText} $${name}` : `$${name}`;
this.createNode('field', name, elem, {
docstring,
signature,
visibility,
isStatic,
});
}
return;
}
}
if (declarators.length > 0) {
// Get field type from the type child
// Java: type is a direct child of field_declaration
@@ -1458,6 +1489,7 @@ export class TreeSitterExtractor {
if (classification === 'struct') this.extractStruct(node);
else if (classification === 'enum') this.extractEnum(node);
else if (classification === 'interface') this.extractInterface(node);
else if (classification === 'trait') this.extractClass(node, 'trait');
else this.extractClass(node);
return;
}