@duytransipher/gitnexus 1.4.6-sipher.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/LICENSE +73 -0
- package/README.md +261 -0
- package/dist/cli/ai-context.d.ts +23 -0
- package/dist/cli/ai-context.js +265 -0
- package/dist/cli/analyze.d.ts +12 -0
- package/dist/cli/analyze.js +345 -0
- package/dist/cli/augment.d.ts +13 -0
- package/dist/cli/augment.js +33 -0
- package/dist/cli/clean.d.ts +10 -0
- package/dist/cli/clean.js +60 -0
- package/dist/cli/eval-server.d.ts +37 -0
- package/dist/cli/eval-server.js +389 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +137 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +18 -0
- package/dist/cli/list.d.ts +6 -0
- package/dist/cli/list.js +30 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +36 -0
- package/dist/cli/serve.d.ts +4 -0
- package/dist/cli/serve.js +6 -0
- package/dist/cli/setup.d.ts +8 -0
- package/dist/cli/setup.js +367 -0
- package/dist/cli/sipher-patched.d.ts +2 -0
- package/dist/cli/sipher-patched.js +77 -0
- package/dist/cli/skill-gen.d.ts +26 -0
- package/dist/cli/skill-gen.js +549 -0
- package/dist/cli/status.d.ts +6 -0
- package/dist/cli/status.js +36 -0
- package/dist/cli/tool.d.ts +60 -0
- package/dist/cli/tool.js +180 -0
- package/dist/cli/wiki.d.ts +15 -0
- package/dist/cli/wiki.js +365 -0
- package/dist/config/ignore-service.d.ts +26 -0
- package/dist/config/ignore-service.js +284 -0
- package/dist/config/supported-languages.d.ts +15 -0
- package/dist/config/supported-languages.js +16 -0
- package/dist/core/augmentation/engine.d.ts +26 -0
- package/dist/core/augmentation/engine.js +240 -0
- package/dist/core/embeddings/embedder.d.ts +60 -0
- package/dist/core/embeddings/embedder.js +251 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +51 -0
- package/dist/core/embeddings/embedding-pipeline.js +356 -0
- package/dist/core/embeddings/index.d.ts +9 -0
- package/dist/core/embeddings/index.js +9 -0
- package/dist/core/embeddings/text-generator.d.ts +24 -0
- package/dist/core/embeddings/text-generator.js +182 -0
- package/dist/core/embeddings/types.d.ts +87 -0
- package/dist/core/embeddings/types.js +32 -0
- package/dist/core/graph/graph.d.ts +2 -0
- package/dist/core/graph/graph.js +66 -0
- package/dist/core/graph/types.d.ts +66 -0
- package/dist/core/graph/types.js +1 -0
- package/dist/core/ingestion/ast-cache.d.ts +11 -0
- package/dist/core/ingestion/ast-cache.js +35 -0
- package/dist/core/ingestion/call-processor.d.ts +23 -0
- package/dist/core/ingestion/call-processor.js +793 -0
- package/dist/core/ingestion/call-routing.d.ts +68 -0
- package/dist/core/ingestion/call-routing.js +129 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +38 -0
- package/dist/core/ingestion/cluster-enricher.js +170 -0
- package/dist/core/ingestion/community-processor.d.ts +39 -0
- package/dist/core/ingestion/community-processor.js +312 -0
- package/dist/core/ingestion/constants.d.ts +16 -0
- package/dist/core/ingestion/constants.js +16 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +40 -0
- package/dist/core/ingestion/entry-point-scoring.js +353 -0
- package/dist/core/ingestion/export-detection.d.ts +18 -0
- package/dist/core/ingestion/export-detection.js +231 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +28 -0
- package/dist/core/ingestion/filesystem-walker.js +81 -0
- package/dist/core/ingestion/framework-detection.d.ts +54 -0
- package/dist/core/ingestion/framework-detection.js +411 -0
- package/dist/core/ingestion/heritage-processor.d.ts +28 -0
- package/dist/core/ingestion/heritage-processor.js +251 -0
- package/dist/core/ingestion/import-processor.d.ts +34 -0
- package/dist/core/ingestion/import-processor.js +398 -0
- package/dist/core/ingestion/language-config.d.ts +46 -0
- package/dist/core/ingestion/language-config.js +167 -0
- package/dist/core/ingestion/mro-processor.d.ts +45 -0
- package/dist/core/ingestion/mro-processor.js +369 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +61 -0
- package/dist/core/ingestion/named-binding-extraction.js +363 -0
- package/dist/core/ingestion/parsing-processor.d.ts +19 -0
- package/dist/core/ingestion/parsing-processor.js +315 -0
- package/dist/core/ingestion/pipeline.d.ts +6 -0
- package/dist/core/ingestion/pipeline.js +401 -0
- package/dist/core/ingestion/process-processor.d.ts +51 -0
- package/dist/core/ingestion/process-processor.js +315 -0
- package/dist/core/ingestion/resolution-context.d.ts +53 -0
- package/dist/core/ingestion/resolution-context.js +132 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +22 -0
- package/dist/core/ingestion/resolvers/csharp.js +109 -0
- package/dist/core/ingestion/resolvers/go.d.ts +19 -0
- package/dist/core/ingestion/resolvers/go.js +42 -0
- package/dist/core/ingestion/resolvers/index.d.ts +18 -0
- package/dist/core/ingestion/resolvers/index.js +13 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +23 -0
- package/dist/core/ingestion/resolvers/jvm.js +87 -0
- package/dist/core/ingestion/resolvers/php.d.ts +15 -0
- package/dist/core/ingestion/resolvers/php.js +35 -0
- package/dist/core/ingestion/resolvers/python.d.ts +19 -0
- package/dist/core/ingestion/resolvers/python.js +52 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +12 -0
- package/dist/core/ingestion/resolvers/ruby.js +15 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +15 -0
- package/dist/core/ingestion/resolvers/rust.js +73 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +28 -0
- package/dist/core/ingestion/resolvers/standard.js +123 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +33 -0
- package/dist/core/ingestion/resolvers/utils.js +122 -0
- package/dist/core/ingestion/structure-processor.d.ts +2 -0
- package/dist/core/ingestion/structure-processor.js +36 -0
- package/dist/core/ingestion/symbol-table.d.ts +63 -0
- package/dist/core/ingestion/symbol-table.js +85 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +15 -0
- package/dist/core/ingestion/tree-sitter-queries.js +888 -0
- package/dist/core/ingestion/type-env.d.ts +49 -0
- package/dist/core/ingestion/type-env.js +613 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +385 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/csharp.js +383 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/go.js +467 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +22 -0
- package/dist/core/ingestion/type-extractors/index.js +31 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +3 -0
- package/dist/core/ingestion/type-extractors/jvm.js +681 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/php.js +549 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/python.js +455 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/ruby.js +389 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/rust.js +456 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +145 -0
- package/dist/core/ingestion/type-extractors/shared.js +810 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/swift.js +137 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +127 -0
- package/dist/core/ingestion/type-extractors/types.js +1 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +2 -0
- package/dist/core/ingestion/type-extractors/typescript.js +494 -0
- package/dist/core/ingestion/utils.d.ts +138 -0
- package/dist/core/ingestion/utils.js +1290 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +122 -0
- package/dist/core/ingestion/workers/parse-worker.js +1126 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +16 -0
- package/dist/core/ingestion/workers/worker-pool.js +128 -0
- package/dist/core/lbug/csv-generator.d.ts +33 -0
- package/dist/core/lbug/csv-generator.js +366 -0
- package/dist/core/lbug/lbug-adapter.d.ts +103 -0
- package/dist/core/lbug/lbug-adapter.js +769 -0
- package/dist/core/lbug/schema.d.ts +53 -0
- package/dist/core/lbug/schema.js +430 -0
- package/dist/core/search/bm25-index.d.ts +23 -0
- package/dist/core/search/bm25-index.js +96 -0
- package/dist/core/search/hybrid-search.d.ts +49 -0
- package/dist/core/search/hybrid-search.js +118 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +5 -0
- package/dist/core/tree-sitter/parser-loader.js +63 -0
- package/dist/core/wiki/generator.d.ts +120 -0
- package/dist/core/wiki/generator.js +939 -0
- package/dist/core/wiki/graph-queries.d.ts +80 -0
- package/dist/core/wiki/graph-queries.js +238 -0
- package/dist/core/wiki/html-viewer.d.ts +10 -0
- package/dist/core/wiki/html-viewer.js +297 -0
- package/dist/core/wiki/llm-client.d.ts +43 -0
- package/dist/core/wiki/llm-client.js +186 -0
- package/dist/core/wiki/prompts.d.ts +53 -0
- package/dist/core/wiki/prompts.js +174 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +3 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +25 -0
- package/dist/mcp/compatible-stdio-transport.js +200 -0
- package/dist/mcp/core/embedder.d.ts +27 -0
- package/dist/mcp/core/embedder.js +108 -0
- package/dist/mcp/core/lbug-adapter.d.ts +57 -0
- package/dist/mcp/core/lbug-adapter.js +455 -0
- package/dist/mcp/local/local-backend.d.ts +181 -0
- package/dist/mcp/local/local-backend.js +1722 -0
- package/dist/mcp/resources.d.ts +31 -0
- package/dist/mcp/resources.js +411 -0
- package/dist/mcp/server.d.ts +23 -0
- package/dist/mcp/server.js +296 -0
- package/dist/mcp/staleness.d.ts +15 -0
- package/dist/mcp/staleness.js +29 -0
- package/dist/mcp/tools.d.ts +24 -0
- package/dist/mcp/tools.js +292 -0
- package/dist/server/api.d.ts +10 -0
- package/dist/server/api.js +344 -0
- package/dist/server/mcp-http.d.ts +13 -0
- package/dist/server/mcp-http.js +100 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +138 -0
- package/dist/storage/repo-manager.js +299 -0
- package/dist/types/pipeline.d.ts +32 -0
- package/dist/types/pipeline.js +18 -0
- package/dist/unreal/bridge.d.ts +4 -0
- package/dist/unreal/bridge.js +113 -0
- package/dist/unreal/config.d.ts +6 -0
- package/dist/unreal/config.js +55 -0
- package/dist/unreal/types.d.ts +105 -0
- package/dist/unreal/types.js +1 -0
- package/hooks/claude/gitnexus-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/package.json +100 -0
- package/scripts/ensure-cli-executable.cjs +21 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/scripts/setup-unreal-gitnexus.ps1 +191 -0
- package/skills/gitnexus-cli.md +82 -0
- package/skills/gitnexus-debugging.md +89 -0
- package/skills/gitnexus-exploring.md +78 -0
- package/skills/gitnexus-guide.md +64 -0
- package/skills/gitnexus-impact-analysis.md +97 -0
- package/skills/gitnexus-pr-review.md +163 -0
- package/skills/gitnexus-refactoring.md +121 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { extractSimpleTypeName, extractVarName, findChildByType, hasTypeAnnotation } from './shared.js';
|
|
2
|
+
const DECLARATION_NODE_TYPES = new Set([
|
|
3
|
+
'property_declaration',
|
|
4
|
+
]);
|
|
5
|
+
/** Swift: let x: Foo = ... */
|
|
6
|
+
const extractDeclaration = (node, env) => {
|
|
7
|
+
// Swift property_declaration has pattern and type_annotation
|
|
8
|
+
const pattern = node.childForFieldName('pattern')
|
|
9
|
+
?? findChildByType(node, 'pattern');
|
|
10
|
+
const typeAnnotation = node.childForFieldName('type')
|
|
11
|
+
?? findChildByType(node, 'type_annotation');
|
|
12
|
+
if (!pattern || !typeAnnotation)
|
|
13
|
+
return;
|
|
14
|
+
const varName = extractVarName(pattern) ?? pattern.text;
|
|
15
|
+
const typeName = extractSimpleTypeName(typeAnnotation);
|
|
16
|
+
if (varName && typeName)
|
|
17
|
+
env.set(varName, typeName);
|
|
18
|
+
};
|
|
19
|
+
/** Swift: parameter → name: type */
|
|
20
|
+
const extractParameter = (node, env) => {
|
|
21
|
+
let nameNode = null;
|
|
22
|
+
let typeNode = null;
|
|
23
|
+
if (node.type === 'parameter') {
|
|
24
|
+
nameNode = node.childForFieldName('name')
|
|
25
|
+
?? node.childForFieldName('internal_name');
|
|
26
|
+
typeNode = node.childForFieldName('type');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
nameNode = node.childForFieldName('name') ?? node.childForFieldName('pattern');
|
|
30
|
+
typeNode = node.childForFieldName('type');
|
|
31
|
+
}
|
|
32
|
+
if (!nameNode || !typeNode)
|
|
33
|
+
return;
|
|
34
|
+
const varName = extractVarName(nameNode);
|
|
35
|
+
const typeName = extractSimpleTypeName(typeNode);
|
|
36
|
+
if (varName && typeName)
|
|
37
|
+
env.set(varName, typeName);
|
|
38
|
+
};
|
|
39
|
+
/** Swift: let user = User(name: "alice") — infer type from call when callee is a known class.
|
|
40
|
+
* Swift initializers are syntactically identical to function calls, so we verify
|
|
41
|
+
* against classNames (which may include cross-file SymbolTable lookups). */
|
|
42
|
+
const extractInitializer = (node, env, classNames) => {
|
|
43
|
+
if (node.type !== 'property_declaration')
|
|
44
|
+
return;
|
|
45
|
+
// Skip if has type annotation — extractDeclaration handled it
|
|
46
|
+
if (node.childForFieldName('type') || findChildByType(node, 'type_annotation'))
|
|
47
|
+
return;
|
|
48
|
+
// Find pattern (variable name)
|
|
49
|
+
const pattern = node.childForFieldName('pattern') ?? findChildByType(node, 'pattern');
|
|
50
|
+
if (!pattern)
|
|
51
|
+
return;
|
|
52
|
+
const varName = extractVarName(pattern) ?? pattern.text;
|
|
53
|
+
if (!varName || env.has(varName))
|
|
54
|
+
return;
|
|
55
|
+
// Find call_expression in the value
|
|
56
|
+
const callExpr = findChildByType(node, 'call_expression');
|
|
57
|
+
if (!callExpr)
|
|
58
|
+
return;
|
|
59
|
+
const callee = callExpr.firstNamedChild;
|
|
60
|
+
if (!callee)
|
|
61
|
+
return;
|
|
62
|
+
// Direct call: User(name: "alice")
|
|
63
|
+
if (callee.type === 'simple_identifier') {
|
|
64
|
+
const calleeName = callee.text;
|
|
65
|
+
if (calleeName && classNames.has(calleeName)) {
|
|
66
|
+
env.set(varName, calleeName);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Explicit init: User.init(name: "alice") — navigation_expression with .init suffix
|
|
71
|
+
if (callee.type === 'navigation_expression') {
|
|
72
|
+
const receiver = callee.firstNamedChild;
|
|
73
|
+
const suffix = callee.lastNamedChild;
|
|
74
|
+
if (receiver?.type === 'simple_identifier' && suffix?.text === 'init') {
|
|
75
|
+
const calleeName = receiver.text;
|
|
76
|
+
if (calleeName && classNames.has(calleeName)) {
|
|
77
|
+
env.set(varName, calleeName);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
/** Swift: let user = User(name: "alice") — scan property_declaration for constructor binding */
|
|
83
|
+
const scanConstructorBinding = (node) => {
|
|
84
|
+
if (node.type !== 'property_declaration')
|
|
85
|
+
return undefined;
|
|
86
|
+
if (hasTypeAnnotation(node))
|
|
87
|
+
return undefined;
|
|
88
|
+
const pattern = node.childForFieldName('pattern');
|
|
89
|
+
if (!pattern)
|
|
90
|
+
return undefined;
|
|
91
|
+
const varName = pattern.text;
|
|
92
|
+
if (!varName)
|
|
93
|
+
return undefined;
|
|
94
|
+
let callExpr = null;
|
|
95
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
96
|
+
const child = node.namedChild(i);
|
|
97
|
+
if (child?.type === 'call_expression') {
|
|
98
|
+
callExpr = child;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!callExpr)
|
|
103
|
+
return undefined;
|
|
104
|
+
const callee = callExpr.firstNamedChild;
|
|
105
|
+
if (!callee)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (callee.type === 'simple_identifier') {
|
|
108
|
+
return { varName, calleeName: callee.text };
|
|
109
|
+
}
|
|
110
|
+
if (callee.type === 'navigation_expression') {
|
|
111
|
+
const receiver = callee.firstNamedChild;
|
|
112
|
+
const suffix = callee.lastNamedChild;
|
|
113
|
+
if (receiver?.type === 'simple_identifier' && suffix?.text === 'init') {
|
|
114
|
+
return { varName, calleeName: receiver.text };
|
|
115
|
+
}
|
|
116
|
+
// General qualified call: service.getUser() → extract method name.
|
|
117
|
+
// tree-sitter-swift may wrap the identifier in navigation_suffix, so
|
|
118
|
+
// check both direct simple_identifier and navigation_suffix > simple_identifier.
|
|
119
|
+
if (suffix?.type === 'simple_identifier') {
|
|
120
|
+
return { varName, calleeName: suffix.text };
|
|
121
|
+
}
|
|
122
|
+
if (suffix?.type === 'navigation_suffix') {
|
|
123
|
+
const inner = suffix.lastNamedChild;
|
|
124
|
+
if (inner?.type === 'simple_identifier') {
|
|
125
|
+
return { varName, calleeName: inner.text };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
131
|
+
export const typeConfig = {
|
|
132
|
+
declarationNodeTypes: DECLARATION_NODE_TYPES,
|
|
133
|
+
extractDeclaration,
|
|
134
|
+
extractParameter,
|
|
135
|
+
extractInitializer,
|
|
136
|
+
scanConstructorBinding,
|
|
137
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { SyntaxNode } from '../utils.js';
|
|
2
|
+
/** Extracts type bindings from a declaration node into the env map */
|
|
3
|
+
export type TypeBindingExtractor = (node: SyntaxNode, env: Map<string, string>) => void;
|
|
4
|
+
/** Extracts type bindings from a parameter node into the env map */
|
|
5
|
+
export type ParameterExtractor = (node: SyntaxNode, env: Map<string, string>) => void;
|
|
6
|
+
/** Minimal interface for checking whether a name is a known class/struct.
|
|
7
|
+
* Narrower than ReadonlySet — only `.has()` is used by extractors. */
|
|
8
|
+
export type ClassNameLookup = {
|
|
9
|
+
has(name: string): boolean;
|
|
10
|
+
};
|
|
11
|
+
/** Extracts type bindings from a constructor-call initializer, with access to known class names */
|
|
12
|
+
export type InitializerExtractor = (node: SyntaxNode, env: Map<string, string>, classNames: ClassNameLookup) => void;
|
|
13
|
+
/** Scans an AST node for untyped `var = callee()` patterns for return-type inference.
|
|
14
|
+
* Returns { varName, calleeName } if the node matches, undefined otherwise.
|
|
15
|
+
* `receiverClassName` — optional hint for method calls on known receivers
|
|
16
|
+
* (e.g. $this->getUser() in PHP provides the enclosing class name). */
|
|
17
|
+
export type ConstructorBindingScanner = (node: SyntaxNode) => {
|
|
18
|
+
varName: string;
|
|
19
|
+
calleeName: string;
|
|
20
|
+
receiverClassName?: string;
|
|
21
|
+
} | undefined;
|
|
22
|
+
/** Extracts a return type string from a method/function definition node.
|
|
23
|
+
* Used for languages where return types are expressed in comments (e.g. YARD @return [Type])
|
|
24
|
+
* rather than in AST fields. Returns undefined if no return type can be determined. */
|
|
25
|
+
export type ReturnTypeExtractor = (node: SyntaxNode) => string | undefined;
|
|
26
|
+
/** Narrow lookup interface for resolving a callee name → return type name.
|
|
27
|
+
* Backed by SymbolTable.lookupFuzzyCallable; passed via ForLoopExtractorContext.
|
|
28
|
+
* Conservative: returns undefined when the callee is ambiguous (0 or 2+ matches). */
|
|
29
|
+
export interface ReturnTypeLookup {
|
|
30
|
+
/** Processed type name after stripping wrappers (e.g., 'User' from 'Promise<User>').
|
|
31
|
+
* Use for call-result variable bindings (`const b = foo()`). */
|
|
32
|
+
lookupReturnType(callee: string): string | undefined;
|
|
33
|
+
/** Raw return type as declared in the symbol (e.g., '[]User', 'List<User>').
|
|
34
|
+
* Use for iterable-element extraction (`for v := range foo()`). */
|
|
35
|
+
lookupRawReturnType(callee: string): string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Context object passed to ForLoopExtractor.
|
|
38
|
+
* Groups the four parameters that were previously positional. */
|
|
39
|
+
export interface ForLoopExtractorContext {
|
|
40
|
+
/** Mutable type-env for the current scope — extractor writes bindings here */
|
|
41
|
+
scopeEnv: Map<string, string>;
|
|
42
|
+
/** Maps `scope\0varName` to the declaration's type annotation AST node */
|
|
43
|
+
declarationTypeNodes: ReadonlyMap<string, SyntaxNode>;
|
|
44
|
+
/** Current scope key, e.g. `"process@42"` */
|
|
45
|
+
scope: string;
|
|
46
|
+
/** Resolves a callee name to its declared return type (undefined = unknown/ambiguous) */
|
|
47
|
+
returnTypeLookup: ReturnTypeLookup;
|
|
48
|
+
}
|
|
49
|
+
/** Extracts loop variable type binding from a for-each statement. */
|
|
50
|
+
export type ForLoopExtractor = (node: SyntaxNode, ctx: ForLoopExtractorContext) => void;
|
|
51
|
+
/** Discriminated union for pending Tier-2 propagation items.
|
|
52
|
+
* - `copy` — `const b = a` (identifier alias, propagate a's type to b)
|
|
53
|
+
* - `callResult` — `const b = foo()` (bind b to foo's declared return type) */
|
|
54
|
+
export type PendingAssignment = {
|
|
55
|
+
kind: 'copy';
|
|
56
|
+
lhs: string;
|
|
57
|
+
rhs: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: 'callResult';
|
|
60
|
+
lhs: string;
|
|
61
|
+
callee: string;
|
|
62
|
+
};
|
|
63
|
+
/** Extracts a pending assignment for Tier 2 propagation.
|
|
64
|
+
* Returns a PendingAssignment when the RHS is a bare identifier (`copy`) or a
|
|
65
|
+
* call expression (`callResult`) and the LHS has no resolved type yet.
|
|
66
|
+
* Returns undefined if the node is not a matching assignment. */
|
|
67
|
+
export type PendingAssignmentExtractor = (node: SyntaxNode, scopeEnv: ReadonlyMap<string, string>) => PendingAssignment | undefined;
|
|
68
|
+
/** Extracts a typed variable binding from a pattern-matching construct.
|
|
69
|
+
* Returns { varName, typeName } for patterns that introduce NEW variables.
|
|
70
|
+
* Examples: `if let Some(user) = opt` (Rust), `x instanceof User user` (Java).
|
|
71
|
+
* Conservative: returns undefined when the source variable's type is unknown.
|
|
72
|
+
*
|
|
73
|
+
* @param scopeEnv Read-only view of already-resolved type bindings in the current scope.
|
|
74
|
+
* @param declarationTypeNodes Maps `scope\0varName` to the original declaration's type
|
|
75
|
+
* annotation AST node. Allows extracting generic type arguments (e.g., T from Result<T,E>)
|
|
76
|
+
* that are stripped during normal TypeEnv extraction.
|
|
77
|
+
* @param scope Current scope key (e.g. `"process@42"`) for declarationTypeNodes lookups. */
|
|
78
|
+
export type PatternBindingExtractor = (node: SyntaxNode, scopeEnv: ReadonlyMap<string, string>, declarationTypeNodes: ReadonlyMap<string, SyntaxNode>, scope: string) => {
|
|
79
|
+
varName: string;
|
|
80
|
+
typeName: string;
|
|
81
|
+
} | undefined;
|
|
82
|
+
/** Per-language type extraction configuration */
|
|
83
|
+
export interface LanguageTypeConfig {
|
|
84
|
+
/** Allow pattern binding to overwrite existing scopeEnv entries.
|
|
85
|
+
* WARNING: Enables function-scope type pollution. Only for languages with
|
|
86
|
+
* smart-cast semantics (e.g., Kotlin `when/is`) where the subject variable
|
|
87
|
+
* already exists in scopeEnv from its declaration. */
|
|
88
|
+
readonly allowPatternBindingOverwrite?: boolean;
|
|
89
|
+
/** Node types that represent typed declarations for this language */
|
|
90
|
+
declarationNodeTypes: ReadonlySet<string>;
|
|
91
|
+
/** AST node types for for-each/for-in statements with explicit element types. */
|
|
92
|
+
forLoopNodeTypes?: ReadonlySet<string>;
|
|
93
|
+
/** Optional allowlist of AST node types on which extractPatternBinding should run.
|
|
94
|
+
* When present, extractPatternBinding is only invoked for nodes whose type is in this set,
|
|
95
|
+
* short-circuiting the call for all other node types. When absent, every node is passed to
|
|
96
|
+
* extractPatternBinding (legacy behaviour). */
|
|
97
|
+
patternBindingNodeTypes?: ReadonlySet<string>;
|
|
98
|
+
/** Extract a (varName → typeName) binding from a declaration node */
|
|
99
|
+
extractDeclaration: TypeBindingExtractor;
|
|
100
|
+
/** Extract a (varName → typeName) binding from a parameter node */
|
|
101
|
+
extractParameter: ParameterExtractor;
|
|
102
|
+
/** Extract a (varName → typeName) binding from a constructor-call initializer.
|
|
103
|
+
* Called as fallback when extractDeclaration produces no binding for a declaration node.
|
|
104
|
+
* Only for languages with syntactic constructor markers (new, composite_literal, ::new).
|
|
105
|
+
* Receives classNames — the set of class/struct names visible in the current file's AST. */
|
|
106
|
+
extractInitializer?: InitializerExtractor;
|
|
107
|
+
/** Scan for untyped `var = callee()` assignments for return-type inference.
|
|
108
|
+
* Called on every AST node during buildTypeEnv walk; returns undefined for non-matches.
|
|
109
|
+
* The callee binding is unverified — the caller must confirm against the SymbolTable. */
|
|
110
|
+
scanConstructorBinding?: ConstructorBindingScanner;
|
|
111
|
+
/** Extract return type from comment-based annotations (e.g. YARD @return [Type]).
|
|
112
|
+
* Called as fallback when extractMethodSignature finds no AST-based return type. */
|
|
113
|
+
extractReturnType?: ReturnTypeExtractor;
|
|
114
|
+
/** Extract loop variable → type binding from a for-each AST node. */
|
|
115
|
+
extractForLoopBinding?: ForLoopExtractor;
|
|
116
|
+
/** Extract pending assignment for Tier 2 propagation.
|
|
117
|
+
* Called on declaration/assignment nodes; returns a PendingAssignment when the RHS
|
|
118
|
+
* is a bare identifier (copy) or call expression (callResult) and the LHS has no
|
|
119
|
+
* resolved type yet. Language-specific because AST shapes differ widely. */
|
|
120
|
+
extractPendingAssignment?: PendingAssignmentExtractor;
|
|
121
|
+
/** Extract a typed variable binding from a pattern-matching construct.
|
|
122
|
+
* Called on every AST node; returns { varName, typeName } when the node introduces a new
|
|
123
|
+
* typed variable via pattern matching (e.g. `if let Some(x) = opt`, `x instanceof T t`).
|
|
124
|
+
* The extractor receives the current scope's resolved bindings (read-only) to look up the
|
|
125
|
+
* source variable's type. Returns undefined for non-matching nodes or unknown source types. */
|
|
126
|
+
extractPatternBinding?: PatternBindingExtractor;
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|