scip-query 0.5.0 → 0.6.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 (199) hide show
  1. package/dist/chunk-2DSS2NGF.js +10 -0
  2. package/dist/chunk-2RLP74AO.js +2 -0
  3. package/dist/chunk-4QJ7LVW5.js +2 -0
  4. package/dist/chunk-4TYGGOLO.js +5 -0
  5. package/dist/chunk-5IADAU5B.js +7 -0
  6. package/dist/chunk-7754WFFV.js +18 -0
  7. package/dist/chunk-7VOF4ZG6.js +2 -0
  8. package/dist/chunk-7Z4COVMC.js +2 -0
  9. package/dist/chunk-AJ5PWKD4.js +2 -0
  10. package/dist/chunk-BDBRZPX3.js +7 -0
  11. package/dist/chunk-BE6EQIWY.js +2 -0
  12. package/dist/chunk-BQ3INTYT.js +8 -0
  13. package/dist/chunk-D7KLLMPB.js +2 -0
  14. package/dist/chunk-D7YBWSON.js +29 -0
  15. package/dist/chunk-DE5ZBHMK.js +39 -0
  16. package/dist/chunk-DHYIJHXZ.js +33 -0
  17. package/dist/chunk-EEF3YEHW.js +2 -0
  18. package/dist/chunk-F2LLHRRZ.js +2 -0
  19. package/dist/chunk-FCC3XJTI.js +2 -0
  20. package/dist/chunk-GNXRLK5G.js +2 -0
  21. package/dist/chunk-GXVB36TG.js +62 -0
  22. package/dist/chunk-HMKJTAZD.js +2 -0
  23. package/dist/chunk-IBGBI3VU.js +2 -0
  24. package/dist/chunk-IYFZS4PV.js +84 -0
  25. package/dist/chunk-JH3A7HTU.js +2 -0
  26. package/dist/chunk-JS2RNIC7.js +2 -0
  27. package/dist/chunk-K5FQFCSN.js +41 -0
  28. package/dist/chunk-K6GBKEQE.js +6 -0
  29. package/dist/chunk-KO7YJRWP.js +12 -0
  30. package/dist/chunk-KYT47WU2.js +4 -0
  31. package/dist/chunk-LORWXBOO.js +2 -0
  32. package/dist/chunk-LX4H4LLG.js +89 -0
  33. package/dist/chunk-N3Z2SJCR.js +2 -0
  34. package/dist/chunk-NTDA4A2D.js +25 -0
  35. package/dist/chunk-NXMYYHDO.js +24 -0
  36. package/dist/chunk-PZ6ESKRH.js +7 -0
  37. package/dist/chunk-QXE6EDY2.js +6 -0
  38. package/dist/chunk-RJ7SPBJ5.js +5 -0
  39. package/dist/chunk-RWE6FHG3.js +3 -0
  40. package/dist/chunk-SDX6MDBL.js +2 -0
  41. package/dist/chunk-SG35Y7J2.js +2 -0
  42. package/dist/chunk-STOGKRJH.js +4 -0
  43. package/dist/chunk-TINPMWJK.js +2 -0
  44. package/dist/chunk-UJB62HV3.js +2 -0
  45. package/dist/chunk-VEUMRDHW.js +2 -0
  46. package/dist/chunk-WCDXJGYT.js +65 -0
  47. package/dist/chunk-WTSTDJZ7.js +6 -0
  48. package/dist/chunk-XAZTIDST.js +2 -0
  49. package/dist/chunk-XVDASCN7.js +35 -0
  50. package/dist/chunk-Y7H6D2EV.js +2 -0
  51. package/dist/chunk-Y7LOQSWY.js +2 -0
  52. package/dist/chunk-YIPCV7M7.js +70 -0
  53. package/dist/chunk-ZSRXMNMK.js +5 -0
  54. package/dist/chunk-ZXKURFVB.js +56 -0
  55. package/dist/cli.js +509 -8758
  56. package/dist/{db-6F9R9e_t.d.ts → db-BSTtBG_H.d.ts} +146 -1
  57. package/dist/index.d.ts +11 -2
  58. package/dist/index.js +13 -1616
  59. package/dist/postinstall.js +4 -100
  60. package/dist/queries/affected.d.ts +1 -1
  61. package/dist/queries/affected.js +1 -8
  62. package/dist/queries/bottlenecks.d.ts +1 -1
  63. package/dist/queries/bottlenecks.js +1 -8
  64. package/dist/queries/by-kind.d.ts +1 -4
  65. package/dist/queries/by-kind.js +1 -10
  66. package/dist/queries/call-graph.d.ts +1 -1
  67. package/dist/queries/call-graph.js +1 -8
  68. package/dist/queries/change-surface.d.ts +1 -1
  69. package/dist/queries/change-surface.js +1 -8
  70. package/dist/queries/code.d.ts +1 -1
  71. package/dist/queries/code.js +1 -8
  72. package/dist/queries/complexity-hotspots.d.ts +5 -10
  73. package/dist/queries/complexity-hotspots.js +1 -8
  74. package/dist/queries/complexity.d.ts +1 -1
  75. package/dist/queries/complexity.js +1 -8
  76. package/dist/queries/convergence.d.ts +1 -1
  77. package/dist/queries/convergence.js +1 -8
  78. package/dist/queries/coupling.d.ts +1 -1
  79. package/dist/queries/coupling.js +1 -10
  80. package/dist/queries/cycles.d.ts +1 -1
  81. package/dist/queries/cycles.js +1 -8
  82. package/dist/queries/dataflow.d.ts +1 -1
  83. package/dist/queries/dataflow.js +1 -8
  84. package/dist/queries/dead.d.ts +1 -1
  85. package/dist/queries/dead.js +1 -9
  86. package/dist/queries/deep-chains.d.ts +9 -1
  87. package/dist/queries/deep-chains.js +1 -8
  88. package/dist/queries/deps.d.ts +1 -1
  89. package/dist/queries/deps.js +1 -10
  90. package/dist/queries/diff-impact.d.ts +1 -1
  91. package/dist/queries/diff-impact.js +1 -7
  92. package/dist/queries/drift.d.ts +1 -1
  93. package/dist/queries/drift.js +1 -8
  94. package/dist/queries/extract-candidates.d.ts +1 -1
  95. package/dist/queries/extract-candidates.js +1 -8
  96. package/dist/queries/fan.d.ts +1 -1
  97. package/dist/queries/fan.js +1 -14
  98. package/dist/queries/files.d.ts +1 -1
  99. package/dist/queries/files.js +1 -6
  100. package/dist/queries/health.d.ts +1 -1
  101. package/dist/queries/health.js +1 -20
  102. package/dist/queries/hierarchy.d.ts +1 -1
  103. package/dist/queries/hierarchy.js +1 -8
  104. package/dist/queries/hotspots.d.ts +1 -1
  105. package/dist/queries/hotspots.js +1 -8
  106. package/dist/queries/imports.d.ts +1 -1
  107. package/dist/queries/imports.js +1 -12
  108. package/dist/queries/index.d.ts +1 -1
  109. package/dist/queries/index.js +1 -197
  110. package/dist/queries/isolated.d.ts +1 -1
  111. package/dist/queries/isolated.js +1 -9
  112. package/dist/queries/members.d.ts +1 -1
  113. package/dist/queries/members.js +1 -8
  114. package/dist/queries/methods.d.ts +1 -1
  115. package/dist/queries/methods.js +1 -8
  116. package/dist/queries/outline.d.ts +1 -1
  117. package/dist/queries/outline.js +1 -8
  118. package/dist/queries/passthrough-candidates.d.ts +1 -1
  119. package/dist/queries/passthrough-candidates.js +1 -8
  120. package/dist/queries/redundant-reexports.d.ts +1 -1
  121. package/dist/queries/redundant-reexports.js +1 -9
  122. package/dist/queries/refs.d.ts +1 -1
  123. package/dist/queries/refs.js +1 -8
  124. package/dist/queries/similar-chains.d.ts +1 -1
  125. package/dist/queries/similar-chains.js +1 -8
  126. package/dist/queries/similar-files.d.ts +1 -1
  127. package/dist/queries/similar-files.js +1 -8
  128. package/dist/queries/similar-signatures.d.ts +1 -1
  129. package/dist/queries/similar-signatures.js +1 -8
  130. package/dist/queries/similar.d.ts +1 -1
  131. package/dist/queries/similar.js +1 -10
  132. package/dist/queries/slice.d.ts +1 -1
  133. package/dist/queries/slice.js +1 -8
  134. package/dist/queries/stale-abstractions.d.ts +15 -5
  135. package/dist/queries/stale-abstractions.js +1 -8
  136. package/dist/queries/stats.d.ts +1 -1
  137. package/dist/queries/stats.js +1 -6
  138. package/dist/queries/surface.d.ts +1 -1
  139. package/dist/queries/surface.js +1 -8
  140. package/dist/queries/symbols.d.ts +1 -1
  141. package/dist/queries/symbols.js +1 -9
  142. package/dist/queries/system.d.ts +1 -1
  143. package/dist/queries/system.js +1 -9
  144. package/dist/queries/trace.d.ts +1 -1
  145. package/dist/queries/trace.js +1 -9
  146. package/dist/queries/wrapper-candidates.d.ts +1 -1
  147. package/dist/queries/wrapper-candidates.js +1 -8
  148. package/dist/reindex-worker.js +7 -672
  149. package/package.json +20 -2
  150. package/dist/chunk-2MQ5DPY6.js +0 -61
  151. package/dist/chunk-2QTYIOJ5.js +0 -165
  152. package/dist/chunk-3VI4YXCL.js +0 -172
  153. package/dist/chunk-3VV2G6U7.js +0 -34
  154. package/dist/chunk-44PFXVXG.js +0 -76
  155. package/dist/chunk-6SLFQR36.js +0 -64
  156. package/dist/chunk-74RFWB5T.js +0 -24
  157. package/dist/chunk-7DBPRGMS.js +0 -221
  158. package/dist/chunk-DTB724R3.js +0 -110
  159. package/dist/chunk-FLOYI6I4.js +0 -185
  160. package/dist/chunk-FO2CBB7U.js +0 -23
  161. package/dist/chunk-GJT3MO2T.js +0 -17
  162. package/dist/chunk-HAP4LJKX.js +0 -66
  163. package/dist/chunk-JCOJQ4I6.js +0 -93
  164. package/dist/chunk-JGQMOS4V.js +0 -59
  165. package/dist/chunk-JMD4WJ2Q.js +0 -213
  166. package/dist/chunk-JSQPZOPO.js +0 -64
  167. package/dist/chunk-JSXGC2EH.js +0 -151
  168. package/dist/chunk-JZN3DRCT.js +0 -59
  169. package/dist/chunk-KMWYB3CX.js +0 -71
  170. package/dist/chunk-MRM755FU.js +0 -37
  171. package/dist/chunk-N2XO3Z5F.js +0 -69
  172. package/dist/chunk-OLW5UL36.js +0 -76
  173. package/dist/chunk-OMCRXXDX.js +0 -2600
  174. package/dist/chunk-OWJOHUZE.js +0 -44
  175. package/dist/chunk-P3VCDYMJ.js +0 -269
  176. package/dist/chunk-PEDH3D4G.js +0 -53
  177. package/dist/chunk-POAN4SCR.js +0 -46
  178. package/dist/chunk-PTMGEBU3.js +0 -101
  179. package/dist/chunk-PU44HK7P.js +0 -87
  180. package/dist/chunk-QJI7EECA.js +0 -327
  181. package/dist/chunk-R5HICGMB.js +0 -110
  182. package/dist/chunk-RJ2D6YWQ.js +0 -49
  183. package/dist/chunk-RZ5GYPBP.js +0 -79
  184. package/dist/chunk-SRLQNO6O.js +0 -101
  185. package/dist/chunk-UGS7HJI4.js +0 -84
  186. package/dist/chunk-VKUUXOE7.js +0 -105
  187. package/dist/chunk-VPUJSJCI.js +0 -84
  188. package/dist/chunk-VRWVV3EP.js +0 -72
  189. package/dist/chunk-WJWQEU4A.js +0 -162
  190. package/dist/chunk-WJZHDUSB.js +0 -40
  191. package/dist/chunk-WWOCQ5W4.js +0 -34
  192. package/dist/chunk-X3Q2OVRL.js +0 -77
  193. package/dist/chunk-Y3P7QKKN.js +0 -27
  194. package/dist/chunk-Y6FAHY4N.js +0 -81
  195. package/dist/chunk-YMSJCSRG.js +0 -213
  196. package/dist/chunk-ZDL3U4W2.js +0 -124
  197. package/dist/chunk-ZXNX5JRE.js +0 -216
  198. package/dist/queries/clean-signature.d.ts +0 -17
  199. package/dist/queries/clean-signature.js +0 -9
