@zuvia-software-solutions/code-mapper 1.4.0
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 +215 -0
- package/dist/cli/ai-context.d.ts +19 -0
- package/dist/cli/ai-context.js +168 -0
- package/dist/cli/analyze.d.ts +7 -0
- package/dist/cli/analyze.js +325 -0
- package/dist/cli/augment.d.ts +7 -0
- package/dist/cli/augment.js +27 -0
- package/dist/cli/clean.d.ts +5 -0
- package/dist/cli/clean.js +56 -0
- package/dist/cli/eval-server.d.ts +25 -0
- package/dist/cli/eval-server.js +365 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +102 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +19 -0
- package/dist/cli/list.d.ts +2 -0
- package/dist/cli/list.js +27 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +35 -0
- package/dist/cli/refresh.d.ts +12 -0
- package/dist/cli/refresh.js +165 -0
- package/dist/cli/serve.d.ts +5 -0
- package/dist/cli/serve.js +8 -0
- package/dist/cli/setup.d.ts +6 -0
- package/dist/cli/setup.js +218 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.js +33 -0
- package/dist/cli/tool.d.ts +28 -0
- package/dist/cli/tool.js +87 -0
- package/dist/config/ignore-service.d.ts +32 -0
- package/dist/config/ignore-service.js +282 -0
- package/dist/config/supported-languages.d.ts +23 -0
- package/dist/config/supported-languages.js +52 -0
- package/dist/core/augmentation/engine.d.ts +22 -0
- package/dist/core/augmentation/engine.js +232 -0
- package/dist/core/embeddings/embedder.d.ts +35 -0
- package/dist/core/embeddings/embedder.js +171 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +41 -0
- package/dist/core/embeddings/embedding-pipeline.js +402 -0
- package/dist/core/embeddings/index.d.ts +5 -0
- package/dist/core/embeddings/index.js +6 -0
- package/dist/core/embeddings/text-generator.d.ts +20 -0
- package/dist/core/embeddings/text-generator.js +159 -0
- package/dist/core/embeddings/types.d.ts +60 -0
- package/dist/core/embeddings/types.js +23 -0
- package/dist/core/graph/graph.d.ts +4 -0
- package/dist/core/graph/graph.js +65 -0
- package/dist/core/graph/types.d.ts +69 -0
- package/dist/core/graph/types.js +3 -0
- package/dist/core/incremental/child-process.d.ts +8 -0
- package/dist/core/incremental/child-process.js +649 -0
- package/dist/core/incremental/refresh-coordinator.d.ts +32 -0
- package/dist/core/incremental/refresh-coordinator.js +147 -0
- package/dist/core/incremental/types.d.ts +78 -0
- package/dist/core/incremental/types.js +153 -0
- package/dist/core/incremental/watcher.d.ts +63 -0
- package/dist/core/incremental/watcher.js +338 -0
- package/dist/core/ingestion/ast-cache.d.ts +12 -0
- package/dist/core/ingestion/ast-cache.js +34 -0
- package/dist/core/ingestion/call-processor.d.ts +34 -0
- package/dist/core/ingestion/call-processor.js +937 -0
- package/dist/core/ingestion/call-routing.d.ts +40 -0
- package/dist/core/ingestion/call-routing.js +97 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +30 -0
- package/dist/core/ingestion/cluster-enricher.js +151 -0
- package/dist/core/ingestion/community-processor.d.ts +26 -0
- package/dist/core/ingestion/community-processor.js +272 -0
- package/dist/core/ingestion/constants.d.ts +5 -0
- package/dist/core/ingestion/constants.js +8 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +23 -0
- package/dist/core/ingestion/entry-point-scoring.js +317 -0
- package/dist/core/ingestion/export-detection.d.ts +11 -0
- package/dist/core/ingestion/export-detection.js +203 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +18 -0
- package/dist/core/ingestion/filesystem-walker.js +64 -0
- package/dist/core/ingestion/framework-detection.d.ts +42 -0
- package/dist/core/ingestion/framework-detection.js +405 -0
- package/dist/core/ingestion/heritage-processor.d.ts +15 -0
- package/dist/core/ingestion/heritage-processor.js +237 -0
- package/dist/core/ingestion/import-processor.d.ts +31 -0
- package/dist/core/ingestion/import-processor.js +416 -0
- package/dist/core/ingestion/language-config.d.ts +32 -0
- package/dist/core/ingestion/language-config.js +161 -0
- package/dist/core/ingestion/mro-processor.d.ts +32 -0
- package/dist/core/ingestion/mro-processor.js +343 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +51 -0
- package/dist/core/ingestion/named-binding-extraction.js +343 -0
- package/dist/core/ingestion/parsing-processor.d.ts +20 -0
- package/dist/core/ingestion/parsing-processor.js +282 -0
- package/dist/core/ingestion/pipeline.d.ts +3 -0
- package/dist/core/ingestion/pipeline.js +416 -0
- package/dist/core/ingestion/process-processor.d.ts +42 -0
- package/dist/core/ingestion/process-processor.js +357 -0
- package/dist/core/ingestion/resolution-context.d.ts +40 -0
- package/dist/core/ingestion/resolution-context.js +171 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +10 -0
- package/dist/core/ingestion/resolvers/csharp.js +101 -0
- package/dist/core/ingestion/resolvers/go.d.ts +8 -0
- package/dist/core/ingestion/resolvers/go.js +33 -0
- package/dist/core/ingestion/resolvers/index.d.ts +14 -0
- package/dist/core/ingestion/resolvers/index.js +10 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +9 -0
- package/dist/core/ingestion/resolvers/jvm.js +74 -0
- package/dist/core/ingestion/resolvers/php.d.ts +7 -0
- package/dist/core/ingestion/resolvers/php.js +30 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +9 -0
- package/dist/core/ingestion/resolvers/ruby.js +13 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +5 -0
- package/dist/core/ingestion/resolvers/rust.js +62 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +16 -0
- package/dist/core/ingestion/resolvers/standard.js +144 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +18 -0
- package/dist/core/ingestion/resolvers/utils.js +113 -0
- package/dist/core/ingestion/structure-processor.d.ts +4 -0
- package/dist/core/ingestion/structure-processor.js +39 -0
- package/dist/core/ingestion/symbol-table.d.ts +34 -0
- package/dist/core/ingestion/symbol-table.js +48 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +20 -0
- package/dist/core/ingestion/tree-sitter-queries.js +691 -0
- package/dist/core/ingestion/type-env.d.ts +52 -0
- package/dist/core/ingestion/type-env.js +349 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +214 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/csharp.js +224 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/go.js +261 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +20 -0
- package/dist/core/ingestion/type-extractors/index.js +30 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +5 -0
- package/dist/core/ingestion/type-extractors/jvm.js +386 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/php.js +280 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/python.js +175 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +12 -0
- package/dist/core/ingestion/type-extractors/ruby.js +218 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/rust.js +290 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +81 -0
- package/dist/core/ingestion/type-extractors/shared.js +322 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/swift.js +140 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +111 -0
- package/dist/core/ingestion/type-extractors/types.js +4 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/typescript.js +227 -0
- package/dist/core/ingestion/utils.d.ts +73 -0
- package/dist/core/ingestion/utils.js +992 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +99 -0
- package/dist/core/ingestion/workers/parse-worker.js +1055 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +15 -0
- package/dist/core/ingestion/workers/worker-pool.js +123 -0
- package/dist/core/lbug/csv-generator.d.ts +28 -0
- package/dist/core/lbug/csv-generator.js +355 -0
- package/dist/core/lbug/lbug-adapter.d.ts +96 -0
- package/dist/core/lbug/lbug-adapter.js +753 -0
- package/dist/core/lbug/schema.d.ts +46 -0
- package/dist/core/lbug/schema.js +402 -0
- package/dist/core/search/bm25-index.d.ts +20 -0
- package/dist/core/search/bm25-index.js +123 -0
- package/dist/core/search/hybrid-search.d.ts +32 -0
- package/dist/core/search/hybrid-search.js +131 -0
- package/dist/core/search/query-cache.d.ts +18 -0
- package/dist/core/search/query-cache.js +47 -0
- package/dist/core/search/query-expansion.d.ts +19 -0
- package/dist/core/search/query-expansion.js +75 -0
- package/dist/core/search/reranker.d.ts +29 -0
- package/dist/core/search/reranker.js +122 -0
- package/dist/core/search/types.d.ts +154 -0
- package/dist/core/search/types.js +51 -0
- package/dist/core/semantic/tsgo-service.d.ts +67 -0
- package/dist/core/semantic/tsgo-service.js +355 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +12 -0
- package/dist/core/tree-sitter/parser-loader.js +71 -0
- package/dist/lib/memory-guard.d.ts +35 -0
- package/dist/lib/memory-guard.js +70 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +6 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +32 -0
- package/dist/mcp/compatible-stdio-transport.js +209 -0
- package/dist/mcp/core/embedder.d.ts +24 -0
- package/dist/mcp/core/embedder.js +168 -0
- package/dist/mcp/core/lbug-adapter.d.ts +29 -0
- package/dist/mcp/core/lbug-adapter.js +330 -0
- package/dist/mcp/local/local-backend.d.ts +188 -0
- package/dist/mcp/local/local-backend.js +2759 -0
- package/dist/mcp/resources.d.ts +22 -0
- package/dist/mcp/resources.js +379 -0
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/server.js +217 -0
- package/dist/mcp/staleness.d.ts +10 -0
- package/dist/mcp/staleness.js +25 -0
- package/dist/mcp/tools.d.ts +21 -0
- package/dist/mcp/tools.js +202 -0
- package/dist/server/api.d.ts +5 -0
- package/dist/server/api.js +340 -0
- package/dist/server/mcp-http.d.ts +7 -0
- package/dist/server/mcp-http.js +95 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +87 -0
- package/dist/storage/repo-manager.js +249 -0
- package/dist/types/pipeline.d.ts +35 -0
- package/dist/types/pipeline.js +20 -0
- package/hooks/claude/code-mapper-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/models/mlx-embedder.py +185 -0
- package/package.json +100 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// code-mapper/src/core/ingestion/type-extractors/typescript.ts
|
|
2
|
+
/** @file typescript.ts
|
|
3
|
+
* @description Type extraction for TypeScript and JavaScript (including JSDoc annotations) */
|
|
4
|
+
import { extractSimpleTypeName, extractVarName, hasTypeAnnotation, unwrapAwait, extractCalleeName } from './shared.js';
|
|
5
|
+
const DECLARATION_NODE_TYPES = new Set([
|
|
6
|
+
'lexical_declaration',
|
|
7
|
+
'variable_declaration',
|
|
8
|
+
'function_declaration', // JSDoc @param on function declarations
|
|
9
|
+
'method_definition', // JSDoc @param on class methods
|
|
10
|
+
]);
|
|
11
|
+
// Normalize a JSDoc type to a simple identifier, stripping prefixes/unions/generics
|
|
12
|
+
const normalizeJsDocType = (raw) => {
|
|
13
|
+
let type = raw.trim();
|
|
14
|
+
// Strip JSDoc nullable/non-nullable prefixes: ?User -> User, !User -> User
|
|
15
|
+
if (type.startsWith('?') || type.startsWith('!'))
|
|
16
|
+
type = type.slice(1);
|
|
17
|
+
// Strip union with null/undefined/void: User|null -> User
|
|
18
|
+
const parts = type.split('|').map(p => p.trim()).filter(p => p !== 'null' && p !== 'undefined' && p !== 'void');
|
|
19
|
+
if (parts.length !== 1)
|
|
20
|
+
return undefined; // ambiguous union
|
|
21
|
+
type = parts[0];
|
|
22
|
+
// Strip module: prefix -- module:models.User -> models.User
|
|
23
|
+
if (type.startsWith('module:'))
|
|
24
|
+
type = type.slice(7);
|
|
25
|
+
// Take last segment of dotted path: models.User -> User
|
|
26
|
+
const segments = type.split('.');
|
|
27
|
+
type = segments[segments.length - 1];
|
|
28
|
+
// Strip generic wrapper: Promise<User> -> Promise (base type, not inner)
|
|
29
|
+
const genericMatch = type.match(/^(\w+)\s*</);
|
|
30
|
+
if (genericMatch)
|
|
31
|
+
type = genericMatch[1];
|
|
32
|
+
// Simple identifier check
|
|
33
|
+
if (/^\w+$/.test(type))
|
|
34
|
+
return type;
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
// Regex to extract JSDoc @param annotations: `@param {Type} name`
|
|
38
|
+
const JSDOC_PARAM_RE = /@param\s*\{([^}]+)\}\s+\[?(\w+)[\]=]?[^\s]*/g;
|
|
39
|
+
/**
|
|
40
|
+
* Collect JSDoc @param type bindings from comment nodes preceding a function/method
|
|
41
|
+
* @returns Map of paramName -> typeName
|
|
42
|
+
*/
|
|
43
|
+
const collectJsDocParams = (funcNode) => {
|
|
44
|
+
const commentTexts = [];
|
|
45
|
+
let sibling = funcNode.previousSibling;
|
|
46
|
+
while (sibling) {
|
|
47
|
+
if (sibling.type === 'comment') {
|
|
48
|
+
commentTexts.unshift(sibling.text);
|
|
49
|
+
}
|
|
50
|
+
else if (sibling.isNamed && sibling.type !== 'decorator') {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
sibling = sibling.previousSibling;
|
|
54
|
+
}
|
|
55
|
+
if (commentTexts.length === 0)
|
|
56
|
+
return new Map();
|
|
57
|
+
const params = new Map();
|
|
58
|
+
const commentBlock = commentTexts.join('\n');
|
|
59
|
+
JSDOC_PARAM_RE.lastIndex = 0;
|
|
60
|
+
let match;
|
|
61
|
+
while ((match = JSDOC_PARAM_RE.exec(commentBlock)) !== null) {
|
|
62
|
+
const typeName = normalizeJsDocType(match[1]);
|
|
63
|
+
const paramName = match[2];
|
|
64
|
+
if (typeName) {
|
|
65
|
+
params.set(paramName, typeName);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return params;
|
|
69
|
+
};
|
|
70
|
+
// TS: const x: Foo = ..., let x: Foo
|
|
71
|
+
// Also: JSDoc @param annotations on function/method definitions (for .js files)
|
|
72
|
+
const extractDeclaration = (node, env) => {
|
|
73
|
+
// JSDoc @param on functions/methods -- pre-populate env with param types
|
|
74
|
+
if (node.type === 'function_declaration' || node.type === 'method_definition') {
|
|
75
|
+
const jsDocParams = collectJsDocParams(node);
|
|
76
|
+
for (const [paramName, typeName] of jsDocParams) {
|
|
77
|
+
if (!env.has(paramName))
|
|
78
|
+
env.set(paramName, typeName);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
83
|
+
const declarator = node.namedChild(i);
|
|
84
|
+
if (declarator?.type !== 'variable_declarator')
|
|
85
|
+
continue;
|
|
86
|
+
const nameNode = declarator.childForFieldName('name');
|
|
87
|
+
const typeAnnotation = declarator.childForFieldName('type');
|
|
88
|
+
if (!nameNode || !typeAnnotation)
|
|
89
|
+
continue;
|
|
90
|
+
const varName = extractVarName(nameNode);
|
|
91
|
+
const typeName = extractSimpleTypeName(typeAnnotation);
|
|
92
|
+
if (varName && typeName)
|
|
93
|
+
env.set(varName, typeName);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// TS: required_parameter / optional_parameter -> name: type
|
|
97
|
+
const extractParameter = (node, env) => {
|
|
98
|
+
let nameNode = null;
|
|
99
|
+
let typeNode = null;
|
|
100
|
+
if (node.type === 'required_parameter' || node.type === 'optional_parameter') {
|
|
101
|
+
nameNode = node.childForFieldName('pattern') ?? node.childForFieldName('name');
|
|
102
|
+
typeNode = node.childForFieldName('type');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// Generic fallback
|
|
106
|
+
nameNode = node.childForFieldName('name') ?? node.childForFieldName('pattern');
|
|
107
|
+
typeNode = node.childForFieldName('type');
|
|
108
|
+
}
|
|
109
|
+
if (!nameNode || !typeNode)
|
|
110
|
+
return;
|
|
111
|
+
const varName = extractVarName(nameNode);
|
|
112
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
113
|
+
if (varName && typeName)
|
|
114
|
+
env.set(varName, typeName);
|
|
115
|
+
};
|
|
116
|
+
// TS: const x = new User() -- infer type from new_expression
|
|
117
|
+
const extractInitializer = (node, env, _classNames) => {
|
|
118
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
119
|
+
const declarator = node.namedChild(i);
|
|
120
|
+
if (declarator?.type !== 'variable_declarator')
|
|
121
|
+
continue;
|
|
122
|
+
// Only activate when there is no explicit type annotation -- extractDeclaration already
|
|
123
|
+
// handles the annotated case and this function is called as a fallback
|
|
124
|
+
if (declarator.childForFieldName('type') !== null)
|
|
125
|
+
continue;
|
|
126
|
+
let valueNode = declarator.childForFieldName('value');
|
|
127
|
+
// Unwrap `new User() as T`, `new User()!`, and double-cast `new User() as unknown as T`
|
|
128
|
+
while (valueNode?.type === 'as_expression' || valueNode?.type === 'non_null_expression') {
|
|
129
|
+
valueNode = valueNode.firstNamedChild;
|
|
130
|
+
}
|
|
131
|
+
if (valueNode?.type !== 'new_expression')
|
|
132
|
+
continue;
|
|
133
|
+
const constructorNode = valueNode.childForFieldName('constructor');
|
|
134
|
+
if (!constructorNode)
|
|
135
|
+
continue;
|
|
136
|
+
const nameNode = declarator.childForFieldName('name');
|
|
137
|
+
if (!nameNode)
|
|
138
|
+
continue;
|
|
139
|
+
const varName = extractVarName(nameNode);
|
|
140
|
+
const typeName = extractSimpleTypeName(constructorNode);
|
|
141
|
+
if (varName && typeName)
|
|
142
|
+
env.set(varName, typeName);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
// TS/JS: const user = getUser() -- variable_declarator with call_expression value
|
|
146
|
+
// Only matches unannotated declarators; annotated ones are handled by extractDeclaration
|
|
147
|
+
// await is unwrapped: const user = await fetchUser() -> callee = 'fetchUser'
|
|
148
|
+
const scanConstructorBinding = (node) => {
|
|
149
|
+
if (node.type !== 'variable_declarator')
|
|
150
|
+
return undefined;
|
|
151
|
+
if (hasTypeAnnotation(node))
|
|
152
|
+
return undefined;
|
|
153
|
+
const nameNode = node.childForFieldName('name');
|
|
154
|
+
if (!nameNode || nameNode.type !== 'identifier')
|
|
155
|
+
return undefined;
|
|
156
|
+
const value = unwrapAwait(node.childForFieldName('value'));
|
|
157
|
+
if (!value || value.type !== 'call_expression')
|
|
158
|
+
return undefined;
|
|
159
|
+
const calleeName = extractCalleeName(value);
|
|
160
|
+
if (!calleeName)
|
|
161
|
+
return undefined;
|
|
162
|
+
return { varName: nameNode.text, calleeName };
|
|
163
|
+
};
|
|
164
|
+
// Regex to extract @returns or @return from JSDoc comments: `@returns {Type}`
|
|
165
|
+
const JSDOC_RETURN_RE = /@returns?\s*\{([^}]+)\}/;
|
|
166
|
+
// Minimal sanitization for JSDoc return types -- preserves generic wrappers
|
|
167
|
+
// (e.g. `Promise<User>`) so extractReturnTypeName in call-processor can apply
|
|
168
|
+
// WRAPPER_GENERICS unwrapping. Unlike normalizeJsDocType (which strips generics),
|
|
169
|
+
// this only strips JSDoc-specific syntax markers
|
|
170
|
+
const sanitizeReturnType = (raw) => {
|
|
171
|
+
let type = raw.trim();
|
|
172
|
+
// Strip JSDoc nullable/non-nullable prefixes: ?User -> User, !User -> User
|
|
173
|
+
if (type.startsWith('?') || type.startsWith('!'))
|
|
174
|
+
type = type.slice(1);
|
|
175
|
+
// Strip module: prefix -- module:models.User -> models.User
|
|
176
|
+
if (type.startsWith('module:'))
|
|
177
|
+
type = type.slice(7);
|
|
178
|
+
// Reject unions (ambiguous)
|
|
179
|
+
if (type.includes('|'))
|
|
180
|
+
return undefined;
|
|
181
|
+
if (!type)
|
|
182
|
+
return undefined;
|
|
183
|
+
return type;
|
|
184
|
+
};
|
|
185
|
+
// Extract return type from JSDoc `@returns {Type}` or `@return {Type}` annotation
|
|
186
|
+
// preceding a function/method definition
|
|
187
|
+
const extractReturnType = (node) => {
|
|
188
|
+
let sibling = node.previousSibling;
|
|
189
|
+
while (sibling) {
|
|
190
|
+
if (sibling.type === 'comment') {
|
|
191
|
+
const match = JSDOC_RETURN_RE.exec(sibling.text);
|
|
192
|
+
if (match)
|
|
193
|
+
return sanitizeReturnType(match[1]);
|
|
194
|
+
}
|
|
195
|
+
else if (sibling.isNamed && sibling.type !== 'decorator')
|
|
196
|
+
break;
|
|
197
|
+
sibling = sibling.previousSibling;
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
};
|
|
201
|
+
// TS/JS: const alias = u -> variable_declarator with name/value fields
|
|
202
|
+
const extractPendingAssignment = (node, scopeEnv) => {
|
|
203
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
204
|
+
const child = node.namedChild(i);
|
|
205
|
+
if (!child || child.type !== 'variable_declarator')
|
|
206
|
+
continue;
|
|
207
|
+
const nameNode = child.childForFieldName('name');
|
|
208
|
+
const valueNode = child.childForFieldName('value');
|
|
209
|
+
if (!nameNode || !valueNode)
|
|
210
|
+
continue;
|
|
211
|
+
const lhs = nameNode.text;
|
|
212
|
+
if (scopeEnv.has(lhs))
|
|
213
|
+
continue;
|
|
214
|
+
if (valueNode.type === 'identifier')
|
|
215
|
+
return { lhs, rhs: valueNode.text };
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
};
|
|
219
|
+
export const typeConfig = {
|
|
220
|
+
declarationNodeTypes: DECLARATION_NODE_TYPES,
|
|
221
|
+
extractDeclaration,
|
|
222
|
+
extractParameter,
|
|
223
|
+
extractInitializer,
|
|
224
|
+
scanConstructorBinding,
|
|
225
|
+
extractReturnType,
|
|
226
|
+
extractPendingAssignment,
|
|
227
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Shared AST utilities for code ingestion
|
|
3
|
+
* @description Tree-sitter node helpers, built-in name filtering, function/class extraction,
|
|
4
|
+
* call-form discrimination, and receiver resolution used across all ingestion modules
|
|
5
|
+
*/
|
|
6
|
+
import type Parser from 'tree-sitter';
|
|
7
|
+
import { SupportedLanguages } from '../../config/supported-languages.js';
|
|
8
|
+
export type SyntaxNode = Parser.SyntaxNode;
|
|
9
|
+
/** Ordered definition capture keys for tree-sitter query matches */
|
|
10
|
+
export declare const DEFINITION_CAPTURE_KEYS: readonly ["definition.function", "definition.class", "definition.interface", "definition.method", "definition.struct", "definition.enum", "definition.namespace", "definition.module", "definition.trait", "definition.impl", "definition.type", "definition.const", "definition.static", "definition.typedef", "definition.macro", "definition.union", "definition.property", "definition.record", "definition.delegate", "definition.annotation", "definition.constructor", "definition.template"];
|
|
11
|
+
/** Extract the definition node from a tree-sitter query capture map */
|
|
12
|
+
export declare const getDefinitionNodeFromCaptures: (captureMap: Record<string, any>) => any | null;
|
|
13
|
+
/** Node types representing function/method definitions across languages */
|
|
14
|
+
export declare const FUNCTION_NODE_TYPES: Set<string>;
|
|
15
|
+
/** Node types for standard function declarations that need C/C++ declarator handling */
|
|
16
|
+
export declare const FUNCTION_DECLARATION_TYPES: Set<string>;
|
|
17
|
+
/** Built-in function/method names that should not be tracked as call targets */
|
|
18
|
+
export declare const BUILT_IN_NAMES: Set<string>;
|
|
19
|
+
/** Check if a name is a built-in or common noise that should be filtered out */
|
|
20
|
+
export declare const isBuiltInOrNoise: (name: string) => boolean;
|
|
21
|
+
/** AST node types representing class-like containers (for HAS_METHOD edges) */
|
|
22
|
+
export declare const CLASS_CONTAINER_TYPES: Set<string>;
|
|
23
|
+
export declare const CONTAINER_TYPE_TO_LABEL: Record<string, string>;
|
|
24
|
+
/** Walk up AST to find enclosing class/struct/impl and return its generateId (handles Go receivers) */
|
|
25
|
+
export declare const findEnclosingClassId: (node: any, filePath: string) => string | null;
|
|
26
|
+
/** Extract function name and label from a function/method AST node (handles C/C++ qualified_identifier) */
|
|
27
|
+
export declare const extractFunctionName: (node: any) => {
|
|
28
|
+
funcName: string | null;
|
|
29
|
+
label: string;
|
|
30
|
+
};
|
|
31
|
+
/** Yield control to the event loop to prevent UI freezes in hot loops */
|
|
32
|
+
export declare const yieldToEventLoop: () => Promise<void>;
|
|
33
|
+
/** Find a child of `childType` within a sibling node of `siblingType` (used for Kotlin AST) */
|
|
34
|
+
export declare const findSiblingChild: (parent: any, siblingType: string, childType: string) => any | null;
|
|
35
|
+
/** Map file extension to SupportedLanguage enum */
|
|
36
|
+
export declare const getLanguageFromFilename: (filename: string) => SupportedLanguages | null;
|
|
37
|
+
export interface MethodSignature {
|
|
38
|
+
parameterCount: number | undefined;
|
|
39
|
+
returnType: string | undefined;
|
|
40
|
+
parameterTypes?: string[];
|
|
41
|
+
}
|
|
42
|
+
/** Extract parameter count and return type from an AST function/method node */
|
|
43
|
+
export declare const extractMethodSignature: (node: SyntaxNode | null | undefined) => MethodSignature;
|
|
44
|
+
/** Count direct arguments for a call expression across common tree-sitter grammars */
|
|
45
|
+
export declare const countCallArguments: (callNode: SyntaxNode | null | undefined) => number | undefined;
|
|
46
|
+
type CallForm = 'free' | 'member' | 'constructor';
|
|
47
|
+
/**
|
|
48
|
+
* Infer whether a captured call site is a free call, member call, or constructor
|
|
49
|
+
*
|
|
50
|
+
* Inspects the AST structure between callNode (@call) and nameNode (@call.name)
|
|
51
|
+
*/
|
|
52
|
+
export declare const inferCallForm: (callNode: SyntaxNode, nameNode: SyntaxNode) => CallForm | undefined;
|
|
53
|
+
/** Extract the receiver identifier for member calls (simple identifiers only) */
|
|
54
|
+
export declare const extractReceiverName: (nameNode: SyntaxNode) => string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Extract the raw receiver AST node for a member call (including chained calls)
|
|
57
|
+
*
|
|
58
|
+
* Unlike extractReceiverName, returns the receiver node regardless of its type
|
|
59
|
+
*/
|
|
60
|
+
export declare const extractReceiverNode: (nameNode: SyntaxNode) => SyntaxNode | undefined;
|
|
61
|
+
export declare const isVerboseIngestionEnabled: () => boolean;
|
|
62
|
+
export declare const CALL_EXPRESSION_TYPES: Set<string>;
|
|
63
|
+
export declare const MAX_CHAIN_DEPTH = 3;
|
|
64
|
+
/**
|
|
65
|
+
* Walk a receiver call expression to accumulate a chain of intermediate method names
|
|
66
|
+
*
|
|
67
|
+
* For `svc.getUser().save()`: { chain: ['getUser'], baseReceiverName: 'svc' }
|
|
68
|
+
*/
|
|
69
|
+
export declare function extractCallChain(receiverCallNode: SyntaxNode): {
|
|
70
|
+
chain: string[];
|
|
71
|
+
baseReceiverName: string | undefined;
|
|
72
|
+
} | undefined;
|
|
73
|
+
export {};
|