gitnexus 1.4.7 → 1.4.9
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 +29 -1
- package/dist/cli/ai-context.d.ts +1 -1
- package/dist/cli/ai-context.js +1 -1
- package/dist/cli/analyze.d.ts +2 -0
- package/dist/cli/analyze.js +54 -21
- package/dist/cli/index-repo.d.ts +15 -0
- package/dist/cli/index-repo.js +115 -0
- package/dist/cli/index.js +13 -3
- package/dist/cli/setup.js +90 -10
- package/dist/cli/wiki.d.ts +4 -0
- package/dist/cli/wiki.js +174 -53
- package/dist/config/supported-languages.d.ts +33 -1
- package/dist/config/supported-languages.js +32 -0
- package/dist/core/embeddings/embedder.d.ts +6 -1
- package/dist/core/embeddings/embedder.js +65 -5
- package/dist/core/embeddings/embedding-pipeline.js +11 -9
- package/dist/core/embeddings/http-client.d.ts +31 -0
- package/dist/core/embeddings/http-client.js +179 -0
- package/dist/core/embeddings/index.d.ts +1 -0
- package/dist/core/embeddings/index.js +1 -0
- package/dist/core/embeddings/types.d.ts +1 -1
- package/dist/core/graph/graph.js +9 -1
- package/dist/core/graph/types.d.ts +11 -2
- package/dist/core/ingestion/call-processor.d.ts +66 -2
- package/dist/core/ingestion/call-processor.js +650 -30
- package/dist/core/ingestion/call-routing.d.ts +9 -18
- package/dist/core/ingestion/call-routing.js +0 -19
- package/dist/core/ingestion/cobol/cobol-copy-expander.d.ts +57 -0
- package/dist/core/ingestion/cobol/cobol-copy-expander.js +385 -0
- package/dist/core/ingestion/cobol/cobol-preprocessor.d.ts +210 -0
- package/dist/core/ingestion/cobol/cobol-preprocessor.js +1509 -0
- package/dist/core/ingestion/cobol/jcl-parser.d.ts +68 -0
- package/dist/core/ingestion/cobol/jcl-parser.js +217 -0
- package/dist/core/ingestion/cobol/jcl-processor.d.ts +33 -0
- package/dist/core/ingestion/cobol/jcl-processor.js +229 -0
- package/dist/core/ingestion/cobol-processor.d.ts +54 -0
- package/dist/core/ingestion/cobol-processor.js +1186 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +17 -0
- package/dist/core/ingestion/entry-point-scoring.js +52 -28
- package/dist/core/ingestion/export-detection.d.ts +47 -8
- package/dist/core/ingestion/export-detection.js +29 -50
- package/dist/core/ingestion/field-extractor.d.ts +29 -0
- package/dist/core/ingestion/field-extractor.js +25 -0
- package/dist/core/ingestion/field-extractors/configs/c-cpp.d.ts +3 -0
- package/dist/core/ingestion/field-extractors/configs/c-cpp.js +108 -0
- package/dist/core/ingestion/field-extractors/configs/csharp.d.ts +8 -0
- package/dist/core/ingestion/field-extractors/configs/csharp.js +73 -0
- package/dist/core/ingestion/field-extractors/configs/dart.d.ts +8 -0
- package/dist/core/ingestion/field-extractors/configs/dart.js +76 -0
- package/dist/core/ingestion/field-extractors/configs/go.d.ts +11 -0
- package/dist/core/ingestion/field-extractors/configs/go.js +64 -0
- package/dist/core/ingestion/field-extractors/configs/helpers.d.ts +44 -0
- package/dist/core/ingestion/field-extractors/configs/helpers.js +134 -0
- package/dist/core/ingestion/field-extractors/configs/jvm.d.ts +3 -0
- package/dist/core/ingestion/field-extractors/configs/jvm.js +118 -0
- package/dist/core/ingestion/field-extractors/configs/php.d.ts +8 -0
- package/dist/core/ingestion/field-extractors/configs/php.js +67 -0
- package/dist/core/ingestion/field-extractors/configs/python.d.ts +12 -0
- package/dist/core/ingestion/field-extractors/configs/python.js +91 -0
- package/dist/core/ingestion/field-extractors/configs/ruby.d.ts +16 -0
- package/dist/core/ingestion/field-extractors/configs/ruby.js +75 -0
- package/dist/core/ingestion/field-extractors/configs/rust.d.ts +9 -0
- package/dist/core/ingestion/field-extractors/configs/rust.js +55 -0
- package/dist/core/ingestion/field-extractors/configs/swift.d.ts +8 -0
- package/dist/core/ingestion/field-extractors/configs/swift.js +63 -0
- package/dist/core/ingestion/field-extractors/configs/typescript-javascript.d.ts +3 -0
- package/dist/core/ingestion/field-extractors/configs/typescript-javascript.js +60 -0
- package/dist/core/ingestion/field-extractors/generic.d.ts +46 -0
- package/dist/core/ingestion/field-extractors/generic.js +111 -0
- package/dist/core/ingestion/field-extractors/typescript.d.ts +77 -0
- package/dist/core/ingestion/field-extractors/typescript.js +291 -0
- package/dist/core/ingestion/field-types.d.ts +59 -0
- package/dist/core/ingestion/field-types.js +2 -0
- package/dist/core/ingestion/framework-detection.d.ts +97 -2
- package/dist/core/ingestion/framework-detection.js +114 -14
- package/dist/core/ingestion/heritage-processor.js +62 -66
- package/dist/core/ingestion/import-processor.d.ts +9 -10
- package/dist/core/ingestion/import-processor.js +150 -196
- package/dist/core/ingestion/{resolvers → import-resolvers}/csharp.d.ts +6 -9
- package/dist/core/ingestion/{resolvers → import-resolvers}/csharp.js +20 -2
- package/dist/core/ingestion/import-resolvers/dart.d.ts +7 -0
- package/dist/core/ingestion/import-resolvers/dart.js +44 -0
- package/dist/core/ingestion/{resolvers → import-resolvers}/go.d.ts +4 -5
- package/dist/core/ingestion/{resolvers → import-resolvers}/go.js +17 -0
- package/dist/core/ingestion/{resolvers → import-resolvers}/jvm.d.ts +10 -1
- package/dist/core/ingestion/import-resolvers/jvm.js +159 -0
- package/dist/core/ingestion/import-resolvers/php.d.ts +25 -0
- package/dist/core/ingestion/import-resolvers/php.js +80 -0
- package/dist/core/ingestion/{resolvers → import-resolvers}/python.d.ts +9 -3
- package/dist/core/ingestion/{resolvers → import-resolvers}/python.js +35 -3
- package/dist/core/ingestion/{resolvers → import-resolvers}/ruby.d.ts +5 -2
- package/dist/core/ingestion/{resolvers → import-resolvers}/ruby.js +7 -2
- package/dist/core/ingestion/{resolvers → import-resolvers}/rust.d.ts +5 -2
- package/dist/core/ingestion/{resolvers → import-resolvers}/rust.js +41 -2
- package/dist/core/ingestion/{resolvers → import-resolvers}/standard.d.ts +15 -7
- package/dist/core/ingestion/{resolvers → import-resolvers}/standard.js +22 -3
- package/dist/core/ingestion/import-resolvers/swift.d.ts +7 -0
- package/dist/core/ingestion/import-resolvers/swift.js +23 -0
- package/dist/core/ingestion/import-resolvers/types.d.ts +44 -0
- package/dist/core/ingestion/import-resolvers/types.js +6 -0
- package/dist/core/ingestion/{resolvers → import-resolvers}/utils.d.ts +2 -0
- package/dist/core/ingestion/{resolvers → import-resolvers}/utils.js +7 -0
- package/dist/core/ingestion/language-config.d.ts +6 -0
- package/dist/core/ingestion/language-config.js +13 -0
- package/dist/core/ingestion/language-provider.d.ts +121 -0
- package/dist/core/ingestion/language-provider.js +24 -0
- package/dist/core/ingestion/languages/c-cpp.d.ts +12 -0
- package/dist/core/ingestion/languages/c-cpp.js +71 -0
- package/dist/core/ingestion/languages/cobol.d.ts +1 -0
- package/dist/core/ingestion/languages/cobol.js +26 -0
- package/dist/core/ingestion/languages/csharp.d.ts +8 -0
- package/dist/core/ingestion/languages/csharp.js +49 -0
- package/dist/core/ingestion/languages/dart.d.ts +12 -0
- package/dist/core/ingestion/languages/dart.js +58 -0
- package/dist/core/ingestion/languages/go.d.ts +11 -0
- package/dist/core/ingestion/languages/go.js +28 -0
- package/dist/core/ingestion/languages/index.d.ts +38 -0
- package/dist/core/ingestion/languages/index.js +63 -0
- package/dist/core/ingestion/languages/java.d.ts +9 -0
- package/dist/core/ingestion/languages/java.js +29 -0
- package/dist/core/ingestion/languages/kotlin.d.ts +9 -0
- package/dist/core/ingestion/languages/kotlin.js +53 -0
- package/dist/core/ingestion/languages/php.d.ts +8 -0
- package/dist/core/ingestion/languages/php.js +145 -0
- package/dist/core/ingestion/languages/python.d.ts +12 -0
- package/dist/core/ingestion/languages/python.js +39 -0
- package/dist/core/ingestion/languages/ruby.d.ts +9 -0
- package/dist/core/ingestion/languages/ruby.js +44 -0
- package/dist/core/ingestion/languages/rust.d.ts +12 -0
- package/dist/core/ingestion/languages/rust.js +44 -0
- package/dist/core/ingestion/languages/swift.d.ts +12 -0
- package/dist/core/ingestion/languages/swift.js +133 -0
- package/dist/core/ingestion/languages/typescript.d.ts +10 -0
- package/dist/core/ingestion/languages/typescript.js +60 -0
- package/dist/core/ingestion/markdown-processor.d.ts +17 -0
- package/dist/core/ingestion/markdown-processor.js +124 -0
- package/dist/core/ingestion/mro-processor.js +22 -18
- package/dist/core/ingestion/named-binding-processor.d.ts +18 -0
- package/dist/core/ingestion/named-binding-processor.js +42 -0
- package/dist/core/ingestion/named-bindings/csharp.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/csharp.js +37 -0
- package/dist/core/ingestion/named-bindings/java.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/java.js +29 -0
- package/dist/core/ingestion/named-bindings/kotlin.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/kotlin.js +36 -0
- package/dist/core/ingestion/named-bindings/php.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/php.js +61 -0
- package/dist/core/ingestion/named-bindings/python.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/python.js +49 -0
- package/dist/core/ingestion/named-bindings/rust.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/rust.js +64 -0
- package/dist/core/ingestion/named-bindings/types.d.ts +16 -0
- package/dist/core/ingestion/named-bindings/types.js +6 -0
- package/dist/core/ingestion/named-bindings/typescript.d.ts +3 -0
- package/dist/core/ingestion/named-bindings/typescript.js +58 -0
- package/dist/core/ingestion/parsing-processor.d.ts +6 -2
- package/dist/core/ingestion/parsing-processor.js +125 -85
- package/dist/core/ingestion/pipeline.d.ts +10 -0
- package/dist/core/ingestion/pipeline.js +1235 -317
- package/dist/core/ingestion/resolution-context.d.ts +5 -0
- package/dist/core/ingestion/resolution-context.js +8 -5
- package/dist/core/ingestion/route-extractors/expo.d.ts +1 -0
- package/dist/core/ingestion/route-extractors/expo.js +36 -0
- package/dist/core/ingestion/route-extractors/middleware.d.ts +47 -0
- package/dist/core/ingestion/route-extractors/middleware.js +143 -0
- package/dist/core/ingestion/route-extractors/nextjs.d.ts +3 -0
- package/dist/core/ingestion/route-extractors/nextjs.js +76 -0
- package/dist/core/ingestion/route-extractors/php.d.ts +7 -0
- package/dist/core/ingestion/route-extractors/php.js +21 -0
- package/dist/core/ingestion/route-extractors/response-shapes.d.ts +20 -0
- package/dist/core/ingestion/route-extractors/response-shapes.js +290 -0
- package/dist/core/ingestion/symbol-table.d.ts +16 -0
- package/dist/core/ingestion/symbol-table.js +20 -6
- package/dist/core/ingestion/tree-sitter-queries.d.ts +10 -9
- package/dist/core/ingestion/tree-sitter-queries.js +274 -11
- package/dist/core/ingestion/type-env.d.ts +42 -18
- package/dist/core/ingestion/type-env.js +481 -106
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +5 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +119 -0
- package/dist/core/ingestion/type-extractors/csharp.js +149 -16
- package/dist/core/ingestion/type-extractors/dart.d.ts +15 -0
- package/dist/core/ingestion/type-extractors/dart.js +371 -0
- package/dist/core/ingestion/type-extractors/jvm.js +169 -66
- package/dist/core/ingestion/type-extractors/rust.js +35 -1
- package/dist/core/ingestion/type-extractors/shared.d.ts +1 -15
- package/dist/core/ingestion/type-extractors/shared.js +14 -112
- package/dist/core/ingestion/type-extractors/swift.js +338 -7
- package/dist/core/ingestion/type-extractors/types.d.ts +40 -8
- package/dist/core/ingestion/type-extractors/typescript.js +141 -9
- package/dist/core/ingestion/utils/ast-helpers.d.ts +83 -0
- package/dist/core/ingestion/utils/ast-helpers.js +817 -0
- package/dist/core/ingestion/utils/call-analysis.d.ts +73 -0
- package/dist/core/ingestion/utils/call-analysis.js +527 -0
- package/dist/core/ingestion/utils/event-loop.d.ts +5 -0
- package/dist/core/ingestion/utils/event-loop.js +5 -0
- package/dist/core/ingestion/utils/language-detection.d.ts +9 -0
- package/dist/core/ingestion/utils/language-detection.js +70 -0
- package/dist/core/ingestion/utils/verbose.d.ts +1 -0
- package/dist/core/ingestion/utils/verbose.js +7 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +55 -5
- package/dist/core/ingestion/workers/parse-worker.js +415 -225
- package/dist/core/lbug/csv-generator.js +51 -1
- package/dist/core/lbug/lbug-adapter.d.ts +10 -0
- package/dist/core/lbug/lbug-adapter.js +75 -4
- package/dist/core/lbug/schema.d.ts +8 -4
- package/dist/core/lbug/schema.js +65 -4
- package/dist/core/tree-sitter/parser-loader.js +7 -1
- package/dist/core/wiki/cursor-client.d.ts +31 -0
- package/dist/core/wiki/cursor-client.js +127 -0
- package/dist/core/wiki/generator.d.ts +28 -9
- package/dist/core/wiki/generator.js +115 -18
- package/dist/core/wiki/graph-queries.d.ts +4 -0
- package/dist/core/wiki/graph-queries.js +7 -1
- package/dist/core/wiki/llm-client.d.ts +2 -0
- package/dist/core/wiki/llm-client.js +8 -4
- package/dist/core/wiki/prompts.d.ts +3 -3
- package/dist/core/wiki/prompts.js +6 -0
- package/dist/mcp/core/embedder.js +11 -3
- package/dist/mcp/core/lbug-adapter.d.ts +5 -0
- package/dist/mcp/core/lbug-adapter.js +23 -2
- package/dist/mcp/local/local-backend.d.ts +38 -5
- package/dist/mcp/local/local-backend.js +804 -63
- package/dist/mcp/resources.js +2 -0
- package/dist/mcp/tools.js +73 -4
- package/dist/server/api.d.ts +19 -1
- package/dist/server/api.js +66 -6
- package/dist/storage/git.d.ts +12 -0
- package/dist/storage/git.js +21 -0
- package/dist/storage/repo-manager.d.ts +3 -0
- package/package.json +25 -16
- package/dist/core/ingestion/named-binding-extraction.d.ts +0 -61
- package/dist/core/ingestion/named-binding-extraction.js +0 -363
- package/dist/core/ingestion/resolvers/index.d.ts +0 -18
- package/dist/core/ingestion/resolvers/index.js +0 -13
- package/dist/core/ingestion/resolvers/jvm.js +0 -87
- package/dist/core/ingestion/resolvers/php.d.ts +0 -15
- package/dist/core/ingestion/resolvers/php.js +0 -35
- package/dist/core/ingestion/type-extractors/index.d.ts +0 -22
- package/dist/core/ingestion/type-extractors/index.js +0 -31
- package/dist/core/ingestion/utils.d.ts +0 -138
- package/dist/core/ingestion/utils.js +0 -1290
- package/scripts/patch-tree-sitter-swift.cjs +0 -74
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dart type extractor — full implementation following type-resolution-system.md.
|
|
3
|
+
*
|
|
4
|
+
* Tier 0: Explicit type annotations (User user = ...)
|
|
5
|
+
* Tier 0b: For-loop element types (for (var u in users))
|
|
6
|
+
* Tier 1: Constructor/initializer inference (var user = User())
|
|
7
|
+
* Tier 2: Assignment chain propagation (copy, fieldAccess, callResult, methodCallResult)
|
|
8
|
+
*
|
|
9
|
+
* Handles tree-sitter-dart's flat sibling AST structure:
|
|
10
|
+
* identifier + selector + selector (not nested call_expression).
|
|
11
|
+
*
|
|
12
|
+
* Credit: Type resolution approach adapted from @xFlaviews' PR #83.
|
|
13
|
+
*/
|
|
14
|
+
import { extractSimpleTypeName, extractVarName, extractElementTypeFromString, resolveIterableElementType } from './shared.js';
|
|
15
|
+
import { findChild } from '../utils/ast-helpers.js';
|
|
16
|
+
// ── Node types ──────────────────────────────────────────────────────────
|
|
17
|
+
const DART_DECLARATION_NODE_TYPES = new Set([
|
|
18
|
+
'initialized_variable_definition',
|
|
19
|
+
'initialized_identifier',
|
|
20
|
+
]);
|
|
21
|
+
const DART_FOR_LOOP_NODE_TYPES = new Set([
|
|
22
|
+
'for_statement',
|
|
23
|
+
]);
|
|
24
|
+
function parseDartRHSChildren(children) {
|
|
25
|
+
let callee;
|
|
26
|
+
let member;
|
|
27
|
+
let hasCall = false;
|
|
28
|
+
for (const child of children) {
|
|
29
|
+
if (child.type === 'identifier' && !callee) {
|
|
30
|
+
callee = child.text;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (child.type === 'selector') {
|
|
34
|
+
const uas = findChild(child, 'unconditional_assignable_selector')
|
|
35
|
+
?? findChild(child, 'conditional_assignable_selector');
|
|
36
|
+
if (uas) {
|
|
37
|
+
const id = findChild(uas, 'identifier');
|
|
38
|
+
if (id && !member)
|
|
39
|
+
member = id.text;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (findChild(child, 'argument_part')) {
|
|
43
|
+
hasCall = true;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { callee, member, hasCall };
|
|
49
|
+
}
|
|
50
|
+
function parseDartRHS(node) {
|
|
51
|
+
const rhsChildren = [];
|
|
52
|
+
let foundEquals = false;
|
|
53
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
54
|
+
const child = node.child(i);
|
|
55
|
+
if (!child)
|
|
56
|
+
continue;
|
|
57
|
+
if (!child.isNamed && child.text === '=') {
|
|
58
|
+
foundEquals = true;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (foundEquals)
|
|
62
|
+
rhsChildren.push(child);
|
|
63
|
+
}
|
|
64
|
+
if (rhsChildren.length === 0)
|
|
65
|
+
return { hasCall: false, isAwait: false };
|
|
66
|
+
const first = rhsChildren[0];
|
|
67
|
+
if (first.type === 'unary_expression') {
|
|
68
|
+
const awaitExpr = findChild(first, 'await_expression');
|
|
69
|
+
if (awaitExpr) {
|
|
70
|
+
const innerChildren = [];
|
|
71
|
+
for (let i = 0; i < awaitExpr.namedChildCount; i++) {
|
|
72
|
+
const c = awaitExpr.namedChild(i);
|
|
73
|
+
if (c && c.type !== 'await')
|
|
74
|
+
innerChildren.push(c);
|
|
75
|
+
}
|
|
76
|
+
return { ...parseDartRHSChildren(innerChildren), isAwait: true };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { ...parseDartRHSChildren(rhsChildren), isAwait: false };
|
|
80
|
+
}
|
|
81
|
+
function hasDartTypeAnnotation(node) {
|
|
82
|
+
return !!(findChild(node, 'type_identifier') || findChild(node, 'nullable_type'));
|
|
83
|
+
}
|
|
84
|
+
// ── Tier 0: Explicit Type Annotations ───────────────────────────────────
|
|
85
|
+
const extractDartDeclaration = (node, env) => {
|
|
86
|
+
// initialized_identifier: comma-separated variable (String a, b, c) — type is on parent
|
|
87
|
+
if (node.type === 'initialized_identifier') {
|
|
88
|
+
const parent = node.parent;
|
|
89
|
+
if (!parent)
|
|
90
|
+
return;
|
|
91
|
+
let typeNode = findChild(parent, 'type_identifier');
|
|
92
|
+
if (!typeNode) {
|
|
93
|
+
const nullable = findChild(parent, 'nullable_type');
|
|
94
|
+
if (nullable)
|
|
95
|
+
typeNode = findChild(nullable, 'type_identifier');
|
|
96
|
+
}
|
|
97
|
+
if (!typeNode)
|
|
98
|
+
return;
|
|
99
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
100
|
+
if (!typeName || typeName === 'dynamic')
|
|
101
|
+
return;
|
|
102
|
+
const nameNode = findChild(node, 'identifier');
|
|
103
|
+
if (!nameNode)
|
|
104
|
+
return;
|
|
105
|
+
const varName = extractVarName(nameNode);
|
|
106
|
+
if (varName)
|
|
107
|
+
env.set(varName, typeName);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let typeNode = findChild(node, 'type_identifier');
|
|
111
|
+
if (!typeNode) {
|
|
112
|
+
const nullable = findChild(node, 'nullable_type');
|
|
113
|
+
if (nullable)
|
|
114
|
+
typeNode = findChild(nullable, 'type_identifier');
|
|
115
|
+
}
|
|
116
|
+
if (!typeNode)
|
|
117
|
+
return;
|
|
118
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
119
|
+
if (!typeName || typeName === 'dynamic')
|
|
120
|
+
return;
|
|
121
|
+
const nameNode = node.childForFieldName('name');
|
|
122
|
+
if (!nameNode)
|
|
123
|
+
return;
|
|
124
|
+
const varName = extractVarName(nameNode);
|
|
125
|
+
if (varName)
|
|
126
|
+
env.set(varName, typeName);
|
|
127
|
+
};
|
|
128
|
+
const extractDartParameter = (node, env) => {
|
|
129
|
+
let typeNode = findChild(node, 'type_identifier');
|
|
130
|
+
if (!typeNode) {
|
|
131
|
+
const nullable = findChild(node, 'nullable_type');
|
|
132
|
+
if (nullable)
|
|
133
|
+
typeNode = findChild(nullable, 'type_identifier');
|
|
134
|
+
}
|
|
135
|
+
if (!typeNode)
|
|
136
|
+
return;
|
|
137
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
138
|
+
if (!typeName || typeName === 'dynamic')
|
|
139
|
+
return;
|
|
140
|
+
const nameNode = node.childForFieldName('name');
|
|
141
|
+
if (!nameNode)
|
|
142
|
+
return;
|
|
143
|
+
const varName = extractVarName(nameNode);
|
|
144
|
+
if (varName)
|
|
145
|
+
env.set(varName, typeName);
|
|
146
|
+
};
|
|
147
|
+
// ── Tier 1: Constructor / Initializer Inference ─────────────────────────
|
|
148
|
+
const extractDartInitializer = (node, env, classNames) => {
|
|
149
|
+
if (node.type !== 'initialized_variable_definition')
|
|
150
|
+
return;
|
|
151
|
+
if (hasDartTypeAnnotation(node))
|
|
152
|
+
return;
|
|
153
|
+
const nameNode = node.childForFieldName('name');
|
|
154
|
+
if (!nameNode)
|
|
155
|
+
return;
|
|
156
|
+
const varName = extractVarName(nameNode);
|
|
157
|
+
if (!varName || env.has(varName))
|
|
158
|
+
return;
|
|
159
|
+
const rhs = parseDartRHS(node);
|
|
160
|
+
if (!rhs.callee || !rhs.hasCall)
|
|
161
|
+
return;
|
|
162
|
+
if (!rhs.member && classNames.has(rhs.callee)) {
|
|
163
|
+
env.set(varName, rhs.callee);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (rhs.member && classNames.has(rhs.callee)) {
|
|
167
|
+
env.set(varName, rhs.callee);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// ── Constructor Binding Scan ────────────────────────────────────────────
|
|
171
|
+
const scanDartConstructorBinding = (node) => {
|
|
172
|
+
if (node.type !== 'initialized_variable_definition')
|
|
173
|
+
return undefined;
|
|
174
|
+
if (hasDartTypeAnnotation(node))
|
|
175
|
+
return undefined;
|
|
176
|
+
const nameNode = node.childForFieldName('name');
|
|
177
|
+
if (!nameNode)
|
|
178
|
+
return undefined;
|
|
179
|
+
const varName = nameNode.text;
|
|
180
|
+
if (!varName)
|
|
181
|
+
return undefined;
|
|
182
|
+
const rhs = parseDartRHS(node);
|
|
183
|
+
if (!rhs.callee)
|
|
184
|
+
return undefined;
|
|
185
|
+
if (rhs.hasCall && !rhs.member)
|
|
186
|
+
return { varName, calleeName: rhs.callee };
|
|
187
|
+
if (rhs.hasCall && rhs.member)
|
|
188
|
+
return { varName, calleeName: rhs.member };
|
|
189
|
+
return undefined;
|
|
190
|
+
};
|
|
191
|
+
// ── Virtual Dispatch ────────────────────────────────────────────────────
|
|
192
|
+
const detectDartConstructorType = (node, classNames) => {
|
|
193
|
+
if (node.type !== 'initialized_variable_definition')
|
|
194
|
+
return undefined;
|
|
195
|
+
const rhs = parseDartRHS(node);
|
|
196
|
+
if (!rhs.callee || !rhs.hasCall)
|
|
197
|
+
return undefined;
|
|
198
|
+
if (!rhs.member && classNames.has(rhs.callee))
|
|
199
|
+
return rhs.callee;
|
|
200
|
+
if (rhs.member && classNames.has(rhs.callee))
|
|
201
|
+
return rhs.callee;
|
|
202
|
+
return undefined;
|
|
203
|
+
};
|
|
204
|
+
// ── Literal Type Inference ──────────────────────────────────────────────
|
|
205
|
+
const inferDartLiteralType = (node) => {
|
|
206
|
+
switch (node.type) {
|
|
207
|
+
case 'decimal_integer_literal':
|
|
208
|
+
case 'hex_integer_literal':
|
|
209
|
+
return 'int';
|
|
210
|
+
case 'decimal_floating_point_literal':
|
|
211
|
+
return 'double';
|
|
212
|
+
case 'string_literal':
|
|
213
|
+
return 'String';
|
|
214
|
+
case 'true':
|
|
215
|
+
case 'false':
|
|
216
|
+
return 'bool';
|
|
217
|
+
case 'null_literal':
|
|
218
|
+
return 'null';
|
|
219
|
+
default:
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
// ── Tier 2: Assignment Chain Propagation ─────────────────────────────────
|
|
224
|
+
const extractDartPendingAssignment = (node, scopeEnv) => {
|
|
225
|
+
if (node.type !== 'initialized_variable_definition')
|
|
226
|
+
return undefined;
|
|
227
|
+
if (hasDartTypeAnnotation(node))
|
|
228
|
+
return undefined;
|
|
229
|
+
const nameNode = node.childForFieldName('name');
|
|
230
|
+
if (!nameNode)
|
|
231
|
+
return undefined;
|
|
232
|
+
const lhs = nameNode.text;
|
|
233
|
+
if (!lhs || scopeEnv.has(lhs))
|
|
234
|
+
return undefined;
|
|
235
|
+
const rhs = parseDartRHS(node);
|
|
236
|
+
if (!rhs.callee)
|
|
237
|
+
return undefined;
|
|
238
|
+
if (!rhs.hasCall && !rhs.member)
|
|
239
|
+
return { kind: 'copy', lhs, rhs: rhs.callee };
|
|
240
|
+
if (!rhs.hasCall && rhs.member)
|
|
241
|
+
return { kind: 'fieldAccess', lhs, receiver: rhs.callee, field: rhs.member };
|
|
242
|
+
if (rhs.hasCall && !rhs.member)
|
|
243
|
+
return { kind: 'callResult', lhs, callee: rhs.callee };
|
|
244
|
+
if (rhs.hasCall && rhs.member)
|
|
245
|
+
return { kind: 'methodCallResult', lhs, receiver: rhs.callee, method: rhs.member };
|
|
246
|
+
return undefined;
|
|
247
|
+
};
|
|
248
|
+
// ── For-Loop Element Type Resolution ────────────────────────────────────
|
|
249
|
+
function extractDartElementTypeFromTypeNode(typeNode) {
|
|
250
|
+
if (typeNode.type === 'type_identifier') {
|
|
251
|
+
const parent = typeNode.parent;
|
|
252
|
+
if (parent) {
|
|
253
|
+
const args = findChild(parent, 'type_arguments');
|
|
254
|
+
if (args && args.namedChildCount >= 1) {
|
|
255
|
+
const lastArg = args.namedChild(args.namedChildCount - 1);
|
|
256
|
+
if (lastArg)
|
|
257
|
+
return extractSimpleTypeName(lastArg);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
const extractDartForLoopBinding = (node, ctx) => {
|
|
264
|
+
if (node.type !== 'for_statement')
|
|
265
|
+
return;
|
|
266
|
+
const { scopeEnv, declarationTypeNodes, scope, returnTypeLookup } = ctx;
|
|
267
|
+
const loopParts = findChild(node, 'for_loop_parts');
|
|
268
|
+
if (!loopParts)
|
|
269
|
+
return;
|
|
270
|
+
const nameNode = loopParts.childForFieldName('name');
|
|
271
|
+
if (!nameNode)
|
|
272
|
+
return;
|
|
273
|
+
const loopVarName = nameNode.text;
|
|
274
|
+
if (!loopVarName)
|
|
275
|
+
return;
|
|
276
|
+
const typeNode = findChild(loopParts, 'type_identifier');
|
|
277
|
+
if (typeNode) {
|
|
278
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
279
|
+
if (typeName && !scopeEnv.has(loopVarName)) {
|
|
280
|
+
scopeEnv.set(loopVarName, typeName);
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const iterableNode = loopParts.childForFieldName('value');
|
|
285
|
+
if (!iterableNode)
|
|
286
|
+
return;
|
|
287
|
+
let iterableName;
|
|
288
|
+
let callExprElementType;
|
|
289
|
+
if (iterableNode.type === 'identifier') {
|
|
290
|
+
iterableName = iterableNode.text;
|
|
291
|
+
}
|
|
292
|
+
else if (iterableNode.type === 'unary_expression') {
|
|
293
|
+
const awaitExpr = findChild(iterableNode, 'await_expression');
|
|
294
|
+
if (awaitExpr) {
|
|
295
|
+
const innerIdent = findChild(awaitExpr, 'identifier');
|
|
296
|
+
if (innerIdent)
|
|
297
|
+
iterableName = innerIdent.text;
|
|
298
|
+
}
|
|
299
|
+
if (!iterableName)
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (iterableName) {
|
|
303
|
+
let hasCallSelector = false;
|
|
304
|
+
let memberName;
|
|
305
|
+
const selectorParent = iterableNode.type === 'unary_expression'
|
|
306
|
+
? findChild(iterableNode, 'await_expression')
|
|
307
|
+
: loopParts;
|
|
308
|
+
if (!selectorParent)
|
|
309
|
+
return;
|
|
310
|
+
let foundIterable = false;
|
|
311
|
+
for (let i = 0; i < selectorParent.childCount; i++) {
|
|
312
|
+
const child = selectorParent.child(i);
|
|
313
|
+
if (!child)
|
|
314
|
+
continue;
|
|
315
|
+
if (child.type === 'identifier' && child.text === iterableName) {
|
|
316
|
+
foundIterable = true;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (child === iterableNode) {
|
|
320
|
+
foundIterable = true;
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if (!foundIterable)
|
|
324
|
+
continue;
|
|
325
|
+
if (child.type === 'selector') {
|
|
326
|
+
const uas = findChild(child, 'unconditional_assignable_selector')
|
|
327
|
+
?? findChild(child, 'conditional_assignable_selector');
|
|
328
|
+
if (uas) {
|
|
329
|
+
const id = findChild(uas, 'identifier');
|
|
330
|
+
if (id)
|
|
331
|
+
memberName = id.text;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (findChild(child, 'argument_part')) {
|
|
335
|
+
hasCallSelector = true;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (hasCallSelector) {
|
|
340
|
+
const callee = memberName ?? iterableName;
|
|
341
|
+
const rawReturn = returnTypeLookup.lookupRawReturnType(callee);
|
|
342
|
+
if (rawReturn)
|
|
343
|
+
callExprElementType = extractElementTypeFromString(rawReturn);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (!iterableName && !callExprElementType)
|
|
347
|
+
return;
|
|
348
|
+
let elementType;
|
|
349
|
+
if (callExprElementType) {
|
|
350
|
+
elementType = callExprElementType;
|
|
351
|
+
}
|
|
352
|
+
else if (iterableName) {
|
|
353
|
+
elementType = resolveIterableElementType(iterableName, node, scopeEnv, declarationTypeNodes, scope, extractDartElementTypeFromTypeNode);
|
|
354
|
+
}
|
|
355
|
+
if (elementType && !scopeEnv.has(loopVarName)) {
|
|
356
|
+
scopeEnv.set(loopVarName, elementType);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
// ── Export ───────────────────────────────────────────────────────────────
|
|
360
|
+
export const typeConfig = {
|
|
361
|
+
declarationNodeTypes: DART_DECLARATION_NODE_TYPES,
|
|
362
|
+
forLoopNodeTypes: DART_FOR_LOOP_NODE_TYPES,
|
|
363
|
+
extractDeclaration: extractDartDeclaration,
|
|
364
|
+
extractParameter: extractDartParameter,
|
|
365
|
+
extractInitializer: extractDartInitializer,
|
|
366
|
+
scanConstructorBinding: scanDartConstructorBinding,
|
|
367
|
+
extractForLoopBinding: extractDartForLoopBinding,
|
|
368
|
+
extractPendingAssignment: extractDartPendingAssignment,
|
|
369
|
+
inferLiteralType: inferDartLiteralType,
|
|
370
|
+
detectConstructorType: detectDartConstructorType,
|
|
371
|
+
};
|