@fabersep/atlas 0.0.0-stage → 0.1.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.
Files changed (143) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +202 -0
  3. package/README.md +139 -2
  4. package/dist/packs/csharp/calls.d.ts +4 -0
  5. package/dist/packs/csharp/calls.js +167 -0
  6. package/dist/packs/csharp/declarations.d.ts +4 -0
  7. package/dist/packs/csharp/declarations.js +142 -0
  8. package/dist/packs/csharp/pack.d.ts +2 -0
  9. package/dist/packs/csharp/pack.js +39 -0
  10. package/dist/packs/csharp/resolve.d.ts +2 -0
  11. package/dist/packs/csharp/resolve.js +35 -0
  12. package/dist/packs/csharp/signals.d.ts +7 -0
  13. package/dist/packs/csharp/signals.js +143 -0
  14. package/dist/packs/dart/calls.d.ts +4 -0
  15. package/dist/packs/dart/calls.js +130 -0
  16. package/dist/packs/dart/declarations.d.ts +11 -0
  17. package/dist/packs/dart/declarations.js +79 -0
  18. package/dist/packs/dart/members.d.ts +4 -0
  19. package/dist/packs/dart/members.js +62 -0
  20. package/dist/packs/dart/pack.d.ts +2 -0
  21. package/dist/packs/dart/pack.js +37 -0
  22. package/dist/packs/dart/resolve.d.ts +2 -0
  23. package/dist/packs/dart/resolve.js +32 -0
  24. package/dist/packs/index.d.ts +3 -0
  25. package/dist/packs/index.js +8 -0
  26. package/dist/packs/json/pack.d.ts +2 -0
  27. package/dist/packs/json/pack.js +27 -0
  28. package/dist/packs/msbuild/pack.d.ts +2 -0
  29. package/dist/packs/msbuild/pack.js +75 -0
  30. package/dist/packs/msbuild/xml.d.ts +16 -0
  31. package/dist/packs/msbuild/xml.js +123 -0
  32. package/dist/packs/typescript/calls.d.ts +4 -0
  33. package/dist/packs/typescript/calls.js +201 -0
  34. package/dist/packs/typescript/declarations.d.ts +9 -0
  35. package/dist/packs/typescript/declarations.js +74 -0
  36. package/dist/packs/typescript/members.d.ts +4 -0
  37. package/dist/packs/typescript/members.js +92 -0
  38. package/dist/packs/typescript/pack.d.ts +2 -0
  39. package/dist/packs/typescript/pack.js +53 -0
  40. package/dist/packs/typescript/resolve.d.ts +2 -0
  41. package/dist/packs/typescript/resolve.js +68 -0
  42. package/dist/packs/typescript/signals.d.ts +7 -0
  43. package/dist/packs/typescript/signals.js +186 -0
  44. package/dist/packs/yaml/pack.d.ts +2 -0
  45. package/dist/packs/yaml/pack.js +35 -0
  46. package/dist/src/cli.d.ts +2 -0
  47. package/dist/src/cli.js +371 -0
  48. package/dist/src/graph/build.d.ts +17 -0
  49. package/dist/src/graph/build.js +41 -0
  50. package/dist/src/graph/metrics.d.ts +12 -0
  51. package/dist/src/graph/metrics.js +75 -0
  52. package/dist/src/graph/topology.d.ts +5 -0
  53. package/dist/src/graph/topology.js +54 -0
  54. package/dist/src/health/compare.d.ts +2 -0
  55. package/dist/src/health/compare.js +38 -0
  56. package/dist/src/health/duplicates.d.ts +11 -0
  57. package/dist/src/health/duplicates.js +66 -0
  58. package/dist/src/health/health.d.ts +12 -0
  59. package/dist/src/health/health.js +94 -0
  60. package/dist/src/health/types.d.ts +101 -0
  61. package/dist/src/health/types.js +5 -0
  62. package/dist/src/index.d.ts +23 -0
  63. package/dist/src/index.js +20 -0
  64. package/dist/src/init/init.d.ts +73 -0
  65. package/dist/src/init/init.js +305 -0
  66. package/dist/src/init/scout.d.ts +45 -0
  67. package/dist/src/init/scout.js +208 -0
  68. package/dist/src/jsonc.d.ts +5 -0
  69. package/dist/src/jsonc.js +34 -0
  70. package/dist/src/mcp/server.d.ts +266 -0
  71. package/dist/src/mcp/server.js +414 -0
  72. package/dist/src/metrics/doctor.d.ts +15 -0
  73. package/dist/src/metrics/doctor.js +125 -0
  74. package/dist/src/metrics/log.d.ts +43 -0
  75. package/dist/src/metrics/log.js +101 -0
  76. package/dist/src/metrics/stats.d.ts +43 -0
  77. package/dist/src/metrics/stats.js +172 -0
  78. package/dist/src/model.d.ts +178 -0
  79. package/dist/src/model.js +2 -0
  80. package/dist/src/outputs.d.ts +16 -0
  81. package/dist/src/outputs.js +48 -0
  82. package/dist/src/packs/calls.d.ts +9 -0
  83. package/dist/src/packs/calls.js +119 -0
  84. package/dist/src/packs/dataShape.d.ts +6 -0
  85. package/dist/src/packs/dataShape.js +54 -0
  86. package/dist/src/packs/pack.d.ts +51 -0
  87. package/dist/src/packs/pack.js +3 -0
  88. package/dist/src/packs/packFiles.d.ts +5 -0
  89. package/dist/src/packs/packFiles.js +12 -0
  90. package/dist/src/packs/symbols.d.ts +39 -0
  91. package/dist/src/packs/symbols.js +98 -0
  92. package/dist/src/packs/treeSitter.d.ts +8 -0
  93. package/dist/src/packs/treeSitter.js +107 -0
  94. package/dist/src/queries/flow.d.ts +42 -0
  95. package/dist/src/queries/flow.js +391 -0
  96. package/dist/src/queries/map.d.ts +28 -0
  97. package/dist/src/queries/map.js +102 -0
  98. package/dist/src/queries/neighborhood.d.ts +35 -0
  99. package/dist/src/queries/neighborhood.js +60 -0
  100. package/dist/src/scan/audit.d.ts +2 -0
  101. package/dist/src/scan/audit.js +41 -0
  102. package/dist/src/scan/records.d.ts +12 -0
  103. package/dist/src/scan/records.js +42 -0
  104. package/dist/src/scan/resolveImports.d.ts +3 -0
  105. package/dist/src/scan/resolveImports.js +47 -0
  106. package/dist/src/scan/roles.d.ts +5 -0
  107. package/dist/src/scan/roles.js +87 -0
  108. package/dist/src/scan/scan.d.ts +24 -0
  109. package/dist/src/scan/scan.js +72 -0
  110. package/dist/src/text/briefs.d.ts +13 -0
  111. package/dist/src/text/briefs.js +43 -0
  112. package/dist/src/text/collapse.d.ts +10 -0
  113. package/dist/src/text/collapse.js +58 -0
  114. package/dist/src/text/declarations.d.ts +12 -0
  115. package/dist/src/text/declarations.js +120 -0
  116. package/dist/src/text/structure.d.ts +2 -0
  117. package/dist/src/text/structure.js +15 -0
  118. package/dist/src/text/tree.d.ts +20 -0
  119. package/dist/src/text/tree.js +49 -0
  120. package/dist/src/tokens.d.ts +4 -0
  121. package/dist/src/tokens.js +9 -0
  122. package/dist/src/version.d.ts +10 -0
  123. package/dist/src/version.js +11 -0
  124. package/dist/src/walk/ignoreRules.d.ts +17 -0
  125. package/dist/src/walk/ignoreRules.js +72 -0
  126. package/dist/src/walk/walk.d.ts +11 -0
  127. package/dist/src/walk/walk.js +29 -0
  128. package/grammars/LICENSE-tree-sitter-dart +20 -0
  129. package/grammars/README.md +11 -0
  130. package/grammars/tree-sitter-dart.wasm +0 -0
  131. package/package.json +68 -4
  132. package/packs/csharp/README.md +9 -0
  133. package/packs/csharp/imports.scm +3 -0
  134. package/packs/csharp/symbols.scm +17 -0
  135. package/packs/dart/imports.scm +5 -0
  136. package/packs/dart/symbols.scm +13 -0
  137. package/packs/msbuild/README.md +11 -0
  138. package/packs/typescript/exports.scm +16 -0
  139. package/packs/typescript/imports.scm +9 -0
  140. package/packs/typescript/symbols.scm +19 -0
  141. package/schema/ast_code_map.schema.json +144 -0
  142. package/schema/schema-lock.json +7 -0
  143. package/schema/topology.schema.json +87 -0
