@liendev/core 0.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +336 -0
- package/dist/config/loader.d.ts +12 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +46 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/merge.d.ts +20 -0
- package/dist/config/merge.d.ts.map +1 -0
- package/dist/config/merge.js +71 -0
- package/dist/config/merge.js.map +1 -0
- package/dist/config/migration-manager.d.ts +46 -0
- package/dist/config/migration-manager.d.ts.map +1 -0
- package/dist/config/migration-manager.js +119 -0
- package/dist/config/migration-manager.js.map +1 -0
- package/dist/config/migration.d.ts +20 -0
- package/dist/config/migration.d.ts.map +1 -0
- package/dist/config/migration.js +155 -0
- package/dist/config/migration.js.map +1 -0
- package/dist/config/schema.d.ts +101 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +58 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/service.d.ts +122 -0
- package/dist/config/service.d.ts.map +1 -0
- package/dist/config/service.js +477 -0
- package/dist/config/service.js.map +1 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +43 -0
- package/dist/constants.js.map +1 -0
- package/dist/embeddings/cache.d.ts +45 -0
- package/dist/embeddings/cache.d.ts.map +1 -0
- package/dist/embeddings/cache.js +109 -0
- package/dist/embeddings/cache.js.map +1 -0
- package/dist/embeddings/local.d.ts +10 -0
- package/dist/embeddings/local.d.ts.map +1 -0
- package/dist/embeddings/local.js +63 -0
- package/dist/embeddings/local.js.map +1 -0
- package/dist/embeddings/types.d.ts +9 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +5 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/errors/codes.d.ts +18 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/codes.js +25 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/errors/index.d.ts +85 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +134 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/frameworks/detector-service.d.ts +59 -0
- package/dist/frameworks/detector-service.d.ts.map +1 -0
- package/dist/frameworks/detector-service.js +219 -0
- package/dist/frameworks/detector-service.js.map +1 -0
- package/dist/frameworks/laravel/config.d.ts +6 -0
- package/dist/frameworks/laravel/config.d.ts.map +1 -0
- package/dist/frameworks/laravel/config.js +68 -0
- package/dist/frameworks/laravel/config.js.map +1 -0
- package/dist/frameworks/laravel/detector.d.ts +6 -0
- package/dist/frameworks/laravel/detector.d.ts.map +1 -0
- package/dist/frameworks/laravel/detector.js +96 -0
- package/dist/frameworks/laravel/detector.js.map +1 -0
- package/dist/frameworks/nodejs/config.d.ts +6 -0
- package/dist/frameworks/nodejs/config.d.ts.map +1 -0
- package/dist/frameworks/nodejs/config.js +57 -0
- package/dist/frameworks/nodejs/config.js.map +1 -0
- package/dist/frameworks/nodejs/detector.d.ts +6 -0
- package/dist/frameworks/nodejs/detector.d.ts.map +1 -0
- package/dist/frameworks/nodejs/detector.js +77 -0
- package/dist/frameworks/nodejs/detector.js.map +1 -0
- package/dist/frameworks/php/config.d.ts +6 -0
- package/dist/frameworks/php/config.d.ts.map +1 -0
- package/dist/frameworks/php/config.js +53 -0
- package/dist/frameworks/php/config.js.map +1 -0
- package/dist/frameworks/php/detector.d.ts +7 -0
- package/dist/frameworks/php/detector.d.ts.map +1 -0
- package/dist/frameworks/php/detector.js +101 -0
- package/dist/frameworks/php/detector.js.map +1 -0
- package/dist/frameworks/registry.d.ts +20 -0
- package/dist/frameworks/registry.d.ts.map +1 -0
- package/dist/frameworks/registry.js +38 -0
- package/dist/frameworks/registry.js.map +1 -0
- package/dist/frameworks/shopify/config.d.ts +6 -0
- package/dist/frameworks/shopify/config.d.ts.map +1 -0
- package/dist/frameworks/shopify/config.js +50 -0
- package/dist/frameworks/shopify/config.js.map +1 -0
- package/dist/frameworks/shopify/detector.d.ts +6 -0
- package/dist/frameworks/shopify/detector.d.ts.map +1 -0
- package/dist/frameworks/shopify/detector.js +103 -0
- package/dist/frameworks/shopify/detector.js.map +1 -0
- package/dist/frameworks/types.d.ts +51 -0
- package/dist/frameworks/types.d.ts.map +1 -0
- package/dist/frameworks/types.js +21 -0
- package/dist/frameworks/types.js.map +1 -0
- package/dist/git/tracker.d.ts +56 -0
- package/dist/git/tracker.d.ts.map +1 -0
- package/dist/git/tracker.js +189 -0
- package/dist/git/tracker.js.map +1 -0
- package/dist/git/utils.d.ts +60 -0
- package/dist/git/utils.d.ts.map +1 -0
- package/dist/git/utils.js +152 -0
- package/dist/git/utils.js.map +1 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +95 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/ast/chunker.d.ts +28 -0
- package/dist/indexer/ast/chunker.d.ts.map +1 -0
- package/dist/indexer/ast/chunker.js +268 -0
- package/dist/indexer/ast/chunker.js.map +1 -0
- package/dist/indexer/ast/complexity/cognitive.d.ts +16 -0
- package/dist/indexer/ast/complexity/cognitive.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/cognitive.js +106 -0
- package/dist/indexer/ast/complexity/cognitive.js.map +1 -0
- package/dist/indexer/ast/complexity/cyclomatic.d.ts +12 -0
- package/dist/indexer/ast/complexity/cyclomatic.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/cyclomatic.js +61 -0
- package/dist/indexer/ast/complexity/cyclomatic.js.map +1 -0
- package/dist/indexer/ast/complexity/halstead.d.ts +55 -0
- package/dist/indexer/ast/complexity/halstead.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/halstead.js +290 -0
- package/dist/indexer/ast/complexity/halstead.js.map +1 -0
- package/dist/indexer/ast/complexity/index.d.ts +13 -0
- package/dist/indexer/ast/complexity/index.d.ts.map +1 -0
- package/dist/indexer/ast/complexity/index.js +12 -0
- package/dist/indexer/ast/complexity/index.js.map +1 -0
- package/dist/indexer/ast/parser.d.ts +27 -0
- package/dist/indexer/ast/parser.d.ts.map +1 -0
- package/dist/indexer/ast/parser.js +103 -0
- package/dist/indexer/ast/parser.js.map +1 -0
- package/dist/indexer/ast/symbols.d.ts +17 -0
- package/dist/indexer/ast/symbols.d.ts.map +1 -0
- package/dist/indexer/ast/symbols.js +265 -0
- package/dist/indexer/ast/symbols.js.map +1 -0
- package/dist/indexer/ast/traversers/index.d.ts +19 -0
- package/dist/indexer/ast/traversers/index.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/index.js +42 -0
- package/dist/indexer/ast/traversers/index.js.map +1 -0
- package/dist/indexer/ast/traversers/php.d.ts +21 -0
- package/dist/indexer/ast/traversers/php.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/php.js +67 -0
- package/dist/indexer/ast/traversers/php.js.map +1 -0
- package/dist/indexer/ast/traversers/python.d.ts +28 -0
- package/dist/indexer/ast/traversers/python.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/python.js +67 -0
- package/dist/indexer/ast/traversers/python.js.map +1 -0
- package/dist/indexer/ast/traversers/types.d.ts +98 -0
- package/dist/indexer/ast/traversers/types.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/types.js +2 -0
- package/dist/indexer/ast/traversers/types.js.map +1 -0
- package/dist/indexer/ast/traversers/typescript.d.ts +29 -0
- package/dist/indexer/ast/traversers/typescript.d.ts.map +1 -0
- package/dist/indexer/ast/traversers/typescript.js +88 -0
- package/dist/indexer/ast/traversers/typescript.js.map +1 -0
- package/dist/indexer/ast/types.d.ts +59 -0
- package/dist/indexer/ast/types.d.ts.map +1 -0
- package/dist/indexer/ast/types.js +2 -0
- package/dist/indexer/ast/types.js.map +1 -0
- package/dist/indexer/change-detector.d.ts +17 -0
- package/dist/indexer/change-detector.d.ts.map +1 -0
- package/dist/indexer/change-detector.js +207 -0
- package/dist/indexer/change-detector.js.map +1 -0
- package/dist/indexer/chunk-batch-processor.d.ts +103 -0
- package/dist/indexer/chunk-batch-processor.d.ts.map +1 -0
- package/dist/indexer/chunk-batch-processor.js +179 -0
- package/dist/indexer/chunk-batch-processor.js.map +1 -0
- package/dist/indexer/chunker.d.ts +10 -0
- package/dist/indexer/chunker.d.ts.map +1 -0
- package/dist/indexer/chunker.js +96 -0
- package/dist/indexer/chunker.js.map +1 -0
- package/dist/indexer/dependency-analyzer.d.ts +60 -0
- package/dist/indexer/dependency-analyzer.d.ts.map +1 -0
- package/dist/indexer/dependency-analyzer.js +261 -0
- package/dist/indexer/dependency-analyzer.js.map +1 -0
- package/dist/indexer/incremental.d.ts +47 -0
- package/dist/indexer/incremental.d.ts.map +1 -0
- package/dist/indexer/incremental.js +284 -0
- package/dist/indexer/incremental.js.map +1 -0
- package/dist/indexer/index.d.ts +80 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +364 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/json-template-chunker.d.ts +9 -0
- package/dist/indexer/json-template-chunker.d.ts.map +1 -0
- package/dist/indexer/json-template-chunker.js +83 -0
- package/dist/indexer/json-template-chunker.js.map +1 -0
- package/dist/indexer/liquid-chunker.d.ts +13 -0
- package/dist/indexer/liquid-chunker.d.ts.map +1 -0
- package/dist/indexer/liquid-chunker.js +272 -0
- package/dist/indexer/liquid-chunker.js.map +1 -0
- package/dist/indexer/manifest.d.ts +122 -0
- package/dist/indexer/manifest.d.ts.map +1 -0
- package/dist/indexer/manifest.js +262 -0
- package/dist/indexer/manifest.js.map +1 -0
- package/dist/indexer/progress-tracker.d.ts +35 -0
- package/dist/indexer/progress-tracker.d.ts.map +1 -0
- package/dist/indexer/progress-tracker.js +33 -0
- package/dist/indexer/progress-tracker.js.map +1 -0
- package/dist/indexer/scanner.d.ts +16 -0
- package/dist/indexer/scanner.d.ts.map +1 -0
- package/dist/indexer/scanner.js +159 -0
- package/dist/indexer/scanner.js.map +1 -0
- package/dist/indexer/symbol-extractor.d.ts +18 -0
- package/dist/indexer/symbol-extractor.d.ts.map +1 -0
- package/dist/indexer/symbol-extractor.js +351 -0
- package/dist/indexer/symbol-extractor.js.map +1 -0
- package/dist/indexer/types.d.ts +34 -0
- package/dist/indexer/types.d.ts.map +1 -0
- package/dist/indexer/types.js +2 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/insights/complexity-analyzer.d.ts +82 -0
- package/dist/insights/complexity-analyzer.d.ts.map +1 -0
- package/dist/insights/complexity-analyzer.js +356 -0
- package/dist/insights/complexity-analyzer.js.map +1 -0
- package/dist/insights/formatters/index.d.ts +11 -0
- package/dist/insights/formatters/index.d.ts.map +1 -0
- package/dist/insights/formatters/index.js +20 -0
- package/dist/insights/formatters/index.js.map +1 -0
- package/dist/insights/formatters/json.d.ts +7 -0
- package/dist/insights/formatters/json.d.ts.map +1 -0
- package/dist/insights/formatters/json.js +14 -0
- package/dist/insights/formatters/json.js.map +1 -0
- package/dist/insights/formatters/sarif.d.ts +6 -0
- package/dist/insights/formatters/sarif.d.ts.map +1 -0
- package/dist/insights/formatters/sarif.js +113 -0
- package/dist/insights/formatters/sarif.js.map +1 -0
- package/dist/insights/formatters/text.d.ts +6 -0
- package/dist/insights/formatters/text.d.ts.map +1 -0
- package/dist/insights/formatters/text.js +154 -0
- package/dist/insights/formatters/text.js.map +1 -0
- package/dist/insights/types.d.ts +73 -0
- package/dist/insights/types.d.ts.map +1 -0
- package/dist/insights/types.js +9 -0
- package/dist/insights/types.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/path-matching.d.ts +69 -0
- package/dist/utils/path-matching.d.ts.map +1 -0
- package/dist/utils/path-matching.js +123 -0
- package/dist/utils/path-matching.js.map +1 -0
- package/dist/utils/result.d.ts +65 -0
- package/dist/utils/result.d.ts.map +1 -0
- package/dist/utils/result.js +67 -0
- package/dist/utils/result.js.map +1 -0
- package/dist/utils/version.d.ts +22 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +28 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/vectordb/batch-insert.d.ts +14 -0
- package/dist/vectordb/batch-insert.d.ts.map +1 -0
- package/dist/vectordb/batch-insert.js +185 -0
- package/dist/vectordb/batch-insert.js.map +1 -0
- package/dist/vectordb/boosting/composer.d.ts +51 -0
- package/dist/vectordb/boosting/composer.d.ts.map +1 -0
- package/dist/vectordb/boosting/composer.js +65 -0
- package/dist/vectordb/boosting/composer.js.map +1 -0
- package/dist/vectordb/boosting/index.d.ts +22 -0
- package/dist/vectordb/boosting/index.d.ts.map +1 -0
- package/dist/vectordb/boosting/index.js +22 -0
- package/dist/vectordb/boosting/index.js.map +1 -0
- package/dist/vectordb/boosting/strategies.d.ts +40 -0
- package/dist/vectordb/boosting/strategies.d.ts.map +1 -0
- package/dist/vectordb/boosting/strategies.js +174 -0
- package/dist/vectordb/boosting/strategies.js.map +1 -0
- package/dist/vectordb/boosting/types.d.ts +20 -0
- package/dist/vectordb/boosting/types.d.ts.map +1 -0
- package/dist/vectordb/boosting/types.js +2 -0
- package/dist/vectordb/boosting/types.js.map +1 -0
- package/dist/vectordb/intent-classifier.d.ts +99 -0
- package/dist/vectordb/intent-classifier.d.ts.map +1 -0
- package/dist/vectordb/intent-classifier.js +193 -0
- package/dist/vectordb/intent-classifier.js.map +1 -0
- package/dist/vectordb/lancedb.d.ts +45 -0
- package/dist/vectordb/lancedb.d.ts.map +1 -0
- package/dist/vectordb/lancedb.js +203 -0
- package/dist/vectordb/lancedb.js.map +1 -0
- package/dist/vectordb/maintenance.d.ts +18 -0
- package/dist/vectordb/maintenance.d.ts.map +1 -0
- package/dist/vectordb/maintenance.js +87 -0
- package/dist/vectordb/maintenance.js.map +1 -0
- package/dist/vectordb/query.d.ts +34 -0
- package/dist/vectordb/query.d.ts.map +1 -0
- package/dist/vectordb/query.js +303 -0
- package/dist/vectordb/query.js.map +1 -0
- package/dist/vectordb/relevance.d.ts +15 -0
- package/dist/vectordb/relevance.d.ts.map +1 -0
- package/dist/vectordb/relevance.js +19 -0
- package/dist/vectordb/relevance.js.map +1 -0
- package/dist/vectordb/types.d.ts +29 -0
- package/dist/vectordb/types.d.ts.map +1 -0
- package/dist/vectordb/types.js +2 -0
- package/dist/vectordb/types.js.map +1 -0
- package/dist/vectordb/version.d.ts +16 -0
- package/dist/vectordb/version.d.ts.map +1 -0
- package/dist/vectordb/version.js +40 -0
- package/dist/vectordb/version.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { calculateComplexity } from './complexity/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract function declaration info (function_declaration, function)
|
|
4
|
+
*/
|
|
5
|
+
function extractFunctionInfo(node, content, parentClass) {
|
|
6
|
+
const nameNode = node.childForFieldName('name');
|
|
7
|
+
if (!nameNode)
|
|
8
|
+
return null;
|
|
9
|
+
return {
|
|
10
|
+
name: nameNode.text,
|
|
11
|
+
type: parentClass ? 'method' : 'function',
|
|
12
|
+
startLine: node.startPosition.row + 1,
|
|
13
|
+
endLine: node.endPosition.row + 1,
|
|
14
|
+
parentClass,
|
|
15
|
+
signature: extractSignature(node, content),
|
|
16
|
+
parameters: extractParameters(node, content),
|
|
17
|
+
returnType: extractReturnType(node, content),
|
|
18
|
+
complexity: calculateComplexity(node),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extract arrow function or function expression info
|
|
23
|
+
*/
|
|
24
|
+
function extractArrowFunctionInfo(node, content, parentClass) {
|
|
25
|
+
// Try to find variable name for arrow functions
|
|
26
|
+
const parent = node.parent;
|
|
27
|
+
let name = 'anonymous';
|
|
28
|
+
if (parent?.type === 'variable_declarator') {
|
|
29
|
+
const nameNode = parent.childForFieldName('name');
|
|
30
|
+
name = nameNode?.text || 'anonymous';
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
type: parentClass ? 'method' : 'function',
|
|
35
|
+
startLine: node.startPosition.row + 1,
|
|
36
|
+
endLine: node.endPosition.row + 1,
|
|
37
|
+
parentClass,
|
|
38
|
+
signature: extractSignature(node, content),
|
|
39
|
+
parameters: extractParameters(node, content),
|
|
40
|
+
complexity: calculateComplexity(node),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Extract method definition info
|
|
45
|
+
*/
|
|
46
|
+
function extractMethodInfo(node, content, parentClass) {
|
|
47
|
+
const nameNode = node.childForFieldName('name');
|
|
48
|
+
if (!nameNode)
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
name: nameNode.text,
|
|
52
|
+
type: 'method',
|
|
53
|
+
startLine: node.startPosition.row + 1,
|
|
54
|
+
endLine: node.endPosition.row + 1,
|
|
55
|
+
parentClass,
|
|
56
|
+
signature: extractSignature(node, content),
|
|
57
|
+
parameters: extractParameters(node, content),
|
|
58
|
+
returnType: extractReturnType(node, content),
|
|
59
|
+
complexity: calculateComplexity(node),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Extract class declaration info
|
|
64
|
+
*/
|
|
65
|
+
function extractClassInfo(node, _content, _parentClass) {
|
|
66
|
+
const nameNode = node.childForFieldName('name');
|
|
67
|
+
if (!nameNode)
|
|
68
|
+
return null;
|
|
69
|
+
return {
|
|
70
|
+
name: nameNode.text,
|
|
71
|
+
type: 'class',
|
|
72
|
+
startLine: node.startPosition.row + 1,
|
|
73
|
+
endLine: node.endPosition.row + 1,
|
|
74
|
+
signature: `class ${nameNode.text}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Extract interface declaration info (TypeScript)
|
|
79
|
+
*/
|
|
80
|
+
function extractInterfaceInfo(node, _content, _parentClass) {
|
|
81
|
+
const nameNode = node.childForFieldName('name');
|
|
82
|
+
if (!nameNode)
|
|
83
|
+
return null;
|
|
84
|
+
return {
|
|
85
|
+
name: nameNode.text,
|
|
86
|
+
type: 'interface',
|
|
87
|
+
startLine: node.startPosition.row + 1,
|
|
88
|
+
endLine: node.endPosition.row + 1,
|
|
89
|
+
signature: `interface ${nameNode.text}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Extract Python function info (def and async def)
|
|
94
|
+
*/
|
|
95
|
+
function extractPythonFunctionInfo(node, content, parentClass) {
|
|
96
|
+
const nameNode = node.childForFieldName('name');
|
|
97
|
+
if (!nameNode)
|
|
98
|
+
return null;
|
|
99
|
+
return {
|
|
100
|
+
name: nameNode.text,
|
|
101
|
+
type: parentClass ? 'method' : 'function',
|
|
102
|
+
startLine: node.startPosition.row + 1,
|
|
103
|
+
endLine: node.endPosition.row + 1,
|
|
104
|
+
parentClass,
|
|
105
|
+
signature: extractSignature(node, content),
|
|
106
|
+
parameters: extractParameters(node, content),
|
|
107
|
+
complexity: calculateComplexity(node),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Extract Python class info
|
|
112
|
+
*/
|
|
113
|
+
function extractPythonClassInfo(node, _content, _parentClass) {
|
|
114
|
+
const nameNode = node.childForFieldName('name');
|
|
115
|
+
if (!nameNode)
|
|
116
|
+
return null;
|
|
117
|
+
return {
|
|
118
|
+
name: nameNode.text,
|
|
119
|
+
type: 'class',
|
|
120
|
+
startLine: node.startPosition.row + 1,
|
|
121
|
+
endLine: node.endPosition.row + 1,
|
|
122
|
+
signature: `class ${nameNode.text}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Map of AST node types to their specialized extractors
|
|
127
|
+
*
|
|
128
|
+
* Note: There is intentional overlap in node type names across languages:
|
|
129
|
+
* - 'function_definition': Used by both PHP and Python
|
|
130
|
+
* - 'class_declaration': Used by TypeScript/JavaScript
|
|
131
|
+
* - 'class_definition': Used by Python
|
|
132
|
+
*
|
|
133
|
+
* This is handled correctly because each file is parsed with its specific language parser.
|
|
134
|
+
*/
|
|
135
|
+
const symbolExtractors = {
|
|
136
|
+
// TypeScript/JavaScript
|
|
137
|
+
'function_declaration': extractFunctionInfo,
|
|
138
|
+
'function': extractFunctionInfo,
|
|
139
|
+
'arrow_function': extractArrowFunctionInfo,
|
|
140
|
+
'function_expression': extractArrowFunctionInfo,
|
|
141
|
+
'method_definition': extractMethodInfo,
|
|
142
|
+
'class_declaration': extractClassInfo,
|
|
143
|
+
'interface_declaration': extractInterfaceInfo,
|
|
144
|
+
// PHP
|
|
145
|
+
'function_definition': extractFunctionInfo, // PHP functions (Python handled via language check in extractSymbolInfo)
|
|
146
|
+
'method_declaration': extractMethodInfo, // PHP methods
|
|
147
|
+
// Python
|
|
148
|
+
'async_function_definition': extractPythonFunctionInfo, // Python async functions
|
|
149
|
+
'class_definition': extractPythonClassInfo, // Python classes
|
|
150
|
+
// Note: Python regular functions use 'function_definition' (same as PHP)
|
|
151
|
+
// They are dispatched to extractPythonFunctionInfo via language check in extractSymbolInfo()
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Extract symbol information from an AST node using specialized extractors
|
|
155
|
+
*
|
|
156
|
+
* @param node - AST node to extract info from
|
|
157
|
+
* @param content - Source code content
|
|
158
|
+
* @param parentClass - Parent class name if this is a method
|
|
159
|
+
* @param language - Programming language (for disambiguating shared node types)
|
|
160
|
+
* @returns Symbol information or null
|
|
161
|
+
*/
|
|
162
|
+
export function extractSymbolInfo(node, content, parentClass, language) {
|
|
163
|
+
// Handle ambiguous node types that are shared between languages
|
|
164
|
+
// PHP and Python both use 'function_definition', but need different extractors
|
|
165
|
+
if (node.type === 'function_definition' && language === 'python') {
|
|
166
|
+
return extractPythonFunctionInfo(node, content, parentClass);
|
|
167
|
+
}
|
|
168
|
+
const extractor = symbolExtractors[node.type];
|
|
169
|
+
return extractor ? extractor(node, content, parentClass) : null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Extract function/method signature
|
|
173
|
+
*/
|
|
174
|
+
function extractSignature(node, content) {
|
|
175
|
+
// Get the first line of the function (up to opening brace or arrow)
|
|
176
|
+
const startLine = node.startPosition.row;
|
|
177
|
+
const lines = content.split('\n');
|
|
178
|
+
let signature = lines[startLine] || '';
|
|
179
|
+
// If signature spans multiple lines, try to get up to the opening brace
|
|
180
|
+
let currentLine = startLine;
|
|
181
|
+
while (currentLine < node.endPosition.row && !signature.includes('{') && !signature.includes('=>')) {
|
|
182
|
+
currentLine++;
|
|
183
|
+
signature += ' ' + (lines[currentLine] || '');
|
|
184
|
+
}
|
|
185
|
+
// Clean up signature
|
|
186
|
+
signature = signature.split('{')[0].split('=>')[0].trim();
|
|
187
|
+
// Limit length
|
|
188
|
+
if (signature.length > 200) {
|
|
189
|
+
signature = signature.substring(0, 197) + '...';
|
|
190
|
+
}
|
|
191
|
+
return signature;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Extract parameter list from function node
|
|
195
|
+
*
|
|
196
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
197
|
+
* with other extract functions (e.g., extractSignature).
|
|
198
|
+
*/
|
|
199
|
+
function extractParameters(node, _content) {
|
|
200
|
+
const parameters = [];
|
|
201
|
+
// Find parameters node
|
|
202
|
+
const paramsNode = node.childForFieldName('parameters');
|
|
203
|
+
if (!paramsNode)
|
|
204
|
+
return parameters;
|
|
205
|
+
// Traverse parameter nodes
|
|
206
|
+
for (let i = 0; i < paramsNode.namedChildCount; i++) {
|
|
207
|
+
const param = paramsNode.namedChild(i);
|
|
208
|
+
if (param) {
|
|
209
|
+
parameters.push(param.text);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return parameters;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Extract return type from function node (TypeScript)
|
|
216
|
+
*
|
|
217
|
+
* Note: The `_content` parameter is unused in this function, but is kept for API consistency
|
|
218
|
+
* with other extract functions (e.g., extractSignature).
|
|
219
|
+
*/
|
|
220
|
+
function extractReturnType(node, _content) {
|
|
221
|
+
const returnTypeNode = node.childForFieldName('return_type');
|
|
222
|
+
if (!returnTypeNode)
|
|
223
|
+
return undefined;
|
|
224
|
+
return returnTypeNode.text;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Extract import statements from a file
|
|
228
|
+
*/
|
|
229
|
+
export function extractImports(rootNode) {
|
|
230
|
+
const imports = [];
|
|
231
|
+
function traverse(node) {
|
|
232
|
+
// Handle import statements (shared node type between languages)
|
|
233
|
+
if (node.type === 'import_statement') {
|
|
234
|
+
// TypeScript/JavaScript: Extract just the module path from 'source' field
|
|
235
|
+
const sourceNode = node.childForFieldName('source');
|
|
236
|
+
if (sourceNode) {
|
|
237
|
+
// TS/JS import with source field
|
|
238
|
+
const importPath = sourceNode.text.replace(/['"]/g, '');
|
|
239
|
+
imports.push(importPath);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// Python import without source field (e.g., "import os")
|
|
243
|
+
const importText = node.text.split('\n')[0];
|
|
244
|
+
imports.push(importText);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Python-specific: from...import statements
|
|
248
|
+
else if (node.type === 'import_from_statement') {
|
|
249
|
+
// Python: Get the entire import line (first line only)
|
|
250
|
+
const importText = node.text.split('\n')[0];
|
|
251
|
+
imports.push(importText);
|
|
252
|
+
}
|
|
253
|
+
// Only traverse top-level nodes for imports
|
|
254
|
+
if (node === rootNode) {
|
|
255
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
256
|
+
const child = node.namedChild(i);
|
|
257
|
+
if (child)
|
|
258
|
+
traverse(child);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
traverse(rootNode);
|
|
263
|
+
return imports;
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=symbols.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../../src/indexer/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,CAAC;iBAAM,CAAC;gBACN,yDAAyD;gBACzD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5C,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,4CAA4C;aACvC,IAAI,IAAI,CAAC,IAAI,KAAK,uBAAuB,EAAE,CAAC;YAC/C,uDAAuD;YACvD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3B,CAAC;QAED,4CAA4C;QAC5C,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBACjC,IAAI,KAAK;oBAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SupportedLanguage } from '../types.js';
|
|
2
|
+
import type { LanguageTraverser } from './types.js';
|
|
3
|
+
export type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get the traverser for a specific language
|
|
6
|
+
*
|
|
7
|
+
* @param language - Programming language
|
|
8
|
+
* @returns Language-specific traverser
|
|
9
|
+
* @throws Error if language is not supported
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTraverser(language: SupportedLanguage): LanguageTraverser;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a language has a traverser implementation
|
|
14
|
+
*
|
|
15
|
+
* @param language - Programming language
|
|
16
|
+
* @returns True if traverser exists
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasTraverser(language: SupportedLanguage): boolean;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAKpD,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAkB7E;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,iBAAiB,CAQ3E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAEjE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TypeScriptTraverser, JavaScriptTraverser } from './typescript.js';
|
|
2
|
+
import { PHPTraverser } from './php.js';
|
|
3
|
+
import { PythonTraverser } from './python.js';
|
|
4
|
+
/**
|
|
5
|
+
* Registry of language traversers
|
|
6
|
+
*
|
|
7
|
+
* Maps each supported language to its traverser implementation.
|
|
8
|
+
* When adding a new language:
|
|
9
|
+
* 1. Create a new traverser class implementing LanguageTraverser
|
|
10
|
+
* 2. Add it to this registry
|
|
11
|
+
* 3. Update SupportedLanguage type in ../types.ts
|
|
12
|
+
*/
|
|
13
|
+
const traverserRegistry = {
|
|
14
|
+
typescript: new TypeScriptTraverser(),
|
|
15
|
+
javascript: new JavaScriptTraverser(),
|
|
16
|
+
php: new PHPTraverser(),
|
|
17
|
+
python: new PythonTraverser(),
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Get the traverser for a specific language
|
|
21
|
+
*
|
|
22
|
+
* @param language - Programming language
|
|
23
|
+
* @returns Language-specific traverser
|
|
24
|
+
* @throws Error if language is not supported
|
|
25
|
+
*/
|
|
26
|
+
export function getTraverser(language) {
|
|
27
|
+
const traverser = traverserRegistry[language];
|
|
28
|
+
if (!traverser) {
|
|
29
|
+
throw new Error(`No traverser available for language: ${language}`);
|
|
30
|
+
}
|
|
31
|
+
return traverser;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a language has a traverser implementation
|
|
35
|
+
*
|
|
36
|
+
* @param language - Programming language
|
|
37
|
+
* @returns True if traverser exists
|
|
38
|
+
*/
|
|
39
|
+
export function hasTraverser(language) {
|
|
40
|
+
return language in traverserRegistry;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9C;;;;;;;;GAQG;AACH,MAAM,iBAAiB,GAAiD;IACtE,UAAU,EAAE,IAAI,mBAAmB,EAAE;IACrC,UAAU,EAAE,IAAI,mBAAmB,EAAE;IACrC,GAAG,EAAE,IAAI,YAAY,EAAE;IACvB,MAAM,EAAE,IAAI,eAAe,EAAE;CAC9B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,QAA2B;IACtD,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAE9C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wCAAwC,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAA2B;IACtD,OAAO,QAAQ,IAAI,iBAAiB,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type Parser from 'tree-sitter';
|
|
2
|
+
import type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* PHP AST traverser
|
|
5
|
+
*
|
|
6
|
+
* Handles PHP AST node types and traversal patterns.
|
|
7
|
+
* PHP uses tree-sitter-php grammar.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PHPTraverser implements LanguageTraverser {
|
|
10
|
+
targetNodeTypes: string[];
|
|
11
|
+
containerTypes: string[];
|
|
12
|
+
declarationTypes: never[];
|
|
13
|
+
functionTypes: string[];
|
|
14
|
+
shouldExtractChildren(node: Parser.SyntaxNode): boolean;
|
|
15
|
+
isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean;
|
|
16
|
+
getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null;
|
|
17
|
+
shouldTraverseChildren(node: Parser.SyntaxNode): boolean;
|
|
18
|
+
findParentContainerName(node: Parser.SyntaxNode): string | undefined;
|
|
19
|
+
findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=php.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php.d.ts","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/php.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE7E;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,iBAAiB;IACpD,eAAe,WAGb;IAEF,cAAc,WAIZ;IAEF,gBAAgB,UAGd;IAEF,aAAa,WAGX;IAEF,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAIvD,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAM5D,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI;IAUnE,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAMxD,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS;IAapE,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,uBAAuB;CAO7E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHP AST traverser
|
|
3
|
+
*
|
|
4
|
+
* Handles PHP AST node types and traversal patterns.
|
|
5
|
+
* PHP uses tree-sitter-php grammar.
|
|
6
|
+
*/
|
|
7
|
+
export class PHPTraverser {
|
|
8
|
+
targetNodeTypes = [
|
|
9
|
+
'function_definition', // function foo() {}
|
|
10
|
+
'method_declaration', // public function bar() {}
|
|
11
|
+
];
|
|
12
|
+
containerTypes = [
|
|
13
|
+
'class_declaration', // We extract methods, not the class itself
|
|
14
|
+
'trait_declaration', // PHP traits
|
|
15
|
+
'interface_declaration', // PHP interfaces (for interface methods)
|
|
16
|
+
];
|
|
17
|
+
declarationTypes = [
|
|
18
|
+
// PHP doesn't have arrow functions or const/let like JS
|
|
19
|
+
// Functions are always defined with 'function' keyword
|
|
20
|
+
];
|
|
21
|
+
functionTypes = [
|
|
22
|
+
'function_definition',
|
|
23
|
+
'method_declaration',
|
|
24
|
+
];
|
|
25
|
+
shouldExtractChildren(node) {
|
|
26
|
+
return this.containerTypes.includes(node.type);
|
|
27
|
+
}
|
|
28
|
+
isDeclarationWithFunction(_node) {
|
|
29
|
+
// PHP doesn't have variable declarations with functions like JS/TS
|
|
30
|
+
// Functions are always defined with 'function' keyword
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
getContainerBody(node) {
|
|
34
|
+
if (node.type === 'class_declaration' ||
|
|
35
|
+
node.type === 'trait_declaration' ||
|
|
36
|
+
node.type === 'interface_declaration') {
|
|
37
|
+
// In PHP, the body is called 'declaration_list'
|
|
38
|
+
return node.childForFieldName('body');
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
shouldTraverseChildren(node) {
|
|
43
|
+
return node.type === 'program' || // Top-level PHP file
|
|
44
|
+
node.type === 'php' || // PHP block
|
|
45
|
+
node.type === 'declaration_list'; // Body of class/trait/interface
|
|
46
|
+
}
|
|
47
|
+
findParentContainerName(node) {
|
|
48
|
+
let current = node.parent;
|
|
49
|
+
while (current) {
|
|
50
|
+
if (current.type === 'class_declaration' ||
|
|
51
|
+
current.type === 'trait_declaration') {
|
|
52
|
+
const nameNode = current.childForFieldName('name');
|
|
53
|
+
return nameNode?.text;
|
|
54
|
+
}
|
|
55
|
+
current = current.parent;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
findFunctionInDeclaration(_node) {
|
|
60
|
+
// PHP doesn't have this pattern
|
|
61
|
+
return {
|
|
62
|
+
hasFunction: false,
|
|
63
|
+
functionNode: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=php.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php.js","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/php.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACvB,eAAe,GAAG;QAChB,qBAAqB,EAAO,oBAAoB;QAChD,oBAAoB,EAAQ,2BAA2B;KACxD,CAAC;IAEF,cAAc,GAAG;QACf,mBAAmB,EAAS,2CAA2C;QACvE,mBAAmB,EAAS,aAAa;QACzC,uBAAuB,EAAK,yCAAyC;KACtE,CAAC;IAEF,gBAAgB,GA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AwB;QAChD,gCAAgC;QAChC,OAAO;YACL,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type Parser from 'tree-sitter';
|
|
2
|
+
import type { LanguageTraverser, DeclarationFunctionInfo } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Python AST traverser
|
|
5
|
+
*
|
|
6
|
+
* Handles Python AST node types and traversal patterns.
|
|
7
|
+
* Python has a simpler structure than TypeScript/JavaScript:
|
|
8
|
+
* - Functions are defined with 'def' or 'async def'
|
|
9
|
+
* - No variable declarations with functions (unlike JS const x = () => {})
|
|
10
|
+
* - Classes contain methods (which are just functions)
|
|
11
|
+
*/
|
|
12
|
+
export declare class PythonTraverser implements LanguageTraverser {
|
|
13
|
+
targetNodeTypes: string[];
|
|
14
|
+
containerTypes: string[];
|
|
15
|
+
declarationTypes: never[];
|
|
16
|
+
functionTypes: string[];
|
|
17
|
+
shouldExtractChildren(node: Parser.SyntaxNode): boolean;
|
|
18
|
+
isDeclarationWithFunction(_node: Parser.SyntaxNode): boolean;
|
|
19
|
+
getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null;
|
|
20
|
+
shouldTraverseChildren(node: Parser.SyntaxNode): boolean;
|
|
21
|
+
findParentContainerName(node: Parser.SyntaxNode): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Python doesn't have this pattern (const x = () => {})
|
|
24
|
+
* Functions are always defined with 'def' or 'async def'
|
|
25
|
+
*/
|
|
26
|
+
findFunctionInDeclaration(_node: Parser.SyntaxNode): DeclarationFunctionInfo;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=python.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/python.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE7E;;;;;;;;GAQG;AACH,qBAAa,eAAgB,YAAW,iBAAiB;IACvD,eAAe,WAGb;IAEF,cAAc,WAEZ;IAEF,gBAAgB,UAGd;IAEF,aAAa,WAGX;IAEF,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAIvD,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAM5D,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI;IAQnE,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO;IAKxD,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS;IAYpE;;;OAGG;IACH,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,GAAG,uBAAuB;CAM7E"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python AST traverser
|
|
3
|
+
*
|
|
4
|
+
* Handles Python AST node types and traversal patterns.
|
|
5
|
+
* Python has a simpler structure than TypeScript/JavaScript:
|
|
6
|
+
* - Functions are defined with 'def' or 'async def'
|
|
7
|
+
* - No variable declarations with functions (unlike JS const x = () => {})
|
|
8
|
+
* - Classes contain methods (which are just functions)
|
|
9
|
+
*/
|
|
10
|
+
export class PythonTraverser {
|
|
11
|
+
targetNodeTypes = [
|
|
12
|
+
'function_definition',
|
|
13
|
+
'async_function_definition',
|
|
14
|
+
];
|
|
15
|
+
containerTypes = [
|
|
16
|
+
'class_definition', // We extract methods, not the class itself
|
|
17
|
+
];
|
|
18
|
+
declarationTypes = [
|
|
19
|
+
// Python doesn't have const/let/var declarations like JS/TS
|
|
20
|
+
// Functions are always defined with 'def' or 'async def'
|
|
21
|
+
];
|
|
22
|
+
functionTypes = [
|
|
23
|
+
'function_definition',
|
|
24
|
+
'async_function_definition',
|
|
25
|
+
];
|
|
26
|
+
shouldExtractChildren(node) {
|
|
27
|
+
return this.containerTypes.includes(node.type);
|
|
28
|
+
}
|
|
29
|
+
isDeclarationWithFunction(_node) {
|
|
30
|
+
// Python doesn't have variable declarations with functions like JS/TS
|
|
31
|
+
// Functions are always defined with 'def' or 'async def'
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
getContainerBody(node) {
|
|
35
|
+
if (node.type === 'class_definition') {
|
|
36
|
+
// In Python, the class body is called 'block'
|
|
37
|
+
return node.childForFieldName('body');
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
shouldTraverseChildren(node) {
|
|
42
|
+
return node.type === 'module' || // Top-level Python file
|
|
43
|
+
node.type === 'block'; // Body of class/function
|
|
44
|
+
}
|
|
45
|
+
findParentContainerName(node) {
|
|
46
|
+
let current = node.parent;
|
|
47
|
+
while (current) {
|
|
48
|
+
if (current.type === 'class_definition') {
|
|
49
|
+
const nameNode = current.childForFieldName('name');
|
|
50
|
+
return nameNode?.text;
|
|
51
|
+
}
|
|
52
|
+
current = current.parent;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Python doesn't have this pattern (const x = () => {})
|
|
58
|
+
* Functions are always defined with 'def' or 'async def'
|
|
59
|
+
*/
|
|
60
|
+
findFunctionInDeclaration(_node) {
|
|
61
|
+
return {
|
|
62
|
+
hasFunction: false,
|
|
63
|
+
functionNode: null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=python.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/python.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAC1B,eAAe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EAAE,KAAK;YAClB,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type Parser from 'tree-sitter';
|
|
2
|
+
/**
|
|
3
|
+
* Language-specific node traversal configuration
|
|
4
|
+
*
|
|
5
|
+
* Each language has different AST node types and structures. This interface
|
|
6
|
+
* allows us to implement language-specific traversal strategies while keeping
|
|
7
|
+
* the core chunking logic language-agnostic.
|
|
8
|
+
*
|
|
9
|
+
* @example TypeScript/JavaScript
|
|
10
|
+
* ```typescript
|
|
11
|
+
* targetNodeTypes: ['function_declaration', 'method_definition', 'interface_declaration']
|
|
12
|
+
* containerTypes: ['class_declaration']
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Python
|
|
16
|
+
* ```typescript
|
|
17
|
+
* targetNodeTypes: ['function_definition', 'async_function_definition']
|
|
18
|
+
* containerTypes: ['class_definition']
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface LanguageTraverser {
|
|
22
|
+
/**
|
|
23
|
+
* AST node types that should be extracted as chunks
|
|
24
|
+
* (e.g., 'function_declaration', 'method_definition' for TypeScript)
|
|
25
|
+
*/
|
|
26
|
+
targetNodeTypes: string[];
|
|
27
|
+
/**
|
|
28
|
+
* AST node types for containers whose children should be extracted
|
|
29
|
+
* (e.g., 'class_declaration' for TypeScript - we extract methods, not the class itself)
|
|
30
|
+
*/
|
|
31
|
+
containerTypes: string[];
|
|
32
|
+
/**
|
|
33
|
+
* AST node types that represent variable declarations that might contain functions
|
|
34
|
+
* (e.g., 'lexical_declaration' for TypeScript const/let with arrow functions)
|
|
35
|
+
*/
|
|
36
|
+
declarationTypes: string[];
|
|
37
|
+
/**
|
|
38
|
+
* AST node types that represent function implementations
|
|
39
|
+
* (used to detect functions inside variable declarations)
|
|
40
|
+
*/
|
|
41
|
+
functionTypes: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Check if a node should have its children extracted instead of being chunked itself
|
|
44
|
+
*
|
|
45
|
+
* @param node - AST node to check
|
|
46
|
+
* @returns True if we should extract children (e.g., class methods), false otherwise
|
|
47
|
+
*/
|
|
48
|
+
shouldExtractChildren(node: Parser.SyntaxNode): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a node is a declaration that might contain a function
|
|
51
|
+
*
|
|
52
|
+
* @param node - AST node to check
|
|
53
|
+
* @returns True if this is a variable declaration that might contain a function
|
|
54
|
+
*/
|
|
55
|
+
isDeclarationWithFunction(node: Parser.SyntaxNode): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Extract the container body node (e.g., class body) for child traversal
|
|
58
|
+
*
|
|
59
|
+
* @param node - Container node (e.g., class_declaration)
|
|
60
|
+
* @returns The body node containing children, or null if not found
|
|
61
|
+
*/
|
|
62
|
+
getContainerBody(node: Parser.SyntaxNode): Parser.SyntaxNode | null;
|
|
63
|
+
/**
|
|
64
|
+
* Check if traversal should continue into this node's children
|
|
65
|
+
*
|
|
66
|
+
* @param node - AST node to check
|
|
67
|
+
* @returns True if we should traverse children (e.g., for 'program', 'export_statement')
|
|
68
|
+
*/
|
|
69
|
+
shouldTraverseChildren(node: Parser.SyntaxNode): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Find the parent container name for a node (e.g., class name for a method)
|
|
72
|
+
*
|
|
73
|
+
* @param node - AST node (e.g., method)
|
|
74
|
+
* @returns Container name (e.g., class name), or undefined if not in a container
|
|
75
|
+
*/
|
|
76
|
+
findParentContainerName(node: Parser.SyntaxNode): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Find a function inside a declaration node (e.g., arrow function in const declaration)
|
|
79
|
+
*
|
|
80
|
+
* @param node - Declaration node to search
|
|
81
|
+
* @returns Information about whether a function was found and the function node itself
|
|
82
|
+
*/
|
|
83
|
+
findFunctionInDeclaration(node: Parser.SyntaxNode): DeclarationFunctionInfo;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Result of finding a function inside a declaration node
|
|
87
|
+
*/
|
|
88
|
+
export interface DeclarationFunctionInfo {
|
|
89
|
+
/**
|
|
90
|
+
* Whether a function was found inside the declaration
|
|
91
|
+
*/
|
|
92
|
+
hasFunction: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The actual function node if found
|
|
95
|
+
*/
|
|
96
|
+
functionNode: Parser.SyntaxNode | null;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAE1B;;;OAGG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;IAEzB;;;OAGG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAE3B;;;OAGG;IACH,aAAa,EAAE,MAAM,EAAE,CAAC;IAExB;;;;;OAKG;IACH,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;IAExD;;;;;OAKG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;IAE5D;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;IAEpE;;;;;OAKG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,OAAO,CAAC;IAEzD;;;;;OAKG;IACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;IAErE;;;;;OAKG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,GAAG,uBAAuB,CAAC;CAC7E;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/indexer/ast/traversers/types.ts"],"names":[],"mappings":""}
|