neuroplex 0.3.0 → 0.5.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 (67) hide show
  1. package/dist/brain/build.js +6 -4
  2. package/dist/brain/build.js.map +1 -1
  3. package/dist/brain/local.d.ts +2 -0
  4. package/dist/brain/local.js.map +1 -1
  5. package/dist/brain/obsidian.js +5 -0
  6. package/dist/brain/obsidian.js.map +1 -1
  7. package/dist/cli/index.js +97 -22
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/config/config.d.ts +24 -0
  10. package/dist/config/config.js +61 -1
  11. package/dist/config/config.js.map +1 -1
  12. package/dist/enrich/tasks.js +2 -0
  13. package/dist/enrich/tasks.js.map +1 -1
  14. package/dist/enrich/write.js +2 -2
  15. package/dist/enrich/write.js.map +1 -1
  16. package/dist/graph/schema.d.ts +3 -1
  17. package/dist/graph/schema.js +3 -0
  18. package/dist/graph/schema.js.map +1 -1
  19. package/dist/mcp/http.js +6 -2
  20. package/dist/mcp/http.js.map +1 -1
  21. package/dist/mcp/server.d.ts +1 -1
  22. package/dist/mcp/server.js +24 -2
  23. package/dist/mcp/server.js.map +1 -1
  24. package/dist/query/cli.d.ts +1 -0
  25. package/dist/query/cli.js +16 -2
  26. package/dist/query/cli.js.map +1 -1
  27. package/dist/query/queries.d.ts +4 -0
  28. package/dist/query/queries.js +5 -3
  29. package/dist/query/queries.js.map +1 -1
  30. package/dist/query/search.js +1 -1
  31. package/dist/query/search.js.map +1 -1
  32. package/dist/query/source.d.ts +36 -0
  33. package/dist/query/source.js +94 -0
  34. package/dist/query/source.js.map +1 -0
  35. package/dist/scan/assemble.d.ts +15 -0
  36. package/dist/scan/assemble.js +243 -15
  37. package/dist/scan/assemble.js.map +1 -1
  38. package/dist/scan/discover.js +3 -0
  39. package/dist/scan/discover.js.map +1 -1
  40. package/dist/scan/docs.d.ts +20 -0
  41. package/dist/scan/docs.js +198 -0
  42. package/dist/scan/docs.js.map +1 -0
  43. package/dist/scan/extract.d.ts +1 -1
  44. package/dist/scan/extract.js +13 -3
  45. package/dist/scan/extract.js.map +1 -1
  46. package/dist/scan/extractors/csharp.d.ts +4 -0
  47. package/dist/scan/extractors/csharp.js +604 -0
  48. package/dist/scan/extractors/csharp.js.map +1 -0
  49. package/dist/scan/extractors/python.js +170 -15
  50. package/dist/scan/extractors/python.js.map +1 -1
  51. package/dist/scan/extractors/typescript.js +405 -23
  52. package/dist/scan/extractors/typescript.js.map +1 -1
  53. package/dist/scan/parser.js +1 -0
  54. package/dist/scan/parser.js.map +1 -1
  55. package/dist/scan/repos.d.ts +38 -0
  56. package/dist/scan/repos.js +155 -0
  57. package/dist/scan/repos.js.map +1 -0
  58. package/dist/scan/scan.d.ts +15 -0
  59. package/dist/scan/scan.js +26 -16
  60. package/dist/scan/scan.js.map +1 -1
  61. package/dist/scan/types.d.ts +40 -1
  62. package/dist/scan/types.js +2 -1
  63. package/dist/scan/types.js.map +1 -1
  64. package/dist/sync/sync.js +37 -16
  65. package/dist/sync/sync.js.map +1 -1
  66. package/package.json +1 -1
  67. package/skills/neuroplex/SKILL.md +10 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../../src/scan/docs.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,CAAC;AAC3B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEhC,mEAAmE;AACnE,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,UAA0B,EAAE,IAAgB;IACrF,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,GAAG;YAAE,UAAU,CAAC,OAAO,GAAG,GAAG,CAAC;QAClC,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,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AAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AACxF,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { type FileExtraction, type LanguageId } from './types.js';
2
- /** Parses one file and extracts its symbols, imports, calls and heritage. */
2
+ /** Parses one file and extracts its symbols, imports, calls, heritage, HTTP data and docs. */
3
3
  export declare function extractSource(source: string, lang: LanguageId): Promise<FileExtraction>;
