refactor: Extract per-language configs and standalone extractors from tree-sitter.ts
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>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
0d63166f9d
commit
c8407ad007
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user