@@ -1,327 +0,0 @@
1
- import {
2
- findFirstSymbolMatch,
3
- getAllDefinitions,
4
- getCalleeRowsForSymbol,
5
- getSourceText
6
- } from "./chunk-OMCRXXDX.js";
7
- import {
8
- isFunctionLikeSymbol,
9
- leafName,
10
- shortenSymbol
11
- } from "./chunk-YMSJCSRG.js";
12
-
13
- // src/queries/similar.ts
14
- function similar(db, symbolPattern, opts = {}) {
15
- const { minSimilarity = 0.4, limit = 20 } = opts;
16
- const target = findCallees(db, symbolPattern);
17
- if (!target) return [];
18
- if (!isFunctionLikeSymbol(target.symbol)) return [];
19
- const candidates = getAllCalleeFingerprints(db, {
20
- minCallees: 3,
21
- excludeSymbol: target.symbol
22
- });
23
- const allFingerprints = [target, ...candidates];
24
- const idfWeights = computeIdf(allFingerprints);
25
- const results = [];
26
- for (const candidate of candidates) {
27
- if (candidate.callees.size < 3) continue;
28
- const { similarity, significantShared } = weightedSimilarity(
29
- target.callees,
30
- candidate.callees,
31
- idfWeights
32
- );
33
- if (similarity < minSimilarity) continue;
34
- if (significantShared.length < 1) continue;
35
- results.push({
36
- symbolA: target.symbol,
37
- shortNameA: shortenSymbol(target.symbol),
38
- fileA: target.file,
39
- symbolB: candidate.symbol,
40
- shortNameB: shortenSymbol(candidate.symbol),
41
- fileB: candidate.file,
42
- similarity,
43
- sharedCallees: significantShared.map(shortenSymbol),
44
- uniqueToA: [...difference(target.callees, candidate.callees)].map(shortenSymbol),
45
- uniqueToB: [...difference(candidate.callees, target.callees)].map(shortenSymbol)
46
- });
47
- }
48
- results.sort((a, b) => b.similarity - a.similarity);
49
- if (results.length > 0) {
50
- return results.slice(0, limit);
51
- }
52
- return similarBySourceShape(db, symbolPattern, { minSimilarity, limit });
53
- }
54
- function similarAll(db, opts = {}) {
55
- const { minSimilarity = 0.5, limit = 20, scope, minCallees = 4, crossFileOnly = false } = opts;
56
- const all = getAllCalleeFingerprints(db, { minCallees, scope });
57
- const idfWeights = computeIdf(all);
58
- const results = [];
59
- for (let i = 0; i < all.length; i++) {
60
- for (let j = i + 1; j < all.length; j++) {
61
- const a = all[i];
62
- const b = all[j];
63
- if (crossFileOnly && a.file === b.file) continue;
64
- const { similarity, significantShared } = weightedSimilarity(
65
- a.callees,
66
- b.callees,
67
- idfWeights
68
- );
69
- if (similarity < minSimilarity) continue;
70
- const sharedCount = intersection(a.callees, b.callees).size;
71
- if (significantShared.length < 2 && sharedCount < 4) continue;
72
- const displayShared = significantShared.length > 0 ? significantShared : [...intersection(a.callees, b.callees)];
73
- results.push({
74
- symbolA: a.symbol,
75
- shortNameA: shortenSymbol(a.symbol),
76
- fileA: a.file,
77
- symbolB: b.symbol,
78
- shortNameB: shortenSymbol(b.symbol),
79
- fileB: b.file,
80
- similarity,
81
- sharedCallees: displayShared.map(shortenSymbol),
82
- uniqueToA: [...difference(a.callees, b.callees)].map(shortenSymbol),
83
- uniqueToB: [...difference(b.callees, a.callees)].map(shortenSymbol)
84
- });
85
- }
86
- if (results.length > limit * 5) break;
87
- }
88
- results.sort((a, b) => b.similarity - a.similarity);
89
- return results.slice(0, limit);
90
- }
91
- function computeIdf(fingerprints) {
92
- const n = fingerprints.length;
93
- if (n === 0) return /* @__PURE__ */ new Map();
94
- const docFreq = /* @__PURE__ */ new Map();
95
- for (const fp of fingerprints) {
96
- for (const callee of fp.callees) {
97
- docFreq.set(callee, (docFreq.get(callee) ?? 0) + 1);
98
- }
99
- }
100
- const idf = /* @__PURE__ */ new Map();
101
- for (const [callee, df] of docFreq) {
102
- idf.set(callee, Math.log(n / df));
103
- }
104
- return idf;
105
- }
106
- function weightedSimilarity(a, b, idf) {
107
- const shared = intersection(a, b);
108
- if (shared.size === 0) return { similarity: 0, significantShared: [], trivialShared: [] };
109
- let dotProduct = 0;
110
- let magA = 0;
111
- let magB = 0;
112
- const allCallees = /* @__PURE__ */ new Set([...a, ...b]);
113
- for (const callee of allCallees) {
114
- const weight = idf.get(callee) ?? 0;
115
- const inA = a.has(callee) ? weight : 0;
116
- const inB = b.has(callee) ? weight : 0;
117
- dotProduct += inA * inB;
118
- magA += inA * inA;
119
- magB += inB * inB;
120
- }
121
- const magnitude = Math.sqrt(magA) * Math.sqrt(magB);
122
- const similarity = magnitude > 0 ? dotProduct / magnitude : 0;
123
- const medianIdf = getMedianIdf(idf);
124
- const significantShared = [];
125
- const trivialShared = [];
126
- for (const callee of shared) {
127
- const weight = idf.get(callee) ?? 0;
128
- if (weight >= medianIdf) {
129
- significantShared.push(callee);
130
- } else {
131
- trivialShared.push(callee);
132
- }
133
- }
134
- significantShared.sort((x, y) => (idf.get(y) ?? 0) - (idf.get(x) ?? 0));
135
- return { similarity, significantShared, trivialShared };
136
- }
137
- function getMedianIdf(idf) {
138
- const values = [...idf.values()].sort((a, b) => a - b);
139
- if (values.length === 0) return 0;
140
- const mid = Math.floor(values.length / 2);
141
- return values.length % 2 === 0 ? (values[mid - 1] + values[mid]) / 2 : values[mid];
142
- }
143
- function findCallees(db, symbolPattern) {
144
- const target = findFirstSymbolMatch(db, symbolPattern);
145
- if (!target) return null;
146
- const calleeRows = getCalleeRowsForSymbol(db, target);
147
- return {
148
- symbol: target.symbol,
149
- file: target.relativePath,
150
- callees: new Set(calleeRows.map((r) => r.symbol))
151
- };
152
- }
153
- function getAllCalleeFingerprints(db, opts) {
154
- const { minCallees, scope, excludeSymbol } = opts;
155
- const fingerprints = [];
156
- for (const definition of getAllDefinitions(db, { scope })) {
157
- if (db.isIgnored(definition.relativePath)) continue;
158
- if (!definition.isFunctionLike) continue;
159
- if (excludeSymbol && definition.symbol === excludeSymbol) continue;
160
- if (definition.endLine - definition.startLine + 1 < 5) continue;
161
- const callees = new Set(
162
- getCalleeRowsForSymbol(db, definition).map((row) => row.symbol)
163
- );
164
- if (callees.size < minCallees) continue;
165
- fingerprints.push({
166
- symbol: definition.symbol,
167
- file: definition.relativePath,
168
- callees
169
- });
170
- }
171
- return fingerprints;
172
- }
173
- function intersection(a, b) {
174
- const result = /* @__PURE__ */ new Set();
175
- for (const item of a) {
176
- if (b.has(item)) result.add(item);
177
- }
178
- return result;
179
- }
180
- function difference(a, b) {
181
- const result = /* @__PURE__ */ new Set();
182
- for (const item of a) {
183
- if (!b.has(item)) result.add(item);
184
- }
185
- return result;
186
- }
187
- function similarBySourceShape(db, symbolPattern, opts) {
188
- const target = findSourceFingerprint(db, symbolPattern);
189
- if (!target || target.tokens.size < 3) {
190
- return [];
191
- }
192
- const minSimilarity = opts.minSimilarity >= 0.5 ? opts.minSimilarity : 0.3;
193
- const results = [];
194
- for (const candidate of getAllSourceFingerprints(db)) {
195
- if (candidate.symbol === target.symbol || candidate.tokens.size < 3) continue;
196
- const shared = intersection(target.tokens, candidate.tokens);
197
- if (shared.size < 2) continue;
198
- const union = /* @__PURE__ */ new Set([...target.tokens, ...candidate.tokens]);
199
- const similarity = union.size > 0 ? shared.size / union.size : 0;
200
- if (similarity < minSimilarity) continue;
201
- results.push({
202
- symbolA: target.symbol,
203
- shortNameA: shortenSymbol(target.symbol),
204
- fileA: target.file,
205
- symbolB: candidate.symbol,
206
- shortNameB: shortenSymbol(candidate.symbol),
207
- fileB: candidate.file,
208
- similarity,
209
- sharedCallees: [...shared].sort(),
210
- uniqueToA: [...difference(target.tokens, candidate.tokens)].sort(),
211
- uniqueToB: [...difference(candidate.tokens, target.tokens)].sort()
212
- });
213
- }
214
- results.sort((a, b) => b.similarity - a.similarity || a.shortNameB.localeCompare(b.shortNameB));
215
- return results.slice(0, opts.limit);
216
- }
217
- function findSourceFingerprint(db, symbolPattern) {
218
- const match = findFirstSymbolMatch(db, symbolPattern);
219
- if (!match || !isFunctionLikeSymbol(match.symbol)) {
220
- return null;
221
- }
222
- const snippet = definitionSnippet(db, match.relativePath, match.startLine, match.endLine, leafName(match.symbol));
223
- const tokens = sourceTokens(snippet, leafName(match.symbol));
224
- if (tokens.size === 0) {
225
- return null;
226
- }
227
- return {
228
- symbol: match.symbol,
229
- file: match.relativePath,
230
- tokens
231
- };
232
- }
233
- function getAllSourceFingerprints(db) {
234
- return getAllDefinitions(db).filter((definition) => definition.isFunctionLike).map((definition) => ({
235
- symbol: definition.symbol,
236
- file: definition.relativePath,
237
- tokens: sourceTokens(
238
- definitionSnippet(db, definition.relativePath, definition.startLine, definition.endLine, definition.leaf),
239
- definition.leaf
240
- )
241
- })).filter((fingerprint) => fingerprint.tokens.size > 0);
242
- }
243
- function definitionSnippet(db, relativePath, startLine, endLine, leaf) {
244
- const source = getSourceText(db, relativePath);
245
- if (!source) {
246
- return "";
247
- }
248
- const lines = source.split("\n");
249
- if (endLine >= startLine && endLine - startLine <= 12) {
250
- return lines.slice(startLine, endLine + 1).join("\n");
251
- }
252
- const markerPatterns = [
253
- new RegExp(`\\bdef\\s+${escapeRegex(leaf)}\\b`),
254
- new RegExp(`\\bfun\\s+${escapeRegex(leaf)}\\b`),
255
- new RegExp(`\\bfn\\s+${escapeRegex(leaf)}\\b`),
256
- new RegExp(`\\bfunction\\s+${escapeRegex(leaf)}\\b`),
257
- new RegExp(`\\b${escapeRegex(leaf)}\\s*\\(`)
258
- ];
259
- const definitionStart = lines.findIndex((line) => markerPatterns.some((pattern) => pattern.test(line)));
260
- if (definitionStart >= 0) {
261
- let definitionEnd = definitionStart;
262
- for (let index = definitionStart + 1; index < lines.length && index <= definitionStart + 8; index++) {
263
- const line = lines[index] ?? "";
264
- if (index > definitionStart && looksLikeDefinitionBoundary(line)) {
265
- break;
266
- }
267
- definitionEnd = index;
268
- if (line.trim() === "" && index > definitionStart + 1) {
269
- break;
270
- }
271
- }
272
- return lines.slice(definitionStart, definitionEnd + 1).join("\n");
273
- }
274
- return lines.slice(startLine, Math.min(lines.length, startLine + 8)).join("\n");
275
- }
276
- function sourceTokens(snippet, leaf) {
277
- if (!snippet) {
278
- return /* @__PURE__ */ new Set();
279
- }
280
- const stopWords = /* @__PURE__ */ new Set([
281
- "public",
282
- "private",
283
- "protected",
284
- "final",
285
- "static",
286
- "class",
287
- "def",
288
- "fun",
289
- "fn",
290
- "function",
291
- "return",
292
- "string",
293
- "bool",
294
- "boolean",
295
- "void",
296
- "unit",
297
- "self",
298
- "this",
299
- "new",
300
- "const",
301
- "let",
302
- "var",
303
- "end",
304
- "pub"
305
- ]);
306
- const normalizedLeafParts = splitIdentifier(leaf);
307
- const normalized = snippet.replace(/["'`]/g, " ").replace(/\b\d+\b/g, " NUM ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^A-Za-z0-9_]+/g, " ").replace(/_/g, " ").toLowerCase();
308
- const tokens = normalized.split(/\s+/).map((token) => token.trim()).filter((token) => token.length > 1).filter((token) => !stopWords.has(token)).filter((token) => !normalizedLeafParts.has(token));
309
- return new Set(tokens);
310
- }
311
- function splitIdentifier(value) {
312
- return new Set(
313
- value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9_]+|_/).map((part) => part.toLowerCase()).filter((part) => part.length > 1)
314
- );
315
- }
316
- function looksLikeDefinitionBoundary(line) {
317
- return /^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(line);
318
- }
319
- function escapeRegex(value) {
320
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
321
- }
322
-
323
- export {
324
- similar,
325
- similarAll
326
- };
327
- //# sourceMappingURL=chunk-QJI7EECA.js.map
@@ -1,110 +0,0 @@
1
- import {
2
- getInactiveBarrelPaths,
3
- isEntrySurface
4
- } from "./chunk-UGS7HJI4.js";
5
- import {
6
- TEST_FILE_PATTERNS,
7
- TEST_SUPPORT_PATH_PATTERNS,
8
- getAllDefinitions
9
- } from "./chunk-OMCRXXDX.js";
10
- import {
11
- isFunctionLikeSymbol,
12
- isModuleLikeSymbol,
13
- shortenSymbol
14
- } from "./chunk-YMSJCSRG.js";
15
-
16
- // src/queries/dead.ts
17
- function dead(db, opts = {}) {
18
- const {
19
- scope,
20
- minLoc = 1,
21
- includeTests = false,
22
- skipBarrels = false,
23
- includeMembers = false
24
- } = opts;
25
- const inactiveBarrelPaths = skipBarrels ? new Set(getInactiveBarrelPaths(db)) : /* @__PURE__ */ new Set();
26
- const referenceRows = db.all(
27
- `SELECT
28
- m.symbol_id,
29
- d.relative_path,
30
- COUNT(*) AS ref_count
31
- FROM mentions m
32
- JOIN chunks c ON m.chunk_id = c.id
33
- JOIN documents d ON c.document_id = d.id
34
- WHERE m.role != 1
35
- ${db.pathExclusionsFor("d")}
36
- GROUP BY m.symbol_id, d.relative_path`
37
- );
38
- const referencesBySymbol = /* @__PURE__ */ new Map();
39
- for (const row of referenceRows) {
40
- if (db.isIgnored(row.relative_path)) continue;
41
- if (inactiveBarrelPaths.has(row.relative_path)) continue;
42
- let refsForSymbol = referencesBySymbol.get(row.symbol_id);
43
- if (!refsForSymbol) {
44
- refsForSymbol = /* @__PURE__ */ new Map();
45
- referencesBySymbol.set(row.symbol_id, refsForSymbol);
46
- }
47
- refsForSymbol.set(row.relative_path, row.ref_count);
48
- }
49
- const definitions = getAllDefinitions(db, { scope }).filter((definition) => !db.isIgnored(definition.relativePath)).filter((definition) => !isModuleLikeSymbol(definition.symbol)).filter((definition) => looksValueLikeDefinition(definition.symbol)).filter((definition) => definition.isFunctionLike || !definition.enclosingSymbol || !looksValueLikeDefinition(definition.enclosingSymbol)).filter((definition) => includeTests || passesTestFileFilter(definition.relativePath)).filter((definition) => includeMembers || looksValueLikeDefinition(definition.symbol)).filter((definition) => definition.endLine - definition.startLine + 1 >= minLoc);
50
- const rows = definitions.map((definition) => {
51
- const refMap = referencesBySymbol.get(definition.symbolId) ?? /* @__PURE__ */ new Map();
52
- const sameFileRefs = refMap.get(definition.relativePath) ?? 0;
53
- let crossFileRefs = 0;
54
- for (const [relativePath, count] of refMap) {
55
- if (relativePath === definition.relativePath) continue;
56
- crossFileRefs += count;
57
- }
58
- return {
59
- relative_path: definition.relativePath,
60
- start_line: definition.startLine,
61
- end_line: definition.endLine,
62
- loc: definition.endLine - definition.startLine + 1,
63
- symbol: definition.symbol,
64
- same_file_refs: sameFileRefs,
65
- cross_file_refs: crossFileRefs
66
- };
67
- }).filter((row) => row.cross_file_refs === 0).sort((a, b) => b.loc - a.loc || a.relative_path.localeCompare(b.relative_path) || a.start_line - b.start_line);
68
- let deadCodeCount = 0;
69
- let fileInternalCount = 0;
70
- let totalLoc = 0;
71
- const symbols = rows.filter((r) => !db.isIgnored(r.relative_path)).filter((r) => !isEntrySurface(db, r.relative_path)).map((r) => {
72
- const kind = r.same_file_refs === 0 ? "dead-code" : "file-internal";
73
- if (kind === "dead-code") deadCodeCount++;
74
- else fileInternalCount++;
75
- totalLoc += r.loc;
76
- return {
77
- relativePath: r.relative_path,
78
- startLine: r.start_line,
79
- endLine: r.end_line,
80
- loc: r.loc,
81
- symbol: r.symbol,
82
- shortName: shortenSymbol(r.symbol),
83
- sameFileRefs: r.same_file_refs,
84
- kind
85
- };
86
- });
87
- return {
88
- symbols,
89
- totalCount: symbols.length,
90
- deadCodeCount,
91
- fileInternalCount,
92
- totalLoc
93
- };
94
- }
95
- function passesTestFileFilter(relativePath) {
96
- const patterns = [.../* @__PURE__ */ new Set([...TEST_FILE_PATTERNS, ...TEST_SUPPORT_PATH_PATTERNS])];
97
- return patterns.every((pattern) => !likeMatches(relativePath, pattern));
98
- }
99
- function likeMatches(value, pattern) {
100
- const regex = new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/%/g, ".*").replace(/_/g, ".")}$`);
101
- return regex.test(value);
102
- }
103
- function looksValueLikeDefinition(rawSymbol) {
104
- return isFunctionLikeSymbol(rawSymbol) || rawSymbol.endsWith("().") || rawSymbol.endsWith(".");
105
- }
106
-
107
- export {
108
- dead
109
- };
110
- //# sourceMappingURL=chunk-R5HICGMB.js.map
@@ -1,49 +0,0 @@
1
- import {
2
- getCalleeRowsForSymbol,
3
- getScopedDefinitions
4
- } from "./chunk-OMCRXXDX.js";
5
- import {
6
- isFunctionLikeSymbol,
7
- shortenSymbol
8
- } from "./chunk-YMSJCSRG.js";
9
-
10
- // src/queries/passthrough-candidates.ts
11
- function passthroughCandidates(db, opts) {
12
- const { scope, maxLoc = 15, limit = 30 } = opts ?? {};
13
- const symbols = getScopedDefinitions(db, scope).filter((definition) => definitionLoc(definition) >= 3 && definitionLoc(definition) <= maxLoc);
14
- const results = [];
15
- for (const sym of symbols) {
16
- if (db.isIgnored(sym.relativePath) || !isFunctionLikeSymbol(sym.symbol)) continue;
17
- const rawCallees = getCalleeRowsForSymbol(db, sym);
18
- const callees = rawCallees.some((callee2) => isFunctionLikeSymbol(callee2.symbol)) ? rawCallees.filter((callee2) => isFunctionLikeSymbol(callee2.symbol)) : rawCallees;
19
- const uniqueCallees = /* @__PURE__ */ new Map();
20
- for (const c of callees) {
21
- if (!uniqueCallees.has(c.symbol)) {
22
- uniqueCallees.set(c.symbol, { symbol: c.symbol, file: c.file });
23
- }
24
- }
25
- if (uniqueCallees.size !== 1) continue;
26
- const [, callee] = [...uniqueCallees.entries()][0];
27
- results.push({
28
- symbol: sym.symbol,
29
- shortName: shortenSymbol(sym.symbol),
30
- file: sym.relativePath,
31
- startLine: sym.startLine,
32
- endLine: sym.endLine,
33
- loc: definitionLoc(sym),
34
- forwardsTo: callee.symbol,
35
- forwardsToShort: shortenSymbol(callee.symbol),
36
- forwardsToFile: callee.file
37
- });
38
- }
39
- results.sort((a, b) => a.loc - b.loc || a.file.localeCompare(b.file));
40
- return results.slice(0, limit);
41
- }
42
- function definitionLoc(definition) {
43
- return definition.endLine - definition.startLine + 1;
44
- }
45
-
46
- export {
47
- passthroughCandidates
48
- };
49
- //# sourceMappingURL=chunk-RJ2D6YWQ.js.map
@@ -1,79 +0,0 @@
1
- import {
2
- getAllDefinitions,
3
- getCalleeRowsForSymbol,
4
- getCallerRowsForSymbol
5
- } from "./chunk-OMCRXXDX.js";
6
- import {
7
- shortenSymbol
8
- } from "./chunk-YMSJCSRG.js";
9
-
10
- // src/queries/bottlenecks.ts
11
- function bottlenecks(db, opts = {}) {
12
- const { limit = 20, scope, minFanIn = 2, minFanOut = 2 } = opts;
13
- const scopeFilter = scope ? `AND def_d.relative_path LIKE '%${scope}%'` : "";
14
- const rows = db.all(
15
- `SELECT * FROM (
16
- SELECT
17
- gs.symbol,
18
- def_d.relative_path AS defined_in,
19
- (SELECT COUNT(DISTINCT ref_c.document_id)
20
- FROM mentions ref_m
21
- JOIN chunks ref_c ON ref_m.chunk_id = ref_c.id
22
- WHERE ref_m.symbol_id = gs.id AND ref_m.role != 1
23
- ) AS fan_in,
24
- (SELECT COUNT(DISTINCT ref_gs.id)
25
- FROM mentions ref_m
26
- JOIN chunks ref_c ON ref_m.chunk_id = ref_c.id
27
- JOIN global_symbols ref_gs ON ref_m.symbol_id = ref_gs.id
28
- JOIN defn_enclosing_ranges ref_der ON ref_gs.id = ref_der.symbol_id
29
- WHERE ref_c.document_id = def_d.id
30
- AND ref_m.role != 1
31
- AND ref_der.document_id != def_d.id
32
- ) AS fan_out
33
- FROM global_symbols gs
34
- JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
35
- JOIN documents def_d ON der.document_id = def_d.id
36
- WHERE 1 = 1
37
- ${db.pathExclusionsFor("def_d")}
38
- ${db.symbolNoiseFor("gs")}
39
- ${scopeFilter}
40
- ) WHERE fan_in >= ? AND fan_out >= ?
41
- ORDER BY (fan_in * fan_out) DESC
42
- LIMIT ?`,
43
- minFanIn,
44
- minFanOut,
45
- limit
46
- );
47
- const indexedResults = rows.filter((r) => !db.isIgnored(r.defined_in)).map((r) => ({
48
- symbol: r.symbol,
49
- shortName: shortenSymbol(r.symbol),
50
- fanIn: r.fan_in,
51
- fanOut: r.fan_out,
52
- score: r.fan_in * r.fan_out,
53
- definedIn: r.defined_in
54
- }));
55
- if (indexedResults.length > 0) {
56
- return indexedResults;
57
- }
58
- return getAllDefinitions(db, { scope }).filter((definition) => !db.isIgnored(definition.relativePath)).map((definition) => {
59
- const fanIn = new Set(
60
- getCallerRowsForSymbol(db, definition, { limit: 500 }).map((row) => row.file)
61
- ).size;
62
- const fanOut = new Set(
63
- getCalleeRowsForSymbol(db, definition, { limit: 500 }).filter((row) => row.file !== definition.relativePath).map((row) => `${row.symbol}|${row.file}`)
64
- ).size;
65
- return {
66
- symbol: definition.symbol,
67
- shortName: shortenSymbol(definition.symbol),
68
- fanIn,
69
- fanOut,
70
- score: fanIn * fanOut,
71
- definedIn: definition.relativePath
72
- };
73
- }).filter((row) => row.fanIn >= minFanIn && row.fanOut >= minFanOut).sort((left, right) => right.score - left.score || right.fanIn - left.fanIn).slice(0, limit);
74
- }
75
-
76
- export {
77
- bottlenecks
78
- };
79
- //# sourceMappingURL=chunk-RZ5GYPBP.js.map
@@ -1,101 +0,0 @@
1
- import {
2
- findEnclosingDefinition,
3
- findExactSymbolMatch,
4
- findFirstSymbolMatch,
5
- getCalleeRowsForSymbol,
6
- getDefinitionsForFile,
7
- getResolvedReferenceSites,
8
- getSourceReferenceSites
9
- } from "./chunk-OMCRXXDX.js";
10
- import {
11
- shortenSymbol
12
- } from "./chunk-YMSJCSRG.js";
13
-
14
- // src/queries/slice.ts
15
- function slice(db, symbolPattern, opts = {}) {
16
- const { direction = "backward", maxDepth = 3 } = opts;
17
- const match = findFirstSymbolMatch(db, symbolPattern);
18
- if (!match) return null;
19
- if (direction === "backward") {
20
- return backwardSlice(db, match, maxDepth);
21
- } else {
22
- return forwardSlice(db, match);
23
- }
24
- }
25
- function backwardSlice(db, match, maxDepth) {
26
- const connected = [];
27
- const visited = /* @__PURE__ */ new Set([match.symbol]);
28
- let frontier = [match];
29
- for (let depth = 1; depth <= maxDepth; depth++) {
30
- if (frontier.length === 0) break;
31
- const nextFrontier = [];
32
- for (const current of frontier) {
33
- const callees = getCalleeRowsForSymbol(db, current);
34
- for (const c of callees) {
35
- if (visited.has(c.symbol)) continue;
36
- visited.add(c.symbol);
37
- connected.push({
38
- symbol: c.symbol,
39
- shortName: shortenSymbol(c.symbol),
40
- file: c.file,
41
- relationship: depth === 1 ? "referenced within definition (callee)" : `depth ${depth} callee`
42
- });
43
- const calleeMatch = findExactSymbolMatch(db, c.symbol);
44
- if (calleeMatch && !db.isIgnored(calleeMatch.relativePath)) {
45
- nextFrontier.push(calleeMatch);
46
- }
47
- }
48
- }
49
- frontier = nextFrontier;
50
- }
51
- return {
52
- symbol: match.symbol,
53
- shortName: shortenSymbol(match.symbol),
54
- direction: "backward",
55
- connectedSymbols: connected
56
- };
57
- }
58
- function forwardSlice(db, match) {
59
- const sourceRefs = getSourceReferenceSites(db, match);
60
- const refs = sourceRefs.length > 0 ? sourceRefs : getResolvedReferenceSites(db, match);
61
- const seenOutputs = /* @__PURE__ */ new Set();
62
- const connected = [];
63
- for (const ref of refs) {
64
- if (connected.length >= 30) break;
65
- if (db.isIgnored(ref.file)) continue;
66
- const enclosingSymbol = ref.enclosingSymbol ?? findEnclosingDefinition(
67
- getDefinitionsForFile(db, ref.file),
68
- ref.line
69
- )?.symbol ?? null;
70
- if (!enclosingSymbol || enclosingSymbol === match.symbol) continue;
71
- const enclosingMatch = findExactSymbolMatch(db, enclosingSymbol);
72
- if (!enclosingMatch) continue;
73
- for (const callee of getCalleeRowsForSymbol(db, enclosingMatch)) {
74
- if (callee.symbol === match.symbol) continue;
75
- if (callee.symbol === enclosingSymbol) continue;
76
- if (callee.file === ref.file) continue;
77
- if (db.isIgnored(callee.file)) continue;
78
- if (seenOutputs.has(callee.symbol)) continue;
79
- seenOutputs.add(callee.symbol);
80
- connected.push({
81
- symbol: callee.symbol,
82
- shortName: shortenSymbol(callee.symbol),
83
- file: callee.file,
84
- relationship: `used alongside target in ${shortenSymbol(enclosingSymbol)}`
85
- });
86
- if (connected.length >= 30) break;
87
- }
88
- }
89
- connected.sort((a, b) => a.file.localeCompare(b.file));
90
- return {
91
- symbol: match.symbol,
92
- shortName: shortenSymbol(match.symbol),
93
- direction: "forward",
94
- connectedSymbols: connected
95
- };
96
- }
97
-
98
- export {
99
- slice
100
- };
101
- //# sourceMappingURL=chunk-SRLQNO6O.js.map