@@ -1,11 +1,21 @@
1
+ import { attachDocs } from './docs.js';
2
+ import { extractCSharp } from './extractors/csharp.js';
1
3
  import { extractPython } from './extractors/python.js';
2
4
  import { extractTypeScript } from './extractors/typescript.js';
3
5
  import { withTree } from './parser.js';
4
6
  import { emptyExtraction } from './types.js';
5
- /** Parses one file and extracts its symbols, imports, calls and heritage. */
7
+ /** Parses one file and extracts its symbols, imports, calls, heritage, HTTP data and docs. */
6
8
  export async function extractSource(source, lang) {
9
+ // Documents have no symbols; their title, intro and sections become the file's doc.
7
10
  if (lang === 'markdown')
8
- return emptyExtraction(); // documents are file nodes only
9
- return withTree(source, lang, (root) => lang === 'python' ? extractPython(root) : extractTypeScript(root, lang));
11
+ return attachDocs(source, emptyExtraction(), lang);
12
+ const extraction = await withTree(source, lang, (root) => {
13
+ if (lang === 'python')
14
+ return extractPython(root);
15
+ if (lang === 'csharp')
16
+ return extractCSharp(root);
17
+ return extractTypeScript(root, lang);
18
+ });
19
+ return attachDocs(source, extraction, lang);
10
20
  }
11
21
  //# sourceMappingURL=extract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/scan/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAwC,MAAM,YAAY,CAAC;AAEnF,6EAA6E;AAC7E,MAAM,CAAC,K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AAO,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type SyntaxNode } from '../parser.js';
