gitnexus 1.6.2-rc.9 → 1.6.2
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/dist/_shared/lbug/schema-constants.d.ts +1 -1
- package/dist/_shared/lbug/schema-constants.d.ts.map +1 -1
- package/dist/_shared/lbug/schema-constants.js +1 -0
- package/dist/_shared/lbug/schema-constants.js.map +1 -1
- package/dist/_shared/mro-strategy.d.ts +38 -16
- package/dist/_shared/mro-strategy.d.ts.map +1 -1
- package/dist/cli/ai-context.js +0 -58
- package/dist/cli/analyze.js +3 -0
- package/dist/core/embeddings/ast-utils.d.ts +22 -0
- package/dist/core/embeddings/ast-utils.js +105 -0
- package/dist/core/embeddings/character-chunk.d.ts +12 -0
- package/dist/core/embeddings/character-chunk.js +43 -0
- package/dist/core/embeddings/chunker.d.ts +14 -0
- package/dist/core/embeddings/chunker.js +234 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +20 -24
- package/dist/core/embeddings/embedding-pipeline.js +176 -107
- package/dist/core/embeddings/line-index.d.ts +7 -0
- package/dist/core/embeddings/line-index.js +42 -0
- package/dist/core/embeddings/server-mapping.d.ts +15 -0
- package/dist/core/embeddings/server-mapping.js +33 -0
- package/dist/core/embeddings/structural-extractor.d.ts +15 -0
- package/dist/core/embeddings/structural-extractor.js +58 -0
- package/dist/core/embeddings/text-generator.d.ts +20 -13
- package/dist/core/embeddings/text-generator.js +151 -119
- package/dist/core/embeddings/types.d.ts +81 -3
- package/dist/core/embeddings/types.js +105 -3
- package/dist/core/group/extractors/http-patterns/node.js +130 -0
- package/dist/core/ingestion/call-extractors/configs/c-cpp.d.ts +3 -0
- package/dist/core/ingestion/call-extractors/configs/c-cpp.js +8 -0
- package/dist/core/ingestion/call-extractors/configs/csharp.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/csharp.js +6 -0
- package/dist/core/ingestion/call-extractors/configs/dart.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/dart.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/go.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/go.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/jvm.d.ts +3 -0
- package/dist/core/ingestion/call-extractors/configs/jvm.js +51 -0
- package/dist/core/ingestion/call-extractors/configs/php.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/php.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/python.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/python.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/ruby.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/ruby.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/rust.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/rust.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/swift.d.ts +2 -0
- package/dist/core/ingestion/call-extractors/configs/swift.js +5 -0
- package/dist/core/ingestion/call-extractors/configs/typescript-javascript.d.ts +3 -0
- package/dist/core/ingestion/call-extractors/configs/typescript-javascript.js +8 -0
- package/dist/core/ingestion/call-extractors/generic.d.ts +5 -0
- package/dist/core/ingestion/call-extractors/generic.js +59 -0
- package/dist/core/ingestion/call-processor.d.ts +2 -4
- package/dist/core/ingestion/call-processor.js +221 -89
- package/dist/core/ingestion/call-routing.d.ts +8 -12
- package/dist/core/ingestion/call-routing.js +13 -34
- package/dist/core/ingestion/call-types.d.ts +135 -0
- package/dist/core/ingestion/call-types.js +2 -0
- package/dist/core/ingestion/class-extractors/configs/c-cpp.d.ts +3 -0
- package/dist/core/ingestion/class-extractors/configs/c-cpp.js +11 -0
- package/dist/core/ingestion/class-extractors/configs/csharp.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/csharp.js +21 -0
- package/dist/core/ingestion/class-extractors/configs/dart.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/dart.js +7 -0
- package/dist/core/ingestion/class-extractors/configs/go.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/go.js +20 -0
- package/dist/core/ingestion/class-extractors/configs/jvm.d.ts +3 -0
- package/dist/core/ingestion/class-extractors/configs/jvm.js +35 -0
- package/dist/core/ingestion/class-extractors/configs/php.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/php.js +7 -0
- package/dist/core/ingestion/class-extractors/configs/python.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/python.js +7 -0
- package/dist/core/ingestion/class-extractors/configs/ruby.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/ruby.js +7 -0
- package/dist/core/ingestion/class-extractors/configs/rust.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/rust.js +7 -0
- package/dist/core/ingestion/class-extractors/configs/swift.d.ts +2 -0
- package/dist/core/ingestion/class-extractors/configs/swift.js +18 -0
- package/dist/core/ingestion/class-extractors/configs/typescript-javascript.d.ts +4 -0
- package/dist/core/ingestion/class-extractors/configs/typescript-javascript.js +28 -0
- package/dist/core/ingestion/field-types.d.ts +1 -1
- package/dist/core/ingestion/heritage-extractors/configs/go.d.ts +13 -0
- package/dist/core/ingestion/heritage-extractors/configs/go.js +20 -0
- package/dist/core/ingestion/heritage-extractors/configs/ruby.d.ts +18 -0
- package/dist/core/ingestion/heritage-extractors/configs/ruby.js +65 -0
- package/dist/core/ingestion/heritage-extractors/generic.d.ts +23 -0
- package/dist/core/ingestion/heritage-extractors/generic.js +47 -0
- package/dist/core/ingestion/heritage-processor.d.ts +9 -0
- package/dist/core/ingestion/heritage-processor.js +120 -85
- package/dist/core/ingestion/heritage-types.d.ts +73 -0
- package/dist/core/ingestion/heritage-types.js +2 -0
- package/dist/core/ingestion/import-resolvers/configs/c-cpp.d.ts +7 -0
- package/dist/core/ingestion/import-resolvers/configs/c-cpp.js +14 -0
- package/dist/core/ingestion/import-resolvers/configs/csharp.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/configs/csharp.js +27 -0
- package/dist/core/ingestion/import-resolvers/configs/dart.d.ts +17 -0
- package/dist/core/ingestion/import-resolvers/{dart.js → configs/dart.js} +26 -16
- package/dist/core/ingestion/import-resolvers/configs/go.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/configs/go.js +26 -0
- package/dist/core/ingestion/import-resolvers/configs/jvm.d.ts +13 -0
- package/dist/core/ingestion/import-resolvers/configs/jvm.js +68 -0
- package/dist/core/ingestion/import-resolvers/configs/php.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/configs/php.js +15 -0
- package/dist/core/ingestion/import-resolvers/configs/python.d.ts +12 -0
- package/dist/core/ingestion/import-resolvers/configs/python.js +41 -0
- package/dist/core/ingestion/import-resolvers/configs/ruby.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/configs/ruby.js +16 -0
- package/dist/core/ingestion/import-resolvers/configs/rust.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/configs/rust.js +54 -0
- package/dist/core/ingestion/import-resolvers/configs/swift.d.ts +8 -0
- package/dist/core/ingestion/import-resolvers/{swift.js → configs/swift.js} +10 -5
- package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.d.ts +9 -0
- package/dist/core/ingestion/import-resolvers/configs/typescript-javascript.js +23 -0
- package/dist/core/ingestion/import-resolvers/csharp.d.ts +4 -5
- package/dist/core/ingestion/import-resolvers/csharp.js +4 -20
- package/dist/core/ingestion/import-resolvers/go.d.ts +4 -5
- package/dist/core/ingestion/import-resolvers/go.js +4 -19
- package/dist/core/ingestion/import-resolvers/jvm.d.ts +5 -10
- package/dist/core/ingestion/import-resolvers/jvm.js +5 -58
- package/dist/core/ingestion/import-resolvers/php.d.ts +4 -5
- package/dist/core/ingestion/import-resolvers/php.js +4 -7
- package/dist/core/ingestion/import-resolvers/python.d.ts +3 -6
- package/dist/core/ingestion/import-resolvers/python.js +3 -18
- package/dist/core/ingestion/import-resolvers/resolver-factory.d.ts +24 -0
- package/dist/core/ingestion/import-resolvers/resolver-factory.js +33 -0
- package/dist/core/ingestion/import-resolvers/ruby.d.ts +4 -5
- package/dist/core/ingestion/import-resolvers/ruby.js +4 -7
- package/dist/core/ingestion/import-resolvers/rust.d.ts +4 -5
- package/dist/core/ingestion/import-resolvers/rust.js +4 -47
- package/dist/core/ingestion/import-resolvers/standard.d.ts +3 -9
- package/dist/core/ingestion/import-resolvers/standard.js +7 -8
- package/dist/core/ingestion/import-resolvers/types.d.ts +24 -0
- package/dist/core/ingestion/language-provider.d.ts +80 -0
- package/dist/core/ingestion/languages/c-cpp.js +18 -12
- package/dist/core/ingestion/languages/csharp.js +13 -21
- package/dist/core/ingestion/languages/dart.js +13 -7
- package/dist/core/ingestion/languages/go.js +14 -20
- package/dist/core/ingestion/languages/java.js +13 -18
- package/dist/core/ingestion/languages/kotlin.js +13 -13
- package/dist/core/ingestion/languages/php.js +13 -7
- package/dist/core/ingestion/languages/python.js +13 -7
- package/dist/core/ingestion/languages/ruby.js +103 -22
- package/dist/core/ingestion/languages/rust.js +13 -7
- package/dist/core/ingestion/languages/swift.js +13 -18
- package/dist/core/ingestion/languages/typescript.js +18 -23
- package/dist/core/ingestion/languages/vue.js +13 -17
- package/dist/core/ingestion/model/heritage-map.d.ts +35 -0
- package/dist/core/ingestion/model/heritage-map.js +110 -9
- package/dist/core/ingestion/model/index.d.ts +2 -2
- package/dist/core/ingestion/model/index.js +1 -1
- package/dist/core/ingestion/model/resolve.d.ts +33 -28
- package/dist/core/ingestion/model/resolve.js +111 -27
- package/dist/core/ingestion/parsing-processor.d.ts +1 -2
- package/dist/core/ingestion/pipeline-phases/parse-impl.d.ts +1 -0
- package/dist/core/ingestion/pipeline-phases/parse-impl.js +9 -3
- package/dist/core/ingestion/pipeline-phases/parse.d.ts +7 -0
- package/dist/core/ingestion/pipeline.d.ts +11 -0
- package/dist/core/ingestion/pipeline.js +9 -2
- package/dist/core/ingestion/tree-sitter-queries.d.ts +11 -11
- package/dist/core/ingestion/tree-sitter-queries.js +81 -0
- package/dist/core/ingestion/type-env.d.ts +1 -1
- package/dist/core/ingestion/utils/ast-helpers.d.ts +1 -1
- package/dist/core/ingestion/utils/ast-helpers.js +22 -2
- package/dist/core/ingestion/utils/ruby-self-call.d.ts +52 -0
- package/dist/core/ingestion/utils/ruby-self-call.js +59 -0
- package/dist/core/ingestion/variable-extractors/configs/c-cpp.d.ts +3 -0
- package/dist/core/ingestion/variable-extractors/configs/c-cpp.js +81 -0
- package/dist/core/ingestion/variable-extractors/configs/csharp.d.ts +9 -0
- package/dist/core/ingestion/variable-extractors/configs/csharp.js +63 -0
- package/dist/core/ingestion/variable-extractors/configs/dart.d.ts +2 -0
- package/dist/core/ingestion/variable-extractors/configs/dart.js +94 -0
- package/dist/core/ingestion/variable-extractors/configs/go.d.ts +2 -0
- package/dist/core/ingestion/variable-extractors/configs/go.js +83 -0
- package/dist/core/ingestion/variable-extractors/configs/jvm.d.ts +18 -0
- package/dist/core/ingestion/variable-extractors/configs/jvm.js +115 -0
- package/dist/core/ingestion/variable-extractors/configs/php.d.ts +14 -0
- package/dist/core/ingestion/variable-extractors/configs/php.js +58 -0
- package/dist/core/ingestion/variable-extractors/configs/python.d.ts +2 -0
- package/dist/core/ingestion/variable-extractors/configs/python.js +101 -0
- package/dist/core/ingestion/variable-extractors/configs/ruby.d.ts +11 -0
- package/dist/core/ingestion/variable-extractors/configs/ruby.js +52 -0
- package/dist/core/ingestion/variable-extractors/configs/rust.d.ts +2 -0
- package/dist/core/ingestion/variable-extractors/configs/rust.js +76 -0
- package/dist/core/ingestion/variable-extractors/configs/swift.d.ts +2 -0
- package/dist/core/ingestion/variable-extractors/configs/swift.js +88 -0
- package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.d.ts +3 -0
- package/dist/core/ingestion/variable-extractors/configs/typescript-javascript.js +83 -0
- package/dist/core/ingestion/variable-extractors/generic.d.ts +5 -0
- package/dist/core/ingestion/variable-extractors/generic.js +80 -0
- package/dist/core/ingestion/variable-types.d.ts +82 -0
- package/dist/core/ingestion/variable-types.js +2 -0
- package/dist/core/ingestion/workers/parse-worker.js +244 -217
- package/dist/core/ingestion/workers/worker-pool.js +3 -0
- package/dist/core/lbug/csv-generator.js +1 -0
- package/dist/core/lbug/lbug-adapter.d.ts +4 -5
- package/dist/core/lbug/lbug-adapter.js +38 -14
- package/dist/core/lbug/schema.d.ts +2 -1
- package/dist/core/lbug/schema.js +10 -1
- package/dist/core/run-analyze.js +6 -7
- package/dist/core/tree-sitter/parser-loader.d.ts +3 -0
- package/dist/core/tree-sitter/parser-loader.js +17 -8
- package/dist/mcp/local/local-backend.js +29 -19
- package/dist/server/api.js +2 -0
- package/dist/types/pipeline.d.ts +6 -0
- package/package.json +8 -7
- package/scripts/build-tree-sitter-proto.cjs +82 -0
- package/vendor/node_modules/node-addon-api/node_addon_api.Makefile +6 -0
- package/vendor/node_modules/node-addon-api/node_addon_api.target.mk +104 -0
- package/vendor/node_modules/node-addon-api/node_addon_api_except.target.mk +108 -0
- package/vendor/node_modules/node-addon-api/node_addon_api_except_all.target.mk +104 -0
- package/vendor/node_modules/node-addon-api/node_addon_api_maybe.target.mk +104 -0
- package/vendor/tree-sitter-proto/package.json +1 -7
- package/dist/core/ingestion/call-sites/extract-language-call-site.d.ts +0 -10
- package/dist/core/ingestion/call-sites/extract-language-call-site.js +0 -22
- package/dist/core/ingestion/call-sites/java.d.ts +0 -9
- package/dist/core/ingestion/call-sites/java.js +0 -30
- package/dist/core/ingestion/import-resolvers/dart.d.ts +0 -7
- package/dist/core/ingestion/import-resolvers/swift.d.ts +0 -7
- package/dist/core/ingestion/import-resolvers/vue.d.ts +0 -8
- package/dist/core/ingestion/import-resolvers/vue.js +0 -9
- package/scripts/preinstall-cleanup.cjs +0 -34
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// gitnexus/src/core/ingestion/variable-extractors/configs/ruby.ts
|
|
2
|
+
import { SupportedLanguages } from '../../../../_shared/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Ruby variable extraction config.
|
|
5
|
+
*
|
|
6
|
+
* Ruby module-level constants use UPPER_CASE identifiers or start with
|
|
7
|
+
* an uppercase letter. Ruby uses:
|
|
8
|
+
* - assignment for variable declarations at module scope
|
|
9
|
+
* - Constants: `MAX_SIZE = 100` or `Config = ...`
|
|
10
|
+
* - Global variables: `$global = ...`
|
|
11
|
+
*/
|
|
12
|
+
export const rubyVariableConfig = {
|
|
13
|
+
language: SupportedLanguages.Ruby,
|
|
14
|
+
constNodeTypes: [],
|
|
15
|
+
staticNodeTypes: [],
|
|
16
|
+
variableNodeTypes: ['assignment'],
|
|
17
|
+
extractName(node) {
|
|
18
|
+
const left = node.childForFieldName('left');
|
|
19
|
+
if (!left)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (left.type === 'identifier' || left.type === 'constant')
|
|
22
|
+
return left.text;
|
|
23
|
+
if (left.type === 'global_variable')
|
|
24
|
+
return left.text;
|
|
25
|
+
return undefined;
|
|
26
|
+
},
|
|
27
|
+
extractType(_node) {
|
|
28
|
+
// Ruby is dynamically typed — no type annotations at module level
|
|
29
|
+
return undefined;
|
|
30
|
+
},
|
|
31
|
+
extractVisibility(_node) {
|
|
32
|
+
const left = _node.childForFieldName('left');
|
|
33
|
+
if (!left)
|
|
34
|
+
return 'public';
|
|
35
|
+
// Constants (uppercase start) and global variables are effectively public
|
|
36
|
+
if (left.type === 'constant' || left.type === 'global_variable')
|
|
37
|
+
return 'public';
|
|
38
|
+
return 'private';
|
|
39
|
+
},
|
|
40
|
+
isConst(node) {
|
|
41
|
+
const left = node.childForFieldName('left');
|
|
42
|
+
return left?.type === 'constant';
|
|
43
|
+
},
|
|
44
|
+
isStatic(_node) {
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
isMutable(node) {
|
|
48
|
+
const left = node.childForFieldName('left');
|
|
49
|
+
// Constants are immutable by convention
|
|
50
|
+
return left?.type !== 'constant';
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// gitnexus/src/core/ingestion/variable-extractors/configs/rust.ts
|
|
2
|
+
import { SupportedLanguages } from '../../../../_shared/index.js';
|
|
3
|
+
import { extractSimpleTypeName } from '../../type-extractors/shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* Rust variable extraction config.
|
|
6
|
+
*
|
|
7
|
+
* Rust has module-scoped const, static, and let declarations:
|
|
8
|
+
* - `const MAX_SIZE: usize = 100;`
|
|
9
|
+
* - `static COUNTER: AtomicUsize = AtomicUsize::new(0);`
|
|
10
|
+
* - `static mut BUFFER: Vec<u8> = Vec::new();`
|
|
11
|
+
* - `let x = 5;` (block-scoped, but included for completeness)
|
|
12
|
+
*
|
|
13
|
+
* tree-sitter-rust uses:
|
|
14
|
+
* - const_item → identifier, type
|
|
15
|
+
* - static_item → identifier, type
|
|
16
|
+
* - let_declaration → identifier, type
|
|
17
|
+
*/
|
|
18
|
+
function hasVisibilityModifier(node) {
|
|
19
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
20
|
+
const child = node.namedChild(i);
|
|
21
|
+
if (child?.type === 'visibility_modifier')
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
function hasMutKeyword(node) {
|
|
27
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
28
|
+
const child = node.child(i);
|
|
29
|
+
if (child?.text === 'mut')
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
export const rustVariableConfig = {
|
|
35
|
+
language: SupportedLanguages.Rust,
|
|
36
|
+
constNodeTypes: ['const_item'],
|
|
37
|
+
staticNodeTypes: ['static_item'],
|
|
38
|
+
variableNodeTypes: ['let_declaration'],
|
|
39
|
+
extractName(node) {
|
|
40
|
+
const name = node.childForFieldName('name');
|
|
41
|
+
if (name)
|
|
42
|
+
return name.text;
|
|
43
|
+
// Fallback: first identifier child
|
|
44
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
45
|
+
const child = node.namedChild(i);
|
|
46
|
+
if (child?.type === 'identifier')
|
|
47
|
+
return child.text;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
},
|
|
51
|
+
extractType(node) {
|
|
52
|
+
const typeNode = node.childForFieldName('type');
|
|
53
|
+
if (typeNode)
|
|
54
|
+
return extractSimpleTypeName(typeNode) ?? typeNode.text?.trim();
|
|
55
|
+
return undefined;
|
|
56
|
+
},
|
|
57
|
+
extractVisibility(node) {
|
|
58
|
+
return hasVisibilityModifier(node) ? 'public' : 'private';
|
|
59
|
+
},
|
|
60
|
+
isConst(node) {
|
|
61
|
+
return node.type === 'const_item';
|
|
62
|
+
},
|
|
63
|
+
isStatic(node) {
|
|
64
|
+
return node.type === 'static_item';
|
|
65
|
+
},
|
|
66
|
+
isMutable(node) {
|
|
67
|
+
if (node.type === 'const_item')
|
|
68
|
+
return false;
|
|
69
|
+
if (node.type === 'static_item')
|
|
70
|
+
return hasMutKeyword(node);
|
|
71
|
+
// let_declaration: check for mut keyword
|
|
72
|
+
if (node.type === 'let_declaration')
|
|
73
|
+
return hasMutKeyword(node);
|
|
74
|
+
return true;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// gitnexus/src/core/ingestion/variable-extractors/configs/swift.ts
|
|
2
|
+
import { SupportedLanguages } from '../../../../_shared/index.js';
|
|
3
|
+
import { extractSimpleTypeName } from '../../type-extractors/shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* Swift variable extraction config.
|
|
6
|
+
*
|
|
7
|
+
* Swift has top-level let/var declarations:
|
|
8
|
+
* - `let maxSize = 100`
|
|
9
|
+
* - `var counter = 0`
|
|
10
|
+
* - `public let apiKey: String = "..."`
|
|
11
|
+
*
|
|
12
|
+
* tree-sitter-swift uses:
|
|
13
|
+
* - property_declaration for both class and top-level declarations
|
|
14
|
+
*/
|
|
15
|
+
function extractSwiftVarName(node) {
|
|
16
|
+
// property_declaration → pattern → ... → simple_identifier / identifier
|
|
17
|
+
const pattern = node.namedChildren.find((c) => c.type === 'pattern');
|
|
18
|
+
if (pattern) {
|
|
19
|
+
const ident = pattern.namedChildren.find((c) => c.type === 'simple_identifier' || c.type === 'identifier');
|
|
20
|
+
if (ident)
|
|
21
|
+
return ident.text;
|
|
22
|
+
}
|
|
23
|
+
// Fallback: look for simple_identifier directly
|
|
24
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
25
|
+
const child = node.namedChild(i);
|
|
26
|
+
if (child?.type === 'simple_identifier')
|
|
27
|
+
return child.text;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function extractSwiftVarType(node) {
|
|
32
|
+
// Look for type_annotation child
|
|
33
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
34
|
+
const child = node.namedChild(i);
|
|
35
|
+
if (child?.type === 'type_annotation') {
|
|
36
|
+
const typeNode = child.firstNamedChild;
|
|
37
|
+
if (typeNode)
|
|
38
|
+
return extractSimpleTypeName(typeNode) ?? typeNode.text?.trim();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
function hasSwiftKeyword(node, keyword) {
|
|
44
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
45
|
+
const child = node.child(i);
|
|
46
|
+
if (child?.text === keyword)
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const SWIFT_VISIBILITY = new Set(['public', 'private', 'internal', 'fileprivate', 'open']);
|
|
52
|
+
export const swiftVariableConfig = {
|
|
53
|
+
language: SupportedLanguages.Swift,
|
|
54
|
+
constNodeTypes: [],
|
|
55
|
+
staticNodeTypes: [],
|
|
56
|
+
variableNodeTypes: ['property_declaration'],
|
|
57
|
+
extractName: extractSwiftVarName,
|
|
58
|
+
extractType: extractSwiftVarType,
|
|
59
|
+
extractVisibility(node) {
|
|
60
|
+
// Check modifiers for visibility keywords
|
|
61
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
62
|
+
const child = node.namedChild(i);
|
|
63
|
+
if (child?.type === 'modifiers') {
|
|
64
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
65
|
+
const mod = child.child(j);
|
|
66
|
+
if (mod && SWIFT_VISIBILITY.has(mod.text))
|
|
67
|
+
return mod.text;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Direct keyword check
|
|
72
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
73
|
+
const child = node.child(i);
|
|
74
|
+
if (child && SWIFT_VISIBILITY.has(child.text))
|
|
75
|
+
return child.text;
|
|
76
|
+
}
|
|
77
|
+
return 'internal'; // Swift default visibility
|
|
78
|
+
},
|
|
79
|
+
isConst(node) {
|
|
80
|
+
return hasSwiftKeyword(node, 'let');
|
|
81
|
+
},
|
|
82
|
+
isStatic(node) {
|
|
83
|
+
return hasSwiftKeyword(node, 'static') || hasSwiftKeyword(node, 'class');
|
|
84
|
+
},
|
|
85
|
+
isMutable(node) {
|
|
86
|
+
return hasSwiftKeyword(node, 'var');
|
|
87
|
+
},
|
|
88
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// gitnexus/src/core/ingestion/variable-extractors/configs/typescript-javascript.ts
|
|
2
|
+
import { SupportedLanguages } from '../../../../_shared/index.js';
|
|
3
|
+
import { hasKeyword, typeFromAnnotation } from '../../field-extractors/configs/helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* TypeScript/JavaScript variable extraction config.
|
|
6
|
+
*
|
|
7
|
+
* Handles module-scoped const/let/var declarations:
|
|
8
|
+
* - `export const X = ...` → public, const
|
|
9
|
+
* - `const X = ...` → private, const
|
|
10
|
+
* - `let x = ...` → private, mutable
|
|
11
|
+
* - `var x = ...` → private, mutable
|
|
12
|
+
*
|
|
13
|
+
* tree-sitter node structure:
|
|
14
|
+
* lexical_declaration (const/let) → variable_declarator → identifier (name)
|
|
15
|
+
* variable_declaration (var) → variable_declarator → identifier (name)
|
|
16
|
+
*/
|
|
17
|
+
function extractNameFromDecl(node) {
|
|
18
|
+
// lexical_declaration / variable_declaration → variable_declarator → name
|
|
19
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
20
|
+
const child = node.namedChild(i);
|
|
21
|
+
if (child?.type === 'variable_declarator') {
|
|
22
|
+
const name = child.childForFieldName('name');
|
|
23
|
+
if (name?.type === 'identifier')
|
|
24
|
+
return name.text;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
function extractTypeFromDecl(node) {
|
|
30
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
31
|
+
const child = node.namedChild(i);
|
|
32
|
+
if (child?.type === 'variable_declarator') {
|
|
33
|
+
return typeFromAnnotation(child);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function extractVisFromDecl(node) {
|
|
39
|
+
// Check parent for export_statement wrapper
|
|
40
|
+
const parent = node.parent;
|
|
41
|
+
if (parent?.type === 'export_statement')
|
|
42
|
+
return 'public';
|
|
43
|
+
// Check for 'export' keyword as direct child
|
|
44
|
+
if (hasKeyword(node, 'export'))
|
|
45
|
+
return 'public';
|
|
46
|
+
return 'private';
|
|
47
|
+
}
|
|
48
|
+
const shared = {
|
|
49
|
+
constNodeTypes: ['lexical_declaration'],
|
|
50
|
+
staticNodeTypes: [],
|
|
51
|
+
variableNodeTypes: ['variable_declaration'],
|
|
52
|
+
extractName: extractNameFromDecl,
|
|
53
|
+
extractType: extractTypeFromDecl,
|
|
54
|
+
extractVisibility: extractVisFromDecl,
|
|
55
|
+
isConst(node) {
|
|
56
|
+
// lexical_declaration with 'const' keyword
|
|
57
|
+
if (node.type === 'lexical_declaration') {
|
|
58
|
+
return hasKeyword(node, 'const');
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
isStatic(_node) {
|
|
63
|
+
// JS/TS module-level variables are not static in the class sense
|
|
64
|
+
return false;
|
|
65
|
+
},
|
|
66
|
+
isMutable(node) {
|
|
67
|
+
// var or let declarations are mutable; const is not
|
|
68
|
+
if (node.type === 'variable_declaration')
|
|
69
|
+
return true;
|
|
70
|
+
if (node.type === 'lexical_declaration') {
|
|
71
|
+
return hasKeyword(node, 'let');
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
export const typescriptVariableConfig = {
|
|
77
|
+
...shared,
|
|
78
|
+
language: SupportedLanguages.TypeScript,
|
|
79
|
+
};
|
|
80
|
+
export const javascriptVariableConfig = {
|
|
81
|
+
...shared,
|
|
82
|
+
language: SupportedLanguages.JavaScript,
|
|
83
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// gitnexus/src/core/ingestion/variable-extractors/generic.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a VariableExtractor from a declarative config.
|
|
4
|
+
*/
|
|
5
|
+
export function createVariableExtractor(config) {
|
|
6
|
+
const staticNodeSet = new Set(config.staticNodeTypes);
|
|
7
|
+
// Combined set for fast isVariableDeclaration checks
|
|
8
|
+
const allNodeTypes = new Set([
|
|
9
|
+
...config.constNodeTypes,
|
|
10
|
+
...config.staticNodeTypes,
|
|
11
|
+
...config.variableNodeTypes,
|
|
12
|
+
]);
|
|
13
|
+
function determineScope(node) {
|
|
14
|
+
// Walk up to determine scope:
|
|
15
|
+
// - 'module': node is inside a top-level program/module/source_file container
|
|
16
|
+
// - 'block': node is inside a function, method, or block scope
|
|
17
|
+
// - 'file': fallback when no recognizable container is found (e.g., standalone snippets)
|
|
18
|
+
let current = node.parent;
|
|
19
|
+
while (current) {
|
|
20
|
+
const t = current.type;
|
|
21
|
+
// Top-level program/module nodes indicate module/file scope
|
|
22
|
+
if (t === 'program' ||
|
|
23
|
+
t === 'source_file' ||
|
|
24
|
+
t === 'module' ||
|
|
25
|
+
t === 'translation_unit' ||
|
|
26
|
+
t === 'compilation_unit') {
|
|
27
|
+
return 'module';
|
|
28
|
+
}
|
|
29
|
+
// Function/method/block boundaries indicate block scope
|
|
30
|
+
if (t === 'function_declaration' ||
|
|
31
|
+
t === 'function_definition' ||
|
|
32
|
+
t === 'function_item' ||
|
|
33
|
+
t === 'method_declaration' ||
|
|
34
|
+
t === 'method_definition' ||
|
|
35
|
+
t === 'arrow_function' ||
|
|
36
|
+
t === 'function_expression' ||
|
|
37
|
+
t === 'lambda' ||
|
|
38
|
+
t === 'block' ||
|
|
39
|
+
t === 'function_body' ||
|
|
40
|
+
t === 'compound_statement') {
|
|
41
|
+
return 'block';
|
|
42
|
+
}
|
|
43
|
+
current = current.parent;
|
|
44
|
+
}
|
|
45
|
+
return 'file';
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
language: config.language,
|
|
49
|
+
isVariableDeclaration(node) {
|
|
50
|
+
return allNodeTypes.has(node.type);
|
|
51
|
+
},
|
|
52
|
+
extract(node, context) {
|
|
53
|
+
if (!allNodeTypes.has(node.type))
|
|
54
|
+
return null;
|
|
55
|
+
const name = config.extractName(node);
|
|
56
|
+
if (!name)
|
|
57
|
+
return null;
|
|
58
|
+
const type = config.extractType(node) ?? null;
|
|
59
|
+
const visibility = config.extractVisibility(node);
|
|
60
|
+
// isConst/isStatic: node type membership is a hint, but config.isConst/isStatic
|
|
61
|
+
// has final say. For languages where const and non-const share a node type
|
|
62
|
+
// (e.g., TS lexical_declaration for both const and let), config.isConst disambiguates.
|
|
63
|
+
const isConst = config.isConst(node);
|
|
64
|
+
const isStatic = staticNodeSet.has(node.type) || config.isStatic(node);
|
|
65
|
+
const isMutable = config.isMutable(node);
|
|
66
|
+
const scope = determineScope(node);
|
|
67
|
+
return {
|
|
68
|
+
name,
|
|
69
|
+
type,
|
|
70
|
+
visibility,
|
|
71
|
+
isConst,
|
|
72
|
+
isStatic,
|
|
73
|
+
isMutable,
|
|
74
|
+
scope,
|
|
75
|
+
sourceFile: context.filePath,
|
|
76
|
+
line: node.startPosition.row + 1,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SupportedLanguages } from '../../_shared/index.js';
|
|
2
|
+
import type { FieldVisibility } from './field-types.js';
|
|
3
|
+
import type { SyntaxNode } from './utils/ast-helpers.js';
|
|
4
|
+
export type VariableVisibility = FieldVisibility;
|
|
5
|
+
/**
|
|
6
|
+
* Scope level for a variable declaration.
|
|
7
|
+
* - 'module': module/package scope (TypeScript `export const`, Go package-level)
|
|
8
|
+
* - 'file': file scope (C/C++ static file-scope, Python module-level)
|
|
9
|
+
* - 'block': block-scoped (JS `let`/`const` inside a function)
|
|
10
|
+
*/
|
|
11
|
+
export type VariableScope = 'module' | 'file' | 'block';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a module/file-scoped variable, constant, or static declaration.
|
|
14
|
+
*/
|
|
15
|
+
export interface VariableInfo {
|
|
16
|
+
/** Variable name */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Declared type annotation (may be null if untyped) */
|
|
19
|
+
type: string | null;
|
|
20
|
+
/** Visibility modifier */
|
|
21
|
+
visibility: VariableVisibility;
|
|
22
|
+
/** Is this a constant (const, val, final)? */
|
|
23
|
+
isConst: boolean;
|
|
24
|
+
/** Is this a static declaration? */
|
|
25
|
+
isStatic: boolean;
|
|
26
|
+
/** Is this mutable (let, var vs const, val)? */
|
|
27
|
+
isMutable: boolean;
|
|
28
|
+
/** Scope of the declaration */
|
|
29
|
+
scope: VariableScope;
|
|
30
|
+
/** Source file path */
|
|
31
|
+
sourceFile: string;
|
|
32
|
+
/** Line number (1-based) */
|
|
33
|
+
line: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Context for variable extraction.
|
|
37
|
+
*/
|
|
38
|
+
export interface VariableExtractorContext {
|
|
39
|
+
/** Current file path */
|
|
40
|
+
filePath: string;
|
|
41
|
+
/** Language ID */
|
|
42
|
+
language: SupportedLanguages;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Variable extractor interface — extracts structured metadata from
|
|
46
|
+
* module/file-scoped variable, constant, and static declarations.
|
|
47
|
+
*/
|
|
48
|
+
export interface VariableExtractor {
|
|
49
|
+
/** Language this extractor handles */
|
|
50
|
+
language: SupportedLanguages;
|
|
51
|
+
/** Extract variable metadata from a declaration node.
|
|
52
|
+
* Returns null if the node is not a recognized variable declaration. */
|
|
53
|
+
extract(node: SyntaxNode, context: VariableExtractorContext): VariableInfo | null;
|
|
54
|
+
/** Check if a node is a recognized variable declaration type. */
|
|
55
|
+
isVariableDeclaration(node: SyntaxNode): boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Declarative config for building a variable extractor via the factory.
|
|
59
|
+
* Follows the same pattern as FieldExtractionConfig and MethodExtractionConfig.
|
|
60
|
+
*/
|
|
61
|
+
export interface VariableExtractionConfig {
|
|
62
|
+
/** Language this config applies to */
|
|
63
|
+
language: SupportedLanguages;
|
|
64
|
+
/** AST node types for const declarations (e.g., 'const_item', 'lexical_declaration') */
|
|
65
|
+
constNodeTypes: string[];
|
|
66
|
+
/** AST node types for static declarations (e.g., 'static_item') */
|
|
67
|
+
staticNodeTypes: string[];
|
|
68
|
+
/** AST node types for variable declarations (e.g., 'variable_declaration') */
|
|
69
|
+
variableNodeTypes: string[];
|
|
70
|
+
/** Extract the variable name from a declaration node */
|
|
71
|
+
extractName: (node: SyntaxNode) => string | undefined;
|
|
72
|
+
/** Extract type annotation from a declaration node */
|
|
73
|
+
extractType: (node: SyntaxNode) => string | undefined;
|
|
74
|
+
/** Extract visibility from a declaration node */
|
|
75
|
+
extractVisibility: (node: SyntaxNode) => VariableVisibility;
|
|
76
|
+
/** Check if a declaration is const/immutable */
|
|
77
|
+
isConst: (node: SyntaxNode) => boolean;
|
|
78
|
+
/** Check if a declaration is static */
|
|
79
|
+
isStatic: (node: SyntaxNode) => boolean;
|
|
80
|
+
/** Check if a declaration is mutable */
|
|
81
|
+
isMutable: (node: SyntaxNode) => boolean;
|
|
82
|
+
}
|