Splits the monolithic tree-sitter.ts (3,358 lines) into modular files: - 14 language config files under src/extraction/languages/ - 3 standalone extractors (Liquid, Svelte, DFM) - Shared helpers and types modules to avoid circular imports Also fixes a bug where Java's extractImport hook incorrectly set handledRefs: true, preventing unresolved reference creation and degrading codegraph_explore results for Java codebases. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { getNodeText, getChildByField } from '../tree-sitter-helpers';
|
|
import type { LanguageExtractor } from '../tree-sitter-types';
|
|
|
|
export const pythonExtractor: LanguageExtractor = {
|
|
functionTypes: ['function_definition'],
|
|
classTypes: ['class_definition'],
|
|
methodTypes: ['function_definition'], // Methods are functions inside classes
|
|
interfaceTypes: [],
|
|
structTypes: [],
|
|
enumTypes: [],
|
|
typeAliasTypes: [],
|
|
importTypes: ['import_statement', 'import_from_statement'],
|
|
callTypes: ['call'],
|
|
variableTypes: ['assignment'], // Python uses assignment for variable declarations
|
|
nameField: 'name',
|
|
bodyField: 'body',
|
|
paramsField: 'parameters',
|
|
returnField: 'return_type',
|
|
getSignature: (node, source) => {
|
|
const params = getChildByField(node, 'parameters');
|
|
const returnType = getChildByField(node, 'return_type');
|
|
if (!params) return undefined;
|
|
let sig = getNodeText(params, source);
|
|
if (returnType) {
|
|
sig += ' -> ' + getNodeText(returnType, source);
|
|
}
|
|
return sig;
|
|
},
|
|
isAsync: (node) => {
|
|
const prev = node.previousSibling;
|
|
return prev?.type === 'async';
|
|
},
|
|
isStatic: (node) => {
|
|
// Check for @staticmethod decorator
|
|
const prev = node.previousNamedSibling;
|
|
if (prev?.type === 'decorator') {
|
|
const text = prev.text;
|
|
return text.includes('staticmethod');
|
|
}
|
|
return false;
|
|
},
|
|
extractImport: (node, source) => {
|
|
const importText = source.substring(node.startIndex, node.endIndex).trim();
|
|
if (node.type === 'import_from_statement') {
|
|
const moduleNode = node.childForFieldName('module_name');
|
|
if (moduleNode) {
|
|
return { moduleName: source.substring(moduleNode.startIndex, moduleNode.endIndex), signature: importText };
|
|
}
|
|
}
|
|
// import_statement creates multiple imports - return null for core fallback
|
|
return null;
|
|
},
|
|
};
|