2
+ import { type FileExtraction } from '../types.js';
3
+ /** Extracts symbols, imports, calls, heritage and HTTP routes from a C# tree. */
4
+ export declare function extractCSharp(root: SyntaxNode): FileExtraction;
@@ -0,0 +1,604 @@
1
+ import { lineRange, namedChildren } from '../parser.js';
2
+ import { emptyExtraction } from '../types.js';
3
+ const TYPE_KINDS = new Map([
4
+ ['class_declaration', 'class'],
5
+ ['record_declaration', 'class'],
6
+ ['struct_declaration', 'class'],
7
+ ['interface_declaration', 'interface'],
8
+ ['enum_declaration', 'type'],
9
+ ]);
10
+ /** Members whose parameters and locals form one variable scope; their calls go to the type. */
11
+ const MEMBER_SCOPES = new Set([
12
+ 'constructor_declaration',
13
+ 'destructor_declaration',
14
+ 'property_declaration',
15
+ 'indexer_declaration',
16
+ 'operator_declaration',
17
+ 'conversion_operator_declaration',
18
+ 'event_declaration',
19
+ ]);
20
+ const VERB_ATTRIBUTES = new Map([
21
+ ['HttpGet', 'GET'],
22
+ ['HttpPost', 'POST'],
23
+ ['HttpPut', 'PUT'],
24
+ ['HttpPatch', 'PATCH'],
25
+ ['HttpDelete', 'DELETE'],
26
+ ['HttpHead', 'HEAD'],
27
+ ['HttpOptions', 'OPTIONS'],
28
+ ]);
29
+ const MINIMAL_API = new Map([
30
+ ['MapGet', 'GET'],
31
+ ['MapPost', 'POST'],
32
+ ['MapPut', 'PUT'],
33
+ ['MapPatch', 'PATCH'],
34
+ ['MapDelete', 'DELETE'],
35
+ ['MapMethods', 'ANY'],
36
+ ]);
37
+ const CLIENT_METHODS = new Map([
38
+ ['GetAsync', 'GET'],
39
+ ['GetFromJsonAsync', 'GET'],
40
+ ['GetStringAsync', 'GET'],
41
+ ['GetStreamAsync', 'GET'],
42
+ ['GetByteArrayAsync', 'GET'],
43
+ ['PostAsync', 'POST'],
44
+ ['PostAsJsonAsync', 'POST'],
45
+ ['PutAsync', 'PUT'],
46
+ ['PutAsJsonAsync', 'PUT'],
47
+ ['PatchAsync', 'PATCH'],
48
+ ['PatchAsJsonAsync', 'PATCH'],
49
+ ['DeleteAsync', 'DELETE'],
50
+ ['DeleteFromJsonAsync', 'DELETE'],
51
+ ]);
52
+ const HANDLER_TYPES = new Set(['lambda_expression', 'anonymous_method_expression', 'identifier', 'member_access_expression']);
53
+ const STRING_TYPES = new Set([
54
+ 'string_literal',
55
+ 'verbatim_string_literal',
56
+ 'raw_string_literal',
57
+ 'interpolated_string_expression',
58
+ ]);
59
+ /** Parents that continue a method chain (`app.MapGet(...).WithName(...)`, `await x.Y()`). */
60
+ const CHAIN_PARENTS = new Set([
61
+ 'invocation_expression',
62
+ 'member_access_expression',
63
+ 'await_expression',
64
+ 'parenthesized_expression',
65
+ ]);
66
+ const INTERFACE_NAME = /^I[A-Z]/;
67
+ /** Extracts symbols, imports, calls, heritage and HTTP routes from a C# tree. */
68
+ export function extractCSharp(root) {
69
+ return new CSharpExtractor().run(root);
70
+ }
71
+ class CSharpExtractor {
72
+ out = emptyExtraction();
73
+ names = new Set();
74
+ seenCalls = new Set();
75
+ /** `var api = app.MapGroup("/api")` → `api` → `/api`. */
76
+ groups = new Map();
77
+ run(root) {
78
+ this.walk(root, {
79
+ owner: undefined,
80
+ type: undefined,
81
+ typeExported: false,
82
+ inInterface: false,
83
+ controller: undefined,
84
+ scopes: [],
85
+ });
86
+ return this.out;
87
+ }
88
+ walk(node, ctx) {
89
+ switch (node.type) {
90
+ case 'ERROR':
91
+ case 'attribute_list':
92
+ return;
93
+ case 'using_directive':
94
+ this.addUsing(node);
95
+ return;
96
+ case 'method_declaration':
97
+ this.visitMethod(node, ctx);
98
+ return;
99
+ case 'field_declaration':
100
+ this.visitConstants(node, ctx);
101
+ break;
102
+ case 'invocation_expression':
103
+ this.visitInvocation(node, ctx);
104
+ return;
105
+ case 'object_creation_expression':
106
+ this.visitCreation(node, ctx);
107
+ break;
108
+ case 'variable_declarator':
109
+ this.trackGroup(node);
110
+ break;
111
+ default:
112
+ if (TYPE_KINDS.has(node.type)) {
113
+ this.visitType(node, ctx);
114
+ return;
115
+ }
116
+ if (MEMBER_SCOPES.has(node.type))
117
+ ctx = withScope(ctx, memberScope(node));
118
+ }
119
+ this.walkChildren(node, ctx);
120
+ }
121
+ walkChildren(node, ctx) {
122
+ for (const child of namedChildren(node))
123
+ this.walk(child, ctx);
124
+ }
125
+ // ---- symbols ----
126
+ visitType(node, ctx) {
127
+ const id = node.childForFieldName('name')?.text;
128
+ const kind = TYPE_KINDS.get(node.type);
129
+ if (!id || !kind) {
130
+ this.walkChildren(node, ctx);
131
+ return;
132
+ }
133
+ const name = ctx.type ? `${ctx.type}.${id}` : id;
134
+ // Top-level types default to `internal`; nested ones to `private` (public inside interfaces).
135
+ const exported = ctx.type
136
+ ? ctx.typeExported && isAccessible(node, ctx.inInterface)
137
+ : isAccessible(node, true);
138
+ this.addSymbol(name, kind, node, exported);
139
+ this.addHeritage(name, node);
140
+ const prefix = attributes(node).find((a) => a.name === 'Route' || a.name === 'RoutePrefix')?.template;
141
+ this.walkChildren(node, {
142
+ owner: name,
143
+ type: name,
144
+ typeExported: exported,
145
+ inInterface: node.type === 'interface_declaration',
146
+ controller: { name: id.replace(/Controller$/, ''), prefix: prefix ?? '' },
147
+ scopes: [{ member: false, types: typeScope(node) }, ...ctx.scopes],
148
+ });
149
+ }
150
+ visitMethod(node, ctx) {
151
+ const id = node.childForFieldName('name')?.text;
152
+ if (!id || !ctx.type) {
153
+ this.walkChildren(node, ctx);
154
+ return;
155
+ }
156
+ const name = `${ctx.type}.${id}`;
157
+ const exported = ctx.typeExported && isAccessible(node, ctx.inInterface);
158
+ const http = ctx.controller ? actionRoute(node, id, ctx.controller) : undefined;
159
+ this.addSymbol(name, http ? 'route' : 'method', node, exported, http);
160
+ this.walkChildren(node, { ...withScope(ctx, memberScope(node)), owner: name });
161
+ }
162
+ /**
163
+ * Public constants (`const`, or `static readonly` with a literal value) become
164
+ * `variable` symbols whose doc carries the value, so catalogs such as
165
+ * permission codes, route names or settings keys are searchable.
166
+ */
167
+ visitConstants(node, ctx) {
168
+ if (!ctx.type)
169
+ return;
170
+ const modifiers = namedChildren(node)
171
+ .filter((c) => c.type === 'modifier')
172
+ .map((c) => c.text);
173
+ const constant = modifiers.includes('const') || (modifiers.includes('static') && modifiers.includes('readonly'));
174
+ if (!constant || !(ctx.typeExported && isAccessible(node, ctx.inInterface)))
175
+ return;
176
+ const declaration = namedChildren(node).find((c) => c.type === 'variable_declaration');
177
+ for (const declarator of declaration ? namedChildren(declaration) : []) {
178
+ if (declarator.type !== 'variable_declarator')
179
+ continue;
180
+ const id = declarator.childForFieldName('name')?.text ?? namedChildren(declarator)[0]?.text;
181
+ const value = namedChildren(declarator).find((c) => /literal$/.test(c.type) && c.type !== 'null_literal');
182
+ // `static readonly` only counts with a literal value (not lists, services or computed values).
183
+ if (!id || (!modifiers.includes('const') && !value))
184
+ continue;
185
+ const name = `${ctx.type}.${id}`;
186
+ if (this.names.has(name))
187
+ continue;
188
+ this.names.add(name);
189
+ this.out.symbols.push({
190
+ name,
191
+ kind: 'variable',
192
+ range: lineRange(node),
193
+ exported: true,
194
+ ...(value && { doc: `= ${value.text.length > 120 ? `${value.text.slice(0, 117)}...` : value.text}` }),
195
+ });
196
+ }
197
+ }
198
+ addSymbol(name, kind, node, exported, http) {
199
+ if (this.names.has(name))
200
+ return;
201
+ this.names.add(name);
202
+ this.out.symbols.push({ name, kind, range: lineRange(node), exported, ...(http ? { http } : {}) });
203
+ }
204
+ /** `name`, or `name (2)`, `name (3)`... when already taken in this file. */
205
+ uniqueName(name) {
206
+ if (!this.names.has(name))
207
+ return name;
208
+ let n = 2;
209
+ while (this.names.has(`${name} (${n})`))
210
+ n++;
211
+ return `${name} (${n})`;
212
+ }
213
+ // ---- imports ----
214
+ addUsing(node) {
215
+ if (node.childForFieldName('name'))
216
+ return; // `using A = B;` aliases
217
+ const target = namedChildren(node).find((c) => c.type === 'qualified_name' || c.type === 'identifier');
218
+ if (target)
219
+ this.out.imports.push({ specifier: target.text, bindings: [], line: line(node) });
220
+ }
221
+ // ---- calls, minimal APIs and requests ----
222
+ visitInvocation(node, ctx) {
223
+ const fn = node.childForFieldName('function');
224
+ const target = fn ? callTarget(fn) : undefined;
225
+ if (target && ctx.owner)
226
+ this.addCall(ctx, target, node);
227
+ // Any receiver counts for client calls (`_factory.CreateClient().GetAsync(...)`).
228
+ const member = fn ? memberName(fn) : undefined;
229
+ const method = member ? CLIENT_METHODS.get(member) : undefined;
230
+ const url = method ? firstStringArg(node) : undefined;
231
+ if (method && url !== undefined)
232
+ this.addRequest(ctx, method, url, node);
233
+ const handler = this.addMinimalRoute(node, fn, member);
234
+ for (const child of namedChildren(node)) {
235
+ if (child.type !== 'argument_list') {
236
+ this.walk(child, ctx);
237
+ continue;
238
+ }
239
+ for (const arg of namedChildren(child)) {
240
+ const value = argValue(arg);
241
+ if (handler && value?.id === handler.node.id) {
242
+ this.walk(value, { ...withScope(ctx, memberScope(value)), owner: handler.name });
243
+ }
244
+ else {
245
+ this.walk(arg, ctx);
246
+ }
247
+ }
248
+ }
249
+ }
250
+ visitCreation(node, ctx) {
251
+ const type = node.childForFieldName('type');
252
+ const callee = type ? typeName(type) : undefined;
253
+ if (!callee || !ctx.owner)
254
+ return;
255
+ this.addCall(ctx, { callee }, node);
256
+ if (callee !== 'HttpRequestMessage')
257
+ return;
258
+ // `new HttpRequestMessage(HttpMethod.Post, "url")`
259
+ const [methodArg, urlArg] = callArgs(node);
260
+ const url = urlArg ? stringValue(urlArg) : undefined;
261
+ if (url !== undefined)
262
+ this.addRequest(ctx, methodArg ? requestMethod(methodArg) : 'GET', url, node);
263
+ }
264
+ addCall(ctx, target, node) {
265
+ const caller = ctx.owner;
266
+ if (!caller)
267
+ return;
268
+ const key = `${caller}\0${target.callee}\0${target.object ?? ''}`;
269
+ if (this.seenCalls.has(key))
270
+ return;
271
+ this.seenCalls.add(key);
272
+ const objectType = target.object !== undefined && target.object !== 'this'
273
+ ? lookupType(ctx.scopes, target.object, target.viaThis === true)
274
+ : undefined;
275
+ this.out.calls.push({
276
+ caller,
277
+ callee: target.callee,
278
+ ...(target.object !== undefined ? { object: target.object } : {}),
279
+ ...(objectType !== undefined ? { objectType } : {}),
280
+ line: line(node),
281
+ });
282
+ }
283
+ addRequest(ctx, method, url, node) {
284
+ if (ctx.owner)
285
+ this.out.requests.push({ caller: ctx.owner, method, url, line: line(node) });
286
+ }
287
+ /** `app.MapGet("/x", handler)` → a `GET /x` route symbol; returns the handler that owns its calls. */
288
+ addMinimalRoute(node, fn, callee) {
289
+ const method = callee ? MINIMAL_API.get(callee) : undefined;
290
+ const receiver = memberReceiver(fn);
291
+ const args = callArgs(node);
292
+ const template = args[0] ? stringValue(args[0]) : undefined;
293
+ const handler = args.at(-1);
294
+ if (!method || !receiver || template === undefined || args.length < 2 || !handler)
295
+ return undefined;
296
+ if (!HANDLER_TYPES.has(handler.type))
297
+ return undefined;
298
+ const path = joinPath(this.groupPrefix(receiver), template);
299
+ const name = this.uniqueName(`${method} ${path}`);
300
+ this.addSymbol(name, 'route', statementOf(node), false, { method, path });
301
+ return { name, node: handler };
302
+ }
303
+ trackGroup(declarator) {
304
+ const name = declarator.childForFieldName('name')?.text;
305
+ const value = namedChildren(declarator).at(-1);
306
+ if (!name || value?.type !== 'invocation_expression')
307
+ return;
308
+ const prefix = this.groupPrefix(value);
309
+ if (prefix)
310
+ this.groups.set(name, prefix);
311
+ }
312
+ /** Route prefix of a `MapGroup` receiver: a tracked variable or a `x.MapGroup("/p")` call. */
313
+ groupPrefix(node) {
314
+ if (node.type === 'identifier')
315
+ return this.groups.get(node.text) ?? '';
316
+ if (node.type !== 'invocation_expression')
317
+ return '';
318
+ const fn = node.childForFieldName('function');
319
+ if (fn?.type !== 'member_access_expression' || fn.childForFieldName('name')?.text !== 'MapGroup')
320
+ return '';
321
+ const first = callArgs(node)[0];
322
+ const prefix = first ? stringValue(first) : undefined;
323
+ const receiver = fn.childForFieldName('expression');
324
+ if (prefix === undefined || !receiver)
325
+ return '';
326
+ return joinPath(this.groupPrefix(receiver), prefix);
327
+ }
328
+ // ---- heritage ----
329
+ addHeritage(symbol, node) {
330
+ const bases = namedChildren(node).find((c) => c.type === 'base_list');
331
+ if (!bases)
332
+ return;
333
+ for (const base of namedChildren(bases)) {
334
+ const target = typeName(base);
335
+ if (!target)
336
+ continue;
337
+ const relation = node.type !== 'interface_declaration' && INTERFACE_NAME.test(target) ? 'implements' : 'extends';
338
+ this.out.heritage.push({ symbol, relation, target });
339
+ }
340
+ }
341
+ }
342
+ // ---- helpers ----
343
+ function line(node) {
344
+ return node.startPosition.row + 1;
345
+ }
346
+ function withScope(ctx, types) {
347
+ return { ...ctx, scopes: [{ member: true, types }, ...ctx.scopes] };
348
+ }
349
+ function modifiers(node) {
350
+ return namedChildren(node)
351
+ .filter((c) => c.type === 'modifier')
352
+ .map((c) => c.text);
353
+ }
354
+ /** `public`/`internal` → true; `private`/`protected` → false; no access modifier → `fallback`. */
355
+ function isAccessible(node, fallback) {
356
+ const mods = modifiers(node);
357
+ if (mods.includes('public') || mods.includes('internal'))
358
+ return true;
359
+ if (mods.includes('private') || mods.includes('protected'))
360
+ return false;
361
+ return fallback;
362
+ }
363
+ /** Simple type name: generics, nullability and namespace qualification dropped. */
364
+ function typeName(node) {
365
+ switch (node.type) {
366
+ case 'identifier':
367
+ case 'predefined_type':
368
+ return node.text;
369
+ case 'generic_name':
370
+ return namedChildren(node).find((c) => c.type === 'identifier')?.text;
371
+ case 'qualified_name':
372
+ case 'alias_qualified_name': {
373
+ const name = node.childForFieldName('name');
374
+ return name ? typeName(name) : undefined;
375
+ }
376
+ case 'nullable_type':
377
+ case 'primary_constructor_base_type': {
378
+ const inner = node.childForFieldName('type') ?? namedChildren(node)[0];
379
+ return inner ? typeName(inner) : undefined;
380
+ }
381
+ default:
382
+ return undefined;
383
+ }
384
+ }
385
+ function addTyped(types, typeNode, nameNode) {
386
+ if (!typeNode || nameNode?.type !== 'identifier' || types.has(nameNode.text))
387
+ return;
388
+ const type = typeName(typeNode);
389
+ if (type)
390
+ types.set(nameNode.text, type);
391
+ }
392
+ /** Variables declared in a variable_declaration (`Foo a, b;`); `var` gives no type. */
393
+ function addDeclaration(types, declaration) {
394
+ const type = declaration.childForFieldName('type');
395
+ if (!type || type.type === 'implicit_type')
396
+ return;
397
+ for (const declarator of namedChildren(declaration)) {
398
+ if (declarator.type === 'variable_declarator')
399
+ addTyped(types, type, declarator.childForFieldName('name'));
400
+ }
401
+ }
402
+ /** Fields, properties and primary-constructor parameters of a type. */
403
+ function typeScope(node) {
404
+ const types = new Map();
405
+ for (const param of namedChildren(namedChildren(node).find((c) => c.type === 'parameter_list') ?? node)) {
406
+ if (param.type === 'parameter')
407
+ addTyped(types, param.childForFieldName('type'), param.childForFieldName('name'));
408
+ }
409
+ const body = node.childForFieldName('body');
410
+ for (const member of body ? namedChildren(body) : []) {
411
+ if (member.type === 'property_declaration') {
412
+ addTyped(types, member.childForFieldName('type'), member.childForFieldName('name'));
413
+ }
414
+ else if (member.type === 'field_declaration') {
415
+ const declaration = namedChildren(member).find((c) => c.type === 'variable_declaration');
416
+ if (declaration)
417
+ addDeclaration(types, declaration);
418
+ }
419
+ }
420
+ return types;
421
+ }
422
+ /** Parameters and explicitly typed locals anywhere inside a member, lambda or local function. */
423
+ function memberScope(node) {
424
+ const types = new Map();
425
+ const visit = (n) => {
426
+ if (n.type === 'parameter' || n.type === 'declaration_expression') {
427
+ addTyped(types, n.childForFieldName('type'), n.childForFieldName('name'));
428
+ }
429
+ else if (n.type === 'variable_declaration') {
430
+ addDeclaration(types, n);
431
+ }
432
+ else if (n.type === 'foreach_statement') {
433
+ const type = n.childForFieldName('type');
434
+ if (type?.type !== 'implicit_type')
435
+ addTyped(types, type, n.childForFieldName('left'));
436
+ }
437
+ for (const child of namedChildren(n))
438
+ visit(child);
439
+ };
440
+ visit(node);
441
+ return types;
442
+ }
443
+ /** Declared type of `name`: locals and parameters first, then fields (only fields for `this.x`). */
444
+ function lookupType(scopes, name, fieldsOnly) {
445
+ for (const scope of scopes) {
446
+ if (fieldsOnly && scope.member)
447
+ continue;
448
+ const type = scope.types.get(name);
449
+ if (type)
450
+ return type;
451
+ }
452
+ return undefined;
453
+ }
454
+ /** `Foo()`, `obj.Bar()`, `this.Bar()`, `this._x.Bar()`, `obj?.Bar()`; undefined for other shapes. */
455
+ function callTarget(fn) {
456
+ if (fn.type === 'identifier')
457
+ return fn.text === 'nameof' ? undefined : { callee: fn.text };
458
+ if (fn.type === 'generic_name')
459
+ return simpleCallee(fn);
460
+ const receiver = fn.type === 'member_access_expression'
461
+ ? fn.childForFieldName('expression')
462
+ : fn.type === 'conditional_access_expression'
463
+ ? fn.childForFieldName('condition')
464
+ : null;
465
+ const callee = memberName(fn);
466
+ if (!callee || !receiver)
467
+ return undefined;
468
+ if (receiver.type === 'identifier' || receiver.type === 'this')
469
+ return { callee, object: receiver.text };
470
+ if (receiver.type === 'member_access_expression' && receiver.childForFieldName('expression')?.type === 'this') {
471
+ const field = receiver.childForFieldName('name');
472
+ if (field?.type === 'identifier')
473
+ return { callee, object: field.text, viaThis: true };
474
+ }
475
+ return undefined; // base.M(), a.b.C(), F().G()...
476
+ }
477
+ /** Member name of `x.Name(...)` / `x?.Name(...)`, generic arguments dropped. */
478
+ function memberName(fn) {
479
+ const nameNode = fn.type === 'member_access_expression'
480
+ ? fn.childForFieldName('name')
481
+ : fn.type === 'conditional_access_expression'
482
+ ? namedChildren(fn).find((c) => c.type === 'member_binding_expression')?.childForFieldName('name')
483
+ : undefined;
484
+ return nameNode ? simpleCallee(nameNode)?.callee : undefined;
485
+ }
486
+ function simpleCallee(node) {
487
+ const name = node.type === 'generic_name' ? namedChildren(node).find((c) => c.type === 'identifier') : node;
488
+ return name?.type === 'identifier' ? { callee: name.text } : undefined;
489
+ }
490
+ /** Receiver of a member call (`app` in `app.MapGet(...)`). */
491
+ function memberReceiver(fn) {
492
+ if (fn?.type !== 'member_access_expression')
493
+ return undefined;
494
+ return fn.childForFieldName('expression') ?? undefined;
495
+ }
496
+ /** Expression of an `argument` node (skipping `name:` labels and `ref`/`out`). */
497
+ function argValue(arg) {
498
+ return namedChildren(arg).at(-1);
499
+ }
500
+ function callArgs(call) {
501
+ const list = call.childForFieldName('arguments') ?? namedChildren(call).find((c) => c.type === 'argument_list');
502
+ if (!list)
503
+ return [];
504
+ return namedChildren(list)
505
+ .filter((a) => a.type === 'argument')
506
+ .map(argValue)
507
+ .filter((v) => v !== undefined);
508
+ }
509
+ function firstStringArg(call) {
510
+ const first = callArgs(call)[0];
511
+ return first ? stringValue(first) : undefined;
512
+ }
513
+ /** Content of a string literal; interpolations become `{}`. Undefined for non-literals. */
514
+ function stringValue(node) {
515
+ if (!STRING_TYPES.has(node.type))
516
+ return undefined;
517
+ if (node.type === 'string_literal')
518
+ return node.text.slice(1, -1);
519
+ if (node.type === 'verbatim_string_literal')
520
+ return node.text.slice(2, -1);
521
+ if (node.type === 'raw_string_literal')
522
+ return node.text.replace(/^"+/, '').replace(/"+$/, '');
523
+ let text = '';
524
+ for (const child of node.children) {
525
+ if (!child)
526
+ continue;
527
+ if (child.type === 'interpolation')
528
+ text += '{}';
529
+ else if (child.isNamed && child.type !== 'interpolation_start' && child.type !== 'interpolation_quote') {
530
+ text += child.text;
531
+ }
532
+ }
533
+ return text;
534
+ }
535
+ /** `HttpMethod.Post` → `POST`; `new HttpMethod("PATCH")` → `PATCH`; otherwise `GET`. */
536
+ function requestMethod(node) {
537
+ if (node.type === 'member_access_expression') {
538
+ return node.childForFieldName('name')?.text.toUpperCase() ?? 'GET';
539
+ }
540
+ if (node.type === 'object_creation_expression') {
541
+ const first = callArgs(node)[0];
542
+ const literal = first ? stringValue(first) : undefined;
543
+ if (literal)
544
+ return literal.toUpperCase();
545
+ }
546
+ return 'GET';
547
+ }
548
+ /** The statement holding a call chain, or the call itself when it is not a statement. */
549
+ function statementOf(call) {
550
+ let top = call;
551
+ while (top.parent && CHAIN_PARENTS.has(top.parent.type))
552
+ top = top.parent;
553
+ return top.parent?.type === 'expression_statement' ? top.parent : call;
554
+ }
555
+ function attributes(node) {
556
+ const result = [];
557
+ for (const list of namedChildren(node)) {
558
+ if (list.type !== 'attribute_list')
559
+ continue;
560
+ for (const attr of namedChildren(list)) {
561
+ const nameNode = attr.childForFieldName('name');
562
+ const name = nameNode ? typeName(nameNode)?.replace(/Attribute$/, '') : undefined;
563
+ if (!name)
564
+ continue;
565
+ const template = attributeTemplate(attr);
566
+ result.push({ name, ...(template !== undefined ? { template } : {}) });
567
+ }
568
+ }
569
+ return result;
570
+ }
571
+ function attributeTemplate(attr) {
572
+ const args = namedChildren(attr).find((c) => c.type === 'attribute_argument_list');
573
+ for (const arg of args ? namedChildren(args) : []) {
574
+ const parts = namedChildren(arg);
575
+ const value = parts.at(-1);
576
+ if (!value || value.type === 'assignment_expression')
577
+ continue; // `Name = "x"`, `Order = 1`
578
+ // `template: "x"` names its argument; other labels are not the template.
579
+ if (parts.length > 1 && parts[0]?.text !== 'template')
580
+ continue;
581
+ return stringValue(value);
582
+ }
583
+ return undefined;
584
+ }
585
+ /** HTTP endpoint of a controller action from its `[HttpX]` / `[Route]` attributes. */
586
+ function actionRoute(node, action, controller) {
587
+ const attrs = attributes(node);
588
+ const verb = attrs.find((a) => VERB_ATTRIBUTES.has(a.name));
589
+ const route = attrs.find((a) => a.name === 'Route');
590
+ if (!verb && !route)
591
+ return undefined;
592
+ const method = verb ? (VERB_ATTRIBUTES.get(verb.name) ?? 'ANY') : 'ANY';
593
+ const template = verb?.template ?? route?.template ?? '';
594
+ const absolute = template.startsWith('/') || template.startsWith('~/');
595
+ const raw = absolute ? template.replace(/^~/, '') : joinPath(controller.prefix, template);
596
+ const path = raw.replace(/\[controller\]/gi, controller.name).replace(/\[action\]/gi, action);
597
+ return { method, path: joinPath(path, '') };
598
+ }
599
+ /** Joins route segments: leading `/`, collapsed slashes, no trailing slash (root stays `/`). */
600
+ function joinPath(prefix, template) {
601
+ const path = `/${prefix}/${template}`.replace(/\/+/g, '/');
602
+ return path.length > 1 ? path.replace(/\/$/, '') : path;
603
+ }
604
+ //# sourceMappingURL=csharp.js.map