scip-query 0.4.3 → 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 -8938
  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 +4 -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 -3
  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 +4 -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 +4 -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 +6 -2
  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-334PCFO3.js +0 -221
  151. package/dist/chunk-46ZTW4AI.js +0 -61
  152. package/dist/chunk-4TYLS5XX.js +0 -10
  153. package/dist/chunk-4YN3PE57.js +0 -124
  154. package/dist/chunk-5YB6UXQ3.js +0 -101
  155. package/dist/chunk-6PVHJ332.js +0 -44
  156. package/dist/chunk-74RFWB5T.js +0 -24
  157. package/dist/chunk-7KGTWDAX.js +0 -87
  158. package/dist/chunk-7OGXSMLY.js +0 -105
  159. package/dist/chunk-AEBM56CO.js +0 -69
  160. package/dist/chunk-B747RITP.js +0 -38
  161. package/dist/chunk-B7LDMCUS.js +0 -110
  162. package/dist/chunk-C2VSV54P.js +0 -110
  163. package/dist/chunk-DIYEUFVP.js +0 -81
  164. package/dist/chunk-E74RY6AQ.js +0 -93
  165. package/dist/chunk-FIMTTUGE.js +0 -165
  166. package/dist/chunk-FMAYH7GS.js +0 -2542
  167. package/dist/chunk-FO2CBB7U.js +0 -23
  168. package/dist/chunk-HESWGDIV.js +0 -162
  169. package/dist/chunk-HL2LXSBW.js +0 -34
  170. package/dist/chunk-HW76DVE4.js +0 -216
  171. package/dist/chunk-IC5NTO47.js +0 -53
  172. package/dist/chunk-J34HAAEQ.js +0 -59
  173. package/dist/chunk-JSXGC2EH.js +0 -151
  174. package/dist/chunk-LQXBFCP2.js +0 -87
  175. package/dist/chunk-NML6M5AS.js +0 -37
  176. package/dist/chunk-NNFP4ZRF.js +0 -72
  177. package/dist/chunk-NWXTQGUE.js +0 -49
  178. package/dist/chunk-NYZ6INK3.js +0 -95
  179. package/dist/chunk-OMVF3BHY.js +0 -84
  180. package/dist/chunk-P3VCDYMJ.js +0 -269
  181. package/dist/chunk-PGQXIAJF.js +0 -79
  182. package/dist/chunk-PKDFXASW.js +0 -76
  183. package/dist/chunk-PSK5BPFE.js +0 -82
  184. package/dist/chunk-QZ4FRB65.js +0 -341
  185. package/dist/chunk-R2QBMQQN.js +0 -185
  186. package/dist/chunk-T3ALCNCP.js +0 -113
  187. package/dist/chunk-T6UVM534.js +0 -213
  188. package/dist/chunk-U74VYTLX.js +0 -46
  189. package/dist/chunk-UIRCHPOU.js +0 -34
  190. package/dist/chunk-UNS6ZQVX.js +0 -71
  191. package/dist/chunk-VJMTX3OR.js +0 -115
  192. package/dist/chunk-XJSPWHNT.js +0 -64
  193. package/dist/chunk-XMZAC2VU.js +0 -84
  194. package/dist/chunk-Y7FKURZG.js +0 -130
  195. package/dist/chunk-YMSJCSRG.js +0 -213
  196. package/dist/chunk-YQIWS5V6.js +0 -172
  197. package/dist/chunk-ZPEI7DRJ.js +0 -66
  198. package/dist/queries/clean-signature.d.ts +0 -9
  199. package/dist/queries/clean-signature.js +0 -7
