devlensio 1.2.0 → 1.4.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 (47) hide show
  1. package/dist/graph/edges/callEdges.js +77 -3
  2. package/dist/graph/edges/callEdges.test.js +1 -1
  3. package/dist/graph/edges/callOrder.test.d.ts +1 -0
  4. package/dist/graph/edges/callOrder.test.js +227 -0
  5. package/dist/graph/edges/propEdges.js +6 -1
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/parser/callFlow.d.ts +15 -0
  9. package/dist/parser/callFlow.js +302 -0
  10. package/dist/parser/callOrder.test.d.ts +1 -0
  11. package/dist/parser/callOrder.test.js +407 -0
  12. package/dist/parser/extractors/components.js +18 -28
  13. package/dist/parser/extractors/functions.d.ts +12 -3
  14. package/dist/parser/extractors/functions.js +58 -36
  15. package/dist/parser/extractors/moduleScope.js +1 -1
  16. package/dist/parser/moduleScope.test.js +5 -3
  17. package/dist/summarizer/index.js +53 -4
  18. package/dist/summarizer/prompts.js +111 -50
  19. package/dist/summarizer/prompts.test.d.ts +1 -0
  20. package/dist/summarizer/prompts.test.js +112 -0
  21. package/dist/types.d.ts +63 -0
  22. package/dist/version.d.ts +1 -0
  23. package/dist/version.js +2 -0
  24. package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
  25. package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
  26. package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
  27. package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
  28. package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
  29. package/extractors/go/calls.go +89 -10
  30. package/extractors/go/nodes.go +29 -11
  31. package/extractors/go/parser.go +311 -21
  32. package/extractors/java/devlens_java_extractor.jar +0 -0
  33. package/extractors/java/src/devlens/extractor/Extractor.java +36 -10
  34. package/extractors/java/src/devlens/extractor/Parser.java +387 -0
  35. package/extractors/java/src/devlens/extractor/edges/Calls.java +66 -10
  36. package/extractors/python/devlens_extractors_python/edges/calls.py +26 -3
  37. package/extractors/python/devlens_extractors_python/parser/__init__.py +4 -3
  38. package/extractors/python/devlens_extractors_python/parser/functions.py +199 -42
  39. package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
  40. package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
  41. package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
  42. package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
  43. package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
  44. package/extractors/rust/src/calls.rs +82 -8
  45. package/extractors/rust/src/nodes.rs +29 -0
  46. package/extractors/rust/src/parser.rs +362 -27
  47. package/package.json +77 -73
