feat: Fix Go struct/interface extraction by refactoring type_spec handling through type alias resolver
Addresses Go's tree-sitter parsing where structs and interfaces are wrapped in type_spec nodes rather than appearing as direct node types. Moves struct_type and interface_type detection from direct node type matching to a new resolveTypeAliasKind resolver that examines the inner type field, ensuring proper extraction with field visiting and inheritance detection.
This commit is contained in:
@@ -5,8 +5,8 @@ export const goExtractor: LanguageExtractor = {
|
||||
functionTypes: ['function_declaration'],
|
||||
classTypes: [], // Go doesn't have classes
|
||||
methodTypes: ['method_declaration'],
|
||||
interfaceTypes: ['interface_type'],
|
||||
structTypes: ['struct_type'],
|
||||
interfaceTypes: [], // Handled via type_spec → resolveTypeAliasKind
|
||||
structTypes: [], // Handled via type_spec → resolveTypeAliasKind
|
||||
enumTypes: [],
|
||||
typeAliasTypes: ['type_spec'], // Go type declarations
|
||||
importTypes: ['import_declaration'],
|
||||
@@ -27,6 +27,15 @@ export const goExtractor: LanguageExtractor = {
|
||||
}
|
||||
return sig;
|
||||
},
|
||||
resolveTypeAliasKind: (node, _source) => {
|
||||
// Go type_spec: `type Foo struct { ... }` or `type Bar interface { ... }`
|
||||
// The inner type is in the 'type' field of the type_spec node
|
||||
const typeChild = getChildByField(node, 'type');
|
||||
if (!typeChild) return undefined;
|
||||
if (typeChild.type === 'struct_type') return 'struct';
|
||||
if (typeChild.type === 'interface_type') return 'interface';
|
||||
return undefined;
|
||||
},
|
||||
getReceiverType: (node, source) => {
|
||||
// Go method_declaration has a "receiver" field: func (sl *scrapeLoop) run(...)
|
||||
// The receiver is a parameter_list containing a parameter_declaration
|
||||
|
||||
Reference in New Issue
Block a user