@@ -1,87 +0,0 @@
1
- import {
2
- findFirstSymbolMatch,
3
- getCalleeRowsForSymbol,
4
- getSourceReferenceSites
5
- } from "./chunk-FMAYH7GS.js";
6
- import {
7
- shortenSymbol
8
- } from "./chunk-YMSJCSRG.js";
9
-
10
- // src/queries/dataflow.ts
11
- function dataflow(db, symbolPattern) {
12
- const match = findFirstSymbolMatch(db, symbolPattern);
13
- if (!match) return null;
14
- const defSites = [{
15
- file: match.relativePath,
16
- line: match.startLine
17
- }];
18
- const sourceUsageSites = getSourceReferenceSites(db, match);
19
- const usageSites = sourceUsageSites.length > 0 ? sourceUsageSites.map((site) => ({
20
- file: site.file,
21
- line: site.line,
22
- enclosing_symbol: site.enclosingSymbol
23
- })) : db.all(
24
- `SELECT d.relative_path AS file, c.start_line AS line,
25
- (SELECT enc_gs.symbol
26
- FROM defn_enclosing_ranges enc_der
27
- JOIN global_symbols enc_gs ON enc_der.symbol_id = enc_gs.id
28
- WHERE enc_der.document_id = d.id
29
- AND enc_der.start_line <= c.start_line
30
- AND enc_der.end_line >= c.end_line
31
- ORDER BY (enc_der.end_line - enc_der.start_line) ASC
32
- LIMIT 1
33
- ) AS enclosing_symbol
34
- FROM mentions m
35
- JOIN chunks c ON m.chunk_id = c.id
36
- JOIN documents d ON c.document_id = d.id
37
- WHERE m.symbol_id = ? AND m.role != 1
38
- ${db.pathExclusionsFor("d")}
39
- ORDER BY d.relative_path, c.start_line`,
40
- match.symbolId
41
- );
42
- const normalizedUsageSites = usageSites.filter((site) => !db.isIgnored(site.file)).map((site) => ({
43
- file: site.file,
44
- line: site.line,
45
- enclosingSymbol: site.enclosing_symbol ?? "(top-level)",
46
- enclosingShort: site.enclosing_symbol ? shortenSymbol(site.enclosing_symbol) : "(top-level)"
47
- }));
48
- const producers = uniqueSymbolRows(getCalleeRowsForSymbol(db, match, { limit: 30 }).map((row) => ({
49
- symbol: row.symbol,
50
- file: row.file
51
- })));
52
- const consumers = uniqueSymbolRows(
53
- normalizedUsageSites.map((site) => ({
54
- symbol: site.enclosingSymbol === "(top-level)" ? site.file : site.enclosingSymbol,
55
- file: site.file
56
- }))
57
- );
58
- return {
59
- symbol: match.symbol,
60
- shortName: shortenSymbol(match.symbol),
61
- relativePath: match.relativePath,
62
- definitionSites: defSites.filter((s) => !db.isIgnored(s.file)),
63
- usageSites: normalizedUsageSites,
64
- producers: producers.filter((p) => !db.isIgnored(p.file)).map((p) => ({ symbol: p.symbol, shortName: shortenSymbol(p.symbol), file: p.file })),
65
- consumers: consumers.filter((c) => !db.isIgnored(c.file)).map((c) => ({
66
- symbol: c.symbol,
67
- shortName: c.symbol === c.file ? "(top-level)" : shortenSymbol(c.symbol),
68
- file: c.file
69
- }))
70
- };
71
- }
72
- function uniqueSymbolRows(rows) {
73
- const seen = /* @__PURE__ */ new Set();
74
- const unique = [];
75
- for (const row of rows) {
76
- const key = `${row.symbol}|${row.file}`;
77
- if (seen.has(key)) continue;
78
- seen.add(key);
79
- unique.push(row);
80
- }
81
- return unique;
82
- }
83
-
84
- export {
85
- dataflow
86
- };
87
- //# sourceMappingURL=chunk-7KGTWDAX.js.map
@@ -1,105 +0,0 @@
1
- import {
2
- buildFileDepGraph,
3
- getCallerRowsForSymbol,
4
- getDefinitionsForFile,
5
- getScopedDefinitions
6
- } from "./chunk-FMAYH7GS.js";
7
- import {
8
- isFunctionLikeSymbol,
9
- shortenSymbol
10
- } from "./chunk-YMSJCSRG.js";
11
-
12
- // src/queries/wrapper-candidates.ts
13
- import { basename, extname } from "path";
14
- function wrapperCandidates(db, opts) {
15
- const { scope, maxLoc = 15, limit = 30 } = opts ?? {};
16
- const reverseFanIn = buildReverseFileFanIn(buildFileDepGraph(db, scope));
17
- const symbols = getScopedDefinitions(db, scope).filter((definition) => definitionLoc(definition) <= maxLoc && definitionLoc(definition) >= 2);
18
- const results = [];
19
- for (const symbol of symbols) {
20
- if (db.isIgnored(symbol.relativePath) || !isFunctionLikeSymbol(symbol.symbol)) continue;
21
- const symbolStem = basename(symbol.relativePath, extname(symbol.relativePath));
22
- const callerRows = dedupeRows(
23
- getCallerRowsForSymbol(db, symbol, { limit: 200 }).filter((row) => row.file !== symbol.relativePath)
24
- ).filter((row) => basename(row.file, extname(row.file)) !== symbolStem);
25
- if (callerRows.length !== 1) continue;
26
- const caller = callerRows[0];
27
- const callerDefinition = getDefinitionsForFile(db, caller.file).find((definition) => definition.symbol === caller.symbol);
28
- const useDefinitionFanIn = callerDefinition?.isFunctionLike ?? false;
29
- let callerFanIn;
30
- if (useDefinitionFanIn && callerDefinition) {
31
- callerFanIn = new Set(
32
- getCallerRowsForSymbol(db, callerDefinition, { limit: 500 }).filter((row) => row.file !== callerDefinition.relativePath).map((row) => row.file)
33
- ).size;
34
- } else {
35
- callerFanIn = fallbackCallerFanIn(db, reverseFanIn, caller.file);
36
- }
37
- if (callerFanIn <= 3) continue;
38
- results.push({
39
- symbol: symbol.symbol,
40
- shortName: shortenSymbol(symbol.symbol),
41
- file: symbol.relativePath,
42
- startLine: symbol.startLine,
43
- endLine: symbol.endLine,
44
- loc: definitionLoc(symbol),
45
- singleCaller: caller.symbol,
46
- singleCallerShort: useDefinitionFanIn ? shortenSymbol(caller.symbol) : basename(caller.file),
47
- callerFanIn
48
- });
49
- }
50
- results.sort((left, right) => right.callerFanIn - left.callerFanIn || right.loc - left.loc);
51
- return results.slice(0, limit);
52
- }
53
- function definitionLoc(definition) {
54
- return definition.endLine - definition.startLine + 1;
55
- }
56
- function dedupeRows(rows) {
57
- const seen = /* @__PURE__ */ new Set();
58
- const unique = [];
59
- for (const row of rows) {
60
- const key = `${row.symbol}|${row.file}`;
61
- if (seen.has(key)) continue;
62
- seen.add(key);
63
- unique.push(row);
64
- }
65
- return unique;
66
- }
67
- function buildReverseFileFanIn(graph) {
68
- const reverse = /* @__PURE__ */ new Map();
69
- for (const [fromFile, deps] of graph) {
70
- if (!reverse.has(fromFile)) {
71
- reverse.set(fromFile, reverse.get(fromFile) ?? 0);
72
- }
73
- for (const dep of deps) {
74
- reverse.set(dep, (reverse.get(dep) ?? 0) + 1);
75
- }
76
- }
77
- return reverse;
78
- }
79
- function fallbackCallerFanIn(db, reverseFanIn, callerFile) {
80
- const functionLikeFanIn = getDefinitionsForFile(db, callerFile).filter((definition) => definition.isFunctionLike).map((definition) => new Set(
81
- getCallerRowsForSymbol(db, definition, { limit: 500 }).filter((row) => row.file !== definition.relativePath).map((row) => row.file)
82
- ).size).sort((left, right) => right - left)[0] ?? 0;
83
- if (functionLikeFanIn > 0) {
84
- return functionLikeFanIn;
85
- }
86
- const direct = reverseFanIn.get(callerFile) ?? 0;
87
- if (direct > 0) {
88
- return direct;
89
- }
90
- const stem = basename(callerFile, extname(callerFile));
91
- let best = 0;
92
- for (const [file, fanIn] of reverseFanIn) {
93
- if (file === callerFile) continue;
94
- if (basename(file, extname(file)) !== stem) continue;
95
- if (fanIn > best) {
96
- best = fanIn;
97
- }
98
- }
99
- return best;
100
- }
101
-
102
- export {
103
- wrapperCandidates
104
- };
105
- //# sourceMappingURL=chunk-7OGXSMLY.js.map
@@ -1,69 +0,0 @@
1
- import {
2
- findFirstSymbolMatch
3
- } from "./chunk-FMAYH7GS.js";
4
- import {
5
- parseSymbol,
6
- shortenSymbol
7
- } from "./chunk-YMSJCSRG.js";
8
-
9
- // src/queries/hierarchy.ts
10
- function hierarchy(db, symbolPattern) {
11
- const match = findFirstSymbolMatch(db, symbolPattern);
12
- if (!match) return [];
13
- const sym = db.get(
14
- `SELECT symbol, enclosing_symbol FROM global_symbols
15
- WHERE id = ? LIMIT 1`,
16
- match.symbolId
17
- );
18
- if (!sym) return [];
19
- const chain = [
20
- { symbol: sym.symbol, shortName: shortenSymbol(sym.symbol), depth: 0 }
21
- ];
22
- let current = sym.enclosing_symbol;
23
- let depth = 1;
24
- const seen = /* @__PURE__ */ new Set([sym.symbol]);
25
- while (current && !seen.has(current) && depth < 20) {
26
- seen.add(current);
27
- const parent = db.get(
28
- `SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?`,
29
- current
30
- );
31
- if (!parent) break;
32
- chain.push({
33
- symbol: parent.symbol,
34
- shortName: shortenSymbol(parent.symbol),
35
- depth
36
- });
37
- current = parent.enclosing_symbol;
38
- depth++;
39
- }
40
- if (chain.length > 1) {
41
- return chain;
42
- }
43
- const parsed = parseSymbol(sym.symbol);
44
- if ("kind" in parsed) {
45
- return chain;
46
- }
47
- const descriptors = parsed.descriptors;
48
- if (descriptors.length <= 1) {
49
- return chain;
50
- }
51
- const syntheticChain = [chain[0]];
52
- for (let i = descriptors.length - 2, syntheticDepth = 1; i >= 0; i--, syntheticDepth++) {
53
- const partial = descriptors.slice(0, i + 1);
54
- const shortName = partial.map(
55
- (descriptor) => descriptor.suffix === "method" ? `${descriptor.name}()` : descriptor.name.replace(/\.(ts|tsx|js|jsx|mjs|cjs|py|pyi|rs|java|scala|kt|kts|rb|go|cs|vb|dart|php|c|cc|cpp|cxx|h|hpp)$/, "")
56
- ).join(":");
57
- syntheticChain.push({
58
- symbol: shortName,
59
- shortName,
60
- depth: syntheticDepth
61
- });
62
- }
63
- return syntheticChain;
64
- }
65
-
66
- export {
67
- hierarchy
68
- };
69
- //# sourceMappingURL=chunk-AEBM56CO.js.map
@@ -1,38 +0,0 @@
1
- import {
2
- cleanSignature
3
- } from "./chunk-4TYLS5XX.js";
4
- import {
5
- getDefinitionsForFile,
6
- resolveIndexedPaths
7
- } from "./chunk-FMAYH7GS.js";
8
- import {
9
- shortenSymbol
10
- } from "./chunk-YMSJCSRG.js";
11
-
12
- // src/queries/symbols.ts
13
- function symbols(db, filePattern) {
14
- const resolvedPaths = resolveIndexedPaths(db, filePattern);
15
- if (resolvedPaths.length === 0) {
16
- return [];
17
- }
18
- return resolvedPaths.flatMap((relativePath) => getDefinitionsForFile(db, relativePath)).filter((row) => !db.isIgnored(row.relativePath)).map((row) => {
19
- const docRow = db.get(
20
- `SELECT REPLACE(SUBSTR(documentation, INSTR(documentation, '|') + 1), char(10), ' ') AS sig
21
- FROM global_symbols
22
- WHERE id = ?`,
23
- row.symbolId
24
- );
25
- return {
26
- startLine: row.startLine,
27
- endLine: row.endLine,
28
- symbol: row.symbol,
29
- shortName: shortenSymbol(row.symbol),
30
- signature: cleanSignature(docRow?.sig ?? null)
31
- };
32
- });
33
- }
34
-
35
- export {
36
- symbols
37
- };
38
- //# sourceMappingURL=chunk-B747RITP.js.map
@@ -1,110 +0,0 @@
1
- import {
2
- findFirstSymbolMatch,
3
- getCalleeRowsForSymbol
4
- } from "./chunk-FMAYH7GS.js";
5
- import {
6
- shortenSymbol
7
- } from "./chunk-YMSJCSRG.js";
8
-
9
- // src/queries/complexity.ts
10
- import { readFileSync } from "fs";
11
- import { join } from "path";
12
- function complexity(db, symbolPattern) {
13
- const match = findFirstSymbolMatch(db, symbolPattern);
14
- if (!match) return null;
15
- const doc = db.get(
16
- `SELECT language FROM documents WHERE relative_path = ?`,
17
- match.relativePath
18
- );
19
- const language = doc?.language ?? "unknown";
20
- const filePath = join(db.config.projectRoot, match.relativePath);
21
- let source = "";
22
- try {
23
- const lines = readFileSync(filePath, "utf-8").split("\n");
24
- source = lines.slice(match.startLine, match.endLine + 1).join("\n");
25
- } catch {
26
- }
27
- const branches = countBranches(source, language);
28
- const loc = match.endLine - match.startLine + 1;
29
- const callees = getCalleeRowsForSymbol(db, match);
30
- const uniqueCallees = new Set(callees.map((c) => c.symbol));
31
- const fanInRow = db.get(
32
- `SELECT COUNT(DISTINCT c.document_id) AS c
33
- FROM mentions m
34
- JOIN chunks c ON m.chunk_id = c.id
35
- WHERE m.symbol_id = ? AND m.role != 1`,
36
- match.symbolId
37
- );
38
- const fanOut = new Set(
39
- callees.filter((c) => c.file !== match.relativePath).map((c) => c.symbol)
40
- ).size;
41
- return {
42
- symbol: match.symbol,
43
- shortName: shortenSymbol(match.symbol),
44
- relativePath: match.relativePath,
45
- startLine: match.startLine,
46
- endLine: match.endLine,
47
- loc,
48
- branches,
49
- cyclomaticEstimate: branches + 1,
50
- calleeCount: uniqueCallees.size,
51
- fanIn: fanInRow?.c ?? 0,
52
- fanOut
53
- };
54
- }
55
- function countBranches(source, language) {
56
- const stripped = stripCommentsAndStrings(source);
57
- let count = 0;
58
- const universalPatterns = [
59
- /\bif\b/g,
60
- /\belse\s+if\b/g,
61
- /\belse\b/g,
62
- /\bfor\b/g,
63
- /\bwhile\b/g,
64
- /\bswitch\b/g,
65
- /\bcase\b/g,
66
- /\bcatch\b/g,
67
- /\?\s*[^?]/g,
68
- // ternary (but not ??)
69
- /&&/g,
70
- /\|\|/g
71
- ];
72
- for (const pattern of universalPatterns) {
73
- const matches = stripped.match(pattern);
74
- if (matches) count += matches.length;
75
- }
76
- if (language === "python") {
77
- const pyPatterns = [/\belif\b/g, /\bexcept\b/g, /\bfinally\b/g];
78
- for (const p of pyPatterns) {
79
- const m = stripped.match(p);
80
- if (m) count += m.length;
81
- }
82
- } else if (language === "rust") {
83
- const rustPatterns = [/\bmatch\b/g, /=>/g, /\bloop\b/g];
84
- for (const p of rustPatterns) {
85
- const m = stripped.match(p);
86
- if (m) count += m.length;
87
- }
88
- } else if (language === "ruby") {
89
- const rubyPatterns = [/\belsif\b/g, /\bunless\b/g, /\brescue\b/g, /\bwhen\b/g];
90
- for (const p of rubyPatterns) {
91
- const m = stripped.match(p);
92
- if (m) count += m.length;
93
- }
94
- } else if (language === "go") {
95
- const goPatterns = [/\bselect\b/g, /\bdefer\b/g];
96
- for (const p of goPatterns) {
97
- const m = stripped.match(p);
98
- if (m) count += m.length;
99
- }
100
- }
101
- return count;
102
- }
103
- function stripCommentsAndStrings(source) {
104
- return source.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*/g, "").replace(/#.*/g, "").replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/'(?:[^'\\]|\\.)*'/g, "''").replace(/`(?:[^`\\]|\\.)*`/g, "``");
105
- }
106
-
107
- export {
108
- complexity
109
- };
110
- //# sourceMappingURL=chunk-B7LDMCUS.js.map
@@ -1,110 +0,0 @@
1
- import {
2
- getInactiveBarrelPaths,
3
- isEntrySurface
4
- } from "./chunk-OMVF3BHY.js";
5
- import {
6
- TEST_FILE_PATTERNS,
7
- TEST_SUPPORT_PATH_PATTERNS,
8
- getAllDefinitions
9
- } from "./chunk-FMAYH7GS.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-C2VSV54P.js.map
@@ -1,81 +0,0 @@
1
- import {
2
- findFirstSymbolMatch,
3
- resolveIndexedFile
4
- } from "./chunk-FMAYH7GS.js";
5
- import {
6
- shortenSymbol
7
- } from "./chunk-YMSJCSRG.js";
8
-
9
- // src/queries/code.ts
10
- import { readFileSync } from "fs";
11
- import { join } from "path";
12
- function code(db, symbolPattern, opts = {}) {
13
- const { context = 0 } = opts;
14
- const fileLineMatch = symbolPattern.match(/^(.+\.\w+):(\d+)-(\d+)$/);
15
- if (fileLineMatch) {
16
- return readFileRange(db, fileLineMatch[1], parseInt(fileLineMatch[2], 10), parseInt(fileLineMatch[3], 10), context);
17
- }
18
- const match = findFirstSymbolMatch(db, symbolPattern);
19
- if (!match) return null;
20
- const doc = db.get(
21
- `SELECT language FROM documents WHERE relative_path = ?`,
22
- match.relativePath
23
- );
24
- const filePath = join(db.config.projectRoot, match.relativePath);
25
- let fileContent;
26
- try {
27
- fileContent = readFileSync(filePath, "utf-8");
28
- } catch {
29
- return null;
30
- }
31
- const lines = fileContent.split("\n");
32
- const startLine = Math.max(0, match.startLine - context);
33
- const endLine = Math.min(lines.length - 1, match.endLine + context);
34
- const source = lines.slice(startLine, endLine + 1).join("\n");
35
- return {
36
- symbol: match.symbol,
37
- shortName: shortenSymbol(match.symbol),
38
- relativePath: match.relativePath,
39
- // 0-indexed, like every other query result. The CLI's displayLine()
40
- // converts once at render time. Returning 1-indexed here caused a
41
- // double-conversion in the CLI and printed labels off by +1.
42
- startLine,
43
- endLine,
44
- language: doc?.language ?? null,
45
- source
46
- };
47
- }
48
- function readFileRange(db, filePath, startLine, endLine, context) {
49
- const resolvedPath = resolveIndexedFile(db, filePath);
50
- if (!resolvedPath) return null;
51
- const doc = db.get(
52
- `SELECT relative_path, language FROM documents WHERE relative_path = ?`,
53
- resolvedPath
54
- );
55
- if (!doc) return null;
56
- const fullPath = join(db.config.projectRoot, doc.relative_path);
57
- let fileContent;
58
- try {
59
- fileContent = readFileSync(fullPath, "utf-8");
60
- } catch {
61
- return null;
62
- }
63
- const lines = fileContent.split("\n");
64
- const start = Math.max(0, startLine - 1 - context);
65
- const end = Math.min(lines.length - 1, endLine - 1 + context);
66
- const source = lines.slice(start, end + 1).join("\n");
67
- return {
68
- symbol: `${doc.relative_path}:${startLine}-${endLine}`,
69
- shortName: `${doc.relative_path}:${startLine}-${endLine}`,
70
- relativePath: doc.relative_path,
71
- startLine: start,
72
- endLine: end,
73
- language: doc.language,
74
- source
75
- };
76
- }
77
-
78
- export {
79
- code
80
- };
81
- //# sourceMappingURL=chunk-DIYEUFVP.js.map
@@ -1,93 +0,0 @@
1
- import {
2
- buildFileDepGraph
3
- } from "./chunk-FMAYH7GS.js";
4
-
5
- // src/queries/similar-files.ts
6
- function similarFiles(db, opts = {}) {
7
- const { minSimilarity = 0.5, limit = 20, scope, filePattern } = opts;
8
- const minDeps = opts.minDeps ?? (filePattern ? 1 : 3);
9
- const profiles = buildFileProfiles(db, { scope, minDeps });
10
- const results = [];
11
- if (filePattern) {
12
- const target = profiles.find((p) => p.file.includes(filePattern));
13
- if (!target) return [];
14
- for (const candidate of profiles) {
15
- if (candidate.file === target.file) continue;
16
- const result = compareProfiles(target, candidate, minSimilarity);
17
- if (result) results.push(result);
18
- }
19
- } else {
20
- for (let i = 0; i < profiles.length; i++) {
21
- for (let j = i + 1; j < profiles.length; j++) {
22
- const result = compareProfiles(profiles[i], profiles[j], minSimilarity);
23
- if (result) results.push(result);
24
- }
25
- if (results.length > limit * 5) break;
26
- }
27
- }
28
- results.sort((a, b) => b.similarity - a.similarity);
29
- return results.slice(0, limit);
30
- }
31
- function buildFileProfiles(db, opts) {
32
- const { scope, minDeps } = opts;
33
- const depMap = buildFileDepGraph(db, scope);
34
- const universalDeps = findUniversalDependencies(depMap);
35
- const profiles = [];
36
- for (const [file, deps] of depMap) {
37
- if (deps.size >= minDeps) {
38
- profiles.push({
39
- file,
40
- deps: new Set([...deps].filter((dep) => !universalDeps.has(dep)))
41
- });
42
- }
43
- }
44
- return profiles;
45
- }
46
- function findUniversalDependencies(depMap) {
47
- const universalDeps = /* @__PURE__ */ new Set();
48
- const fileCount = depMap.size;
49
- if (fileCount === 0) return universalDeps;
50
- const depCounts = /* @__PURE__ */ new Map();
51
- for (const deps of depMap.values()) {
52
- for (const dep of deps) {
53
- depCounts.set(dep, (depCounts.get(dep) ?? 0) + 1);
54
- }
55
- }
56
- for (const [dep, count] of depCounts) {
57
- if (count >= 6 && count / fileCount > 0.8) {
58
- universalDeps.add(dep);
59
- }
60
- }
61
- return universalDeps;
62
- }
63
- function compareProfiles(a, b, minSimilarity) {
64
- const shared = /* @__PURE__ */ new Set();
65
- for (const dep of a.deps) {
66
- if (b.deps.has(dep)) shared.add(dep);
67
- }
68
- if (shared.size === 0) return null;
69
- const unionSize = (/* @__PURE__ */ new Set([...a.deps, ...b.deps])).size;
70
- const similarity = shared.size / unionSize;
71
- if (similarity < minSimilarity) return null;
72
- const uniqueA = [];
73
- for (const dep of a.deps) {
74
- if (!b.deps.has(dep)) uniqueA.push(dep);
75
- }
76
- const uniqueB = [];
77
- for (const dep of b.deps) {
78
- if (!a.deps.has(dep)) uniqueB.push(dep);
79
- }
80
- return {
81
- fileA: a.file,
82
- fileB: b.file,
83
- similarity,
84
- sharedDeps: [...shared],
85
- uniqueToA: uniqueA,
86
- uniqueToB: uniqueB
87
- };
88
- }
89
-
90
- export {
91
- similarFiles
92
- };
93
- //# sourceMappingURL=chunk-E74RY6AQ.js.map