@@ -0,0 +1,302 @@
1
+ import { SyntaxKind } from "ts-morph";
2
+ // callOrder/v1. See docs/CALL_ORDER.md. Everything here is metadata only: the
3
+ // set of recorded call sites is decided by the caller's walk, never by this file.
4
+ const FUNCTION_LIKE = new Set([
5
+ SyntaxKind.FunctionDeclaration,
6
+ SyntaxKind.FunctionExpression,
7
+ SyntaxKind.ArrowFunction,
8
+ SyntaxKind.MethodDeclaration,
9
+ SyntaxKind.Constructor,
10
+ SyntaxKind.GetAccessor,
11
+ SyntaxKind.SetAccessor,
12
+ SyntaxKind.ClassDeclaration,
13
+ SyntaxKind.ClassExpression,
14
+ ]);
15
+ const LOOP_KINDS = new Set([
16
+ SyntaxKind.ForStatement,
17
+ SyntaxKind.ForOfStatement,
18
+ SyntaxKind.ForInStatement,
19
+ SyntaxKind.WhileStatement,
20
+ SyntaxKind.DoStatement,
21
+ ]);
22
+ const TIMER_APIS = new Set(["setTimeout", "setInterval"]);
23
+ const MICROTASK_APIS = new Set(["queueMicrotask", "setImmediate", "nextTick"]);
24
+ const EVENT_APIS = new Set([
25
+ "addEventListener", "on", "once", "addListener", "prependListener", "subscribe",
26
+ ]);
27
+ const POST_RENDER_APIS = new Set([
28
+ "useEffect", "useLayoutEffect", "useInsertionEffect",
29
+ ]);
30
+ const PROMISE_APIS = new Set(["then", "catch", "finally"]);
31
+ const ITERATION_APIS = new Set([
32
+ "map", "forEach", "filter", "reduce", "reduceRight", "some", "every", "find",
33
+ "findIndex", "findLast", "flatMap", "sort", "toSorted",
34
+ ]);
35
+ const EXECUTOR_APIS = new Set(["submit", "execute"]);
36
+ const PARALLEL_COMBINATORS = new Set(["all", "allSettled", "race", "any"]);
37
+ function unwrapParens(node) {
38
+ let n = node;
39
+ while (n && n.getKind() === SyntaxKind.ParenthesizedExpression) {
40
+ n = n.getExpression();
41
+ }
42
+ return n;
43
+ }
44
+ export function isIifeCallee(callee) {
45
+ const expr = unwrapParens(callee);
46
+ if (!expr)
47
+ return false;
48
+ return (expr.getKind() === SyntaxKind.ArrowFunction ||
49
+ expr.getKind() === SyntaxKind.FunctionExpression);
50
+ }
51
+ function calleeText(call) {
52
+ const expression = call.getExpression?.();
53
+ return expression ? expression.getText() : "";
54
+ }
55
+ function memberName(text) {
56
+ const dot = text.lastIndexOf(".");
57
+ return dot === -1 ? text : text.slice(dot + 1);
58
+ }
59
+ // Nearest enclosing call expression, ignoring any that sit beyond a function
60
+ // boundary: arguments of a callback belong to the callback, not to the call that
61
+ // received it.
62
+ function enclosingCallWithinFrame(call, boundary) {
63
+ let child = call;
64
+ let parent = call.getParent();
65
+ while (parent && parent !== boundary) {
66
+ if (FUNCTION_LIKE.has(parent.getKind()))
67
+ return undefined;
68
+ if (parent.getKind() === SyntaxKind.CallExpression ||
69
+ parent.getKind() === SyntaxKind.NewExpression) {
70
+ return parent;
71
+ }
72
+ child = parent;
73
+ parent = parent.getParent();
74
+ }
75
+ return undefined;
76
+ }
77
+ function nearestEnclosingFunction(call, boundary) {
78
+ let parent = call.getParent();
79
+ while (parent && parent !== boundary) {
80
+ if (parent.getKind() === SyntaxKind.FunctionDeclaration ||
81
+ parent.getKind() === SyntaxKind.FunctionExpression ||
82
+ parent.getKind() === SyntaxKind.ArrowFunction ||
83
+ parent.getKind() === SyntaxKind.MethodDeclaration) {
84
+ return parent;
85
+ }
86
+ parent = parent.getParent();
87
+ }
88
+ return undefined;
89
+ }
90
+ function isInsideJsxHandler(call, boundary) {
91
+ let parent = call.getParent();
92
+ while (parent && parent !== boundary) {
93
+ if (parent.getKind() === SyntaxKind.JsxExpression) {
94
+ const attribute = parent.getParent();
95
+ if (attribute && attribute.getKind() === SyntaxKind.JsxAttribute) {
96
+ const holder = attribute.getParent();
97
+ if (holder &&
98
+ (holder.getKind() === SyntaxKind.JsxOpeningElement ||
99
+ holder.getKind() === SyntaxKind.JsxSelfClosingElement)) {
100
+ return true;
101
+ }
102
+ }
103
+ }
104
+ parent = parent.getParent();
105
+ }
106
+ return false;
107
+ }
108
+ function computeScope(call, owner, isFileOwner) {
109
+ if (isFileOwner)
110
+ return "module";
111
+ if (isInsideJsxHandler(call, owner))
112
+ return "handler";
113
+ const fn = nearestEnclosingFunction(call, owner);
114
+ if (!fn)
115
+ return "inline";
116
+ if (fn.getKind() === SyntaxKind.FunctionDeclaration)
117
+ return "nested";
118
+ const parent = unwrapParens(fn.getParent());
119
+ if (!parent)
120
+ return "callback";
121
+ if (parent.getKind() === SyntaxKind.VariableDeclaration)
122
+ return "nested";
123
+ if (parent.getKind() === SyntaxKind.PropertyAssignment)
124
+ return "nested";
125
+ if (parent.getKind() === SyntaxKind.JsxExpression)
126
+ return "handler";
127
+ return "callback";
128
+ }
129
+ // The call that receives `fn` as an argument, looking through arrays so
130
+ // Promise.all([...]) members are found too.
131
+ function callReceiving(fn) {
132
+ let node = unwrapParens(fn.getParent());
133
+ while (node) {
134
+ if (node.getKind() === SyntaxKind.CallExpression ||
135
+ node.getKind() === SyntaxKind.NewExpression) {
136
+ return node;
137
+ }
138
+ if (node.getKind() === SyntaxKind.ArrayLiteralExpression ||
139
+ node.getKind() === SyntaxKind.ParenthesizedExpression ||
140
+ node.getKind() === SyntaxKind.SpreadElement) {
141
+ node = unwrapParens(node.getParent());
142
+ continue;
143
+ }
144
+ return undefined;
145
+ }
146
+ return undefined;
147
+ }
148
+ function computeDefer(call, owner) {
149
+ const result = {};
150
+ const fn = nearestEnclosingFunction(call, owner);
151
+ if (fn) {
152
+ const receiver = callReceiving(fn);
153
+ if (receiver) {
154
+ const text = calleeText(receiver);
155
+ const member = memberName(text);
156
+ const root = text.split(".")[0];
157
+ if (TIMER_APIS.has(text) || TIMER_APIS.has(member)) {
158
+ result.defer = "timer";
159
+ result.deferDetail = text;
160
+ }
161
+ else if (MICROTASK_APIS.has(text) || MICROTASK_APIS.has(member)) {
162
+ result.defer = "microtask";
163
+ result.deferDetail = text;
164
+ }
165
+ else if (POST_RENDER_APIS.has(text)) {
166
+ result.defer = "postRender";
167
+ result.deferDetail = text;
168
+ }
169
+ else if (PROMISE_APIS.has(member) || text === "new Promise") {
170
+ result.defer = "promise";
171
+ result.deferDetail = text;
172
+ }
173
+ else if (EVENT_APIS.has(member) && root !== "Promise") {
174
+ result.defer = "event";
175
+ result.deferDetail = text;
176
+ }
177
+ else if (ITERATION_APIS.has(member)) {
178
+ result.repeat = true;
179
+ result.deferDetail = text;
180
+ }
181
+ else if (EXECUTOR_APIS.has(member)) {
182
+ result.conc = true;
183
+ result.deferDetail = text;
184
+ }
185
+ else if (root === "Promise" && PARALLEL_COMBINATORS.has(member)) {
186
+ result.conc = true;
187
+ result.deferDetail = text;
188
+ }
189
+ // An unrecognised callback argument is NOT a detachment claim. Most helpers that
190
+ // take a callback call it synchronously (runText, withRetry, map-like wrappers),
191
+ // so the honest record is scope "callback" with no defer. The "unknown" value is
192
+ // reserved for a position known to be detached whose scheduler cannot be named.
193
+ }
194
+ }
195
+ // Promise.all([a(), b()]) members run in parallel even though they are not
196
+ // callbacks. Walk to the call that owns the array literal.
197
+ let parent = call.getParent();
198
+ while (parent && parent !== owner) {
199
+ if (FUNCTION_LIKE.has(parent.getKind()))
200
+ break;
201
+ if (parent.getKind() === SyntaxKind.ArrayLiteralExpression &&
202
+ parent.getParent() &&
203
+ parent.getParent().getKind() === SyntaxKind.CallExpression) {
204
+ const ownerCall = parent.getParent();
205
+ const text = calleeText(ownerCall);
206
+ if (text.startsWith("Promise.") && PARALLEL_COMBINATORS.has(memberName(text))) {
207
+ result.conc = true;
208
+ result.deferDetail = text;
209
+ }
210
+ }
211
+ parent = parent.getParent();
212
+ }
213
+ return result;
214
+ }
215
+ function computeMaybeAndRepeat(call, owner) {
216
+ const result = {};
217
+ let child = call;
218
+ let parent = call.getParent();
219
+ while (parent && parent !== owner) {
220
+ if (FUNCTION_LIKE.has(parent.getKind()))
221
+ break;
222
+ const kind = parent.getKind();
223
+ if (kind === SyntaxKind.TryStatement) {
224
+ const finallyBlock = parent.getFinallyBlock?.();
225
+ if (finallyBlock && child === finallyBlock)
226
+ result.defer = "onReturn";
227
+ }
228
+ if (kind === SyntaxKind.IfStatement) {
229
+ const thenStatement = parent.getThenStatement?.();
230
+ const elseStatement = parent.getElseStatement?.();
231
+ if (child === thenStatement || child === elseStatement)
232
+ result.maybe = true;
233
+ }
234
+ if (kind === SyntaxKind.ConditionalExpression) {
235
+ const whenTrue = parent.getWhenTrue?.();
236
+ const whenFalse = parent.getWhenFalse?.();
237
+ if (child === whenTrue || child === whenFalse)
238
+ result.maybe = true;
239
+ }
240
+ if (kind === SyntaxKind.BinaryExpression) {
241
+ const operator = parent.getOperatorToken?.()?.getKind?.();
242
+ const right = parent.getRight?.();
243
+ const conditional = operator === SyntaxKind.AmpersandAmpersandToken ||
244
+ operator === SyntaxKind.BarBarToken ||
245
+ operator === SyntaxKind.QuestionQuestionToken;
246
+ if (conditional && child === right)
247
+ result.maybe = true;
248
+ }
249
+ if (kind === SyntaxKind.CaseClause || kind === SyntaxKind.DefaultClause || kind === SyntaxKind.CatchClause) {
250
+ result.maybe = true;
251
+ }
252
+ if (LOOP_KINDS.has(kind)) {
253
+ const body = parent.getStatement?.() ?? parent.getBody?.();
254
+ if (body && child === body)
255
+ result.repeat = true;
256
+ }
257
+ child = parent;
258
+ parent = parent.getParent();
259
+ }
260
+ return result;
261
+ }
262
+ function jsxAttributeName(call, boundary) {
263
+ let parent = call.getParent();
264
+ while (parent && parent !== boundary) {
265
+ if (parent.getKind() === SyntaxKind.JsxExpression) {
266
+ const attribute = parent.getParent();
267
+ if (attribute && attribute.getKind() === SyntaxKind.JsxAttribute) {
268
+ return attribute.getNameNode?.()?.getText?.();
269
+ }
270
+ }
271
+ parent = parent.getParent();
272
+ }
273
+ return undefined;
274
+ }
275
+ function isAwaited(call) {
276
+ const parent = call.getParent();
277
+ return Boolean(parent && parent.getKind() === SyntaxKind.AwaitExpression);
278
+ }
279
+ export function annotateCall(call, owner, isFileOwner, ordinals) {
280
+ const annotations = {
281
+ col: call.getStart() - call.getStartLinePos(),
282
+ scope: computeScope(call, owner, isFileOwner),
283
+ };
284
+ const enclosing = enclosingCallWithinFrame(call, owner);
285
+ if (enclosing) {
286
+ const order = ordinals.get(enclosing);
287
+ if (order !== undefined)
288
+ annotations.nested = order;
289
+ }
290
+ if (isAwaited(call))
291
+ annotations.awaited = true;
292
+ Object.assign(annotations, computeDefer(call, owner));
293
+ Object.assign(annotations, computeMaybeAndRepeat(call, owner));
294
+ // A JSX attribute handler is triggered by the user, never by the render pass.
295
+ if (annotations.scope === "handler" && !annotations.defer) {
296
+ annotations.defer = "event";
297
+ const attribute = jsxAttributeName(call, owner);
298
+ if (attribute)
299
+ annotations.deferDetail = `on${attribute.replace(/^on/, "")}`;
300
+ }
301
+ return annotations;
302
+ }
@@ -0,0 +1 @@
1
+ export {};