@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,224 @@
|
|
|
1
|
+
// code-mapper/src/core/ingestion/type-extractors/csharp.ts
|
|
2
|
+
/** @file csharp.ts
|
|
3
|
+
* @description Type extraction for C# (typed declarations, var inference, pattern matching) */
|
|
4
|
+
import { extractSimpleTypeName, extractVarName, findChildByType, unwrapAwait } from './shared.js';
|
|
5
|
+
const DECLARATION_NODE_TYPES = new Set([
|
|
6
|
+
'local_declaration_statement',
|
|
7
|
+
'variable_declaration',
|
|
8
|
+
'field_declaration',
|
|
9
|
+
'is_pattern_expression',
|
|
10
|
+
]);
|
|
11
|
+
// C#: Type x = ...; var x = new Type(); obj is Type x
|
|
12
|
+
const extractDeclaration = (node, env) => {
|
|
13
|
+
// C# pattern matching: `obj is User user` -> is_pattern_expression > declaration_pattern
|
|
14
|
+
if (node.type === 'is_pattern_expression') {
|
|
15
|
+
const pattern = node.childForFieldName('pattern');
|
|
16
|
+
if (pattern?.type === 'declaration_pattern') {
|
|
17
|
+
const typeNode = pattern.childForFieldName('type');
|
|
18
|
+
const nameNode = pattern.childForFieldName('name');
|
|
19
|
+
if (typeNode && nameNode) {
|
|
20
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
21
|
+
const varName = extractVarName(nameNode);
|
|
22
|
+
if (typeName && varName)
|
|
23
|
+
env.set(varName, typeName);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// C# tree-sitter: local_declaration_statement > variable_declaration > ...
|
|
29
|
+
// Recursively descend through wrapper nodes
|
|
30
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
31
|
+
const child = node.namedChild(i);
|
|
32
|
+
if (!child)
|
|
33
|
+
continue;
|
|
34
|
+
if (child.type === 'variable_declaration' || child.type === 'local_declaration_statement') {
|
|
35
|
+
extractDeclaration(child, env);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// At variable_declaration level: first child is type, rest are variable_declarators
|
|
40
|
+
let typeNode = null;
|
|
41
|
+
const declarators = [];
|
|
42
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
43
|
+
const child = node.namedChild(i);
|
|
44
|
+
if (!child)
|
|
45
|
+
continue;
|
|
46
|
+
if (!typeNode && child.type !== 'variable_declarator' && child.type !== 'equals_value_clause') {
|
|
47
|
+
// First non-declarator child is the type (identifier, implicit_type, generic_name, etc.)
|
|
48
|
+
typeNode = child;
|
|
49
|
+
}
|
|
50
|
+
if (child.type === 'variable_declarator') {
|
|
51
|
+
declarators.push(child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!typeNode || declarators.length === 0)
|
|
55
|
+
return;
|
|
56
|
+
// Handle 'var x = new Foo()' -- infer from object_creation_expression
|
|
57
|
+
let typeName;
|
|
58
|
+
if (typeNode.type === 'implicit_type' && typeNode.text === 'var') {
|
|
59
|
+
// Try to infer from initializer: var x = new Foo()
|
|
60
|
+
// tree-sitter-c-sharp may put object_creation_expression as direct child
|
|
61
|
+
// or inside equals_value_clause depending on grammar version
|
|
62
|
+
if (declarators.length === 1) {
|
|
63
|
+
const initializer = findChildByType(declarators[0], 'object_creation_expression')
|
|
64
|
+
?? findChildByType(declarators[0], 'equals_value_clause')?.firstNamedChild;
|
|
65
|
+
if (initializer?.type === 'object_creation_expression') {
|
|
66
|
+
const ctorType = initializer.childForFieldName('type');
|
|
67
|
+
if (ctorType)
|
|
68
|
+
typeName = extractSimpleTypeName(ctorType);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
typeName = extractSimpleTypeName(typeNode);
|
|
74
|
+
}
|
|
75
|
+
if (!typeName)
|
|
76
|
+
return;
|
|
77
|
+
for (const decl of declarators) {
|
|
78
|
+
const nameNode = decl.childForFieldName('name') ?? decl.firstNamedChild;
|
|
79
|
+
if (nameNode) {
|
|
80
|
+
const varName = extractVarName(nameNode);
|
|
81
|
+
if (varName)
|
|
82
|
+
env.set(varName, typeName);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
// C#: parameter -> type name
|
|
87
|
+
const extractParameter = (node, env) => {
|
|
88
|
+
let nameNode = null;
|
|
89
|
+
let typeNode = null;
|
|
90
|
+
if (node.type === 'parameter') {
|
|
91
|
+
typeNode = node.childForFieldName('type');
|
|
92
|
+
nameNode = node.childForFieldName('name');
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
nameNode = node.childForFieldName('name') ?? node.childForFieldName('pattern');
|
|
96
|
+
typeNode = node.childForFieldName('type');
|
|
97
|
+
}
|
|
98
|
+
if (!nameNode || !typeNode)
|
|
99
|
+
return;
|
|
100
|
+
const varName = extractVarName(nameNode);
|
|
101
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
102
|
+
if (varName && typeName)
|
|
103
|
+
env.set(varName, typeName);
|
|
104
|
+
};
|
|
105
|
+
// C#: var x = SomeFactory(...) -> bind x to SomeFactory (constructor-like call)
|
|
106
|
+
const scanConstructorBinding = (node) => {
|
|
107
|
+
if (node.type !== 'variable_declaration')
|
|
108
|
+
return undefined;
|
|
109
|
+
// Find type and declarator children by iterating (C# grammar doesn't expose 'type' as a named field)
|
|
110
|
+
let typeNode = null;
|
|
111
|
+
let declarator = null;
|
|
112
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
113
|
+
const child = node.namedChild(i);
|
|
114
|
+
if (!child)
|
|
115
|
+
continue;
|
|
116
|
+
if (child.type === 'variable_declarator') {
|
|
117
|
+
if (!declarator)
|
|
118
|
+
declarator = child;
|
|
119
|
+
}
|
|
120
|
+
else if (!typeNode) {
|
|
121
|
+
typeNode = child;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Only handle implicit_type (var) -- explicit types handled by extractDeclaration
|
|
125
|
+
if (!typeNode || typeNode.type !== 'implicit_type')
|
|
126
|
+
return undefined;
|
|
127
|
+
if (!declarator)
|
|
128
|
+
return undefined;
|
|
129
|
+
const nameNode = declarator.childForFieldName('name') ?? declarator.firstNamedChild;
|
|
130
|
+
if (!nameNode || nameNode.type !== 'identifier')
|
|
131
|
+
return undefined;
|
|
132
|
+
// Find the initializer value: either inside equals_value_clause or as a direct child
|
|
133
|
+
// (tree-sitter-c-sharp puts invocation_expression directly inside variable_declarator)
|
|
134
|
+
let value = null;
|
|
135
|
+
for (let i = 0; i < declarator.namedChildCount; i++) {
|
|
136
|
+
const child = declarator.namedChild(i);
|
|
137
|
+
if (!child)
|
|
138
|
+
continue;
|
|
139
|
+
if (child.type === 'equals_value_clause') {
|
|
140
|
+
value = child.firstNamedChild;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (child.type === 'invocation_expression' || child.type === 'object_creation_expression' || child.type === 'await_expression') {
|
|
144
|
+
value = child;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!value)
|
|
149
|
+
return undefined;
|
|
150
|
+
// Unwrap await: `var user = await svc.GetUserAsync()` -> await_expression wraps invocation_expression
|
|
151
|
+
value = unwrapAwait(value);
|
|
152
|
+
if (!value)
|
|
153
|
+
return undefined;
|
|
154
|
+
// Skip object_creation_expression (new User()) -- handled by extractInitializer
|
|
155
|
+
if (value.type === 'object_creation_expression')
|
|
156
|
+
return undefined;
|
|
157
|
+
if (value.type !== 'invocation_expression')
|
|
158
|
+
return undefined;
|
|
159
|
+
const func = value.firstNamedChild;
|
|
160
|
+
if (!func)
|
|
161
|
+
return undefined;
|
|
162
|
+
const calleeName = extractSimpleTypeName(func);
|
|
163
|
+
if (!calleeName)
|
|
164
|
+
return undefined;
|
|
165
|
+
return { varName: nameNode.text, calleeName };
|
|
166
|
+
};
|
|
167
|
+
const FOR_LOOP_NODE_TYPES = new Set([
|
|
168
|
+
'foreach_statement',
|
|
169
|
+
]);
|
|
170
|
+
// C#: foreach (User user in users) -- extract loop variable binding
|
|
171
|
+
const extractForLoopBinding = (node, scopeEnv) => {
|
|
172
|
+
const typeNode = node.childForFieldName('type');
|
|
173
|
+
// The loop variable name is in the 'left' field in tree-sitter-c-sharp
|
|
174
|
+
const nameNode = node.childForFieldName('left');
|
|
175
|
+
if (!typeNode || !nameNode)
|
|
176
|
+
return;
|
|
177
|
+
// Skip 'var' -- type would need to be inferred from the collection element type
|
|
178
|
+
if (typeNode.type === 'implicit_type' && typeNode.text === 'var')
|
|
179
|
+
return;
|
|
180
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
181
|
+
const varName = extractVarName(nameNode);
|
|
182
|
+
if (typeName && varName)
|
|
183
|
+
scopeEnv.set(varName, typeName);
|
|
184
|
+
};
|
|
185
|
+
// C#: var alias = u -> variable_declarator with name + equals_value_clause
|
|
186
|
+
// Only local_declaration_statement and variable_declaration contain variable_declarator
|
|
187
|
+
// children; is_pattern_expression and field_declaration never do -- skip them early
|
|
188
|
+
const extractPendingAssignment = (node, scopeEnv) => {
|
|
189
|
+
if (node.type === 'is_pattern_expression' || node.type === 'field_declaration')
|
|
190
|
+
return undefined;
|
|
191
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
192
|
+
const child = node.namedChild(i);
|
|
193
|
+
if (!child || child.type !== 'variable_declarator')
|
|
194
|
+
continue;
|
|
195
|
+
const nameNode = child.childForFieldName('name');
|
|
196
|
+
if (!nameNode)
|
|
197
|
+
continue;
|
|
198
|
+
const lhs = nameNode.text;
|
|
199
|
+
if (scopeEnv.has(lhs))
|
|
200
|
+
continue;
|
|
201
|
+
// C# wraps value in equals_value_clause; fall back to last named child
|
|
202
|
+
let evc = null;
|
|
203
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
204
|
+
if (child.child(j)?.type === 'equals_value_clause') {
|
|
205
|
+
evc = child.child(j);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const valueNode = evc?.firstNamedChild ?? child.namedChild(child.namedChildCount - 1);
|
|
210
|
+
if (valueNode && valueNode !== nameNode && (valueNode.type === 'identifier' || valueNode.type === 'simple_identifier')) {
|
|
211
|
+
return { lhs, rhs: valueNode.text };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
};
|
|
216
|
+
export const typeConfig = {
|
|
217
|
+
declarationNodeTypes: DECLARATION_NODE_TYPES,
|
|
218
|
+
forLoopNodeTypes: FOR_LOOP_NODE_TYPES,
|
|
219
|
+
extractDeclaration,
|
|
220
|
+
extractParameter,
|
|
221
|
+
scanConstructorBinding,
|
|
222
|
+
extractForLoopBinding,
|
|
223
|
+
extractPendingAssignment,
|
|
224
|
+
};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// code-mapper/src/core/ingestion/type-extractors/go.ts
|
|
2
|
+
/** @file go.ts
|
|
3
|
+
* @description Type extraction for Go (var declarations, short var declarations, composite literals) */
|
|
4
|
+
import { extractSimpleTypeName, extractVarName } from './shared.js';
|
|
5
|
+
const DECLARATION_NODE_TYPES = new Set([
|
|
6
|
+
'var_declaration',
|
|
7
|
+
'var_spec',
|
|
8
|
+
'short_var_declaration',
|
|
9
|
+
]);
|
|
10
|
+
// Go: var x Foo
|
|
11
|
+
const extractGoVarDeclaration = (node, env) => {
|
|
12
|
+
// var_declaration contains var_spec children
|
|
13
|
+
if (node.type === 'var_declaration') {
|
|
14
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
15
|
+
const spec = node.namedChild(i);
|
|
16
|
+
if (spec?.type === 'var_spec')
|
|
17
|
+
extractGoVarDeclaration(spec, env);
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// var_spec: name type [= value]
|
|
22
|
+
const nameNode = node.childForFieldName('name');
|
|
23
|
+
const typeNode = node.childForFieldName('type');
|
|
24
|
+
if (!nameNode || !typeNode)
|
|
25
|
+
return;
|
|
26
|
+
const varName = extractVarName(nameNode);
|
|
27
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
28
|
+
if (varName && typeName)
|
|
29
|
+
env.set(varName, typeName);
|
|
30
|
+
};
|
|
31
|
+
// Go: x := Foo{...} -- infer type from composite literal (handles multi-assignment)
|
|
32
|
+
const extractGoShortVarDeclaration = (node, env) => {
|
|
33
|
+
const left = node.childForFieldName('left');
|
|
34
|
+
const right = node.childForFieldName('right');
|
|
35
|
+
if (!left || !right)
|
|
36
|
+
return;
|
|
37
|
+
// Collect LHS names and RHS values (may be expression_lists for multi-assignment)
|
|
38
|
+
const lhsNodes = [];
|
|
39
|
+
const rhsNodes = [];
|
|
40
|
+
if (left.type === 'expression_list') {
|
|
41
|
+
for (let i = 0; i < left.namedChildCount; i++) {
|
|
42
|
+
const c = left.namedChild(i);
|
|
43
|
+
if (c)
|
|
44
|
+
lhsNodes.push(c);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
lhsNodes.push(left);
|
|
49
|
+
}
|
|
50
|
+
if (right.type === 'expression_list') {
|
|
51
|
+
for (let i = 0; i < right.namedChildCount; i++) {
|
|
52
|
+
const c = right.namedChild(i);
|
|
53
|
+
if (c)
|
|
54
|
+
rhsNodes.push(c);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
rhsNodes.push(right);
|
|
59
|
+
}
|
|
60
|
+
// Pair each LHS name with its corresponding RHS value
|
|
61
|
+
const count = Math.min(lhsNodes.length, rhsNodes.length);
|
|
62
|
+
for (let i = 0; i < count; i++) {
|
|
63
|
+
let valueNode = rhsNodes[i];
|
|
64
|
+
// Unwrap &User{} -- unary_expression (address-of) wrapping composite_literal
|
|
65
|
+
if (valueNode.type === 'unary_expression' && valueNode.firstNamedChild?.type === 'composite_literal') {
|
|
66
|
+
valueNode = valueNode.firstNamedChild;
|
|
67
|
+
}
|
|
68
|
+
// Go built-in new(User) -- call_expression with 'new' callee and type argument
|
|
69
|
+
// Go built-in make([]User, 0) / make(map[string]User) -- extract element/value type
|
|
70
|
+
if (valueNode.type === 'call_expression') {
|
|
71
|
+
const funcNode = valueNode.childForFieldName('function');
|
|
72
|
+
if (funcNode?.text === 'new') {
|
|
73
|
+
const args = valueNode.childForFieldName('arguments');
|
|
74
|
+
if (args?.firstNamedChild) {
|
|
75
|
+
const typeName = extractSimpleTypeName(args.firstNamedChild);
|
|
76
|
+
const varName = extractVarName(lhsNodes[i]);
|
|
77
|
+
if (varName && typeName)
|
|
78
|
+
env.set(varName, typeName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else if (funcNode?.text === 'make') {
|
|
82
|
+
const args = valueNode.childForFieldName('arguments');
|
|
83
|
+
const firstArg = args?.firstNamedChild;
|
|
84
|
+
if (firstArg) {
|
|
85
|
+
let innerType = null;
|
|
86
|
+
if (firstArg.type === 'slice_type') {
|
|
87
|
+
innerType = firstArg.childForFieldName('element');
|
|
88
|
+
}
|
|
89
|
+
else if (firstArg.type === 'map_type') {
|
|
90
|
+
innerType = firstArg.childForFieldName('value');
|
|
91
|
+
}
|
|
92
|
+
if (innerType) {
|
|
93
|
+
const typeName = extractSimpleTypeName(innerType);
|
|
94
|
+
const varName = extractVarName(lhsNodes[i]);
|
|
95
|
+
if (varName && typeName)
|
|
96
|
+
env.set(varName, typeName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
// Go type assertion: user := iface.(User) -- type_assertion_expression with 'type' field
|
|
103
|
+
if (valueNode.type === 'type_assertion_expression') {
|
|
104
|
+
const typeNode = valueNode.childForFieldName('type');
|
|
105
|
+
if (typeNode) {
|
|
106
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
107
|
+
const varName = extractVarName(lhsNodes[i]);
|
|
108
|
+
if (varName && typeName)
|
|
109
|
+
env.set(varName, typeName);
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (valueNode.type !== 'composite_literal')
|
|
114
|
+
continue;
|
|
115
|
+
const typeNode = valueNode.childForFieldName('type');
|
|
116
|
+
if (!typeNode)
|
|
117
|
+
continue;
|
|
118
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
119
|
+
if (!typeName)
|
|
120
|
+
continue;
|
|
121
|
+
const varName = extractVarName(lhsNodes[i]);
|
|
122
|
+
if (varName)
|
|
123
|
+
env.set(varName, typeName);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const extractDeclaration = (node, env) => {
|
|
127
|
+
if (node.type === 'var_declaration' || node.type === 'var_spec') {
|
|
128
|
+
extractGoVarDeclaration(node, env);
|
|
129
|
+
}
|
|
130
|
+
else if (node.type === 'short_var_declaration') {
|
|
131
|
+
extractGoShortVarDeclaration(node, env);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
// Go: parameter -> name type
|
|
135
|
+
const extractParameter = (node, env) => {
|
|
136
|
+
let nameNode = null;
|
|
137
|
+
let typeNode = null;
|
|
138
|
+
if (node.type === 'parameter') {
|
|
139
|
+
nameNode = node.childForFieldName('name');
|
|
140
|
+
typeNode = node.childForFieldName('type');
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
nameNode = node.childForFieldName('name') ?? node.childForFieldName('pattern');
|
|
144
|
+
typeNode = node.childForFieldName('type');
|
|
145
|
+
}
|
|
146
|
+
if (!nameNode || !typeNode)
|
|
147
|
+
return;
|
|
148
|
+
const varName = extractVarName(nameNode);
|
|
149
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
150
|
+
if (varName && typeName)
|
|
151
|
+
env.set(varName, typeName);
|
|
152
|
+
};
|
|
153
|
+
// Go: user := NewUser(...) -- infer type from single-assignment call expression
|
|
154
|
+
const scanConstructorBinding = (node) => {
|
|
155
|
+
if (node.type !== 'short_var_declaration')
|
|
156
|
+
return undefined;
|
|
157
|
+
const left = node.childForFieldName('left');
|
|
158
|
+
const right = node.childForFieldName('right');
|
|
159
|
+
if (!left || !right)
|
|
160
|
+
return undefined;
|
|
161
|
+
const leftIds = left.type === 'expression_list' ? left.namedChildren : [left];
|
|
162
|
+
const rightExprs = right.type === 'expression_list' ? right.namedChildren : [right];
|
|
163
|
+
// Multi-return: user, err := NewUser() -- bind first var when second is err/ok/_
|
|
164
|
+
if (leftIds.length === 2 && rightExprs.length === 1) {
|
|
165
|
+
const secondVar = leftIds[1];
|
|
166
|
+
const isErrorOrDiscard = secondVar.text === '_' ||
|
|
167
|
+
secondVar.text === 'err' ||
|
|
168
|
+
secondVar.text === 'ok' ||
|
|
169
|
+
secondVar.text === 'error';
|
|
170
|
+
if (isErrorOrDiscard && leftIds[0].type === 'identifier') {
|
|
171
|
+
if (rightExprs[0].type !== 'call_expression')
|
|
172
|
+
return undefined;
|
|
173
|
+
const func = rightExprs[0].childForFieldName('function');
|
|
174
|
+
if (!func)
|
|
175
|
+
return undefined;
|
|
176
|
+
if (func.text === 'new' || func.text === 'make')
|
|
177
|
+
return undefined;
|
|
178
|
+
const calleeName = extractSimpleTypeName(func);
|
|
179
|
+
if (!calleeName)
|
|
180
|
+
return undefined;
|
|
181
|
+
return { varName: leftIds[0].text, calleeName };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Single assignment only
|
|
185
|
+
if (leftIds.length !== 1 || leftIds[0].type !== 'identifier')
|
|
186
|
+
return undefined;
|
|
187
|
+
if (rightExprs.length !== 1 || rightExprs[0].type !== 'call_expression')
|
|
188
|
+
return undefined;
|
|
189
|
+
const func = rightExprs[0].childForFieldName('function');
|
|
190
|
+
if (!func)
|
|
191
|
+
return undefined;
|
|
192
|
+
// Skip new() and make() -- already handled by extractDeclaration
|
|
193
|
+
if (func.text === 'new' || func.text === 'make')
|
|
194
|
+
return undefined;
|
|
195
|
+
const calleeName = extractSimpleTypeName(func);
|
|
196
|
+
if (!calleeName)
|
|
197
|
+
return undefined;
|
|
198
|
+
return { varName: leftIds[0].text, calleeName };
|
|
199
|
+
};
|
|
200
|
+
// Go: alias := u (short_var_declaration) or var b = u (var_spec)
|
|
201
|
+
const extractPendingAssignment = (node, scopeEnv) => {
|
|
202
|
+
if (node.type === 'short_var_declaration') {
|
|
203
|
+
const left = node.childForFieldName('left');
|
|
204
|
+
const right = node.childForFieldName('right');
|
|
205
|
+
if (!left || !right)
|
|
206
|
+
return undefined;
|
|
207
|
+
const lhsNode = left.type === 'expression_list' ? left.firstNamedChild : left;
|
|
208
|
+
const rhsNode = right.type === 'expression_list' ? right.firstNamedChild : right;
|
|
209
|
+
if (!lhsNode || !rhsNode)
|
|
210
|
+
return undefined;
|
|
211
|
+
if (lhsNode.type !== 'identifier')
|
|
212
|
+
return undefined;
|
|
213
|
+
const lhs = lhsNode.text;
|
|
214
|
+
if (scopeEnv.has(lhs))
|
|
215
|
+
return undefined;
|
|
216
|
+
if (rhsNode.type === 'identifier')
|
|
217
|
+
return { lhs, rhs: rhsNode.text };
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
if (node.type === 'var_spec' || node.type === 'var_declaration') {
|
|
221
|
+
// var_declaration contains var_spec children; var_spec has name + expression_list value
|
|
222
|
+
const specs = [];
|
|
223
|
+
if (node.type === 'var_declaration') {
|
|
224
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
225
|
+
const c = node.namedChild(i);
|
|
226
|
+
if (c?.type === 'var_spec')
|
|
227
|
+
specs.push(c);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
specs.push(node);
|
|
232
|
+
}
|
|
233
|
+
for (const spec of specs) {
|
|
234
|
+
const nameNode = spec.childForFieldName('name');
|
|
235
|
+
if (!nameNode || nameNode.type !== 'identifier')
|
|
236
|
+
continue;
|
|
237
|
+
const lhs = nameNode.text;
|
|
238
|
+
if (scopeEnv.has(lhs))
|
|
239
|
+
continue;
|
|
240
|
+
// Check if the last named child is a bare identifier (no type annotation between name and value)
|
|
241
|
+
let exprList = null;
|
|
242
|
+
for (let i = 0; i < spec.childCount; i++) {
|
|
243
|
+
if (spec.child(i)?.type === 'expression_list') {
|
|
244
|
+
exprList = spec.child(i);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const rhsNode = exprList?.firstNamedChild;
|
|
249
|
+
if (rhsNode?.type === 'identifier')
|
|
250
|
+
return { lhs, rhs: rhsNode.text };
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return undefined;
|
|
254
|
+
};
|
|
255
|
+
export const typeConfig = {
|
|
256
|
+
declarationNodeTypes: DECLARATION_NODE_TYPES,
|
|
257
|
+
extractDeclaration,
|
|
258
|
+
extractParameter,
|
|
259
|
+
scanConstructorBinding,
|
|
260
|
+
extractPendingAssignment,
|
|
261
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @file index.ts
|
|
2
|
+
* @description Per-language type extraction configs assembled into a dispatch map keyed by SupportedLanguages */
|
|
3
|
+
import type { LanguageTypeConfig } from './types.js';
|
|
4
|
+
export declare const typeConfigs: {
|
|
5
|
+
javascript: LanguageTypeConfig;
|
|
6
|
+
typescript: LanguageTypeConfig;
|
|
7
|
+
java: LanguageTypeConfig;
|
|
8
|
+
kotlin: LanguageTypeConfig;
|
|
9
|
+
csharp: LanguageTypeConfig;
|
|
10
|
+
go: LanguageTypeConfig;
|
|
11
|
+
rust: LanguageTypeConfig;
|
|
12
|
+
python: LanguageTypeConfig;
|
|
13
|
+
swift: LanguageTypeConfig;
|
|
14
|
+
c: LanguageTypeConfig;
|
|
15
|
+
cpp: LanguageTypeConfig;
|
|
16
|
+
php: LanguageTypeConfig;
|
|
17
|
+
ruby: LanguageTypeConfig;
|
|
18
|
+
};
|
|
19
|
+
export type { LanguageTypeConfig, TypeBindingExtractor, ParameterExtractor, ConstructorBindingScanner, ForLoopExtractor, PendingAssignmentExtractor, PatternBindingExtractor, } from './types.js';
|
|
20
|
+
export { TYPED_PARAMETER_TYPES, extractSimpleTypeName, extractGenericTypeArgs, extractVarName, findChildByType, extractRubyConstructorAssignment } from './shared.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// code-mapper/src/core/ingestion/type-extractors/index.ts
|
|
2
|
+
/** @file index.ts
|
|
3
|
+
* @description Per-language type extraction configs assembled into a dispatch map keyed by SupportedLanguages */
|
|
4
|
+
import { SupportedLanguages } from '../../../config/supported-languages.js';
|
|
5
|
+
import { typeConfig as typescriptConfig } from './typescript.js';
|
|
6
|
+
import { javaTypeConfig, kotlinTypeConfig } from './jvm.js';
|
|
7
|
+
import { typeConfig as csharpConfig } from './csharp.js';
|
|
8
|
+
import { typeConfig as goConfig } from './go.js';
|
|
9
|
+
import { typeConfig as rustConfig } from './rust.js';
|
|
10
|
+
import { typeConfig as pythonConfig } from './python.js';
|
|
11
|
+
import { typeConfig as swiftConfig } from './swift.js';
|
|
12
|
+
import { typeConfig as cCppConfig } from './c-cpp.js';
|
|
13
|
+
import { typeConfig as phpConfig } from './php.js';
|
|
14
|
+
import { typeConfig as rubyConfig } from './ruby.js';
|
|
15
|
+
export const typeConfigs = {
|
|
16
|
+
[SupportedLanguages.JavaScript]: typescriptConfig,
|
|
17
|
+
[SupportedLanguages.TypeScript]: typescriptConfig,
|
|
18
|
+
[SupportedLanguages.Java]: javaTypeConfig,
|
|
19
|
+
[SupportedLanguages.Kotlin]: kotlinTypeConfig,
|
|
20
|
+
[SupportedLanguages.CSharp]: csharpConfig,
|
|
21
|
+
[SupportedLanguages.Go]: goConfig,
|
|
22
|
+
[SupportedLanguages.Rust]: rustConfig,
|
|
23
|
+
[SupportedLanguages.Python]: pythonConfig,
|
|
24
|
+
[SupportedLanguages.Swift]: swiftConfig,
|
|
25
|
+
[SupportedLanguages.C]: cCppConfig,
|
|
26
|
+
[SupportedLanguages.CPlusPlus]: cCppConfig,
|
|
27
|
+
[SupportedLanguages.PHP]: phpConfig,
|
|
28
|
+
[SupportedLanguages.Ruby]: rubyConfig,
|
|
29
|
+
};
|
|
30
|
+
export { TYPED_PARAMETER_TYPES, extractSimpleTypeName, extractGenericTypeArgs, extractVarName, findChildByType, extractRubyConstructorAssignment } from './shared.js';
|