@@ -0,0 +1,142 @@
1
+ import { oneLine } from '../../src/tokens.js';
2
+ import { childOfType, declared, hasToken } from '../../src/packs/symbols.js';
3
+ /** C# declarations: types (top level or nested in a type) and their members, with modifiers and types. */
4
+ const TYPE_KINDS = {
5
+ class_declaration: 'class', struct_declaration: 'class', record_declaration: 'class',
6
+ interface_declaration: 'interface', enum_declaration: 'enum',
7
+ };
8
+ const CALLABLE_KINDS = {
9
+ method_declaration: 'method', operator_declaration: 'method', conversion_operator_declaration: 'method',
10
+ destructor_declaration: 'method', indexer_declaration: 'method', constructor_declaration: 'constructor',
11
+ };
12
+ /** Where a callable's signature ends. */
13
+ const CALLABLE_BODIES = new Set(['block', 'arrow_expression_clause', 'accessor_list']);
14
+ const LEADING = new Set(['attribute_list', 'comment']);
15
+ /** Members of an interface or enum are public without a modifier; those of a class, struct or record are private. */
16
+ const PUBLIC_BY_DEFAULT = new Set(['interface_declaration', 'enum_declaration']);
17
+ /** `IOrderService` in a base list names an interface, by the .NET naming convention. */
18
+ const INTERFACE_NAME = /^I[A-Z]/;
19
+ const modifiers = (node) => node.children.filter((c) => c?.type === 'modifier').map((c) => c.text);
20
+ /** The text from the first real token (attributes and comments skipped) to `stop`, on one line, without a trailing `{`, `;`, `=>` or `=`. */
21
+ function header(source, node, stop) {
22
+ const first = node.children.find((c) => !!c && !LEADING.has(c.type)) ?? node;
23
+ return oneLine(source.slice(first.startIndex, stop ? stop.startIndex : node.endIndex)).replace(/\s*(\{|;|=>|=)$/, '');
24
+ }
25
+ /** protected (any combination) and private as written; public and internal are visible to other files of the project. */
26
+ function visibilityOf(mods, fallback) {
27
+ if (mods.includes('protected'))
28
+ return 'protected';
29
+ if (mods.includes('private'))
30
+ return 'private';
31
+ if (mods.includes('public') || mods.includes('internal'))
32
+ return 'public';
33
+ return fallback;
34
+ }
35
+ /** The type a member declaration sits in, or undefined for a top-level type. */
36
+ function ownerOf(node) {
37
+ const owner = node.parent?.parent;
38
+ return owner && (owner.type in TYPE_KINDS) ? owner : undefined;
39
+ }
40
+ function access(node) {
41
+ const mods = modifiers(node);
42
+ const owner = ownerOf(node);
43
+ const visibility = visibilityOf(mods, !owner || PUBLIC_BY_DEFAULT.has(owner.type) ? 'public' : 'private');
44
+ return { visibility, exported: visibility !== 'private', ...(mods.includes('static') ? { static: true } : {}) };
45
+ }
46
+ /** The last part of a base type's name, without type arguments or a namespace. */
47
+ const simpleName = (ref) => ref.replace(/[<(].*$/s, '').split('.').pop().trim();
48
+ /** A base list splits into extends and implements: interfaces extend interfaces, structs only implement. */
49
+ function heritage(node) {
50
+ const list = childOfType(node, 'base_list');
51
+ if (!list)
52
+ return {};
53
+ const bases = list.namedChildren.filter((c) => !!c).map((c) => oneLine(c.type === 'primary_constructor_base_type' ? c.text.replace(/\(.*$/s, '') : c.text));
54
+ const isStruct = node.type === 'struct_declaration' || hasToken(node, 'struct');
55
+ const isInterface = (ref) => isStruct || INTERFACE_NAME.test(simpleName(ref));
56
+ if (node.type === 'interface_declaration')
57
+ return { extends: bases };
58
+ const ext = bases.filter((b) => !isInterface(b));
59
+ const impl = bases.filter(isInterface);
60
+ return { ...(ext.length ? { extends: ext } : {}), ...(impl.length ? { implements: impl } : {}) };
61
+ }
62
+ function typeDeclaration(node, source) {
63
+ const body = node.childForFieldName('body');
64
+ const name = node.childForFieldName('name')?.text ?? '';
65
+ return declared(node, { kind: TYPE_KINDS[node.type], name, signature: header(source, node, body?.type === ';' ? null : body), ...access(node), ...heritage(node) });
66
+ }
67
+ function delegate(node, source) {
68
+ const type = (node.childForFieldName('returns') ?? node.childForFieldName('type'))?.text;
69
+ return declared(node, { kind: 'type', name: node.childForFieldName('name')?.text ?? '', signature: header(source, node), ...(type ? { type } : {}), ...access(node) });
70
+ }
71
+ function callableName(node) {
72
+ const name = node.childForFieldName('name')?.text ?? '';
73
+ if (node.type === 'destructor_declaration')
74
+ return `~${name}`;
75
+ if (node.type === 'indexer_declaration')
76
+ return 'this[]';
77
+ if (node.type === 'operator_declaration')
78
+ return `operator ${node.childForFieldName('operator')?.text ?? ''}`;
79
+ if (node.type === 'conversion_operator_declaration')
80
+ return `operator ${node.childForFieldName('type')?.text ?? ''}`;
81
+ return name;
82
+ }
83
+ function callable(node, source) {
84
+ const body = node.children.find((c) => !!c && CALLABLE_BODIES.has(c.type));
85
+ const type = node.type === 'constructor_declaration' || node.type === 'destructor_declaration' ? undefined : (node.childForFieldName('returns') ?? node.childForFieldName('type'))?.text;
86
+ return declared(node, { kind: CALLABLE_KINDS[node.type], name: callableName(node), signature: header(source, node, body), ...(type ? { type } : {}), ...access(node) });
87
+ }
88
+ /** `{ get; private set; }` from the accessors, without their bodies; an expression-bodied property is `{ get; }`. */
89
+ function accessors(node) {
90
+ const list = node.childForFieldName('accessors');
91
+ if (!list)
92
+ return '{ get; }';
93
+ const each = list.namedChildren.filter((c) => c?.type === 'accessor_declaration')
94
+ .map((a) => [...modifiers(a), a.childForFieldName('name')?.text ?? ''].join(' '));
95
+ return `{ ${each.map((a) => `${a};`).join(' ')} }`;
96
+ }
97
+ /** A property is a field of the map with its accessors in the signature. */
98
+ function property(node, source) {
99
+ const type = node.childForFieldName('type')?.text;
100
+ const name = node.childForFieldName('name')?.text ?? '';
101
+ const signature = `${header(source, node, node.childForFieldName('name'))} ${name} ${accessors(node)}`;
102
+ return declared(node, { kind: 'field', name, signature, ...(type ? { type } : {}), ...access(node) });
103
+ }
104
+ /** `private readonly int a = 1, b;` gives the fields `a` and `b`, each with the declaration's modifiers and type. */
105
+ function fields(node, source) {
106
+ const variables = childOfType(node, 'variable_declaration');
107
+ if (!variables)
108
+ return [];
109
+ const type = variables.childForFieldName('type');
110
+ const prefix = header(source, node, type ? type.nextSibling : variables).replace(/\s*\{$/, '');
111
+ return variables.namedChildren.filter((c) => c?.type === 'variable_declarator').map((v) => {
112
+ const name = v.childForFieldName('name')?.text ?? childOfType(v, 'identifier')?.text ?? '';
113
+ return declared(v, { kind: 'field', name, signature: `${prefix} ${name}`, ...(type ? { type: type.text } : {}), ...access(node) });
114
+ });
115
+ }
116
+ function enumMember(node) {
117
+ return declared(node, { kind: 'enumMember', name: node.childForFieldName('name')?.text ?? '', signature: oneLine(node.text), exported: true, visibility: 'public' });
118
+ }
119
+ /** A positional record parameter is a public property of the record. */
120
+ function recordParameter(node) {
121
+ const type = node.childForFieldName('type')?.text;
122
+ const name = node.childForFieldName('name')?.text ?? '';
123
+ return declared(node, { kind: 'field', name, signature: oneLine(node.text), ...(type ? { type } : {}), exported: true, visibility: 'public' });
124
+ }
125
+ /** The declarations one captured node gives (a field declaration gives one per variable). */
126
+ export function describe(node, source) {
127
+ if (node.type in TYPE_KINDS)
128
+ return [typeDeclaration(node, source)];
129
+ if (node.type === 'delegate_declaration')
130
+ return [delegate(node, source)];
131
+ if (node.type in CALLABLE_KINDS)
132
+ return [callable(node, source)];
133
+ if (node.type === 'property_declaration' || node.type === 'event_declaration')
134
+ return [property(node, source)];
135
+ if (node.type === 'field_declaration' || node.type === 'event_field_declaration')
136
+ return fields(node, source);
137
+ if (node.type === 'enum_member_declaration')
138
+ return [enumMember(node)];
139
+ if (node.type === 'parameter')
140
+ return [recordParameter(node)];
141
+ return [];
142
+ }
@@ -0,0 +1,2 @@
1
+ import type { LanguagePack } from '../../src/packs/pack.js';
2
+ export declare const csharpPack: LanguagePack;
@@ -0,0 +1,39 @@
1
+ import { nest, withNesting } from '../../src/packs/symbols.js';
2
+ import { query, withTree } from '../../src/packs/treeSitter.js';
3
+ import { readPackFile } from '../../src/packs/packFiles.js';
4
+ import { withCSharpCalls } from './calls.js';
5
+ import { describe } from './declarations.js';
6
+ import { resolveCSharp } from './resolve.js';
7
+ import { csharpAstRoles, withCSharpSignals } from './signals.js';
8
+ /** C# (Tree-sitter grammar `c_sharp`, from the pinned tree-sitter-c-sharp package). */
9
+ const QUERIES = { symbols: readPackFile(import.meta.url, 'symbols.scm'), imports: readPackFile(import.meta.url, 'imports.scm') };
10
+ /** The statements and expressions that open a nesting level (code health, FR-07). */
11
+ const BLOCKS = new Set([
12
+ 'if_statement', 'for_statement', 'foreach_statement', 'while_statement', 'do_statement', 'switch_statement', 'switch_expression',
13
+ 'try_statement', 'using_statement', 'lock_statement',
14
+ ]);
15
+ /** The name a using directive imports: its last name node that is not the alias. */
16
+ const NAME_TYPES = new Set(['identifier', 'qualified_name', 'generic_name', 'alias_qualified_name']);
17
+ function captured(language, key, root) {
18
+ return query(language, `csharp-${key}`, QUERIES[key]).captures(root).map((c) => c.node);
19
+ }
20
+ function imports(language, root) {
21
+ return captured(language, 'imports', root).flatMap((node) => {
22
+ const alias = node.childForFieldName('name');
23
+ const target = node.namedChildren.filter((c) => !!c && NAME_TYPES.has(c.type) && c.id !== alias?.id).pop();
24
+ return target ? [{ specifier: target.text.replace(/\s+/g, ''), line: node.startPosition.row + 1 }] : [];
25
+ });
26
+ }
27
+ export const csharpPack = {
28
+ id: 'csharp',
29
+ claims: (file) => file.endsWith('.cs'),
30
+ parse: ({ content }) => withTree('c_sharp', content, (root, language) => {
31
+ const roles = csharpAstRoles(root);
32
+ return {
33
+ symbols: nest(withCSharpCalls(withCSharpSignals(withNesting(captured(language, 'symbols', root).flatMap((node) => describe(node, content)), root, BLOCKS), root), root)),
34
+ imports: imports(language, root),
35
+ ...(roles.length ? { roles } : {}),
36
+ };
37
+ }),
38
+ resolve: resolveCSharp,
39
+ };
@@ -0,0 +1,2 @@
1
+ import type { Resolution, ResolveInput } from '../../src/packs/pack.js';
2
+ export declare function resolveCSharp({ raw, project }: ResolveInput): Resolution | Resolution[];
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Resolves a `using` to the project's .cs files that declare that namespace (all of them); a namespace no project file
3
+ * declares is a package (`System.Text`, `Serilog`). `using static X.Y.Type;` and `using A = X.Y.Type;` name a type, so
4
+ * the namespace it sits in is tried next.
5
+ */
6
+ /** A namespace declaration at the start of a line (file-scoped or block); nested block namespaces count by their own name. */
7
+ const NAMESPACE = /^[ \t]*namespace[ \t]+([A-Za-z_][\w.]*)/gm;
8
+ const indexes = new WeakMap();
9
+ function namespaceIndex(project) {
10
+ let index = indexes.get(project);
11
+ if (!index) {
12
+ index = new Map();
13
+ for (const file of project.paths().filter((p) => p.endsWith('.cs'))) {
14
+ for (const match of (project.read(file) ?? '').matchAll(NAMESPACE)) {
15
+ const files = index.get(match[1]) ?? [];
16
+ if (!files.includes(file))
17
+ files.push(file);
18
+ index.set(match[1], files);
19
+ }
20
+ }
21
+ indexes.set(project, index);
22
+ }
23
+ return index;
24
+ }
25
+ export function resolveCSharp({ raw, project }) {
26
+ const name = raw.specifier.replace(/^global::/, '').replace(/<.*$/s, '');
27
+ const index = namespaceIndex(project);
28
+ const parent = name.includes('.') ? name.slice(0, name.lastIndexOf('.')) : undefined;
29
+ for (const namespace of parent ? [name, parent] : [name]) {
30
+ const files = index.get(namespace);
31
+ if (files)
32
+ return files.map((target) => ({ kind: 'file', target }));
33
+ }
34
+ return { kind: 'package', package: name };
35
+ }
@@ -0,0 +1,7 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import type { RoleTag } from '../../src/model.js';
3
+ import { type Declared } from '../../src/packs/symbols.js';
4
+ /** Attaches `entrypoints` and `throws` signals to declared C# symbols. */
5
+ export declare function withCSharpSignals(items: Declared[], root: Node): Declared[];
6
+ /** Extracts file-level AST role hints (attributes and framework base types) from a C# tree. */
7
+ export declare function csharpAstRoles(root: Node): RoleTag[];
@@ -0,0 +1,143 @@
1
+ import { FUNCTION_KINDS } from '../../src/packs/symbols.js';
2
+ /** Deterministic AST signals for C#: attribute entrypoints, thrown exceptions, and AST role hints. */
3
+ const HTTP_ATTRIBUTES = {
4
+ HttpGet: 'GET', HttpPost: 'POST', HttpPut: 'PUT', HttpPatch: 'PATCH', HttpDelete: 'DELETE',
5
+ HttpHead: 'HEAD', HttpOptions: 'OPTIONS',
6
+ };
7
+ const AUTH_ATTRIBUTES = new Set(['Authorize', 'AllowAnonymous']);
8
+ const JOB_ATTRIBUTES = new Set(['Function', 'FunctionName', 'QueueTrigger', 'TimerTrigger', 'ServiceBusTrigger']);
9
+ const DB_ATTRIBUTES = new Set(['Table', 'EntityTypeConfiguration']);
10
+ function unquote(text) {
11
+ return text.replace(/^@?"|"$/g, '').trim();
12
+ }
13
+ function parseAttribute(attr) {
14
+ const rawName = attr.childForFieldName('name')?.text;
15
+ if (!rawName)
16
+ return undefined;
17
+ const simple = rawName.split('.').pop().replace(/Attribute$/, '');
18
+ const argsList = attr.children.find((c) => c?.type === 'attribute_argument_list');
19
+ const firstArg = argsList?.namedChildren.find((c) => c?.type === 'attribute_argument');
20
+ const expr = firstArg?.namedChildren[firstArg.namedChildren.length - 1];
21
+ const arg = expr ? unquote(expr.text) : undefined;
22
+ return { name: simple, ...(arg ? { arg } : {}) };
23
+ }
24
+ function attributesOf(node) {
25
+ const out = [];
26
+ for (const c of node.children) {
27
+ if (c?.type !== 'attribute_list')
28
+ continue;
29
+ for (const a of c.namedChildren) {
30
+ if (a?.type === 'attribute') {
31
+ const info = parseAttribute(a);
32
+ if (info)
33
+ out.push(info);
34
+ }
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ function entrypointsFromAttributes(attrs) {
40
+ const out = [];
41
+ for (const a of attrs) {
42
+ if (a.name in HTTP_ATTRIBUTES) {
43
+ const verb = HTTP_ATTRIBUTES[a.name];
44
+ const route = a.arg ? (a.arg.startsWith('/') ? a.arg : `/${a.arg}`) : '/';
45
+ out.push(`${verb} ${route}`);
46
+ }
47
+ else if (a.name === 'Route') {
48
+ out.push(a.arg ? `route:${a.arg}` : 'route:/');
49
+ }
50
+ else if (JOB_ATTRIBUTES.has(a.name)) {
51
+ out.push(a.arg ? `job:${a.arg}` : `job:${a.name}`);
52
+ }
53
+ }
54
+ return [...new Set(out)];
55
+ }
56
+ /** Collects exception names from `throw new X(...)` statements/expressions inside a node's range. */
57
+ function throwsIn(root, start, end) {
58
+ const found = new Set();
59
+ const walk = (node) => {
60
+ if (node.endIndex <= start || node.startIndex >= end)
61
+ return;
62
+ if ((node.type === 'throw_statement' || node.type === 'throw_expression') && node.startIndex >= start && node.endIndex <= end) {
63
+ const expr = node.namedChildren[0];
64
+ if (expr?.type === 'object_creation_expression') {
65
+ const typeNode = expr.childForFieldName('type');
66
+ if (typeNode) {
67
+ const simple = typeNode.text.replace(/<.*$/s, '').split('.').pop().trim();
68
+ if (simple)
69
+ found.add(simple);
70
+ }
71
+ }
72
+ return;
73
+ }
74
+ for (const c of node.children)
75
+ if (c)
76
+ walk(c);
77
+ };
78
+ walk(root);
79
+ return [...found];
80
+ }
81
+ function indexNodesByRange(root) {
82
+ const byRange = new Map();
83
+ const walk = (node) => {
84
+ if (node.type === 'class_declaration' || node.type === 'struct_declaration' ||
85
+ node.type === 'record_declaration' || node.type === 'method_declaration') {
86
+ byRange.set(`${node.startIndex}:${node.endIndex}`, node);
87
+ }
88
+ for (const c of node.children)
89
+ if (c)
90
+ walk(c);
91
+ };
92
+ walk(root);
93
+ return byRange;
94
+ }
95
+ /** Attaches `entrypoints` and `throws` signals to declared C# symbols. */
96
+ export function withCSharpSignals(items, root) {
97
+ const byRange = indexNodesByRange(root);
98
+ return items.map((item) => {
99
+ const astNode = byRange.get(`${item.start}:${item.end}`);
100
+ const entrypoints = astNode ? entrypointsFromAttributes(attributesOf(astNode)) : [];
101
+ const throws = FUNCTION_KINDS.has(item.kind) ? throwsIn(root, item.start, item.end) : [];
102
+ return {
103
+ ...item,
104
+ ...(entrypoints.length ? { entrypoints } : {}),
105
+ ...(throws.length ? { throws } : {}),
106
+ };
107
+ });
108
+ }
109
+ /** Extracts file-level AST role hints (attributes and framework base types) from a C# tree. */
110
+ export function csharpAstRoles(root) {
111
+ const roles = new Set();
112
+ const walk = (node) => {
113
+ if (node.type === 'attribute') {
114
+ const a = parseAttribute(node);
115
+ if (a) {
116
+ if (a.name in HTTP_ATTRIBUTES || a.name === 'Route' || a.name === 'ApiController')
117
+ roles.add('http');
118
+ else if (AUTH_ATTRIBUTES.has(a.name))
119
+ roles.add('auth');
120
+ else if (JOB_ATTRIBUTES.has(a.name))
121
+ roles.add('job');
122
+ else if (DB_ATTRIBUTES.has(a.name))
123
+ roles.add('db');
124
+ }
125
+ }
126
+ else if (node.type === 'base_list') {
127
+ const text = node.text;
128
+ if (/\b(ControllerBase|Controller)\b/.test(text))
129
+ roles.add('http');
130
+ if (/\bDbContext\b/.test(text))
131
+ roles.add('db');
132
+ if (/\b(BackgroundService|IHostedService)\b/.test(text))
133
+ roles.add('job');
134
+ if (/\b(IRequestHandler|INotificationHandler)\b/.test(text))
135
+ roles.add('event');
136
+ }
137
+ for (const c of node.children)
138
+ if (c)
139
+ walk(c);
140
+ };
141
+ walk(root);
142
+ return [...roles];
143
+ }
@@ -0,0 +1,4 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type Declared } from '../../src/packs/symbols.js';
3
+ /** Attaches static `calls` sites to callable Dart declarations. */
4
+ export declare function withDartCalls(items: Declared[], root: Node): Declared[];
@@ -0,0 +1,130 @@
1
+ import { cleanTypeName, dedupeCalls, detectBoundary, isNoiseCall } from '../../src/packs/calls.js';
2
+ import { CONTAINER_KINDS, FUNCTION_KINDS } from '../../src/packs/symbols.js';
3
+ /** Static call extraction for Dart/Flutter. */
4
+ function buildOwnerFieldTypes(items) {
5
+ const containers = items.filter((d) => CONTAINER_KINDS.has(d.kind));
6
+ const result = new Map();
7
+ for (const c of containers) {
8
+ const types = new Map();
9
+ for (const m of items) {
10
+ if (m.start > c.start && m.end <= c.end && (m.kind === 'field' || m.kind === 'getter')) {
11
+ const t = cleanTypeName(m.type);
12
+ if (t)
13
+ types.set(m.name, t);
14
+ }
15
+ }
16
+ result.set(`${c.start}:${c.end}`, types);
17
+ }
18
+ return result;
19
+ }
20
+ function enclosingContainer(item, containers) {
21
+ let best;
22
+ for (const c of containers) {
23
+ if (item.start > c.start && item.end <= c.end) {
24
+ if (!best || c.start > best.start)
25
+ best = c;
26
+ }
27
+ }
28
+ return best;
29
+ }
30
+ function selectorMemberName(selector) {
31
+ for (const c of selector.namedChildren) {
32
+ if (c?.type === 'unconditional_assignable_selector' || c?.type === 'conditional_assignable_selector') {
33
+ const id = c.namedChildren.find((n) => n?.type === 'identifier');
34
+ if (id)
35
+ return id.text;
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ function isCallSelector(selector) {
41
+ return selector.namedChildren.some((c) => c?.type === 'argument_part');
42
+ }
43
+ function extractCallsInRange(root, start, end, ownerName, fieldTypes) {
44
+ const sites = [];
45
+ const walk = (node) => {
46
+ if (node.endIndex <= start || node.startIndex >= end)
47
+ return;
48
+ const children = node.namedChildren.filter((c) => !!c);
49
+ for (let i = 0; i < children.length; i++) {
50
+ const head = children[i];
51
+ if (head.startIndex < start || head.endIndex > end)
52
+ continue;
53
+ if (head.type !== 'identifier' && head.type !== 'this')
54
+ continue;
55
+ // Look ahead for consecutive `selector` siblings
56
+ const chain = [head.text];
57
+ let j = i + 1;
58
+ while (j < children.length && children[j].type === 'selector') {
59
+ const sel = children[j];
60
+ if (isCallSelector(sel)) {
61
+ const line = head.startPosition.row + 1;
62
+ if (chain.length === 1) {
63
+ const method = chain[0];
64
+ if (method !== 'this' && !isNoiseCall(undefined, undefined, method, false)) {
65
+ const boundary = detectBoundary('calls', undefined, undefined, method);
66
+ sites.push({ callee: method, method, line, kind: 'calls', ...(boundary ? { boundary } : {}) });
67
+ }
68
+ }
69
+ else {
70
+ const method = chain[chain.length - 1];
71
+ let receiver;
72
+ let receiverType;
73
+ let isThisMember = false;
74
+ if (chain[0] === 'this' && chain.length === 2) {
75
+ receiver = 'this';
76
+ receiverType = ownerName;
77
+ isThisMember = true;
78
+ }
79
+ else if (chain[0] === 'this' && chain.length >= 3) {
80
+ receiver = chain[1];
81
+ receiverType = fieldTypes.get(receiver);
82
+ isThisMember = true;
83
+ }
84
+ else {
85
+ receiver = chain[chain.length - 2];
86
+ receiverType = fieldTypes.get(receiver);
87
+ isThisMember = receiver.startsWith('_') || receiverType !== undefined;
88
+ }
89
+ if (!isNoiseCall(receiver, receiverType, method, isThisMember)) {
90
+ const boundary = detectBoundary('calls', receiver, receiverType, method);
91
+ sites.push({
92
+ callee: chain.join('.'),
93
+ receiver,
94
+ ...(receiverType ? { receiverType } : {}),
95
+ method,
96
+ line,
97
+ kind: 'calls',
98
+ ...(boundary ? { boundary } : {}),
99
+ });
100
+ }
101
+ }
102
+ break;
103
+ }
104
+ const member = selectorMemberName(sel);
105
+ if (!member)
106
+ break;
107
+ chain.push(member);
108
+ j++;
109
+ }
110
+ }
111
+ for (const c of node.children)
112
+ if (c)
113
+ walk(c);
114
+ };
115
+ walk(root);
116
+ return dedupeCalls(sites);
117
+ }
118
+ /** Attaches static `calls` sites to callable Dart declarations. */
119
+ export function withDartCalls(items, root) {
120
+ const containers = items.filter((d) => CONTAINER_KINDS.has(d.kind));
121
+ const fieldTypeMaps = buildOwnerFieldTypes(items);
122
+ return items.map((item) => {
123
+ if (!FUNCTION_KINDS.has(item.kind))
124
+ return item;
125
+ const owner = enclosingContainer(item, containers);
126
+ const fieldTypes = owner ? (fieldTypeMaps.get(`${owner.start}:${owner.end}`) ?? new Map()) : new Map();
127
+ const calls = extractCallsInRange(root, item.start, item.end, owner?.name, fieldTypes);
128
+ return calls.length ? { ...item, calls } : item;
129
+ });
130
+ }
@@ -0,0 +1,11 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type Declared, type SymbolFields } from '../../src/packs/symbols.js';
3
+ export declare const MODIFIERS: RegExp;
4
+ /** A leading underscore makes a name private; an unnamed extension is private to its library as well. */
5
+ export declare function nameFields(name: string): Pick<SymbolFields, 'name' | 'exported' | 'visibility'>;
6
+ /** The node a declaration's range ends with: its body when the body is the next sibling. */
7
+ export declare function withBody(node: Node): Node;
8
+ /** A function, getter or setter signature: its text is the signature, the text before the name its return type. */
9
+ export declare function signatureFields(sig: Node, source: string): Pick<SymbolFields, 'name' | 'signature' | 'type' | 'exported' | 'visibility'>;
10
+ /** A top-level declaration, or undefined for a node this module does not handle. */
11
+ export declare function describeTopLevel(node: Node, source: string): Declared | undefined;
@@ -0,0 +1,79 @@
1
+ import { oneLine } from '../../src/tokens.js';
2
+ import { childOfType, declared, header, splitList } from '../../src/packs/symbols.js';
3
+ /** Top-level Dart declarations. A leading underscore makes a name private to its library. */
4
+ const MAX_TYPE_ALIAS = 200;
5
+ const CONTAINERS = {
6
+ class_definition: 'class', mixin_declaration: 'mixin', extension_declaration: 'extension', enum_declaration: 'enum',
7
+ };
8
+ /** Tokens that may precede a top-level variable's names: modifiers and the type. */
9
+ const VARIABLE_PREFIX = new Set([
10
+ 'final_builtin', 'const_builtin', 'late', 'var', 'external', 'type_identifier', 'type_arguments', 'nullable_type',
11
+ 'function_type', 'void_type', 'record_type', 'inferred_type', '?',
12
+ ]);
13
+ export const MODIFIERS = /\b(static|final|const|late|var|covariant|external)\s+/g;
14
+ /** A leading underscore makes a name private; an unnamed extension is private to its library as well. */
15
+ export function nameFields(name) {
16
+ const isPrivate = name === '' || name.split('.').pop().startsWith('_');
17
+ return { name, exported: !isPrivate, visibility: isPrivate ? 'private' : 'public' };
18
+ }
19
+ /** The node a declaration's range ends with: its body when the body is the next sibling. */
20
+ export function withBody(node) {
21
+ const next = node.nextSibling;
22
+ return next?.type === 'function_body' ? next : node;
23
+ }
24
+ /** The text after a keyword token inside `node`, split as a list (`with A, B` gives A and B). */
25
+ function listAfter(node, keyword, stop) {
26
+ if (!node)
27
+ return undefined;
28
+ const text = oneLine(stop ? node.text.slice(0, stop.startIndex - node.startIndex) : node.text).replace(new RegExp(`^${keyword}\\s+`), '');
29
+ return text ? splitList(text) : undefined;
30
+ }
31
+ function heritage(node) {
32
+ const superclass = childOfType(node, 'superclass');
33
+ const mixins = childOfType(superclass ?? node, 'mixins');
34
+ const ext = superclass && superclass.children[0]?.type === 'extends' ? listAfter(superclass, 'extends', mixins) : undefined;
35
+ const fields = { extends: ext, mixins: listAfter(mixins, 'with'), implements: listAfter(childOfType(node, 'interfaces'), 'implements') };
36
+ return Object.fromEntries(Object.entries(fields).filter(([, v]) => v?.length));
37
+ }
38
+ function container(node, source) {
39
+ const name = (node.childForFieldName('name') ?? childOfType(node, 'identifier'))?.text ?? '';
40
+ const body = node.childForFieldName('body') ?? childOfType(node, 'class_body', 'extension_body', 'enum_body');
41
+ return declared(node, { kind: CONTAINERS[node.type], signature: header(source, node, body), ...nameFields(name), ...heritage(node) });
42
+ }
43
+ function typeAlias(node) {
44
+ const text = oneLine(node.text).replace(/;$/, '');
45
+ const name = childOfType(node, 'type_identifier')?.text ?? '';
46
+ return declared(node, { kind: 'type', signature: text.length > MAX_TYPE_ALIAS ? `${text.slice(0, MAX_TYPE_ALIAS)}…` : text, ...nameFields(name) });
47
+ }
48
+ /** A function, getter or setter signature: its text is the signature, the text before the name its return type. */
49
+ export function signatureFields(sig, source) {
50
+ const nameNode = sig.childForFieldName('name') ?? childOfType(sig, 'identifier');
51
+ const before = nameNode ? oneLine(source.slice(sig.startIndex, nameNode.startIndex)).replace(/\b(get|set|static|external)\b/g, '').trim() : '';
52
+ return { signature: oneLine(sig.text), ...(before ? { type: before } : {}), ...nameFields(nameNode?.text ?? '') };
53
+ }
54
+ function topLevelFunction(node, source) {
55
+ return declared(node, { kind: 'function', ...signatureFields(node, source) }, withBody(node));
56
+ }
57
+ /** `final int a = 1, b = 2;` at top level: the modifiers and type are the siblings before the name list. */
58
+ function topLevelVariable(node, source) {
59
+ const list = node.parent;
60
+ let first = list;
61
+ while (first.previousSibling && VARIABLE_PREFIX.has(first.previousSibling.type))
62
+ first = first.previousSibling;
63
+ const prefix = first === list ? '' : oneLine(source.slice(first.startIndex, list.startIndex));
64
+ const name = childOfType(node, 'identifier')?.text ?? '';
65
+ const type = prefix.replace(MODIFIERS, '').replace(/^(final|const|late|var)$/, '').trim();
66
+ return declared(node, { kind: 'variable', signature: prefix ? `${prefix} ${name}` : name, ...(type ? { type } : {}), ...nameFields(name) });
67
+ }
68
+ /** A top-level declaration, or undefined for a node this module does not handle. */
69
+ export function describeTopLevel(node, source) {
70
+ if (node.type in CONTAINERS)
71
+ return container(node, source);
72
+ if (node.type === 'type_alias')
73
+ return typeAlias(node);
74
+ if (['function_signature', 'getter_signature', 'setter_signature'].includes(node.type))
75
+ return topLevelFunction(node, source);
76
+ if (node.type === 'static_final_declaration' || node.type === 'initialized_identifier')
77
+ return topLevelVariable(node, source);
78
+ return undefined;
79
+ }
@@ -0,0 +1,4 @@
1
+ import type { Node } from 'web-tree-sitter';
2
+ import { type Declared } from '../../src/packs/symbols.js';
3
+ /** A member declaration (a `declaration` or `method_signature` wrapper, or an enum constant). */
4
+ export declare function describeMember(node: Node, source: string): Declared[];