scip-query 0.6.4 → 0.6.6
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.
- package/README.md +74 -35
- package/dist/augment-vue-worker.js +2 -0
- package/dist/chunk-25HOGELX.js +2 -0
- package/dist/chunk-2TLYCK2L.js +11 -0
- package/dist/chunk-3PVIYZ74.js +84 -0
- package/dist/chunk-4TX5IMMK.js +12 -0
- package/dist/chunk-6DVA22YE.js +2 -0
- package/dist/{chunk-CGAO6FHN.js → chunk-6GPFHZP3.js} +2 -2
- package/dist/chunk-7LSCW7NF.js +6 -0
- package/dist/chunk-7PRMSA4Z.js +2 -0
- package/dist/chunk-7X7FLQC5.js +2 -0
- package/dist/chunk-7YI2M2AQ.js +2 -0
- package/dist/chunk-AADJ7MCQ.js +2 -0
- package/dist/chunk-AV7BOODV.js +4 -0
- package/dist/chunk-AXP4H62Q.js +6 -0
- package/dist/chunk-C4C3T4K3.js +2 -0
- package/dist/chunk-CSRPJCWO.js +2 -0
- package/dist/chunk-CYJMOTIH.js +2 -0
- package/dist/chunk-DLWRLPKO.js +29 -0
- package/dist/chunk-E2V5SE6M.js +70 -0
- package/dist/{chunk-ZE3BTHTS.js → chunk-ERRUE5G4.js} +4 -4
- package/dist/chunk-GBDZY73J.js +2 -0
- package/dist/chunk-GPY33RTH.js +19 -0
- package/dist/{chunk-4TYGGOLO.js → chunk-H4DXD2FB.js} +1 -1
- package/dist/{chunk-LAXFZ3UW.js → chunk-HVNVO6UW.js} +4 -4
- package/dist/chunk-I377UMS2.js +2 -0
- package/dist/chunk-IKQYNTW3.js +2 -0
- package/dist/chunk-IZ4KV37N.js +7 -0
- package/dist/{chunk-KYT47WU2.js → chunk-KAM4C6ZD.js} +1 -1
- package/dist/{chunk-OOMAS234.js → chunk-KBGFYKOJ.js} +2 -2
- package/dist/chunk-KW2F3WSV.js +5 -0
- package/dist/chunk-LJ2YWNQF.js +2 -0
- package/dist/chunk-MO65UK5V.js +6 -0
- package/dist/{chunk-6UJ5PXER.js → chunk-MXWC53GJ.js} +4 -4
- package/dist/chunk-NIN762LD.js +5 -0
- package/dist/{chunk-5OVBASGY.js → chunk-O6VBAW7P.js} +2 -2
- package/dist/{chunk-IVT2U2BV.js → chunk-OQZF2DQJ.js} +3 -3
- package/dist/chunk-PIRXZGV6.js +2 -0
- package/dist/{chunk-GALIM3IE.js → chunk-Q2ALKKSE.js} +4 -4
- package/dist/chunk-Q4R2IYA3.js +7 -0
- package/dist/{chunk-AW3QJT4O.js → chunk-QFBJZHMV.js} +3 -3
- package/dist/chunk-QFZE73XF.js +84 -0
- package/dist/chunk-QPJG6VRT.js +16 -0
- package/dist/chunk-QRYEOK3M.js +2 -0
- package/dist/{chunk-LORWXBOO.js → chunk-RKTDEIHF.js} +1 -1
- package/dist/chunk-TBJDUS4E.js +71 -0
- package/dist/chunk-TLRA5TR6.js +2 -0
- package/dist/chunk-TUV2VI7D.js +7 -0
- package/dist/chunk-UAPNU7UP.js +2 -0
- package/dist/chunk-URCJTFOD.js +2 -0
- package/dist/chunk-UUIWMLDX.js +39 -0
- package/dist/chunk-VEXS3I3N.js +2 -0
- package/dist/chunk-VRC3WKKE.js +2 -0
- package/dist/chunk-WFDTS7XL.js +2 -0
- package/dist/chunk-Y4DS3MDC.js +5 -0
- package/dist/chunk-YJODB2F5.js +2 -0
- package/dist/{chunk-QID23O53.js → chunk-YXMHTJYY.js} +2 -2
- package/dist/chunk-Z4AMQWVY.js +90 -0
- package/dist/chunk-ZHHMG4UC.js +114 -0
- package/dist/cli.js +487 -388
- package/dist/{db-DKhNQ75l.d.ts → db-BZPa7dzJ.d.ts} +19 -9
- package/dist/index.d.ts +224 -13
- package/dist/index.js +45 -31
- package/dist/postinstall.js +1 -1
- package/dist/queries/affected.d.ts +1 -1
- package/dist/queries/affected.js +1 -1
- package/dist/queries/bottlenecks.d.ts +1 -1
- package/dist/queries/bottlenecks.js +1 -1
- package/dist/queries/by-kind.d.ts +1 -1
- package/dist/queries/by-kind.js +1 -1
- package/dist/queries/call-graph.d.ts +1 -1
- package/dist/queries/call-graph.js +1 -1
- package/dist/queries/change-surface.d.ts +1 -1
- package/dist/queries/change-surface.js +1 -1
- package/dist/queries/code.d.ts +1 -1
- package/dist/queries/code.js +1 -1
- package/dist/queries/complexity-hotspots.d.ts +1 -1
- package/dist/queries/complexity-hotspots.js +1 -1
- package/dist/queries/complexity.d.ts +1 -1
- package/dist/queries/complexity.js +1 -1
- package/dist/queries/convergence.d.ts +1 -1
- package/dist/queries/convergence.js +1 -1
- package/dist/queries/coupling.d.ts +1 -1
- package/dist/queries/coupling.js +1 -1
- package/dist/queries/cycles.d.ts +1 -1
- package/dist/queries/cycles.js +1 -1
- package/dist/queries/dataflow.d.ts +1 -1
- package/dist/queries/dataflow.js +1 -1
- package/dist/queries/dead.d.ts +1 -1
- package/dist/queries/dead.js +1 -1
- package/dist/queries/deep-chains.d.ts +1 -1
- package/dist/queries/deep-chains.js +1 -1
- package/dist/queries/deps.d.ts +1 -1
- package/dist/queries/deps.js +1 -1
- package/dist/queries/diff-impact.d.ts +1 -1
- package/dist/queries/diff-impact.js +1 -1
- package/dist/queries/drift-policy.d.ts +6 -0
- package/dist/queries/drift-policy.js +2 -0
- package/dist/queries/drift.d.ts +1 -1
- package/dist/queries/drift.js +1 -1
- package/dist/queries/extract-candidates.d.ts +1 -1
- package/dist/queries/extract-candidates.js +1 -1
- package/dist/queries/fan.d.ts +1 -1
- package/dist/queries/fan.js +1 -1
- package/dist/queries/files.d.ts +1 -1
- package/dist/queries/files.js +1 -1
- package/dist/queries/health.d.ts +1 -1
- package/dist/queries/health.js +1 -1
- package/dist/queries/hierarchy.d.ts +1 -1
- package/dist/queries/hierarchy.js +1 -1
- package/dist/queries/hotspots.d.ts +1 -1
- package/dist/queries/hotspots.js +1 -1
- package/dist/queries/imports.d.ts +1 -1
- package/dist/queries/imports.js +1 -1
- package/dist/queries/index.d.ts +1 -1
- package/dist/queries/index.js +1 -1
- package/dist/queries/isolated.d.ts +1 -1
- package/dist/queries/isolated.js +1 -1
- package/dist/queries/members.d.ts +1 -1
- package/dist/queries/members.js +1 -1
- package/dist/queries/methods.d.ts +1 -1
- package/dist/queries/methods.js +1 -1
- package/dist/queries/outline.d.ts +1 -1
- package/dist/queries/outline.js +1 -1
- package/dist/queries/passthrough-candidates.d.ts +1 -1
- package/dist/queries/passthrough-candidates.js +1 -1
- package/dist/queries/redundant-reexports.d.ts +1 -1
- package/dist/queries/redundant-reexports.js +1 -1
- package/dist/queries/refs.d.ts +1 -1
- package/dist/queries/refs.js +1 -1
- package/dist/queries/similar-chains.d.ts +1 -1
- package/dist/queries/similar-chains.js +1 -1
- package/dist/queries/similar-files.d.ts +1 -1
- package/dist/queries/similar-files.js +1 -1
- package/dist/queries/similar-signatures.d.ts +1 -1
- package/dist/queries/similar-signatures.js +1 -1
- package/dist/queries/similar.d.ts +1 -1
- package/dist/queries/similar.js +1 -1
- package/dist/queries/slice.d.ts +1 -1
- package/dist/queries/slice.js +1 -1
- package/dist/queries/stale-abstractions.d.ts +1 -1
- package/dist/queries/stale-abstractions.js +1 -1
- package/dist/queries/stats.d.ts +1 -1
- package/dist/queries/stats.js +1 -1
- package/dist/queries/surface.d.ts +1 -1
- package/dist/queries/surface.js +1 -1
- package/dist/queries/symbols.d.ts +1 -1
- package/dist/queries/symbols.js +1 -1
- package/dist/queries/system.d.ts +1 -1
- package/dist/queries/system.js +1 -1
- package/dist/queries/trace.d.ts +1 -1
- package/dist/queries/trace.js +1 -1
- package/dist/queries/wrapper-candidates.d.ts +1 -1
- package/dist/queries/wrapper-candidates.js +1 -1
- package/dist/reindex-worker.js +10 -63
- package/package.json +5 -3
- package/dist/chunk-2DQK2IDZ.js +0 -19
- package/dist/chunk-4HCKXL7T.js +0 -6
- package/dist/chunk-4Q2D5BMS.js +0 -2
- package/dist/chunk-5IM4IQ6N.js +0 -2
- package/dist/chunk-5NSYCQWM.js +0 -6
- package/dist/chunk-6QKHOBC6.js +0 -2
- package/dist/chunk-6U5UHIRD.js +0 -5
- package/dist/chunk-AQFXC7CF.js +0 -2
- package/dist/chunk-BSONDC3H.js +0 -7
- package/dist/chunk-ECT6SOBO.js +0 -2
- package/dist/chunk-FFE3RZ65.js +0 -2
- package/dist/chunk-FT4WPAEX.js +0 -65
- package/dist/chunk-G6HYVVRV.js +0 -2
- package/dist/chunk-GVVKLMXG.js +0 -10
- package/dist/chunk-HVM6SQPQ.js +0 -2
- package/dist/chunk-IDCWMWWP.js +0 -5
- package/dist/chunk-IJO2HZFL.js +0 -2
- package/dist/chunk-INPQVQ6O.js +0 -12
- package/dist/chunk-JSBWVSES.js +0 -39
- package/dist/chunk-MFVPKCS5.js +0 -2
- package/dist/chunk-MWCN46ZX.js +0 -89
- package/dist/chunk-N3Z2SJCR.js +0 -2
- package/dist/chunk-NKU7Z242.js +0 -8
- package/dist/chunk-P6IUCZA3.js +0 -24
- package/dist/chunk-PM3GTZ4I.js +0 -2
- package/dist/chunk-QL5MJOVA.js +0 -84
- package/dist/chunk-QWFK4QOQ.js +0 -2
- package/dist/chunk-RBYC6PHE.js +0 -2
- package/dist/chunk-TS7E5XBZ.js +0 -29
- package/dist/chunk-TUC6IWTY.js +0 -2
- package/dist/chunk-USMVRM6F.js +0 -2
- package/dist/chunk-VTZPTRKS.js +0 -7
- package/dist/chunk-WUYKGQSK.js +0 -2
- package/dist/chunk-X7LOLGYY.js +0 -2
- package/dist/chunk-XGOEZVMA.js +0 -7
- package/dist/chunk-Y6NOLG4X.js +0 -70
- package/dist/chunk-YVQ7CIKO.js +0 -6
- package/dist/chunk-ZIFKQQW2.js +0 -4
- package/dist/chunk-ZOR6FW74.js +0 -2
- package/dist/chunk-ZPZLVFJQ.js +0 -41
- package/dist/chunk-ZZ3F6P3X.js +0 -2
package/dist/cli.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{program as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
WHERE local_der.symbol_id = gs.id
|
|
8
|
-
${this.pathExclusionsFor("local_d").trimStart()}
|
|
9
|
-
)
|
|
10
|
-
OR EXISTS (
|
|
11
|
-
SELECT 1
|
|
12
|
-
FROM mentions local_m
|
|
13
|
-
JOIN chunks local_c ON local_m.chunk_id = local_c.id
|
|
14
|
-
JOIN documents local_d ON local_c.document_id = local_d.id
|
|
15
|
-
WHERE local_m.symbol_id = gs.id
|
|
16
|
-
AND local_m.role = 1
|
|
17
|
-
${this.pathExclusionsFor("local_d").trimStart()}
|
|
18
|
-
)
|
|
19
|
-
)`}get pathExclusions(){return this.pathExclusionsFor("d")}get symbolNoise(){return this.symbolNoiseFor("gs")}pathExclusionsFor(...n){return n.flatMap(t=>[`AND ${t}.relative_path NOT LIKE 'node_modules/%'`,`AND ${t}.relative_path NOT LIKE '.git/%'`]).join(`
|
|
20
|
-
`)}symbolNoiseFor(n){return`AND ${n}.symbol NOT LIKE '%().(%' AND ${n}.symbol NOT LIKE '%typeLiteral%'`}all(n,...t){return this.db.prepare(n).all(...t)}get(n,...t){return this.db.prepare(n).get(...t)}sizeBytes(){try{return os(this.config.dbPath).size}catch{return 0}}lastModified(){try{return os(this.config.dbPath).mtime}catch{return null}}close(){this.db.close()}};import _r from"ignore";import{readFileSync as xr,existsSync as Sn}from"fs";import{dirname as _n,isAbsolute as rs,join as xn,relative as Ir,resolve as Nr}from"path";function Ue(e){let n=_r(),t=!1,s=vr(e);for(let i of s)try{let o=xr(i,"utf-8");n.add(o),t=!0}catch{}return t||n.add(Cr),{isIgnored:i=>as(n,e,i),filter:i=>i.filter(o=>!as(n,e,o))}}function vr(e){let n=[],t=xn(e,".gitignore");Sn(t)&&n.push(t);let s=_n(e),i=0;for(;s!==_n(s)&&i<5;){let o=xn(s,".gitignore");if(Sn(o)&&n.push(o),Sn(xn(s,".git")))break;s=_n(s),i++}return n}var Cr=`
|
|
2
|
+
var Ga=Object.defineProperty;var Ka=(e,t)=>{for(var n in t)Ga(e,n,{get:t[n],enumerable:!0})};import{program as S}from"commander";import{createRequire as ES}from"module";import{existsSync as qa,realpathSync as za}from"fs";import{fileURLToPath as DS}from"url";import{readFileSync as Ya,writeFileSync as Qa,existsSync as jr,mkdirSync as Xa}from"fs";import{join as $e,resolve as Ar}from"path";import{createHash as Za}from"crypto";import{homedir as el}from"os";var Br=".scipquery.json",tl={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function ve(e){let t=$e(e,Br);if(!jr(t))return{};try{let n=Ya(t,"utf-8");return JSON.parse(n)}catch{return{}}}function Wr(e){return{...tl,...e.watch}}function nl(e,t){let n=process.env.SCIP_QUERY_CACHE_DIR;if(n)return Mn(n);if(t?.dbPath)return Mn(Ar(e,t.dbPath));let i=process.env.XDG_CACHE_HOME||$e(el(),".cache"),s=Za("sha256").update(Ar(e)).digest("hex").slice(0,12),o=$e(i,"scip-query","projects",s);return Mn(o)}function Ne(e,t){let n=nl(e,t);return{cacheDir:n,dbPath:$e(n,"index.db"),indexPath:$e(n,"index.scip"),metaPath:$e(n,"meta.json")}}function Hr(e,t){let n=$e(e,Br);return jr(n)||Qa(n,JSON.stringify({languages:t,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
|
|
3
|
+
`),n}function Mn(e){return Xa(e,{recursive:!0}),e}import{execFile as Nu,execFileSync as Eu}from"child_process";import{closeSync as Du,existsSync as We,mkdirSync as Di,mkdtempSync as Lu,openSync as ku,readFileSync as wu,renameSync as Ze,rmSync as et,writeFileSync as Li}from"fs";import{cpus as Pu}from"os";import{basename as Kt,dirname as Be,extname as Ou,join as se}from"path";import{execFileSync as jt}from"child_process";import{platform as Bt,arch as rl}from"os";var Vr=Bt()==="win32",Ur="v0.7.0";function At(e){let t=Vr?"where":"which";try{return jt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Fn(){try{return jt(Vr?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function il(){let e=Bt(),t=rl(),n,r,i;switch(e){case"darwin":n="darwin",i="tar.gz";break;case"linux":n="linux",i="tar.gz";break;case"win32":n="windows",i="zip";break;default:return null}switch(t){case"arm64":r="arm64";break;case"x64":r="amd64";break;default:return null}let s=`scip-${n}-${r}.${i}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${Ur}/${s}`,filename:s}}function Tn(){let e=il();console.log("\nThe `scip` CLI is required but not found on PATH.\n"),Bt()==="darwin"?(console.log("Install via Homebrew:"),console.log(` brew install sourcegraph/scip/scip
|
|
4
|
+
`),console.log("Or download manually:")):console.log("Download from:"),console.log(e?` ${e.url}
|
|
5
|
+
`:` https://github.com/sourcegraph/scip/releases/tag/${Ur}
|
|
6
|
+
`),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function Jr(e){if(Bt()==="darwin"&&At("brew")){e("Installing scip CLI via Homebrew...");try{if(jt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`Homebrew install failed: ${n}`)}}if(At("go")){e("Installing scip CLI via go install...");try{if(jt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),At("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(t){let n=t instanceof Error?t.message:String(t);e(`go install failed: ${n}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import bl from"better-sqlite3";import{execFileSync as Sl}from"child_process";import{existsSync as xl,readdirSync as _l,readFileSync as Il}from"fs";import{extname as Ht,join as Qr}from"path";import sl from"ignore";import{readFileSync as ol,existsSync as $n}from"fs";import{dirname as An,isAbsolute as qr,join as jn,relative as al,resolve as ll}from"path";function Ye(e){let t=sl(),n=!1,r=cl(e);for(let i of r)try{let s=ol(i,"utf-8");t.add(s),n=!0}catch{}return n||t.add(ul),{isIgnored:i=>zr(t,e,i),filter:i=>i.filter(s=>!zr(t,e,s))}}function cl(e){let t=[],n=jn(e,".gitignore");$n(n)&&t.push(n);let r=An(e),i=0;for(;r!==An(r)&&i<5;){let s=jn(r,".gitignore");if($n(s)&&t.push(s),$n(jn(r,".git")))break;r=An(r),i++}return t}var ul=`
|
|
21
7
|
# Dependencies
|
|
22
8
|
node_modules/
|
|
23
9
|
vendor/
|
|
@@ -74,15 +60,24 @@ Thumbs.db
|
|
|
74
60
|
|
|
75
61
|
# Type definitions (often noise in queries)
|
|
76
62
|
*.d.ts
|
|
77
|
-
`;function
|
|
78
|
-
`),t}function In(e){return wr(e,{recursive:!0}),e}import{execFileSync as js}from"child_process";import{existsSync as Bs,renameSync as Ws,rmSync as Ua}from"fs";import{basename as qa,dirname as za,extname as Va,join as At}from"path";import{execFileSync as Dt}from"child_process";import{platform as kt,arch as Pr}from"os";var ps=kt()==="win32",fs="v0.7.0";function wt(e){let n=ps?"where":"which";try{return Dt(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function Nn(){try{return Dt(ps?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function Mr(){let e=kt(),n=Pr(),t,s,i;switch(e){case"darwin":t="darwin",i="tar.gz";break;case"linux":t="linux",i="tar.gz";break;case"win32":t="windows",i="zip";break;default:return null}switch(n){case"arm64":s="arm64";break;case"x64":s="amd64";break;default:return null}let o=`scip-${t}-${s}.${i}`;return{url:`https://github.com/sourcegraph/scip/releases/download/${fs}/${o}`,filename:o}}function vn(){let e=Mr();console.log("\nThe `scip` CLI is required but not found on PATH.\n"),kt()==="darwin"?(console.log("Install via Homebrew:"),console.log(` brew install sourcegraph/scip/scip
|
|
79
|
-
`),console.log("Or download manually:")):console.log("Download from:"),console.log(e?` ${e.url}
|
|
80
|
-
`:` https://github.com/sourcegraph/scip/releases/tag/${fs}
|
|
81
|
-
`),console.log("After installing, ensure `scip` is on your PATH and run `scip-query reindex`.")}function gs(e){if(kt()==="darwin"&&wt("brew")){e("Installing scip CLI via Homebrew...");try{if(Dt("brew",["install","sourcegraph/scip/scip"],{stdio:"inherit",timeout:3e5,env:process.env}),wt("scip"))return e("Successfully installed scip CLI via Homebrew"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`Homebrew install failed: ${t}`)}}if(wt("go")){e("Installing scip CLI via go install...");try{if(Dt("go",["install","github.com/sourcegraph/scip/cmd/scip@latest"],{stdio:"inherit",timeout:3e5,env:process.env}),wt("scip"))return e("Successfully installed scip CLI via go install"),!0}catch(n){let t=n instanceof Error?n.message:String(n);e(`go install failed: ${t}`)}}return e("Could not auto-install scip CLI."),e("Install manually from: https://github.com/sourcegraph/scip/releases"),!1}import Wr from"better-sqlite3";import{existsSync as Hr,readdirSync as Jr,readFileSync as Ur}from"fs";import{extname as En,join as bs}from"path";import{readdirSync as Fr}from"fs";import{extname as hs,join as Tr}from"path";function W(e){let n=new WeakMap,t=s=>{let i=n.get(s);return i||(i=new Map,n.set(s,i)),i};return{get(s,i,o){let a=t(s);if(a.has(i))return a.get(i);let r=o();return a.set(i,r),r},invalidate(s,i){n.get(s)?.delete(i)},invalidateAll(s){n.delete(s)},size(s){return n.get(s)?.size??0}}}function je(e){let n=new WeakMap;return{get(t,s){let i=n.get(t);if(i)return i.value;let o=s();return n.set(t,{value:o}),o},invalidate(t){n.delete(t)},has(t){return n.has(t)}}}function Ot(e){let n=new WeakMap,t=s=>{let i=n.get(s);return i||(i=new Map,n.set(s,i)),i};return{get(s,i,o,a){let r=t(s),l=r.get(i);if(l&&l.source===o)return l.value;let c=a();return r.set(i,{source:o,value:c}),c},invalidate(s,i){n.get(s)?.delete(i)},invalidateAll(s){n.delete(s)}}}var Ar=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue",".rs",".py",".pyi",".java",".kt",".kts",".scala",".sc",".rb",".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx",".cs",".vb",".php",".dart"],ys=[".vue"],Cn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Re(e,n={}){let t=n.includeIndexed??!0,s=n.includeAuxiliary??!0,i=n.extensions?new Set(n.extensions.map(a=>a.toLowerCase())):new Set(Ar.map(a=>a.toLowerCase())),o=`${t?"1":"0"}|${s?"1":"0"}|${[...i].sort().join(",")}`;return jr.get(e,o,()=>{let a=new Set;if(t){let r=e.all(`SELECT relative_path
|
|
63
|
+
`;function zr(e,t,n){let r=dl(t,n);if(!r)return!1;try{return e.ignores(r)}catch{return!1}}function dl(e,t){if(!t||t===".")return null;if(!qr(t)&&!t.startsWith(".."))return t.replaceAll("\\","/");let n=qr(t)?t:ll(e,t),r=al(e,n).replaceAll("\\","/");return!r||r==="."||r.startsWith("..")?null:r}import{readdirSync as ml}from"fs";import{extname as Gr,join as pl}from"path";function $(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s){let o=n(r);if(o.has(i))return o.get(i);let a=s();return o.set(i,a),a},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)},size(r){return t.get(r)?.size??0}}}function Ae(e){let t=new WeakMap;return{get(n,r){let i=t.get(n);if(i)return i.value;let s=r();return t.set(n,{value:s}),s},invalidate(n){t.delete(n)},has(n){return t.has(n)}}}function Wt(e){let t=new WeakMap,n=r=>{let i=t.get(r);return i||(i=new Map,t.set(r,i)),i};return{get(r,i,s,o){let a=n(r),l=a.get(i);if(l&&l.source===s)return l.value;let c=o();return a.set(i,{source:s,value:c}),c},invalidate(r,i){t.get(r)?.delete(i)},invalidateAll(r){t.delete(r)}}}var fl=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue",".rs",".py",".pyi",".java",".kt",".kts",".scala",".sc",".rb",".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx",".cs",".vb",".php",".dart"],Kr=[".vue"],Yr=new Set(fl.map(e=>e.toLowerCase())),gl=[...Yr].sort().join(","),Bn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Ee(e,t={}){let n=t.includeIndexed??!0,r=t.includeAuxiliary??!0,i=t.extensions?.map(l=>l.toLowerCase()),s=i?new Set(i):Yr,o=i?[...s].sort().join(","):gl,a=`${n?"1":"0"}|${r?"1":"0"}|${o}`;return hl.get(e,a,()=>{let l=new Set;if(n){let c=e.all(`SELECT relative_path
|
|
82
64
|
FROM documents
|
|
83
65
|
WHERE 1 = 1
|
|
84
|
-
${e.pathExclusionsFor("documents")}`);for(let
|
|
85
|
-
VALUES (?, ?, NULL, ?)`),l=i.transaction(m=>{let u=0;for(let d of m){if(o.has(d))continue;let g=Ur(bs(e.projectRoot,d),"utf-8"),p=a.run(zr(d),d,g);u+=Number(p.changes)}return u})(s),c={scanned:s.length,inserted:l,existing:s.length-l};return e.onStatus?.(`Augmented SQLite documents with ${l} auxiliary source file${l===1?"":"s"} (${c.existing} already present).`),c}finally{i.close()}}function qr(e,n){let t=[],s=i=>{let o=i?bs(e,i):e,a=[];try{a=Jr(o,{withFileTypes:!0})}catch{return}for(let r of a){if(Cn.has(r.name))continue;let l=i?`${i}/${r.name}`:r.name;if(r.isDirectory()){s(l);continue}n.has(En(r.name).toLowerCase())&&t.push(l)}};return s(""),t.sort()}function zr(e){return En(e).toLowerCase()===".vue"?"vue":En(e).replace(/^\./,"").toLowerCase()||"source"}import{existsSync as Vr,readdirSync as _s}from"fs";import{extname as Gr,join as xs}from"path";var Yr=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),Kr=[{language:"typescript",files:["tsconfig.json","tsconfig.base.json"],extensions:[".ts",".tsx",".mts",".cts"]},{language:"rust",files:["Cargo.toml"],extensions:[".rs"]},{language:"go",files:["go.mod"],extensions:[".go"]},{language:"java",files:["pom.xml","build.gradle","build.gradle.kts"],extensions:[".java"]},{language:"kotlin",files:["build.gradle.kts"],extensions:[".kt",".kts"]},{language:"scala",files:["build.sbt"],extensions:[".scala"]},{language:"python",files:["pyproject.toml","setup.py","setup.cfg","Pipfile"],extensions:[".py",".pyi"]},{language:"ruby",files:["Gemfile"],extensions:[".rb"]},{language:"cpp",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".cc",".cpp",".cxx",".hpp",".hh",".hxx"]},{language:"c",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".c",".h"]},{language:"csharp",globs:["*.csproj","*.sln"],extensions:[".cs"]},{language:"vb",globs:["*.vbproj"],extensions:[".vb"]},{language:"dart",files:["pubspec.yaml"],extensions:[".dart"]},{language:"php",files:["composer.json"],extensions:[".php"]},{language:"javascript",files:["package.json"],extensions:[".js",".jsx",".mjs",".cjs"]}];function qe(e){let n=[],t=Qr(e),s=ta(e);for(let i of Kr){if(Xr(e,i.files)){n.push(i.language);continue}if(Zr(t,i.globs)){n.push(i.language);continue}na(s,i.extensions)&&n.push(i.language)}return n.includes("typescript")&&Ss(n,"javascript"),n.includes("cpp")&&!s.has(".c")&&Ss(n,"c"),n}function Qr(e){try{return _s(e)}catch{return[]}}function Xr(e,n){return n?.length?n.some(t=>Vr(xs(e,t))):!1}function Zr(e,n){return n?.length?e.some(t=>n.some(s=>ea(t,s))):!1}function ea(e,n){if(n==="*")return!0;if(!n.includes("*"))return e===n;let[t,s]=n.split("*");return e.startsWith(t??"")&&e.endsWith(s??"")}function ta(e){let n=new Set,t=[e];for(;t.length>0;){let s=t.pop();if(!s)continue;let i;try{i=_s(s,{withFileTypes:!0})}catch{continue}for(let o of i){if(o.name.startsWith(".")&&!o.name.endsWith("proj")&&!o.name.endsWith("sln")&&o.isDirectory())continue;let a=xs(s,o.name);if(o.isDirectory()){Yr.has(o.name)||t.push(a);continue}let r=Gr(o.name).toLowerCase();r&&n.add(r)}}return n}function na(e,n){return n?.length?n.some(t=>e.has(t)):!1}function Ss(e,n){let t=e.indexOf(n);t!==-1&&e.splice(t,1)}import{existsSync as Is,readdirSync as sa}from"fs";import{join as Rn}from"path";var ia={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:n})=>{let t=["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"];return n&&t.splice(2,0,"--pnpm-workspaces"),{binary:"npx",args:t}},markerFiles:["tsconfig.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},javascript:{language:"javascript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-typescript","index","--infer-tsconfig","--output",e,"--no-progress-bar"]}),markerFiles:["package.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},java:{language:"java",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["pom.xml","build.gradle"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},scala:{language:"scala",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.sbt"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},kotlin:{language:"kotlin",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.gradle.kts"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},rust:{language:"rust",indexerBinary:"rust-analyzer",checkCommand:"rust-analyzer --version",indexArgs:({outputPath:e})=>({binary:"rust-analyzer",args:["scip",".","--output",e]}),markerFiles:["Cargo.toml"],installMethods:[{label:"rustup",prerequisite:"rustup",binary:"rustup",args:["component","add","rust-analyzer"]}],installUrl:"https://github.com/rust-lang/rust-analyzer"},python:{language:"python",indexerBinary:"scip-python",binaryAliases:["scip-python-plus"],checkCommand:"npx scip-python --version",indexArgs:({outputPath:e})=>({binary:"npx",args:["scip-python","index","--output",e,"--project-name","project"]}),markerFiles:["pyproject.toml","setup.py"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","scip-python-plus"]}],installUrl:"https://github.com/PlunderStruck/scip-python",bundledNpmPackage:"scip-python-plus"},ruby:{language:"ruby",indexerBinary:"scip-ruby",checkCommand:"scip-ruby --version",indexArgs:({indexerBinary:e})=>({binary:e,args:["--dir","."]}),defaultOutputPath:"index.scip",markerFiles:["Gemfile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-ruby/releases"},go:{language:"go",indexerBinary:"scip-go",checkCommand:"scip-go --version",indexArgs:({outputPath:e})=>({binary:"scip-go",args:["--output",e]}),markerFiles:["go.mod"],installMethods:[{label:"go install",prerequisite:"go",binary:"go",args:["install","github.com/sourcegraph/scip-go@latest"]}],installUrl:"https://github.com/sourcegraph/scip-go"},cpp:{language:"cpp",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},c:{language:"c",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},csharp:{language:"csharp",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",Ns(e,[".sln",".csproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.csproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},vb:{language:"vb",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:n})=>({binary:"scip-dotnet",args:["index",Ns(e,[".sln",".vbproj"])??e,"--output",n,"--working-directory",e]}),markerFiles:["*.vbproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},dart:{language:"dart",indexerBinary:"scip-dart",checkCommand:"scip-dart --version",indexArgs:({indexerBinary:e,outputPath:n})=>({binary:e,args:["--output",n]}),markerFiles:["pubspec.yaml"],installMethods:[{label:"dart pub",prerequisite:"dart",binary:"dart",args:["pub","global","activate","scip_dart"]}],installUrl:"https://github.com/Workiva/scip-dart/releases"},php:{language:"php",indexerBinary:"scip-php",projectLocalBinaries:["vendor/davidrjenni/scip-php/bin/scip-php","vendor/bin/scip-php"],checkCommand:"scip-php --version",indexArgs:({projectRoot:e,indexerBinary:n})=>{let t=Rn(e,"vendor","bin","scip-php"),s=Rn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",Is(s)?s:Is(t)?t:n]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function $t(e){return ia[e]}function Ns(e,n){let t;try{t=sa(e)}catch{return null}for(let s of t)if(n.some(i=>s.endsWith(i)))return Rn(e,s);return null}import{readFileSync as oa,writeFileSync as ra}from"fs";import{create as Ln}from"@bufbuild/protobuf";import{deserializeSCIP as aa,serializeSCIP as la,DocumentSchema as ca,IndexSchema as ua,SymbolInformationSchema as ma}from"@c4312/scip";function da(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let n=pa(e),t=fa(e.flatMap(i=>i.documents??[])),s=Cs(e.flatMap(i=>i.externalSymbols??[]));return Ln(ua,{metadata:n,documents:t,externalSymbols:s})}function vs(e,n){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let t=e.map(i=>aa(oa(i))),s=da(t);return ra(n,Buffer.from(la(s))),{documentCount:s.documents.length,externalSymbolCount:s.externalSymbols.length,inputCount:e.length}}function pa(e){let n=e[0]?.metadata;if(!n)return;let t=n.projectRoot;for(let s of e.slice(1)){let i=s.metadata?.projectRoot;if(t&&i&&i!==t)throw new Error(`Cannot merge SCIP indexes with different project roots: ${t} vs ${i}`)}return n}function fa(e){let n=new Map;for(let t of e){let s=n.get(t.relativePath);if(!s){n.set(t.relativePath,t);continue}n.set(t.relativePath,Ln(ca,{language:s.language||t.language,relativePath:s.relativePath||t.relativePath,occurrences:[...s.occurrences,...t.occurrences],symbols:Cs([...s.symbols,...t.symbols]),text:ha(s.text,t.text),positionEncoding:s.positionEncoding||t.positionEncoding}))}return[...n.values()]}function Cs(e){let n=new Map;for(let t of e){let s=n.get(t.symbol);if(!s){n.set(t.symbol,t);continue}n.set(t.symbol,Ln(ma,{symbol:s.symbol,documentation:ya([...s.documentation,...t.documentation]),relationships:ga([...s.relationships,...t.relationships]),kind:s.kind||t.kind,displayName:s.displayName||t.displayName,enclosingSymbol:s.enclosingSymbol||t.enclosingSymbol,signatureDocumentation:s.signatureDocumentation??t.signatureDocumentation}))}return[...n.values()]}function ga(e){let n=new Set,t=[];for(let s of e){let i=[s.symbol,s.isReference?"1":"0",s.isImplementation?"1":"0",s.isTypeDefinition?"1":"0",s.isDefinition?"1":"0"].join("|");n.has(i)||(n.add(i),t.push(s))}return t}function ha(e,n){return e?n?e.length>=n.length?e:n:e:n}function ya(e){return[...new Set(e)]}import{execFileSync as Pt}from"child_process";import{existsSync as wn}from"fs";import{createRequire as ba}from"module";import{platform as Es}from"os";import{join as Rs}from"path";var Sa=ba(import.meta.url),_a=Es()==="win32";function lt(e){let n=_a?"where":"which";try{return Pt(n,[e],{stdio:"pipe"}),!0}catch{return!1}}function Ls(e){return[e.indexerBinary,...e.binaryAliases??[]]}function Mt(e){let n=Ls(e);return n.length===1?n[0]:n.join(" or ")}function ze(e){for(let n of Ls(e))if(lt(n))return n;return Ds(e)?e.indexerBinary:null}function ws(e){return ze(e)!==null||Ds(e)}function Ds(e){if(!e.bundledNpmPackage)return!1;try{return Sa.resolve(`${e.bundledNpmPackage}/package.json`),!0}catch{return!1}}function Dn(e,n){for(let t of e.projectLocalBinaries??[]){let s=Rs(n,t);if(wn(s))return s}return null}function xa(e,n){return Dn(e,n)??ze(e)}function ks(e,n=process.env,t=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||kn(t,n))return n;let s=Ps(t,n);return s?{...n,DOTNET_ROOT:s}:n}function Os(e,n){let t=Mt(e),s=n?xa(e,n):ze(e);if(!s)return{language:e.language,binaryLabel:t,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:t,installed:!0,runnable:!0,resolvedBinary:s};let i=Ia(s);return{language:e.language,binaryLabel:t,installed:!0,runnable:i.runnable,resolvedBinary:s,installUrl:e.installUrl,note:i.note}}function $s(e,n){let t=e.installMethods,s=Mt(e);if(!t?.length)return n(`No auto-install method available for ${s}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1;for(let i of t)if(lt(i.prerequisite)){n(`Installing ${s} via ${i.label}...`);try{Pt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let o=ze(e);if(o){let a=o===e.indexerBinary?"":` (using ${o})`;return n(`Successfully installed ${s} via ${i.label}${a}`),!0}n(`${i.label} command completed but ${s} was not found on PATH`)}catch(o){let a=o instanceof Error?o.message:String(o);n(`${i.label} install failed: ${a}`)}}return n(`Could not auto-install ${s}.`),e.installUrl&&n(`Install manually from: ${e.installUrl}`),!1}function Ia(e){if(kn(e,process.env))return{runnable:!0};let n=Ps(e,process.env);if(n)return{runnable:!0,note:`using .NET 9 runtime from ${n}`};let t=Ms(process.env);return{runnable:!1,note:t.length>0?`.NET 9 runtime still unavailable after checking ${t.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function Ps(e,n){for(let t of Ms(n))if(kn(e,{...n,DOTNET_ROOT:t}))return t;return null}function Ms(e){let n=[],t=e.DOTNET_ROOT;if(t&&wn(t)&&n.push(t),Es()==="darwin"&<("brew"))try{let s=Pt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Rs(s,"libexec");wn(i)&&!n.includes(i)&&n.push(i)}catch{}return n}function kn(e,n){try{return Pt(e,["--version"],{stdio:"pipe",env:n}),!0}catch{return!1}}import Na from"better-sqlite3";import{createRequire as va}from"module";import{existsSync as Fs,readFileSync as Ft}from"fs";import{dirname as Ca,extname as Ea,join as Ts,relative as Ra,resolve as La}from"path";import{pathToFileURL as wa}from"url";function On(e){Be({projectRoot:e.projectRoot,dbPath:e.dbPath});let n=La(e.projectRoot,e.tsconfig);if(!Fs(n))throw new Error(`Vue tsconfig not found at ${n}`);let t=ka(e.projectRoot,n),s=t.fileNames.filter(o=>o.endsWith(".vue")),i=new Na(e.dbPath);try{Da(i);let o=Oa(i,e.projectRoot),a=$a(i,e.projectRoot,s),r=[],l=0;for(let m of s){let u=t.language.scripts.get(m),d=u?.generated?.languagePlugin.typescript?.getServiceScript(u.generated.root)?.code;if(!u||!d){l++;continue}let g=t.language.maps.get(d,u),p=Ft(m,"utf-8");for(let f of Fa(p)){let y=Ta(g,f.start);if(y===null)continue;let b=(t.languageService.getDefinitionAtPosition(m,y+1)??[]).find(x=>!ja(e.projectRoot,x.fileName));if(!b){l++;continue}let _=Pa(b,o,a,t,e.projectRoot);if(_===null){l++;continue}let S=As(p,f.start);r.push({sourceFile:Tt(e.projectRoot,m),sourceLine:S.line,sourceStartChar:S.character,sourceEndChar:S.character+f.text.length,symbolId:_})}}let c=Ma(i,r);return e.onStatus?.(`Resolved ${r.length} Vue references with Volar; inserted ${c} mentions.`),{vueFiles:s.length,resolvedReferences:r.length,insertedMentions:c,skippedReferences:l,syntheticSymbols:a.syntheticSymbols}}finally{i.close()}}function Da(e){e.transaction(()=>{e.prepare(`
|
|
66
|
+
${e.pathExclusionsFor("documents")}`);for(let u of c)e.isIgnored(u.relative_path)||s.has(Gr(u.relative_path).toLowerCase())&&l.add(u.relative_path)}if(r)for(let c of yl(e.config.projectRoot,s))e.isIgnored(c)||l.add(c);return[...l].sort()})}var hl=$("source-files");function yl(e,t){let n=new Set,r=i=>{let s=i?pl(e,i):e,o;try{o=ml(s,{withFileTypes:!0})}catch{return}for(let a of o)if(!Bn.has(a.name)){if(a.isDirectory()){r(i?`${i}/${a.name}`:a.name);continue}t.has(Gr(a.name).toLowerCase())&&n.add(i?`${i}/${a.name}`:a.name)}};return r(""),n}function De(e){let t=new Set((e.extensions??Kr).map(s=>s.toLowerCase()));if(t.size===0)return{scanned:0,inserted:0,existing:0};if(!xl(e.dbPath))throw new Error(`SCIP SQLite database not found at ${e.dbPath}`);let n=Ye(e.projectRoot),r=Rl(e.projectRoot,t).filter(s=>!n.isIgnored(s)),i=new bl(e.dbPath);try{let s=vl(i,r),o=i.prepare(`INSERT OR IGNORE INTO documents (language, relative_path, position_encoding, text)
|
|
67
|
+
VALUES (?, ?, NULL, ?)`),l=i.transaction(u=>{let d=0;for(let m of u){if(s.has(m))continue;let g=Il(Qr(e.projectRoot,m),"utf-8"),p=o.run(Nl(m),m,g);d+=Number(p.changes)}return d})(r),c={scanned:r.length,inserted:l,existing:r.length-l};return e.onStatus?.(`Augmented SQLite documents with ${l} auxiliary source file${l===1?"":"s"} (${c.existing} already present).`),c}finally{i.close()}}function Rl(e,t){let n=Cl(e,t);if(n)return n;let r=[],i=s=>{let o=s?Qr(e,s):e,a;try{a=_l(o,{withFileTypes:!0})}catch{return}for(let l of a){if(Bn.has(l.name))continue;let c=s?`${s}/${l.name}`:l.name;if(l.isDirectory()){i(c);continue}t.has(Ht(l.name).toLowerCase())&&r.push(c)}};return i(""),r.sort()}function Cl(e,t){try{return Sl("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}).split(`
|
|
68
|
+
`).filter(r=>r&&t.has(Ht(r).toLowerCase())).sort()}catch{return null}}function vl(e,t){let n=new Set,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT relative_path FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.add(a.relative_path)}return n}function Nl(e){return Ht(e).toLowerCase()===".vue"?"vue":Ht(e).replace(/^\./,"").toLowerCase()||"source"}import{execFileSync as El}from"child_process";import{existsSync as Dl,readdirSync as Zr}from"fs";import{extname as ei,join as ti}from"path";var Ll=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),kl=[{language:"typescript",files:["tsconfig.json","tsconfig.base.json"],extensions:[".ts",".tsx",".mts",".cts"]},{language:"rust",files:["Cargo.toml"],extensions:[".rs"]},{language:"go",files:["go.mod"],extensions:[".go"]},{language:"java",files:["pom.xml","build.gradle","build.gradle.kts"],extensions:[".java"]},{language:"kotlin",files:["build.gradle.kts"],extensions:[".kt",".kts"]},{language:"scala",files:["build.sbt"],extensions:[".scala"]},{language:"python",files:["pyproject.toml","setup.py","setup.cfg","Pipfile"],extensions:[".py",".pyi"]},{language:"ruby",files:["Gemfile"],extensions:[".rb"]},{language:"cpp",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".cc",".cpp",".cxx",".hpp",".hh",".hxx"]},{language:"c",files:["compile_commands.json","CMakeLists.txt","Makefile"],extensions:[".c",".h"]},{language:"csharp",globs:["*.csproj","*.sln"],extensions:[".cs"]},{language:"vb",globs:["*.vbproj"],extensions:[".vb"]},{language:"dart",files:["pubspec.yaml"],extensions:[".dart"]},{language:"php",files:["composer.json"],extensions:[".php"]},{language:"javascript",files:["package.json"],extensions:[".js",".jsx",".mjs",".cjs"]}];function je(e){let t=[],n=wl(e),r=Fl(e);for(let i of kl){if(Pl(e,i.files)){t.push(i.language);continue}if(Ol(n,i.globs)){t.push(i.language);continue}$l(r,i.extensions)&&t.push(i.language)}return t.includes("typescript")&&Xr(t,"javascript"),t.includes("cpp")&&!r.has(".c")&&Xr(t,"c"),t}function wl(e){try{return Zr(e)}catch{return[]}}function Pl(e,t){return t?.length?t.some(n=>Dl(ti(e,n))):!1}function Ol(e,t){return t?.length?e.some(n=>t.some(r=>Ml(n,r))):!1}function Ml(e,t){if(t==="*")return!0;if(!t.includes("*"))return e===t;let[n,r]=t.split("*");return e.startsWith(n??"")&&e.endsWith(r??"")}function Fl(e){let t=Tl(e);if(t)return t;let n=new Set,r=[e];for(;r.length>0;){let i=r.pop();if(!i)continue;let s;try{s=Zr(i,{withFileTypes:!0})}catch{continue}for(let o of s){if(o.name.startsWith(".")&&!o.name.endsWith("proj")&&!o.name.endsWith("sln")&&o.isDirectory())continue;let a=ti(i,o.name);if(o.isDirectory()){Ll.has(o.name)||r.push(a);continue}let l=ei(o.name).toLowerCase();l&&n.add(l)}}return n}function Tl(e){try{let t=El("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:26214400,stdio:["ignore","pipe","ignore"]}),n=new Set;for(let r of t.split(`
|
|
69
|
+
`)){if(!r)continue;let i=ei(r).toLowerCase();i&&n.add(i)}return n}catch{return null}}function $l(e,t){return t?.length?t.some(n=>e.has(n)):!1}function Xr(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}import{existsSync as ni,readdirSync as Al}from"fs";import{join as Wn}from"path";var jl={typescript:{language:"typescript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,pnpmWorkspaces:t,indexerBinary:n})=>{let r=["index","--infer-tsconfig","--output",e,"--no-progress-bar"];return t&&r.splice(1,0,"--pnpm-workspaces"),{binary:n,args:r}},markerFiles:["tsconfig.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},javascript:{language:"javascript",indexerBinary:"scip-typescript",checkCommand:"npx scip-typescript --version",indexArgs:({outputPath:e,indexerBinary:t})=>({binary:t,args:["index","--infer-tsconfig","--output",e,"--no-progress-bar"]}),markerFiles:["package.json"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","@sourcegraph/scip-typescript"]}],installUrl:"https://github.com/sourcegraph/scip-typescript",bundledNpmPackage:"@sourcegraph/scip-typescript"},java:{language:"java",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["pom.xml","build.gradle"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},scala:{language:"scala",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.sbt"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},kotlin:{language:"kotlin",indexerBinary:"scip-java",checkCommand:"scip-java --version",indexArgs:({outputPath:e})=>({binary:"scip-java",args:["index","--output",e]}),markerFiles:["build.gradle.kts"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-java/releases"},rust:{language:"rust",indexerBinary:"rust-analyzer",checkCommand:"rust-analyzer --version",indexArgs:({outputPath:e})=>({binary:"rust-analyzer",args:["scip",".","--output",e]}),markerFiles:["Cargo.toml"],installMethods:[{label:"rustup",prerequisite:"rustup",binary:"rustup",args:["component","add","rust-analyzer"]}],installUrl:"https://github.com/rust-lang/rust-analyzer"},python:{language:"python",indexerBinary:"scip-python-plus",binaryAliases:["scip-python"],checkCommand:"scip-python-plus --version",indexArgs:({outputPath:e,indexerBinary:t})=>({binary:t,args:["index","--output",e,"--project-name","project"]}),markerFiles:["pyproject.toml","setup.py"],installMethods:[{label:"npm",prerequisite:"npm",binary:"npm",args:["install","-g","scip-python-plus"]}],installUrl:"https://github.com/PlunderStruck/scip-python",bundledNpmPackage:"scip-python-plus"},ruby:{language:"ruby",indexerBinary:"scip-ruby",checkCommand:"scip-ruby --version",indexArgs:({indexerBinary:e})=>({binary:e,args:["--dir","."]}),defaultOutputPath:"index.scip",markerFiles:["Gemfile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-ruby/releases"},go:{language:"go",indexerBinary:"scip-go",checkCommand:"scip-go --version",indexArgs:({outputPath:e})=>({binary:"scip-go",args:["--output",e]}),markerFiles:["go.mod"],installMethods:[{label:"go install",prerequisite:"go",binary:"go",args:["install","github.com/sourcegraph/scip-go@latest"]}],installUrl:"https://github.com/sourcegraph/scip-go"},cpp:{language:"cpp",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},c:{language:"c",indexerBinary:"scip-clang",checkCommand:"scip-clang --version",indexArgs:({outputPath:e})=>({binary:"scip-clang",args:["--compdb-path","compile_commands.json","--index-output-path",e]}),markerFiles:["CMakeLists.txt","Makefile"],installMethods:[],installUrl:"https://github.com/sourcegraph/scip-clang/releases"},csharp:{language:"csharp",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:t})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".csproj"])??e,"--output",t,"--working-directory",e]}),markerFiles:["*.csproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},vb:{language:"vb",indexerBinary:"scip-dotnet",checkCommand:"scip-dotnet --version",indexArgs:({projectRoot:e,outputPath:t})=>({binary:"scip-dotnet",args:["index",ri(e,[".sln",".vbproj"])??e,"--output",t,"--working-directory",e]}),markerFiles:["*.vbproj","*.sln"],installMethods:[{label:"dotnet",prerequisite:"dotnet",binary:"dotnet",args:["tool","install","--global","scip-dotnet"]}],installUrl:"https://github.com/sourcegraph/scip-dotnet/releases"},dart:{language:"dart",indexerBinary:"scip-dart",checkCommand:"scip-dart --version",indexArgs:({indexerBinary:e,outputPath:t})=>({binary:e,args:["--output",t]}),markerFiles:["pubspec.yaml"],installMethods:[{label:"dart pub",prerequisite:"dart",binary:"dart",args:["pub","global","activate","scip_dart"]}],installUrl:"https://github.com/Workiva/scip-dart/releases"},php:{language:"php",indexerBinary:"scip-php",projectLocalBinaries:["vendor/davidrjenni/scip-php/bin/scip-php","vendor/bin/scip-php"],checkCommand:"scip-php --version",indexArgs:({projectRoot:e,indexerBinary:t})=>{let n=Wn(e,"vendor","bin","scip-php"),r=Wn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",ni(r)?r:ni(n)?n:t]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function Vt(e){return jl[e]}function ri(e,t){let n;try{n=Al(e)}catch{return null}for(let r of n)if(t.some(i=>r.endsWith(i)))return Wn(e,r);return null}import{readFileSync as Bl,writeFileSync as Wl}from"fs";import{create as Hn}from"@bufbuild/protobuf";import{deserializeSCIP as Hl,serializeSCIP as Vl,DocumentSchema as Ul,IndexSchema as Jl,SymbolInformationSchema as ql}from"@c4312/scip";function zl(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let t=Gl(e),n=Kl(e.flatMap(i=>i.documents??[])),r=si(e.flatMap(i=>i.externalSymbols??[]));return Hn(Jl,{metadata:t,documents:n,externalSymbols:r})}function ii(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let n=e.map(i=>Hl(Bl(i))),r=zl(n);return Wl(t,Buffer.from(Vl(r))),{documentCount:r.documents.length,externalSymbolCount:r.externalSymbols.length,inputCount:e.length}}function Gl(e){let t=e[0]?.metadata;if(!t)return;let n=t.projectRoot;for(let r of e.slice(1)){let i=r.metadata?.projectRoot;if(n&&i&&i!==n)throw new Error(`Cannot merge SCIP indexes with different project roots: ${n} vs ${i}`)}return t}function Kl(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);if(!r){t.set(n.relativePath,n);continue}t.set(n.relativePath,Hn(Ul,{language:r.language||n.language,relativePath:r.relativePath||n.relativePath,occurrences:[...r.occurrences,...n.occurrences],symbols:si([...r.symbols,...n.symbols]),text:Ql(r.text,n.text),positionEncoding:r.positionEncoding||n.positionEncoding}))}return[...t.values()]}function si(e){let t=new Map;for(let n of e){let r=t.get(n.symbol);if(!r){t.set(n.symbol,n);continue}t.set(n.symbol,Hn(ql,{symbol:r.symbol,documentation:Xl([...r.documentation,...n.documentation]),relationships:Yl([...r.relationships,...n.relationships]),kind:r.kind||n.kind,displayName:r.displayName||n.displayName,enclosingSymbol:r.enclosingSymbol||n.enclosingSymbol,signatureDocumentation:r.signatureDocumentation??n.signatureDocumentation}))}return[...t.values()]}function Yl(e){let t=new Set,n=[];for(let r of e){let i=[r.symbol,r.isReference?"1":"0",r.isImplementation?"1":"0",r.isTypeDefinition?"1":"0",r.isDefinition?"1":"0"].join("|");t.has(i)||(t.add(i),n.push(r))}return n}function Ql(e,t){return e?t?e.length>=t.length?e:t:e:t}function Xl(e){return[...new Set(e)]}import{execFileSync as Zl}from"child_process";import{createHash as ec}from"crypto";import{readdirSync as tc,readFileSync as nc}from"fs";import{join as oi}from"path";function rc(e){return(ic(e)??sc(e)).filter(t=>t&&!ai(t)).sort()}function Ut(e){return rc(e).map(t=>{let n=oi(e,t);try{let r=nc(n);return{path:t,size:r.byteLength,hash:ec("sha256").update(r).digest("hex")}}catch{return{path:t,size:-1,hash:"unreadable"}}})}function ic(e){try{return Zl("git",["-C",e,"ls-files","-co","--exclude-standard","--","."],{encoding:"utf-8",maxBuffer:50*1024*1024,stdio:["ignore","pipe","ignore"]}).split(`
|
|
70
|
+
`).filter(Boolean)}catch{return null}}function sc(e){let t=[],n=[""];for(;n.length>0;){let r=n.pop(),i=r?oi(e,r):e,s;try{s=tc(i,{withFileTypes:!0})}catch{continue}for(let o of s){let a=r?`${r}/${o.name}`:o.name;if(o.isDirectory()){ai(a)||n.push(a);continue}t.push(a)}}return t}function ai(e){return e.split("/").some(n=>oc.has(n))||e.endsWith(".db")||e.endsWith(".db-wal")||e.endsWith(".db-shm")||e.endsWith(".scip")}var oc=new Set([".git","node_modules",".scipquery-cache",".stryker-tmp","dist","build","coverage",".next",".nuxt","target"]);import{readFileSync as ac,writeFileSync as lc}from"fs";import{create as li}from"@bufbuild/protobuf";import{deserializeSCIP as cc,DocumentSchema as uc,IndexSchema as dc,serializeSCIP as mc,SymbolRole as pc}from"@c4312/scip";function ci(e){let t;try{t=cc(ac(e))}catch{return{removedDefinitionOccurrences:0,touchedDocuments:0}}let n=fc(t);return n.removedDefinitionOccurrences>0&&lc(e,Buffer.from(mc(n.index))),{removedDefinitionOccurrences:n.removedDefinitionOccurrences,touchedDocuments:n.touchedDocuments}}function fc(e){let t=new Set;for(let s of e.documents)for(let o of s.symbols)o.symbol&&t.add(o.symbol);for(let s of e.externalSymbols)s.symbol&&t.add(s.symbol);let n=0,r=0,i=[];for(let s of e.documents){let o=s.occurrences.filter(a=>(a.symbolRoles&pc.Definition)===0||t.has(a.symbol)?!0:(n+=1,!1));if(o.length===s.occurrences.length){i.push(s);continue}r+=1,i.push(li(uc,{language:s.language,relativePath:s.relativePath,occurrences:o,symbols:s.symbols,text:s.text,positionEncoding:s.positionEncoding}))}return{index:n===0?e:li(dc,{metadata:e.metadata,documents:i,externalSymbols:e.externalSymbols}),removedDefinitionOccurrences:n,touchedDocuments:r}}import{execFileSync as qt}from"child_process";import{existsSync as Vn,readFileSync as gc}from"fs";import{createRequire as hc}from"module";import{platform as di}from"os";import{dirname as ui,join as Jt}from"path";var yc=hc(import.meta.url),bc=di()==="win32";function mt(e){let t=bc?"where":"which";try{return qt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Un(e){return[e.indexerBinary,...e.binaryAliases??[]]}function zt(e){let t=Un(e);return t.length===1?t[0]:t.join(" or ")}function Qe(e){for(let t of Un(e))if(mt(t))return t;return xc(e)}function mi(e){return Qe(e)!==null||Sc(e)}function Sc(e){return pi(e)!==null}function xc(e){let t=pi(e);if(!t)return null;let r=JSON.parse(gc(t,"utf8")).bin;if(!r)return null;if(typeof r=="string")return Jt(ui(t),r);for(let i of Un(e)){let s=r[i];if(s)return Jt(ui(t),s)}return null}function pi(e){if(!e.bundledNpmPackage)return null;try{return yc.resolve(`${e.bundledNpmPackage}/package.json`)}catch{return null}}function Jn(e,t){for(let n of e.projectLocalBinaries??[]){let r=Jt(t,n);if(Vn(r))return r}return null}function _c(e,t){return Jn(e,t)??Qe(e)}function fi(e,t=process.env,n=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||qn(n,t))return t;let r=yi(n,t);return r?{...t,DOTNET_ROOT:r}:t}function gi(e,t){let n=zt(e),r=t?_c(e,t):Qe(e);if(!r)return{language:e.language,binaryLabel:n,installed:!1,runnable:!1,resolvedBinary:null,installUrl:e.installUrl};if(e.indexerBinary!=="scip-dotnet")return{language:e.language,binaryLabel:n,installed:!0,runnable:!0,resolvedBinary:r};let i=Ic(r);return{language:e.language,binaryLabel:n,installed:!0,runnable:i.runnable,resolvedBinary:r,installUrl:e.installUrl,note:i.note}}function hi(e,t){let n=e.installMethods,r=zt(e);if(!n?.length)return t(`No auto-install method available for ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1;for(let i of n)if(mt(i.prerequisite)){t(`Installing ${r} via ${i.label}...`);try{qt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let s=Qe(e);if(s){let o=s===e.indexerBinary?"":` (using ${s})`;return t(`Successfully installed ${r} via ${i.label}${o}`),!0}t(`${i.label} command completed but ${r} was not found on PATH`)}catch(s){let o=s instanceof Error?s.message:String(s);t(`${i.label} install failed: ${o}`)}}return t(`Could not auto-install ${r}.`),e.installUrl&&t(`Install manually from: ${e.installUrl}`),!1}function Ic(e){if(qn(e,process.env))return{runnable:!0};let t=yi(e,process.env);if(t)return{runnable:!0,note:`using .NET 9 runtime from ${t}`};let n=bi(process.env);return{runnable:!1,note:n.length>0?`.NET 9 runtime still unavailable after checking ${n.join(", ")}`:"binary is present, but scip-dotnet still needs a .NET 9 runtime"}}function yi(e,t){for(let n of bi(t))if(qn(e,{...t,DOTNET_ROOT:n}))return n;return null}function bi(e){let t=[],n=e.DOTNET_ROOT;if(n&&Vn(n)&&t.push(n),di()==="darwin"&&mt("brew"))try{let r=qt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Jt(r,"libexec");Vn(i)&&!t.includes(i)&&t.push(i)}catch{}return t}function qn(e,t){try{return qt(e,["--version"],{stdio:"pipe",env:t}),!0}catch{return!1}}import Rc from"better-sqlite3";import{createRequire as Cc}from"module";import{existsSync as xi,mkdtempSync as vc,readFileSync as pt,rmSync as Nc,statSync as Ec,writeFileSync as Dc}from"fs";import{cpus as Lc,tmpdir as kc}from"os";import{dirname as Gn,extname as wc,join as Xe,relative as Pc,resolve as _i}from"path";import{pathToFileURL as Oc}from"url";import{Worker as Mc}from"worker_threads";function Kn(e){De({projectRoot:e.projectRoot,dbPath:e.dbPath});let t=_i(e.projectRoot,e.tsconfig);if(!xi(t))throw new Error(`Vue tsconfig not found at ${t}`);let n=new Rc(e.dbPath);try{let r=nu(n,e.projectRoot),i=Xe(Gn(e.dbPath),"augment-vue-meta.json"),s=Si(n,e.projectRoot,e.tsconfig),o=Fc(i,s,e.onStatus);if(o)return o;let a=du(n,e.projectRoot,r),l=Tc(n,e,t,r,a),c=gu(l.occurrences),u=$c(n,e,r,a,c);e.onStatus?.(`Resolved ${c.length} Vue references with Volar; inserted ${u} mentions.`);let d=Ac(r,c,u,l,a);return Bc(i,Si(n,e.projectRoot,e.tsconfig),d),d}finally{n.close()}}function Fc(e,t,n){let r=jc(e,t);return r&&n?.(`Vue references unchanged; reused ${r.resolvedReferences} cached resolved references.`),r}function Tc(e,t,n,r,i){if(Gc(r))return Kc({projectRoot:t.projectRoot,dbPath:t.dbPath,tsconfig:t.tsconfig,vueFiles:r});let s=_u(),o=ru(t.projectRoot,n);return Wc({projectRoot:t.projectRoot,vueFiles:o.fileNames.filter(a=>a.endsWith(".vue")),context:o,symbolLookup:lu(e,t.projectRoot,s),vueSymbolLookup:i,sourceCache:s})}function $c(e,t,n,r,i){return mu(e,t.projectRoot,n,r,i)}function Ac(e,t,n,r,i){return{vueFiles:e.length,resolvedReferences:t.length,insertedMentions:n,skippedReferences:r.skippedReferences,syntheticSymbols:i.syntheticSymbols}}function jc(e,t){try{let n=JSON.parse(pt(e,"utf-8"));return JSON.stringify(n.fingerprint)===JSON.stringify(t)?n.result:null}catch{return null}}function Bc(e,t,n){Dc(e,JSON.stringify({updatedAt:new Date().toISOString(),fingerprint:t,result:n},null,2)+`
|
|
71
|
+
`)}function Si(e,t,n){let r=e.prepare(`
|
|
72
|
+
SELECT
|
|
73
|
+
(SELECT COUNT(*) FROM documents) AS documents,
|
|
74
|
+
(SELECT COUNT(*) FROM global_symbols) AS symbols,
|
|
75
|
+
(SELECT COUNT(*) FROM chunks) AS chunks,
|
|
76
|
+
(SELECT COUNT(*) FROM mentions) AS mentions,
|
|
77
|
+
(SELECT COUNT(*) FROM defn_enclosing_ranges) AS ranges,
|
|
78
|
+
(SELECT MAX(id) FROM chunks) AS maxChunkId,
|
|
79
|
+
(SELECT MAX(id) FROM global_symbols) AS maxSymbolId
|
|
80
|
+
`).get();return{version:2,tsconfig:n,files:Ut(t),db:r}}function Wc(e){let t=[],n=0,r=e.tasks??e.vueFiles.map(i=>({fileName:i,startOffset:0,endOffset:Number.POSITIVE_INFINITY,countFileSkip:!0}));for(let i of r){let s=Hc(e,i);t.push(...s.occurrences),n+=s.skippedReferences}return{occurrences:t,skippedReferences:n}}function Hc(e,t){let n=e.context.language.scripts.get(t.fileName),r=n?.generated?.languagePlugin.typescript?.getServiceScript(n.generated.root)?.code;if(!n||!r)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let i=e.sourceCache(t.fileName);if(!i)return{occurrences:[],skippedReferences:t.countFileSkip?1:0};let s=e.context.language.maps.get(r,n),o=ft(e.projectRoot,t.fileName),a=[...yu(i.text)],l={tokens:a.filter(c=>c.start>=t.startOffset&&c.start<t.endOffset),tokenByStart:new Map(a.map(c=>[c.start,c])),tokenTextCounts:Jc(a),processedStarts:new Set};return Vc({...e,fileName:t.fileName,sourceInfo:i,sourceFile:o,map:s,tokenContext:l})}function Vc(e){let t=[],n=0;for(let r of e.tokenContext.tokens){if(e.tokenContext.processedStarts.has(r.start))continue;let i=bu(e.map,r.start);if(i===null)continue;let o=(e.context.languageService.getDefinitionAtPosition(e.fileName,i+1)??[]).find(l=>!Su(e.projectRoot,l.fileName));if(!o){n++;continue}let a=fu(o,e.symbolLookup,e.vueSymbolLookup,e.context,e.projectRoot);if(a===null){n++;continue}Ii(t,e.sourceInfo,e.sourceFile,r,a),e.tokenContext.processedStarts.add(r.start),Uc(t,e,r,i,a)}return{occurrences:t,skippedReferences:n}}function Uc(e,t,n,r,i){if(!((t.tokenContext.tokenTextCounts.get(n.text)??0)<=1))for(let s of qc(t.context.languageService,t.fileName,r+1,t.map,n,t.tokenContext.tokenByStart)){if(t.tokenContext.processedStarts.has(s))continue;let o=t.tokenContext.tokenByStart.get(s);o&&(Ii(e,t.sourceInfo,t.sourceFile,o,i),t.tokenContext.processedStarts.add(s))}}function Ii(e,t,n,r,i){let s=Ei(t,r.start);e.push({sourceFile:n,sourceLine:s.line,sourceStartChar:s.character,sourceEndChar:s.character+r.text.length,symbolId:i})}function Jc(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return t}function qc(e,t,n,r,i,s){let o=e.getDocumentHighlights?.(t,n,[t])??[],a=[];for(let l of o)if(l.fileName===t)for(let c of l.highlightSpans){let u=zc(r,c.textSpan.start,s,i.text);u!==null&&a.push(u)}return a}function zc(e,t,n,r){let i=n.get(t);if(i?.text===r)return i.start;let s=Ni(e,t);if(s===null)return null;let o=n.get(s);return o?.text===r?o.start:null}function Gc(e){return e.length>=8&&Ri(e.length)>1}function Kc(e){let t=Ri(e.vueFiles.length),n=Qc(e.vueFiles),r=Zc(n,t),i=new URL("./augment-vue-worker.js",import.meta.url),s=vc(Xe(kc(),"scip-query-vue-workers-")),o=new SharedArrayBuffer(4),a=new Int32Array(o),l=Yc(),c=Date.now();try{for(let d=0;d<r.length;d++)new Mc(i,{workerData:{projectRoot:e.projectRoot,dbPath:e.dbPath,tsconfig:e.tsconfig,tasks:r[d],resultPath:Xe(s,`${d}.json`),sharedBuffer:o}});for(;Atomics.load(a,0)<r.length;){if(Date.now()-c>l)throw new Error(`Vue reference workers timed out after ${(l/1e3).toFixed(0)}s`);Atomics.wait(a,0,Atomics.load(a,0),100)}let u=r.map((d,m)=>{let g=JSON.parse(pt(Xe(s,`${m}.json`),"utf-8"));if(!g.ok)throw new Error(`Vue reference worker failed: ${g.error}`);return g.result});return{occurrences:u.flatMap(d=>d.occurrences),skippedReferences:u.reduce((d,m)=>d+m.skippedReferences,0)}}finally{Nc(s,{recursive:!0,force:!0})}}function Ri(e){let t=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKERS??0),n=Number.isFinite(t)&&t>0?t:Math.min(8,Math.max(1,Lc().length-1));return Math.max(1,Math.min(e,n))}function Yc(){let e=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKER_TIMEOUT_MS??0);return Number.isFinite(e)&&e>0?e:3e5}function Qc(e){let t=Xc(),n=[];for(let r of e){let i=Ci(r),s=Math.max(1,Math.ceil(i/t));for(let o=0;o<s;o++)n.push({fileName:r,startOffset:Math.floor(i*o/s),endOffset:o===s-1?Number.POSITIVE_INFINITY:Math.floor(i*(o+1)/s),countFileSkip:o===0})}return n}function Xc(){return Number.POSITIVE_INFINITY}function Zc(e,t){let n=Array.from({length:t},()=>({tasks:[],weight:0})),r=e.map(i=>({task:i,weight:eu(i)})).sort((i,s)=>s.weight-i.weight);for(let i of r){let s=n.reduce((o,a)=>a.weight<o.weight?a:o);s.tasks.push(i.task),s.weight+=i.weight}return n.map(i=>i.tasks).filter(i=>i.length>0)}function eu(e){return Number.isFinite(e.endOffset)?Math.max(1,e.endOffset-e.startOffset):Math.max(1,Ci(e.fileName)-e.startOffset)}function Ci(e){try{return Ec(e).size}catch{return 1}}function tu(e){e.transaction(()=>{e.prepare(`
|
|
86
81
|
DELETE FROM mentions
|
|
87
82
|
WHERE chunk_id IN (
|
|
88
83
|
SELECT c.id
|
|
@@ -97,48 +92,79 @@ Thumbs.db
|
|
|
97
92
|
FROM documents
|
|
98
93
|
WHERE language = 'vue' OR relative_path LIKE '%.vue'
|
|
99
94
|
)
|
|
100
|
-
`).run()})()}function
|
|
101
|
-
SELECT
|
|
95
|
+
`).run()})()}function nu(e,t){return e.prepare(`
|
|
96
|
+
SELECT relative_path AS relativePath
|
|
97
|
+
FROM documents
|
|
98
|
+
WHERE language = 'vue' OR relative_path LIKE '%.vue'
|
|
99
|
+
ORDER BY relative_path
|
|
100
|
+
`).all().map(r=>_i(t,r.relativePath))}function ru(e,t){let{vueCore:n,ts:r,volarTs:i}=iu(e),{parsed:s,vueOptions:o}=su(n,r,t),a=Gn(t),l=n.createVueLanguagePlugin(r,s.options,o,g=>g),c=ou(n,r,l),u=au(a,s),{languageServiceHost:d}=i.createLanguageServiceHost(r,r.sys,c,g=>g,u),m=r.createLanguageService(d);return{ts:r,language:c,languageService:m,fileNames:s.fileNames,configDir:a}}function iu(e){let t=Cc(Oc(Xe(e,"package.json")).href);return{vueCore:zn(t,"@vue/language-core",e),ts:zn(t,"typescript",e),volarTs:zn(t,"@volar/typescript",e)}}function su(e,t,n){let r=t.readConfigFile(n,t.sys.readFile);if(r.error||!r.config)throw new Error(`Failed to read ${n}`);let s=e.createParsedCommandLine(t,t.sys,n).vueOptions;return typeof e.createGlobalTypesWriter=="function"&&(s.globalTypesPath=e.createGlobalTypesWriter(s,t.sys.writeFile)),{parsed:t.parseJsonConfigFileContent(r.config,t.sys,Gn(n),void 0,n,void 0,e.getAllExtensions(s).map(o=>({extension:o.slice(1),isMixedContent:!0,scriptKind:t.ScriptKind.Deferred}))),vueOptions:s}}function ou(e,t,n){let r={},i=e.createLanguage([n],new Map,s=>{if(!xi(s))return;let o=pt(s,"utf-8");r.current?.scripts.set(s,t.ScriptSnapshot.fromString(o),n.getLanguageId(s)??xu(s))});return r.current=i,i}function au(e,t){return{getCurrentDirectory:()=>e,getCompilationSettings:()=>t.options,getScriptFileNames:()=>t.fileNames,getProjectReferences:()=>t.projectReferences,getProjectVersion:()=>"0"}}function zn(e,t,n){try{return e(t)}catch(r){throw(typeof r=="object"&&r!==null&&"code"in r?r.code:null)==="MODULE_NOT_FOUND"?new Error(`Vue augmentation requires ${t} to be installed in ${n}. Install Vue/Volar dependencies for that project, then rerun augment-vue.`,{cause:r}):r}}function lu(e,t,n){let r=cu(e);return i=>{let s=ft(t,i.fileName),o=n(i.fileName);if(!o)return null;let a=Ei(o,i.textSpan.start),l=r.get(s);if(!l)return null;let c=l.containingByLine.get(a.line);return c!==void 0?c:uu(l.starts,a.line,2)}}function cu(e){let t=e.prepare(`
|
|
101
|
+
SELECT
|
|
102
|
+
d.relative_path AS relativePath,
|
|
103
|
+
der.start_line AS startLine,
|
|
104
|
+
der.end_line AS endLine,
|
|
105
|
+
der.symbol_id AS symbolId
|
|
102
106
|
FROM defn_enclosing_ranges der
|
|
103
107
|
JOIN documents d ON d.id = der.document_id
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
AND der.end_line >= ?
|
|
107
|
-
ORDER BY (der.end_line - der.start_line) ASC
|
|
108
|
-
LIMIT 1
|
|
109
|
-
`),s=e.prepare(`
|
|
110
|
-
SELECT der.symbol_id AS symbolId
|
|
111
|
-
FROM defn_enclosing_ranges der
|
|
112
|
-
JOIN documents d ON d.id = der.document_id
|
|
113
|
-
WHERE d.relative_path = ?
|
|
114
|
-
AND der.start_line BETWEEN ? AND ?
|
|
115
|
-
ORDER BY ABS(der.start_line - ?) ASC
|
|
116
|
-
LIMIT 1
|
|
117
|
-
`);return i=>{let o=Tt(n,i.fileName),a=Wa(i.fileName);if(!a)return null;let r=As(a,i.textSpan.start),l=t.get(o,r.line,r.line);return l?l.symbolId:s.get(o,Math.max(0,r.line-2),r.line+2,r.line)?.symbolId??null}}function $a(e,n,t){let s=Ha(n),i=e.prepare("SELECT id FROM global_symbols WHERE symbol = ?"),o=e.prepare(`
|
|
108
|
+
ORDER BY d.relative_path, (der.end_line - der.start_line) DESC
|
|
109
|
+
`).all(),n=new Map;for(let r of t){let i=n.get(r.relativePath);i||(i={containingByLine:new Map,starts:[]},n.set(r.relativePath,i)),i.starts.push({line:r.startLine,symbolId:r.symbolId});for(let s=r.startLine;s<=r.endLine;s++)i.containingByLine.set(s,r.symbolId)}for(let r of n.values())r.starts.sort((i,s)=>i.line-s.line);return n}function uu(e,t,n){let r=0,i=e.length-1;for(;r<=i;){let o=Math.floor((r+i)/2);e[o].line<t?r=o+1:i=o-1}let s=null;for(let o of[i,r]){let a=e[o];if(!a)continue;let l=Math.abs(a.line-t);l>n||(!s||l<s.distance)&&(s={distance:l,symbolId:a.symbolId})}return s?.symbolId??null}function du(e,t,n){let r=Cu(t),i=e.prepare("SELECT id FROM global_symbols WHERE symbol = ?"),s=e.prepare(`
|
|
118
110
|
INSERT OR IGNORE INTO global_symbols (symbol, display_name, kind, documentation)
|
|
119
111
|
VALUES (?, ?, ?, ?)
|
|
120
|
-
`),a=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),
|
|
112
|
+
`),o=0,a=new Map;return e.transaction(()=>{for(let c of n){let u=ft(t,c),d=vu(r.name,r.version,u);s.run(d,"default",7,`Vue component|${u}`);let m=i.get(d);m&&(o++,a.set(c,m.id))}})(),{get(c){return a.get(c)??null},syntheticSymbols:o}}function mu(e,t,n,r,i){return e.transaction(()=>(tu(e),pu(e,t,n,r),hu(e,i)))()}function pu(e,t,n,r){let i=e.prepare("SELECT id FROM documents WHERE relative_path = ?"),s=e.prepare(`
|
|
121
113
|
INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
|
|
122
114
|
VALUES (?, ?, ?, ?, X'00')
|
|
123
|
-
`),
|
|
115
|
+
`),o=e.prepare(`
|
|
124
116
|
INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
|
|
125
117
|
VALUES (?, ?, 1)
|
|
126
|
-
`)
|
|
118
|
+
`);for(let a of n){let l=r.get(a);if(!l)continue;let c=ft(t,a),u=i.get(c);if(!u)continue;let d=s.run(u.id,-1,0,0);o.run(Number(d.lastInsertRowid),l)}}function fu(e,t,n,r,i){if(e.fileName.endsWith(".vue")){let s=r.language.scripts.get(e.fileName),o=s?.generated?.languagePlugin.typescript?.getServiceScript(s.generated.root)?.code;if(s&&o){let a=r.language.maps.get(o,s);if(Ni(a,e.textSpan.start)!==null)return n.get(e.fileName)}return e.fileName.startsWith(i)?n.get(e.fileName):null}return t(e)}function gu(e){let t=new Set,n=[];for(let r of e){let i=vi(r);t.has(i)||(t.add(i),n.push(r))}return n}function vi(e){return[e.sourceFile,e.sourceLine,e.sourceStartChar,e.sourceEndChar,e.symbolId].join(":")}function hu(e,t){let n=Ru(e,[...new Set(t.map(l=>l.sourceFile))]),r=e.prepare(`
|
|
127
119
|
INSERT INTO chunks (document_id, chunk_index, start_line, end_line, occurrences)
|
|
128
120
|
VALUES (?, ?, ?, ?, X'00')
|
|
129
121
|
`),i=e.prepare(`
|
|
130
122
|
INSERT OR IGNORE INTO mentions (chunk_id, symbol_id, role)
|
|
131
123
|
VALUES (?, ?, 0)
|
|
132
|
-
`),
|
|
133
|
-
Install from: https://github.com/sourcegraph/scip/releases`);if(
|
|
134
|
-
Install manually from: https://github.com/sourcegraph/scip/releases`)}let
|
|
135
|
-
`)[0]}`;s(`Skipping ${p}: ${q}`),d.push({language:p,reason:q});continue}Ga(y,n,f),u.push({language:p,scipPath:f})}if(u.length===0){let p=d.map(f=>` - ${f.language}: ${f.reason}`).join(`
|
|
124
|
+
`),s=new Set,o=0,a=0;for(let l of t){let c=vi(l);if(s.has(c))continue;s.add(c);let u=n.get(l.sourceFile);if(!u)continue;let d=r.run(u,a++,l.sourceLine,l.sourceLine),m=i.run(Number(d.lastInsertRowid),l.symbolId);o+=Number(m.changes)}return o}function*yu(e){let t=/\b[A-Za-z_$][A-Za-z0-9_$]*\b/g,n=new Set(["script","setup","template","style","lang","scoped","true","false","null","undefined","const","let","var","import","from","export","return","if","else","for","while","function","class","type","interface","as","await","async"]),r;for(;r=t.exec(e);){let i=r[0];n.has(i)||(yield{text:i,start:r.index,end:r.index+i.length})}}function bu(e,t){for(let[n]of e.toGeneratedLocation(t,r=>!!r.navigation))return n;return null}function Ni(e,t){let n=e;for(let[r]of n.toSourceLocation(t,i=>!!i.navigation))return r;return null}function Ei(e,t){let n=0,r=e.lineStarts.length-1;for(;n<=r;){let s=Math.floor((n+r)/2);e.lineStarts[s]<=t?n=s+1:r=s-1}let i=Math.max(0,r);return{line:i,character:t-e.lineStarts[i]}}function Su(e,t){return ft(e,t).startsWith("node_modules/")}function ft(e,t){return Pc(e,t).replaceAll("\\","/")}function xu(e){switch(wc(e)){case".vue":return"vue";case".tsx":return"typescriptreact";case".ts":case".mts":case".cts":return"typescript";case".jsx":return"javascriptreact";case".js":case".mjs":case".cjs":return"javascript";case".json":return"json";default:return"typescript"}}function _u(){let e=new Map;return t=>{if(e.has(t))return e.get(t)??null;try{let n=pt(t,"utf-8"),r={text:n,lineStarts:Iu(n)};return e.set(t,r),r}catch{return e.set(t,null),null}}}function Iu(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return t}function Ru(e,t){let n=new Map,r=500;for(let i=0;i<t.length;i+=r){let s=t.slice(i,i+r),o=e.prepare(`SELECT id, relative_path AS relativePath FROM documents WHERE relative_path IN (${s.map(()=>"?").join(",")})`).all(...s);for(let a of o)n.set(a.relativePath,a.id)}return n}function Cu(e){try{let t=JSON.parse(pt(Xe(e,"package.json"),"utf-8"));return{name:t.name??"workspace",version:t.version??"0.0.0"}}catch{return{name:"workspace",version:"0.0.0"}}}function vu(e,t,n){let r=n.split("/").map(i=>`\`${i.replaceAll("`","")}\``).join("/");return`scip-vue npm ${e} ${t} ${r}/default.`}async function ki(e){let{projectRoot:t,maxHeapMb:n=8192,onStatus:r=console.log,skipAutoInstall:i=!1}=e,s=Mu(e),o=Date.now();Di(Be(s.outputScip),{recursive:!0}),Di(Be(s.outputDb),{recursive:!0});let a=e.languages??je(t);if(a.length===0)throw new Error("No supported languages detected in this project. Looked for: tsconfig.json, Cargo.toml, go.mod, pyproject.toml, etc.");r(`Detected languages: ${a.join(", ")}`);let l=rd(t,a,{pnpmWorkspaces:e.pnpmWorkspaces}),c=Qu(se(Be(s.outputDb),"index.lock")),u=null;try{let d=Fu({opts:e,paths:s,languages:a,fingerprint:l,start:o,onStatus:r});if(d)return d;Bu(i,r);let m=Tu(s);return u=m.runDir,await $u({opts:e,languages:a,projectRoot:t,paths:s,tempPaths:m,fingerprint:l,start:o,maxHeapMb:n,skipAutoInstall:i,onStatus:r})}finally{u&&et(u,{recursive:!0,force:!0}),c()}}function Mu(e){let t=e.outputScip??se(e.projectRoot,"index.scip"),n=e.outputDb??se(e.projectRoot,"index.db");return{outputScip:t,outputDb:n,metaPath:se(Be(n),"meta.json")}}function Fu(e){if(e.opts.skipIfUnchanged===!1||!We(e.paths.outputScip)||!We(e.paths.outputDb)||!id(e.paths.metaPath,e.fingerprint))return null;De({projectRoot:e.opts.projectRoot,dbPath:e.paths.outputDb,onStatus:e.onStatus});let t=Date.now()-e.start;return e.onStatus(`Index unchanged; reused existing SQLite index in ${(t/1e3).toFixed(1)}s`),{languages:e.languages,indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:t,reused:!0,skipped:[]}}function Tu(e){let t=Lu(se(Be(e.outputDb),"reindex-"));return{runDir:t,tempOutputScip:se(t,Kt(e.outputScip)),tempOutputDb:se(t,Kt(e.outputDb)),tempMetaPath:se(t,Kt(e.metaPath))}}async function $u(e){let t={...process.env,NODE_OPTIONS:`--max-old-space-size=${e.maxHeapMb}`},{indexedOutputs:n,skippedLanguages:r}=await Au(e,t);ju(e,t,n,r);let i=Date.now()-e.start;return e.onStatus(`Done in ${(i/1e3).toFixed(1)}s`),{languages:n.map(s=>s.language),indexPath:e.paths.outputScip,dbPath:e.paths.outputDb,durationMs:i,reused:!1,skipped:r}}async function Au(e,t){let{preparedRuns:n,skippedLanguages:r}=Wu({languages:e.languages,tempOutputScip:e.tempPaths.tempOutputScip,projectRoot:e.projectRoot,env:t,skipAutoInstall:e.skipAutoInstall,pnpmWorkspaces:e.opts.pnpmWorkspaces,onStatus:e.onStatus}),i=await ed(n,e.projectRoot,e.onStatus,e.opts.indexerConcurrency),{indexedOutputs:s}=Vu(i,r);return Uu(s,r,e.languages,e.opts.allowPartial,e.onStatus),{indexedOutputs:s,skippedLanguages:r}}function ju(e,t,n,r){Ju(n,e.tempPaths.tempOutputScip,e.onStatus),qu(e.tempPaths.tempOutputScip,e.tempPaths.tempOutputDb,t,e.onStatus),De({projectRoot:e.projectRoot,dbPath:e.tempPaths.tempOutputDb,onStatus:e.onStatus}),sd(e.tempPaths.tempMetaPath,{version:2,status:r.length===0?"complete":"partial",updatedAt:new Date().toISOString(),fingerprint:e.fingerprint,requestedLanguages:e.languages,indexedLanguages:n.map(i=>i.language),skipped:[...r]}),Xu({tempOutputScip:e.tempPaths.tempOutputScip,tempOutputDb:e.tempPaths.tempOutputDb,tempMetaPath:e.tempPaths.tempMetaPath,outputScip:e.paths.outputScip,outputDb:e.paths.outputDb,metaPath:e.paths.metaPath})}function Bu(e,t){if(!mt("scip")){if(e)throw new Error(`The scip CLI is required but not found on PATH.
|
|
125
|
+
Install from: https://github.com/sourcegraph/scip/releases`);if(t("scip CLI not found on PATH. Attempting auto-install..."),!Jr(t))throw new Error(`The scip CLI is required but could not be installed.
|
|
126
|
+
Install manually from: https://github.com/sourcegraph/scip/releases`)}}function Wu(e){let t=[],n=[],r=e.languages.map((i,s)=>({language:i,scipPath:e.languages.length>1?Yu(e.tempOutputScip,i,s):e.tempOutputScip}));for(let{language:i,scipPath:s}of r){let o=Hu({...e,language:i,scipPath:s});"skipped"in o?n.push(o.skipped):t.push(o.prepared)}return{preparedRuns:t,skippedLanguages:n}}function Hu(e){let t=Vt(e.language),n=zt(t),r=Jn(t,e.projectRoot);if(!r&&!mi(t)){if(e.skipAutoInstall){let a=`${n} not found on PATH (auto-install disabled). ${t.installUrl??""}`.trim();return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}if(e.onStatus(`${n} not found. Attempting auto-install...`),!hi(t,e.onStatus)){let a=`${n} could not be auto-installed. ${t.installUrl?`Install manually from ${t.installUrl}`:`Install ${n} and put it on PATH.`}`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}}let i=r??Qe(t);if(!i){let a=`${n} was not found after installation checks.`;return e.onStatus(`Skipping ${e.language}: ${a}`),{skipped:{language:e.language,reason:a}}}let{binary:s,args:o}=t.indexArgs({projectRoot:e.projectRoot,outputPath:e.scipPath,pnpmWorkspaces:e.pnpmWorkspaces,indexerBinary:i});return{prepared:{language:e.language,scipPath:e.scipPath,config:t,resolvedBinary:i,binary:s,args:o,env:fi(t,e.env,i)}}}function Vu(e,t){let n=[];for(let r of e)r.skipped?t.push(r.skipped):n.push({language:r.language,scipPath:r.scipPath});return{indexedOutputs:n}}function Uu(e,t,n,r,i){if(e.length===0){let s=t.map(o=>` - ${o.language}: ${o.reason}`).join(`
|
|
136
127
|
`);throw new Error(`No language indexers ran successfully. Install at least one indexer for the languages in this project.
|
|
137
|
-
`+
|
|
128
|
+
`+s)}if(t.length!==0&&(i(`Indexed ${e.length} of ${n.length} languages; skipped ${t.map(s=>s.language).join(", ")}.`),!r))throw new Error(`Failed to index all required languages; preserving the previous index. Pass --allow-partial to intentionally write an incomplete index.
|
|
129
|
+
`+t.map(s=>` - ${s.language}: ${s.reason}`).join(`
|
|
130
|
+
`))}function Ju(e,t,n){e.length>1?(n(`Merging ${e.length} language indexes...`),ii(e.map(r=>r.scipPath),t)):e[0].scipPath!==t&&Ze(e[0].scipPath,t)}function qu(e,t,n,r){if(r("Converting to SQLite..."),!We(e))throw new Error(`SCIP index not found at ${e} after indexing`);try{let i=ci(e);i.removedDefinitionOccurrences>0&&r(`Sanitized ${i.removedDefinitionOccurrences} invalid definition occurrences across ${i.touchedDocuments} documents before SQLite conversion.`),Eu("scip",["expt-convert","--output",t,e],{env:n,stdio:"pipe",maxBuffer:50*1024*1024})}catch(i){let s=i instanceof Error?i.message:String(i);throw new Error(`Failed to convert SCIP index to SQLite: ${s}`,{cause:i})}}function zu(e,t,n){if(!e.defaultOutputPath)return;let r=se(t,e.defaultOutputPath);n!==r&&We(r)&&Ze(r,n)}function Gu(e,t,n){if(!e.defaultOutputPath)return null;let r=se(t,e.defaultOutputPath);if(r===n)return null;let i=`${n}.default-output-backup`;return et(i,{force:!0}),We(r)?(Ze(r,i),{defaultOutputPath:r,backupPath:i}):{defaultOutputPath:r,backupPath:null}}function Ku(e){e&&(et(e.defaultOutputPath,{force:!0}),e.backupPath&&We(e.backupPath)&&Ze(e.backupPath,e.defaultOutputPath))}function Yu(e,t,n){let r=Ou(e)||".scip",i=Kt(e,r);return se(Be(e),`${i}.${n+1}.${t}${r}`)}function Qu(e){let t;try{t=ku(e,"wx")}catch(n){throw(typeof n=="object"&&n&&"code"in n?n.code:void 0)==="EEXIST"?new Error(`Another scip-query reindex is already running for ${Be(e)}.`,{cause:n}):n}return Li(t,JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()})+`
|
|
131
|
+
`),()=>{try{Du(t)}finally{et(e,{force:!0})}}}function Xu(e){Yn(e.tempOutputScip,e.outputScip),Yn(e.tempOutputDb,e.outputDb),Yn(e.tempMetaPath,e.metaPath)}function Yn(e,t){et(`${t}.tmp-replace`,{force:!0}),Ze(e,`${t}.tmp-replace`),Ze(`${t}.tmp-replace`,t)}function Zu(e,t){if(e<=1)return 1;let n=Number(process.env.SCIP_QUERY_INDEXER_CONCURRENCY??0),r=Number.isFinite(t)&&t&&t>0?t:Number.isFinite(n)&&n>0?n:Math.min(2,Math.max(1,Pu().length-1));return Math.max(1,Math.min(e,Math.floor(r)))}async function ed(e,t,n,r){let i=e.filter(c=>c.config.defaultOutputPath),s=e.filter(c=>!c.config.defaultOutputPath),o=[],a=Zu(s.length,r),l=await nd(s,a,c=>Qn(c,t,n));if(a>1){let c=new Map;for(let u of l.filter(d=>d.skipped)){let d=s.find(m=>m.language===u.language);d&&(n(`Retrying ${d.language} indexer serially after parallel failure...`),c.set(d.language,await Qn(d,t,n)))}o.push(...l.map(u=>c.get(u.language)??u))}else o.push(...l);for(let c of i)o.push(await Qn(c,t,n));return o.sort((c,u)=>e.findIndex(d=>d.language===c.language)-e.findIndex(d=>d.language===u.language))}async function Qn(e,t,n){n(`Indexing ${e.language} with ${e.resolvedBinary}...`),et(e.scipPath,{force:!0});let r=Gu(e.config,t,e.scipPath);try{await td(e.binary,e.args,{cwd:t,env:e.env,maxBuffer:50*1024*1024}),zu(e.config,t,e.scipPath)}catch(i){let s=i instanceof Error?i.message:String(i),o=`${e.resolvedBinary} indexer failed: ${s.split(`
|
|
132
|
+
`)[0]}`;return n(`Skipping ${e.language}: ${o}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:o}}}finally{Ku(r)}if(!We(e.scipPath)){let i=`${e.resolvedBinary} indexer completed but did not produce ${e.scipPath}`;return n(`Skipping ${e.language}: ${i}`),{language:e.language,scipPath:e.scipPath,skipped:{language:e.language,reason:i}}}return{language:e.language,scipPath:e.scipPath}}function td(e,t,n){return new Promise((r,i)=>{Nu(e,[...t],n,s=>{s?i(s):r()})})}async function nd(e,t,n){if(e.length===0)return[];let r=new Array(e.length),i=0,s=Math.max(1,Math.min(e.length,t)),o=Array.from({length:s},async()=>{for(;i<e.length;){let a=i++;r[a]=await n(e[a])}});return await Promise.all(o),r}function rd(e,t,n){return{version:1,languages:[...t].sort(),pnpmWorkspaces:n.pnpmWorkspaces===!0,files:Ut(e)}}function id(e,t){try{let n=JSON.parse(wu(e,"utf-8"));return n.version===2&&n.status==="complete"&&Gt(n.fingerprint)===Gt(t)&&Gt([...n.indexedLanguages??[]].sort())===Gt(t.languages)}catch{return!1}}function sd(e,t){Li(e,`${JSON.stringify(t,null,2)}
|
|
133
|
+
`)}function Gt(e){return JSON.stringify(e)}import{createRequire as dd}from"module";import{existsSync as gt,readFileSync as od,readdirSync as ad,statSync as ld}from"fs";import A from"path";var Zn=["tsconfig.json","tsconfig.app.json","tsconfig.node.json","tsconfig.base.json"];function er(e,t){let r=t?A.dirname(A.join(e,t)):e,i=A.resolve(e);for(;r.startsWith(i);){for(let o of Zn){let a=A.join(r,o);if(gt(a))return a}let s=A.dirname(r);if(s===r)break;r=s}for(let s of Zn){let o=A.join(e,s);if(gt(o))return o}return null}function wi(e){let t=e.config.projectRoot,n=new Set(tr(t,e.config.semantic?.typescript?.tsconfigs)),r=e.all(`SELECT relative_path
|
|
134
|
+
FROM documents
|
|
135
|
+
WHERE (
|
|
136
|
+
relative_path LIKE '%.ts'
|
|
137
|
+
OR relative_path LIKE '%.tsx'
|
|
138
|
+
OR relative_path LIKE '%.mts'
|
|
139
|
+
OR relative_path LIKE '%.cts'
|
|
140
|
+
OR relative_path LIKE '%.js'
|
|
141
|
+
OR relative_path LIKE '%.jsx'
|
|
142
|
+
OR relative_path LIKE '%.mjs'
|
|
143
|
+
OR relative_path LIKE '%.cjs'
|
|
144
|
+
)
|
|
145
|
+
${e.pathExclusionsFor("documents")}`);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=er(t,i.relative_path);s&&n.add(A.resolve(s))}if(n.size===0){let i=er(t);i&&n.add(A.resolve(i))}return[...n].filter(i=>!Pi(t,i)).sort((i,s)=>i.localeCompare(s))}function tr(e,t=[]){let n=new Set;for(let r of t){let i=A.isAbsolute(r)?r:A.join(e,r);gt(i)&&n.add(A.resolve(i))}for(let r of cd(e))for(let i of Zn){let s=A.join(r,i);gt(s)&&n.add(A.resolve(s))}if(n.size===0){let r=er(e);r&&n.add(A.resolve(r))}return[...n].filter(r=>!Pi(e,r)).sort((r,i)=>r.localeCompare(i))}function cd(e){let t=A.join(e,"package.json");if(!gt(t))return[];let n;try{n=JSON.parse(od(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>ud(e,i))}function ud(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=A.join(e,t);return Xn(o)?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=A.join(e,r||".");return Xn(s)?ad(s).map(o=>A.join(s,o,i)).filter(Xn):[]}function Xn(e){try{return ld(e).isDirectory()}catch{return!1}}function Pi(e,t){let n=A.relative(e,t).replace(/\\/g,"/");return n.startsWith("..")||n.includes("/node_modules/")||n.startsWith("node_modules/")||n.includes("/dist/")||n.startsWith("dist/")}var md=dd(import.meta.url);function nr(e,t=[]){let n=pd(),r=tr(e,t),i=r[0];return n?r.length===0?{available:!1,dependencyAvailable:n,reason:"no tsconfig found"}:{available:!0,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r}:{available:!1,dependencyAvailable:n,tsconfigPath:i,tsconfigPaths:r,reason:"ts-morph is not installed"}}function pd(){try{return md.resolve("ts-morph"),!0}catch{return!1}}import{watch as fd}from"fs";import{existsSync as Oi,renameSync as Mi}from"fs";import{join as gd,relative as hd}from"path";import{fork as yd}from"child_process";import bd from"ignore";var Yt=class{projectRoot;watchConfig;indexPaths;languages;pnpmWorkspaces;onStatus;onReindexComplete;onError;status={state:"idle"};debounceTimer=null;cooldownTimer=null;dirty=!1;changedFiles=0;reindexInFlight=!1;lastReindexEnd=0;fsWatchers=[];gitignoreFilter;extraIgnore;stopped=!1;constructor(t){this.projectRoot=t.projectRoot,this.watchConfig=Wr(t.config),this.indexPaths=Ne(t.projectRoot,t.config),this.languages=t.languages,this.pnpmWorkspaces=t.config.indexer?.typescript?.pnpmWorkspaces??!1,this.onStatus=t.onStatus??(()=>{}),this.onReindexComplete=t.onReindexComplete??(()=>{}),this.onError=t.onError??(n=>console.error(n.message)),this.gitignoreFilter=Ye(t.projectRoot),this.extraIgnore=bd(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let t=fd(this.projectRoot,{recursive:!0},(n,r)=>{r&&!this.stopped&&this.handleFileChange(r)});this.fsWatchers.push(t)}catch{this.onError(new Error("Failed to start file watcher. On Linux, you may need to increase inotify limits: sysctl -w fs.inotify.max_user_watches=524288"))}}stop(){this.stopped=!0;for(let t of this.fsWatchers)t.close();this.fsWatchers=[],this.clearDebounceTimer(),this.clearCooldownTimer(),this.setStatus({state:"idle"})}handleFileChange(t){let n=hd(this.projectRoot,gd(this.projectRoot,t));if(this.gitignoreFilter.isIgnored(n)||this.extraIgnore.ignores(n)||t.endsWith("index.db")||t.endsWith("index.scip")||t.endsWith("index.db.tmp")||t.endsWith(".scipquery.json"))return;if(this.changedFiles++,this.reindexInFlight){this.dirty=!0,this.setStatus({state:"indexing",startedAt:this.status.startedAt});return}if(this.status.state==="cooldown"){this.dirty=!0,this.setStatus({state:"cooldown",until:this.status.until,dirty:!0});return}this.clearDebounceTimer();let r=Date.now()+this.watchConfig.debounceMs;this.setStatus({state:"waiting",changedFiles:this.changedFiles,reindexAt:r}),this.debounceTimer=setTimeout(()=>{this.debounceTimer=null,this.triggerReindex()},this.watchConfig.debounceMs)}triggerReindex(){if(this.reindexInFlight||this.stopped)return;let t=Date.now()-this.lastReindexEnd;if(this.lastReindexEnd>0&&t<this.watchConfig.cooldownMs){let r=this.watchConfig.cooldownMs-t;this.dirty=!0;let i=Date.now()+r;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped&&(this.dirty=!1,this.triggerReindex())},r);return}this.reindexInFlight=!0,this.dirty=!1,this.changedFiles=0;let n=Date.now();this.setStatus({state:"indexing",startedAt:n}),this.runReindex().then(r=>{if(this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onReindexComplete(r),this.dirty&&!this.stopped){let i=Date.now()+this.watchConfig.cooldownMs;this.setStatus({state:"cooldown",until:i,dirty:!0}),this.cooldownTimer=setTimeout(()=>{this.cooldownTimer=null,this.dirty&&!this.stopped?(this.dirty=!1,this.triggerReindex()):this.setStatus({state:"idle"})},this.watchConfig.cooldownMs)}else this.setStatus({state:"idle"})}).catch(r=>{this.reindexInFlight=!1,this.lastReindexEnd=Date.now(),this.onError(r instanceof Error?r:new Error(String(r))),this.setStatus({state:"idle"})})}runReindex(){return new Promise((t,n)=>{let r=Date.now(),i=this.indexPaths.dbPath+".tmp",s=Sd(this.indexPaths.indexPath),o=yd(new URL("./reindex-worker.js",import.meta.url).pathname,[],{env:{...process.env,SCIP_REINDEX_PROJECT_ROOT:this.projectRoot,SCIP_REINDEX_OUTPUT_SCIP:s,SCIP_REINDEX_OUTPUT_DB:i,SCIP_REINDEX_LANGUAGES:this.languages?.join(",")??"",SCIP_REINDEX_PNPM_WORKSPACES:this.pnpmWorkspaces?"1":""},stdio:"pipe"});o.on("exit",a=>{if(a===0)try{Oi(i)&&Mi(i,this.indexPaths.dbPath),Oi(s)&&Mi(s,this.indexPaths.indexPath),t(Date.now()-r)}catch(l){n(new Error(`Atomic swap failed: ${l}`))}else n(new Error(`Reindex worker exited with code ${a}`))}),o.on("error",n)})}setStatus(t){this.status=t,this.onStatus(t)}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}clearCooldownTimer(){this.cooldownTimer&&(clearTimeout(this.cooldownTimer),this.cooldownTimer=null)}};function Sd(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}import{existsSync as rr,mkdirSync as xd,symlinkSync as _d,readlinkSync as Id,unlinkSync as Rd}from"fs";import{join as Qt,dirname as Fi,resolve as ir}from"path";import{homedir as Ti,platform as Cd}from"os";import{fileURLToPath as vd}from"url";var Nd=Cd()==="win32",sr=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function $i(e={}){let t=e.quiet?()=>{}:console.log,n=vd(import.meta.url),r=ir(Fi(n),"..","skills"),i=[Qt(Ti(),".claude","skills"),Qt(Ti(),".codex","skills")],s={installed:[],skipped:[],alreadyLinked:[]};for(let o of i){let a=Fi(o);if(!rr(a))continue;xd(o,{recursive:!0});let l=o.includes(".codex")?"Codex":"Claude";for(let c of sr){let u=Qt(r,c),d=Qt(o,c);if(!rr(u)){s.skipped.push(`${l}/${c}`);continue}if(rr(d)){try{let m=Id(d);if(ir(m)===ir(u)){s.alreadyLinked.push(`${l}/${c}`),t(` ok: ${c} \u2192 ${l} (already linked)`);continue}}catch{s.skipped.push(`${l}/${c}`),t(` skip: ${c} \u2192 ${l} (exists, not a symlink)`);continue}Rd(d)}_d(u,d,Nd?"junction":"dir"),s.installed.push(`${l}/${c}`),t(` done: ${c} \u2192 ${l}`)}}return s}function be(e){return e+1}function me(e,t){return`${be(e)}-${be(t)}`}function pe(e,t,n){return`${e}:${me(t,n)}`}var b={empty(e){console.log(e)},list(e,t){for(let n of e)console.log(t(n))},groupedByFile(e,t,n=r=>r.relativePath){let r="";for(let i of e){let s=n(i);s!==r&&(r&&console.log(""),console.log(s),r=s),console.log(t(i))}},sectionedReport(e){let t=!0;for(let n of e)if(!(n.skipIfEmpty&&n.rows.length===0)){t||console.log(""),t=!1,n.title!==void 0&&console.log(`\u2550\u2550\u2550 ${n.title} \u2550\u2550\u2550`),n.explanation!==void 0&&console.log(n.explanation);for(let r of n.rows)console.log(r)}},table(e,t,n){console.log(` ${e.join(" ")}`);let r=n??e.map(i=>i.length);console.log(` ${r.map(i=>"\u2500".repeat(i)).join(" ")}`);for(let i of t)console.log(i)}};import{existsSync as Va}from"fs";import{join as CS}from"path";import Ed from"better-sqlite3";var Xt=class{db;config;pathFilter;constructor(t,n){this.config=t,this.pathFilter=n??null,this.db=new Ed(t.dbPath,{readonly:!0}),this.db.pragma("busy_timeout = 5000")}isIgnored(t){return this.pathFilter?.isIgnored(t)??!1}get localSymbolPredicate(){return`(
|
|
146
|
+
EXISTS (
|
|
147
|
+
SELECT 1
|
|
148
|
+
FROM defn_enclosing_ranges local_der
|
|
149
|
+
JOIN documents local_d ON local_der.document_id = local_d.id
|
|
150
|
+
WHERE local_der.symbol_id = gs.id
|
|
151
|
+
${this.pathExclusionsFor("local_d").trimStart()}
|
|
152
|
+
)
|
|
153
|
+
OR EXISTS (
|
|
154
|
+
SELECT 1
|
|
155
|
+
FROM mentions local_m
|
|
156
|
+
JOIN chunks local_c ON local_m.chunk_id = local_c.id
|
|
157
|
+
JOIN documents local_d ON local_c.document_id = local_d.id
|
|
158
|
+
WHERE local_m.symbol_id = gs.id
|
|
159
|
+
AND local_m.role = 1
|
|
160
|
+
${this.pathExclusionsFor("local_d").trimStart()}
|
|
161
|
+
)
|
|
162
|
+
)`}get pathExclusions(){return this.pathExclusionsFor("d")}get symbolNoise(){return this.symbolNoiseFor("gs")}pathExclusionsFor(...t){return t.flatMap(n=>[`AND ${n}.relative_path NOT LIKE 'node_modules/%'`,`AND ${n}.relative_path NOT LIKE '.git/%'`]).join(`
|
|
163
|
+
`)}symbolNoiseFor(t){return`AND ${t}.symbol NOT LIKE '%().(%' AND ${t}.symbol NOT LIKE '%typeLiteral%'`}all(t,...n){return this.db.prepare(t).all(...n)}get(t,...n){return this.db.prepare(t).get(...n)}close(){this.db.close()}};var x={};Ka(x,{affected:()=>ga,bottlenecks:()=>Go,byKind:()=>Ko,callGraph:()=>ta,changeSurface:()=>ha,code:()=>Ma,complexity:()=>Ta,complexityHotspots:()=>Pn,convergence:()=>wa,coupling:()=>Uo,cycles:()=>In,dataflow:()=>$a,dead:()=>_n,deepChains:()=>Zo,deps:()=>vo,diffImpact:()=>Sa,drift:()=>En,extractCandidates:()=>vn,fanIn:()=>Bo,fanOut:()=>Wo,files:()=>Ai,health:()=>La,hierarchy:()=>ea,hotspots:()=>wo,importedBy:()=>Mo,imports:()=>Oo,isolated:()=>Rn,kindCounts:()=>Yo,members:()=>jo,methods:()=>Io,outline:()=>Ao,passthroughCandidates:()=>kn,rdeps:()=>No,redundantReexports:()=>ja,refs:()=>Ro,similar:()=>ia,similarAll:()=>Cn,similarChains:()=>pa,similarFiles:()=>da,similarSignatures:()=>Wa,slice:()=>Aa,staleAbstractions:()=>wn,stats:()=>Zt,surface:()=>Do,symbols:()=>as,system:()=>Eo,topCoupling:()=>Jo,topFanIn:()=>Ho,topFanOut:()=>Vo,trace:()=>Co,unusedImports:()=>Fo,wrapperCandidates:()=>Ln});import{statSync as Dd}from"fs";function Zt(e){let t=e.get("SELECT COUNT(*) as c FROM documents").c,n=e.get("SELECT COUNT(*) as c FROM global_symbols").c,r=e.get("SELECT COUNT(*) as c FROM mentions WHERE role = 1").c,i=e.get("SELECT COUNT(*) as c FROM mentions WHERE role != 1").c;return{documents:t,symbols:n,definitions:r,references:i,...Ld(e.config.dbPath)}}function Ld(e){try{let t=Dd(e);return{indexSizeBytes:t.size,lastBuilt:t.mtime}}catch{return{indexSizeBytes:0,lastBuilt:null}}}function kd(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function Ai(e,t){let n=kd(t);return e.all(`SELECT relative_path FROM documents
|
|
138
164
|
WHERE relative_path LIKE ?
|
|
139
|
-
ORDER BY relative_path`,
|
|
140
|
-
`);for(let
|
|
141
|
-
`.repeat(
|
|
165
|
+
ORDER BY relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path}))}import{extname as Vi}from"path";import{createRequire as Td}from"module";import{existsSync as wd,readFileSync as Pd}from"fs";import{join as Od}from"path";var Md=$("source-text");function w(e,t){let n=t.replace(/\\/g,"/");return Md.get(e,n,()=>{let r=Od(e.config.projectRoot,n);return wd(r)?Pd(r,"utf-8"):""})}var Fd=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift|extract)?/i;function or(e,t,n){if(n<=0)return!1;let r=w(e,t);if(!r)return!1;let i=r.split(`
|
|
166
|
+
`);for(let s=n-1;s>=0&&s>=n-5;s-=1){let o=(i[s]??"").trim();if(o!==""){if(Fd.test(o))return!0;if(!o.startsWith("//")&&!o.startsWith("*")&&!o.startsWith("/*")&&!o.startsWith("@")&&!o.startsWith("#"))return!1}}return!1}var q=Td(import.meta.url),en=null,ji=!1;function Ui(){if(ji)return null;if(en)return en;try{return en=q("tree-sitter"),en}catch{return ji=!0,null}}var $d={".rs":"rust",".ts":"typescript",".mts":"typescript",".cts":"typescript",".tsx":"tsx",".js":"javascript",".jsx":"javascript",".mjs":"javascript",".cjs":"javascript",".py":"python",".pyi":"python",".java":"java",".kt":"kotlin",".kts":"kotlin",".scala":"scala",".sc":"scala",".rb":"ruby",".c":"c",".h":"c",".cc":"cpp",".cpp":"cpp",".cxx":"cpp",".hpp":"cpp",".hh":"cpp",".hxx":"cpp",".cs":"csharp",".php":"php",".vb":"vb"},Bi=new Map,ar=new Set;function Ji(e){if(ar.has(e))return null;let t=Bi.get(e);if(t)return t;let n;try{switch(e){case"rust":n=q("tree-sitter-rust");break;case"typescript":n=q("tree-sitter-typescript").typescript;break;case"tsx":n=q("tree-sitter-typescript").tsx;break;case"javascript":n=q("tree-sitter-javascript");break;case"python":n=q("tree-sitter-python");break;case"java":n=q("tree-sitter-java");break;case"kotlin":n=q("tree-sitter-kotlin");break;case"scala":n=q("tree-sitter-scala");break;case"ruby":n=q("tree-sitter-ruby");break;case"c":n=q("tree-sitter-c");break;case"cpp":n=q("tree-sitter-cpp");break;case"csharp":n=q("tree-sitter-c-sharp");break;case"php":n=q("tree-sitter-php").php;break;case"vb":{let r=q("tree-sitter-vb-dotnet");n=r.language??r;break}}}catch{return ar.add(e),null}return Bi.set(e,n),n}var Wi=new Map;function qi(e){let t=Wi.get(e);if(t)return t;let n=Ji(e);if(!n)return null;let r=Ui();if(!r)return null;let i=new r;try{i.setLanguage(n)}catch{return ar.add(e),null}return Wi.set(e,i),i}function M(e){return $d[Vi(e).toLowerCase()]??null}function yt(e){return Vi(e).toLowerCase()===".vue"}var zi=Wt("ast-trees");function P(e,t){if(yt(t))return Ad(e,t);let n=M(t);if(!n)return null;let r=w(e,t);return r?zi.get(e,t,r,()=>{let i=qi(n);if(!i)return null;try{return Gi(i,r)}catch{return null}}):null}function Ad(e,t){let n=w(e,t);return n?zi.get(e,t,n,()=>{let r=jd(n);if(!r)return null;let i=qi(r.language);if(!i)return null;let s=`
|
|
167
|
+
`.repeat(r.startLine)+r.body;try{return Gi(i,s)}catch{return null}}):null}function Gi(e,t){return e.parse(r=>r>=t.length?null:t.slice(r,Math.min(t.length,r+16384)))}function jd(e){let t=[],n=/<script\b([^>]*)>([\s\S]*?)<\/script>/g;for(let l of e.matchAll(n))typeof l.index=="number"&&t.push({tagOpen:l[1]??"",body:l[2]??"",openIdx:l.index+(l[0].length-(l[2]?.length??0)-9)});if(t.length===0)return null;let r=t.find(l=>/\bsetup\b/.test(l.tagOpen))??t[0],s=r.tagOpen.match(/\blang\s*=\s*["']?([\w-]+)/)?.[1]?.toLowerCase(),o=s==="ts"||s==="typescript"?"typescript":s==="tsx"?"tsx":"javascript",a=Bd(e,r.openIdx);return{body:r.body,startLine:a,language:o}}function Bd(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}var tt=new Map;function Wd(e,t){let n=`${e}::${t}`;if(tt.has(n))return tt.get(n)??null;let r=Ji(e);if(!r)return tt.set(n,null),null;let i=Ui();if(!i)return tt.set(n,null),null;try{let s=new i.Query(r,t);return tt.set(n,s),s}catch{return tt.set(n,null),null}}var Hd={rust:`
|
|
142
168
|
(function_item name: (identifier) @name) @def
|
|
143
169
|
(function_signature_item name: (identifier) @name) @def
|
|
144
170
|
`,typescript:`
|
|
@@ -164,7 +190,7 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
|
|
|
164
190
|
(variable_declarator name: (identifier) @name value: (function_expression)) @def
|
|
165
191
|
`,python:`
|
|
166
192
|
(function_definition name: (identifier) @name) @def
|
|
167
|
-
`},
|
|
193
|
+
`},Vd=new WeakMap;function Ki(e,t){return Qi(e,t,Vd,Hd,n=>{let r=[];for(let i of n){let s=null,o=null;for(let a of i.captures)a.name==="name"?s=a.node.text:a.name==="def"&&(o={startLine:a.node.startPosition.row,endLine:a.node.endPosition.row});s&&o&&r.push({name:s,startLine:o.startLine,endLine:o.endLine})}return r})}var Ud={rust:`
|
|
168
194
|
(call_expression function: (_) @target) @call
|
|
169
195
|
(macro_invocation macro: (_) @target) @call
|
|
170
196
|
`,typescript:`
|
|
@@ -178,73 +204,96 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
|
|
|
178
204
|
(new_expression constructor: (_) @target) @call
|
|
179
205
|
`,python:`
|
|
180
206
|
(call function: (_) @target) @call
|
|
181
|
-
`},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
`},Jd=new WeakMap;function tn(e,t){return Qi(e,t,Jd,Ud,n=>{let r=[];for(let i of n){let s=null,o=null;for(let l of i.captures)l.name==="target"?s=l.node:l.name==="call"&&(o=l.node);if(!s||!o)continue;let a=ht(s);a&&r.push({calleeLeaf:a,memberAccess:qd(s),line:o.startPosition.row})}return r})}function qd(e){switch(e.type){case"field_expression":case"member_expression":case"attribute":return!0;default:return!1}}function Yi(e,t){return nn(e,t,zd,()=>new Map,(n,r,i)=>{let s=(l,c)=>{if(l===c)return;let u=i.get(l);u||(u=new Set,i.set(l,u)),u.add(c)},o=r==="python"?new Set(["identifier"]):new Set(["type_identifier"]),a=(l,c)=>{let u=d=>{o.has(d.type)&&d.text!==c&&s(d.text,c);for(let m of d.children)u(m)};for(let d of l.children)u(d)};if(r==="rust")for(let l of n.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let c=l.namedChildren.find(d=>d.type==="type_identifier")?.text;if(!c)continue;let u=l.namedChildren.find(d=>d.type==="field_declaration_list"||d.type==="enum_variant_list"||d.type==="ordered_field_declaration_list");u&&a(u,c),l.type==="type_item"&&a(l,c)}else if(r==="python")for(let l of n.rootNode.descendantsOfType("class_definition")){let c=l.namedChildren.find(d=>d.type==="identifier")?.text;if(!c)continue;let u=l.namedChildren.find(d=>d.type==="block");if(u)for(let d of u.descendantsOfType("type"))for(let m of d.descendantsOfType("identifier"))m.text!==c&&s(m.text,c)}else for(let l of n.rootNode.descendantsOfType(["interface_declaration","type_alias_declaration","class_declaration"])){let c=l.namedChildren.find(u=>u.type==="type_identifier")?.text;c&&a(l,c)}})??new Map}function nn(e,t,n,r,i){let s=M(t);if(!s)return null;let o=P(e,t);if(!o)return null;let a=n.get(o);if(a)return a;let l=r();return i(o,s,l),n.set(o,l),l}function Qi(e,t,n,r,i){let s=M(t);if(!s)return null;let o=r[s];if(!o)return null;let a=P(e,t);if(!a)return null;let l=n.get(a);if(l)return l;let c=Wd(s,o);if(!c)return null;let u=i(c.matches(a.rootNode));return n.set(a,u),u}var zd=new WeakMap,Hi=new WeakMap;function Xi(e,t,n,r){let i=M(t);if(!i)return null;let s=P(e,t);if(!s)return null;let o=Hi.get(s);return o||(o=Gd(s,i),Hi.set(s,o)),o.get(`${n}:${r}`)??null}function Gd(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{if(n.has(s.type)){let o=s.namedChildren.find(l=>l.type==="parameters"||l.type==="formal_parameters"),a=0;if(o)for(let l of o.namedChildren)l.type==="comment"||l.type==="line_comment"||l.type==="block_comment"||(a+=1);r.set(`${s.startPosition.row}:${s.endPosition.row}`,{paramCount:a})}for(let o of s.children)i(o)};return i(e.rootNode),r}function ht(e){switch(e.type){case"identifier":case"type_identifier":case"property_identifier":case"shorthand_property_identifier":return e.text;case"field_expression":case"member_expression":case"attribute":{let t=e.namedChild(e.namedChildCount-1);return t?ht(t):null}case"scoped_identifier":{let t=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return t?ht(t):null}case"super":case"self":case"this":return null;default:return null}}var Kd={"/":"namespace","#":"type",".":"term","[":"type-param",":":"meta","!":"macro"};function H(e){if(e.startsWith("local "))return{kind:"local",id:e.slice(6),raw:e};let t=e.split(" ");if(t.length<4)return{scheme:t[0]??"",manager:t[1]??"",packageName:t[2]??"",version:"",descriptors:[],raw:e};let n=t[0],r=t[1],i=e.slice(n.length+1+r.length+1),s;if(i.startsWith("`")){let c=i.indexOf("`",1);c===-1?(s=i.slice(1),i=""):(s=i.slice(1,c),i=i.slice(c+2))}else{let c=i.indexOf(" ");c===-1?(s=i,i=""):(s=i.slice(0,c),i=i.slice(c+1))}let o,a=i.indexOf(" ");a===-1?(o=i,i=""):(o=i.slice(0,a),i=i.slice(a+1));let l=Yd(i);return{scheme:n,manager:r,packageName:s,version:o,descriptors:l,raw:e}}function Yd(e){let t=[],n=0;for(;n<e.length;){if(e[n]==="["){let s=e.indexOf("]",n+1);if(s===-1){t.push({name:e.slice(n+1),suffix:"type-param"});break}t.push({name:e.slice(n+1,s),suffix:"type-param"}),n=s+1;continue}if(e[n]==="("&&(t.length===0||n===0||Zi(e[n-1]))){let s=e.indexOf(")",n+1);if(s!==-1&&e[s+1]!=="."){t.push({name:e.slice(n+1,s),suffix:"parameter"}),n=s+1;continue}}let r;if(e[n]==="`"){let s=e.indexOf("`",n+1);if(s===-1){r=e.slice(n+1),t.push({name:r,suffix:"term"});break}r=e.slice(n+1,s),n=s+1}else{let s=n;for(;n<e.length&&!Zi(e[n]);)n++;r=e.slice(s,n)}if(n>=e.length){r&&t.push({name:r,suffix:"term"});break}let i=e[n];if(i==="("){let s=e.indexOf(")",n+1);s!==-1&&e[s+1]==="."?(t.push({name:r,suffix:"method"}),n=s+2):s!==-1?(t.push({name:r,suffix:"method"}),n=s+1):(t.push({name:r,suffix:"term"}),n++)}else{let s=Kd[i];s&&t.push({name:r,suffix:s}),n+=1}}return t}function Zi(e){return e==="/"||e==="#"||e==="."||e==="("||e==="["||e===":"||e==="!"}function h(e){let t=H(e);if("kind"in t&&t.kind==="local")return`local:${t.id}`;let n=t;if(n.descriptors.length===0)return n.raw;let r=[];for(let i of n.descriptors){let s=Qd(i);s&&r.push(s)}return r.join(":")}function Qd(e){let t=e.suffix==="namespace"?Xd(e.name):e.name;return t?e.suffix==="method"?`${t}()`:t:""}function Xd(e){return e.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/,"").replace(/\.(py|pyi)$/,"").replace(/\.(rs)$/,"").replace(/\.(java|scala|kt|kts)$/,"").replace(/\.(rb)$/,"").replace(/\.(go)$/,"").replace(/\.(cs|vb)$/,"").replace(/\.(dart)$/,"").replace(/\.(php)$/,"").replace(/\.(c|cc|cpp|cxx|h|hpp)$/,"")}function D(e){let t=H(e);if("kind"in t&&t.kind==="local")return t.id;let n=t;return n.descriptors.length===0?"":n.descriptors[n.descriptors.length-1].name}function V(e){let t=H(e);if("kind"in t&&t.kind==="local")return null;let n=t;return n.descriptors[n.descriptors.length-1]?.suffix??null}function U(e){return e.endsWith("().")||V(e)==="method"}function W(e){let t=V(e);return t==="method"||t==="term"}function Le(e){return V(e)==="namespace"}var Zd=/^rust-analyzer\b.*[\s/]impl#\[[^\]]+\]\[[^\]]+\]/;function rn(e){return Zd.test(e)}var em=new Set(["test","tests","_tests"]);function ke(e){let t=H(e);if("kind"in t)return!1;for(let n=0;n<t.descriptors.length-1;n+=1){let r=t.descriptors[n];if(r?.suffix==="namespace"&&r.name&&em.has(r.name))return!0}return!1}function es(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length!==i.length+1)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function ts(e,t){let n=H(e),r=H(t);if("kind"in n||"kind"in r)return!1;let i=n.descriptors,s=r.descriptors;if(s.length<=i.length)return!1;for(let o=0;o<i.length;o++){let a=i[o],l=s[o];if(a.name!==l.name||a.suffix!==l.suffix)return!1}return!0}function He(e){return!e||!e.trim()?null:e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim()||null}function Ve(e){if(!e)return null;let t=ns(e);if(t)return t.replace(/\n/g," ");let n=e.indexOf("|");if(n===-1)return e.replace(/\n/g," ");let r=e.slice(n+1);return(ns(r)??r).replace(/\n/g," ")}function ns(e){return/^```(?:\w+)?\s*\n?([\s\S]*?)\n?```/.exec(e.trimStart())?.[1]?.trim()||null}var tm=$("file-definitions");function Q(e,t){return tm.get(e,t,()=>{let n=sm(nm(e,t),rm(e,t));return am(e,t,n.map(im))})}function nm(e,t){return e.all(`SELECT
|
|
208
|
+
gs.id,
|
|
209
|
+
gs.symbol,
|
|
210
|
+
der.document_id,
|
|
211
|
+
der.start_line,
|
|
212
|
+
der.end_line,
|
|
213
|
+
d.relative_path,
|
|
214
|
+
gs.display_name,
|
|
215
|
+
gs.kind,
|
|
216
|
+
gs.documentation,
|
|
217
|
+
gs.enclosing_symbol
|
|
218
|
+
FROM global_symbols gs
|
|
219
|
+
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
220
|
+
JOIN documents d ON der.document_id = d.id
|
|
221
|
+
WHERE d.relative_path = ?
|
|
222
|
+
${e.symbolNoiseFor("gs")}
|
|
223
|
+
ORDER BY der.start_line, der.end_line`,t)}function rm(e,t){return e.all(`SELECT
|
|
224
|
+
gs.id,
|
|
225
|
+
gs.symbol,
|
|
226
|
+
c.document_id,
|
|
227
|
+
MIN(c.start_line) AS start_line,
|
|
228
|
+
MAX(c.end_line) AS end_line,
|
|
229
|
+
d.relative_path,
|
|
230
|
+
gs.display_name,
|
|
231
|
+
gs.kind,
|
|
232
|
+
gs.documentation,
|
|
233
|
+
gs.enclosing_symbol
|
|
234
|
+
FROM global_symbols gs
|
|
235
|
+
JOIN mentions m ON m.symbol_id = gs.id
|
|
236
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
237
|
+
JOIN documents d ON c.document_id = d.id
|
|
238
|
+
WHERE d.relative_path = ?
|
|
239
|
+
AND m.role = 1
|
|
240
|
+
${e.symbolNoiseFor("gs")}
|
|
241
|
+
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
|
|
242
|
+
ORDER BY start_line, end_line`,t)}function im(e){return{symbolId:e.id,symbol:e.symbol,documentId:e.document_id,startLine:e.start_line,endLine:e.end_line,relativePath:e.relative_path,leaf:D(e.symbol),parentTypeName:Je(e.symbol),isFunctionLike:W(e.symbol),isTypeLike:V(e.symbol)==="type",kind:e.kind??null,documentation:e.documentation??null,enclosingSymbol:e.enclosing_symbol??null}}function sm(e,t){let n=new Map;for(let r of t)e.length>0&&!om(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()].sort((r,i)=>r.start_line-i.start_line||r.end_line-i.end_line||r.symbol.localeCompare(i.symbol))}function om(e){if(Je(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function oe(e,t={}){return lr(e,t.scope)}function lr(e,t){let n=t?`AND relative_path LIKE '%${t}%'`:"";return e.all(`SELECT relative_path
|
|
217
243
|
FROM documents
|
|
218
244
|
WHERE 1 = 1
|
|
219
245
|
${e.pathExclusionsFor("documents")}
|
|
220
|
-
${
|
|
221
|
-
ORDER BY relative_path`).flatMap(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
${n}
|
|
247
|
+
ORDER BY relative_path`).flatMap(r=>Q(e,r.relative_path)).filter(r=>!e.isIgnored(r.relativePath))}function nt(e,t,n={}){if(t.length===0)return[];let r=t.flatMap(i=>Q(e,i)).filter(i=>!e.isIgnored(i.relativePath));return n.onlyDocumented&&(r=r.filter(i=>i.documentation!==null&&i.documentation!=="")),n.sort&&(r=r.sort((i,s)=>i.relativePath.localeCompare(s.relativePath)||i.startLine-s.startLine||i.endLine-s.endLine)),r.map(i=>({startLine:i.startLine,endLine:i.endLine,symbol:i.symbol,shortName:h(i.symbol),signature:He(Ve(i.documentation)),relativePath:i.relativePath,enclosingSymbol:i.enclosingSymbol}))}function ae(e,t){let n=null;for(let r of e)r.startLine>t||r.endLine<t||(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}function Ue(e,t){let n=Q(e,t.relative_path).find(r=>r.symbolId===t.id);return n?{symbolId:n.symbolId,symbol:n.symbol,documentId:n.documentId,startLine:n.startLine,endLine:n.endLine,relativePath:n.relativePath}:{symbolId:t.id,symbol:t.symbol,documentId:t.document_id,startLine:t.start_line,endLine:t.end_line,relativePath:t.relative_path}}function am(e,t,n){let r=w(e,t),i=Ki(e,t);return i?pm(n,i,r):r?lm(n,r):n}function lm(e,t){let n=t.split(/\r?\n/),r=cm(e,n),i=um(e,r),s=dm(i,n);return mm(e,s)}function cm(e,t){let n=e.some(i=>sn(i.symbol))?gm(t):null,r=new Map;for(let i of e)r.set(i.symbolId,fm(t,n,i));return r}function um(e,t){return e.filter(n=>sn(n.symbol)).map(n=>({definition:n,startLine:t.get(n.symbolId)??n.startLine})).sort((n,r)=>n.startLine-r.startLine||n.definition.startLine-r.definition.startLine||n.definition.symbol.localeCompare(r.definition.symbol))}function dm(e,t){let n=new Map;for(let r=0;r<e.length;r+=1){let i=e[r],s=e[r+1],o=s?Math.max(i.startLine,s.startLine-1):t.length-1;n.set(i.definition.symbolId,{startLine:i.startLine,endLine:hm(t,i.definition,i.startLine,o)})}return n}function mm(e,t){return e.map(n=>{let r=t.get(n.symbolId);return r?{...n,startLine:r.startLine,endLine:r.endLine}:n})}function pm(e,t,n=null){let r=new Map;for(let i of t){let s=r.get(i.name);s?s.push(i):r.set(i.name,[i])}return e.map(i=>{if(!sn(i.symbol)||!i.leaf)return rs(i,n);let s=r.get(i.leaf);if(!s||s.length===0)return rs(i,n);let o=s[0],a=Math.abs(o.startLine-i.startLine);for(let l=1;l<s.length;l+=1){let c=s[l],u=Math.abs(c.startLine-i.startLine);u<a&&(o=c,a=u)}return{...i,startLine:o.startLine,endLine:o.endLine}})}function rs(e,t){if(!t||!e.leaf||V(e.symbol)!=="term"||Je(e.symbol)!==null)return e;let n=e.leaf.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp(`\\b(?:export\\s+)?(?:const|let|var)\\s+${n}\\b`),s=t.split(/\r?\n/).findIndex(o=>r.test(o));return s>=0?{...e,startLine:s,endLine:s}:e}function fm(e,t,n){if(!sn(n.symbol))return n.startLine;let r=Math.max(0,Math.min(n.startLine,e.length-1));if(!t)return r;let i=t.get(n.leaf);if(!i||i.length===0)return r;let s=null;for(let o of i){let a=Math.abs(o-n.startLine);(!s||a<s.distance)&&(s={line:o,distance:a})}return s?.line??r}function gm(e){let t=/\b(?:function|def|fn)\s+([A-Za-z_$][\w$]*)/g,n=/\b([A-Za-z_$][\w$]*)\s*[:=]\s*(?:async\s*)?(?:function\b|\()/g,r=/^\s*(?:(?:export|public|private|protected|static|readonly|async|abstract|get|set)\s+)*([A-Za-z_$][\w$]*)\s*(?:<[^(]*>)?\s*\(/,i=/\b([A-Za-z_$][\w$]*)\s*\(/g,s=new Map,o=(a,l)=>{let c=s.get(a);if(!c){s.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};for(let a=0;a<e.length;a+=1){let l=e[a]??"";for(let u of l.matchAll(t))u[1]&&o(u[1],a);for(let u of l.matchAll(n))u[1]&&o(u[1],a);let c=l.match(r);c?.[1]&&o(c[1],a);for(let u of l.matchAll(i))u[1]&&o(u[1],a)}return s}function hm(e,t,n,r){let i=Math.max(n,Math.min(e.length-1,r)),s=Math.max(n,Math.min(i,t.endLine)),o=0,a=0,l=!1;for(let c=n;c<=i;c+=1){let u=ym(e[c]??"");for(let d of u)d==="{"?(o+=1,l=!0):d==="}"?o=Math.max(0,o-1):d==="("?a+=1:d===")"&&(a=Math.max(0,a-1));if(l&&o===0||!l&&a===0&&c>=s)return c}return s}function ym(e){let t="",n=null,r=!1;for(let i=0;i<e.length;i+=1){let s=e[i],o=e[i+1];if(!n&&s==="/"&&o==="/"){t+=" ".repeat(e.length-i);break}if(n){if(r){r=!1,t+=" ";continue}if(s==="\\"){r=!0,t+=" ";continue}s===n&&(n=null),t+=" ";continue}if(s==='"'||s==="'"||s==="`"){n=s,t+=" ";continue}t+=s}return t}function sn(e){return e.includes("().")}function Je(e){let t=H(e);if("kind"in t)return null;for(let n=t.descriptors.length-2;n>=0;n--){let r=t.descriptors[n];if(r?.suffix==="type")return r.name}return null}function cr(e){let t=H(e);if("kind"in t)return[];let n=[];for(let r=t.descriptors.length-2;r>=0;r-=1){let i=t.descriptors[r];i?.suffix==="type"&&i.name&&n.push(i.name)}return n}import{existsSync as Pm}from"fs";import{basename as is,isAbsolute as Om,join as Mm}from"path";function E(e,t){let n=it(e,t.trim());if(n)return n;let r=Rm(e,t);if(r)return r;let i=bm(e,t);return i||Im(e,t)}function bm(e,t){let n=mr(t),r=dr(n);if(!r)return null;let i=`%${r.path}%`,s=r.leaf,a=Sm(e,i,s,n)[0];return a?Ue(e,a):null}function Sm(e,t,n,r){let i=ur([],[...xm(e,t,n),..._m(e,t,n)]).filter(s=>!e.isIgnored(s.relative_path)).filter(s=>rt(s,r)>1);return i.sort((s,o)=>rt(o,r)-rt(s,r)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.start_line-o.start_line||s.symbol.localeCompare(o.symbol)),i}function xm(e,t,n){return e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
|
|
248
|
+
FROM global_symbols gs
|
|
249
|
+
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
250
|
+
JOIN documents d ON der.document_id = d.id
|
|
251
|
+
WHERE d.relative_path LIKE ?
|
|
252
|
+
AND (gs.display_name = ? OR gs.symbol LIKE ?)
|
|
253
|
+
${e.pathExclusionsFor("d")}`,t,n,`%/${n}.%`)}function _m(e,t,n){return e.all(`SELECT
|
|
254
|
+
gs.id,
|
|
255
|
+
gs.symbol,
|
|
256
|
+
c.document_id,
|
|
257
|
+
MIN(c.start_line) AS start_line,
|
|
258
|
+
MAX(c.end_line) AS end_line,
|
|
259
|
+
d.relative_path,
|
|
260
|
+
gs.display_name,
|
|
261
|
+
gs.documentation
|
|
262
|
+
FROM global_symbols gs
|
|
263
|
+
JOIN mentions m ON m.symbol_id = gs.id
|
|
264
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
265
|
+
JOIN documents d ON c.document_id = d.id
|
|
266
|
+
WHERE m.role = 1
|
|
267
|
+
AND d.relative_path LIKE ?
|
|
268
|
+
AND (gs.display_name = ? OR gs.symbol LIKE ?)
|
|
269
|
+
${e.pathExclusionsFor("d")}
|
|
270
|
+
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation`,t,n,`%/${n}.%`)}function Im(e,t){let n=mr(t),r=km(t),i=Em(e,r),s=wm(i,t,n);if(s&&!e.isIgnored(s.relative_path))return Ue(e,s);let o=null;for(let a of i){if(e.isIgnored(a.relative_path))continue;let l=Lm(a,t,n,r);l<=0||(!o||l>o.score)&&(o={row:a,score:l})}return o?Ue(e,o.row):null}function Rm(e,t){let n=t.match(/^(.+):(\d+)-(\d+)$/);if(!n)return null;let[,r,i,s]=n,o=Math.max(0,parseInt(i,10)-1),a=Math.max(o,parseInt(s,10)-1),l=Cm(e,r,o,a)??vm(e,r,o,a);return l&&!e.isIgnored(l.relative_path)?Ue(e,l):null}function Cm(e,t,n,r){return e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
|
|
271
|
+
FROM global_symbols gs
|
|
272
|
+
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
273
|
+
JOIN documents d ON der.document_id = d.id
|
|
274
|
+
WHERE d.relative_path LIKE ?
|
|
275
|
+
AND der.start_line <= ? AND der.end_line >= ?
|
|
276
|
+
${e.pathExclusionsFor("d")}
|
|
277
|
+
ORDER BY (der.end_line - der.start_line) ASC
|
|
278
|
+
LIMIT 1`,`%${t}%`,n,r)}function vm(e,t,n,r){return e.get(`SELECT gs.id, gs.symbol, c.document_id, MIN(c.start_line) AS start_line, MAX(c.end_line) AS end_line, d.relative_path
|
|
279
|
+
FROM global_symbols gs
|
|
280
|
+
JOIN mentions m ON m.symbol_id = gs.id
|
|
281
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
282
|
+
JOIN documents d ON c.document_id = d.id
|
|
283
|
+
WHERE m.role = 1
|
|
284
|
+
AND d.relative_path LIKE ?
|
|
285
|
+
AND c.start_line <= ? AND c.end_line >= ?
|
|
286
|
+
${e.pathExclusionsFor("d")}
|
|
287
|
+
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
|
|
288
|
+
ORDER BY (MAX(c.end_line) - MIN(c.start_line)) ASC
|
|
289
|
+
LIMIT 1`,`%${t}%`,n,r)}function it(e,t){let r=e.get(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path
|
|
241
290
|
FROM global_symbols gs
|
|
242
291
|
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
243
292
|
JOIN documents d ON der.document_id = d.id
|
|
244
293
|
WHERE gs.symbol = ?
|
|
245
294
|
${e.pathExclusionsFor("d")}
|
|
246
295
|
ORDER BY d.relative_path, der.start_line
|
|
247
|
-
LIMIT 1`,
|
|
296
|
+
LIMIT 1`,t)??e.get(`SELECT
|
|
248
297
|
gs.id,
|
|
249
298
|
gs.symbol,
|
|
250
299
|
c.document_id,
|
|
@@ -260,19 +309,20 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
|
|
|
260
309
|
${e.pathExclusionsFor("d")}
|
|
261
310
|
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path
|
|
262
311
|
ORDER BY d.relative_path, start_line
|
|
263
|
-
LIMIT 1`,
|
|
312
|
+
LIMIT 1`,t);return!r||e.isIgnored(r.relative_path)?null:Ue(e,r)}function on(e,t){if("symbol"in t&&"relativePath"in t)return t;let n=Nm(e,t.symbolId)[0];return n?Ue(e,n):null}function Nm(e,t){let n=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
|
|
264
313
|
FROM global_symbols gs
|
|
265
314
|
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
266
315
|
JOIN documents d ON der.document_id = d.id
|
|
267
316
|
WHERE gs.id = ?
|
|
268
|
-
ORDER BY der.start_line, der.end_line`,
|
|
317
|
+
ORDER BY der.start_line, der.end_line`,t),r=e.all(`SELECT
|
|
269
318
|
gs.id,
|
|
270
319
|
gs.symbol,
|
|
271
320
|
c.document_id,
|
|
272
321
|
MIN(c.start_line) AS start_line,
|
|
273
322
|
MAX(c.end_line) AS end_line,
|
|
274
323
|
d.relative_path,
|
|
275
|
-
gs.display_name
|
|
324
|
+
gs.display_name,
|
|
325
|
+
gs.documentation
|
|
276
326
|
FROM global_symbols gs
|
|
277
327
|
JOIN mentions m ON m.symbol_id = gs.id
|
|
278
328
|
JOIN chunks c ON m.chunk_id = c.id
|
|
@@ -280,71 +330,164 @@ Install manually from: https://github.com/sourcegraph/scip/releases`)}let c={...
|
|
|
280
330
|
WHERE gs.id = ?
|
|
281
331
|
AND m.role = 1
|
|
282
332
|
${e.pathExclusionsFor("d")}
|
|
283
|
-
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name
|
|
284
|
-
ORDER BY start_line, end_line`,n)}function
|
|
333
|
+
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation
|
|
334
|
+
ORDER BY start_line, end_line`,t);return ur(n,r)}function Em(e,t){let n=t.map(()=>"(gs.symbol LIKE ? OR d.relative_path LIKE ? OR COALESCE(gs.display_name, '') LIKE ?)"),r=t.flatMap(o=>{let a=`%${o}%`;return[a,a,a]}),i=e.all(`SELECT gs.id, gs.symbol, der.document_id, der.start_line, der.end_line, d.relative_path, gs.display_name, gs.documentation
|
|
285
335
|
FROM global_symbols gs
|
|
286
336
|
JOIN defn_enclosing_ranges der ON gs.id = der.symbol_id
|
|
287
337
|
JOIN documents d ON der.document_id = d.id
|
|
288
|
-
WHERE ${
|
|
338
|
+
WHERE ${n.join(`
|
|
289
339
|
AND `)}
|
|
290
340
|
${e.pathExclusionsFor("d")}
|
|
291
|
-
LIMIT 200`,...s
|
|
341
|
+
LIMIT 200`,...r),s=e.all(`SELECT
|
|
292
342
|
gs.id,
|
|
293
343
|
gs.symbol,
|
|
294
344
|
c.document_id,
|
|
295
345
|
MIN(c.start_line) AS start_line,
|
|
296
346
|
MAX(c.end_line) AS end_line,
|
|
297
347
|
d.relative_path,
|
|
298
|
-
gs.display_name
|
|
348
|
+
gs.display_name,
|
|
349
|
+
gs.documentation
|
|
299
350
|
FROM global_symbols gs
|
|
300
351
|
JOIN mentions m ON m.symbol_id = gs.id
|
|
301
352
|
JOIN chunks c ON m.chunk_id = c.id
|
|
302
353
|
JOIN documents d ON c.document_id = d.id
|
|
303
354
|
WHERE m.role = 1
|
|
304
|
-
AND ${
|
|
355
|
+
AND ${n.join(`
|
|
305
356
|
AND `)}
|
|
306
357
|
${e.pathExclusionsFor("d")}
|
|
307
|
-
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name
|
|
308
|
-
LIMIT 200`,...s)}function
|
|
358
|
+
GROUP BY gs.id, gs.symbol, c.document_id, d.relative_path, gs.display_name, gs.documentation
|
|
359
|
+
LIMIT 200`,...r);return ur(i,s)}function ur(e,t){let n=new Map;for(let r of t)e.length>0&&!Dm(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()]}function Dm(e){if(Je(e.symbol)!==null)return!1;let n=(e.documentation??"").replace(/^```\w*\s*/,"").replace(/\s*```$/,"").trim();return/^(?:var|let|const|function|class|interface|type|enum)\b/.test(n)}function Lm(e,t,n,r){let i=t.trim(),s=n,o=s.replace(/\(\)$/,""),a=t.toLowerCase(),l=n.toLowerCase(),c=l.replace(/\(\)$/,""),u=e.symbol,d=h(e.symbol),m=D(e.symbol),g=e.display_name??"",p=e.symbol.toLowerCase(),f=d.toLowerCase(),y=m.toLowerCase(),L=g.toLowerCase(),k=e.relative_path.toLowerCase(),F=/[/:.]/.test(n),T=dr(n),R=T?.leaf.toLowerCase(),_=0;return(u===i||u===s)&&(_+=1150),(d===i||d===s)&&(_+=1100),g===o&&(_+=1180),m===o&&(_+=1160),(`${m}()`===i||`${m}()`===s)&&(_+=955),(p===a||p===l)&&(_+=1e3),(f===a||f===l)&&(_+=950),(k===a||k===l)&&(_+=925),(k.endsWith(`/${l}`)||k.endsWith(`/${a}`))&&(_+=875),L===c&&(_+=850),y===c&&(_+=825),(`${y}()`===a||`${y}()`===l)&&(_+=820),(f.endsWith(`:${l}`)||f.endsWith(`:${c}`)||f.endsWith(`:${c}()`))&&(_+=800),p.includes(l)&&(_+=120),f.includes(l)&&(_+=140),k.includes(l)&&(_+=140),L.includes(l)&&(_+=110),r.every(O=>{let N=O.toLowerCase();return p.includes(N)||f.includes(N)||k.includes(N)||L.includes(N)})&&(_+=100+r.length*15),T&&k.includes(T.path.toLowerCase())&&(_+=360,R&&(y===R||`${y}()`===R||`${y}()`==`${R}()`)&&(_+=700),U(e.symbol)&&(_+=180)),W(e.symbol)&&y===c&&(_+=60),!F&&Le(e.symbol)&&(_-=160),_-=Math.min(50,Math.max(0,e.end_line-e.start_line)),_}function dr(e){let t=e.trim().replace(/\\/g,"/"),n=t.lastIndexOf("/");if(n<=0||n===t.length-1)return null;let r=t.slice(n+1).replace(/\(\)$/,"");return!r||r.includes(".")?null:{path:t.slice(0,n),leaf:r}}function mr(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function km(e){let t=mr(e),n=t.split(/[^A-Za-z0-9_]+/).map(r=>r.trim()).filter(r=>r.length>0);return n.length>0?[...new Set(n)]:[t]}function wm(e,t,n){let r=t.trim(),i=e.filter(s=>{let o=h(s.symbol),a=(s.display_name??"").trim();return s.symbol===r||o===r||o===n||a===r||a===n||`${a}()`===r||rt(s,n)>1||s.relative_path===r});return i.length===0?null:(i.sort((s,o)=>rt(o,n)-rt(s,n)||s.end_line-s.start_line-(o.end_line-o.start_line)||s.relative_path.localeCompare(o.relative_path)||s.symbol.localeCompare(o.symbol)),i[0]??null)}function rt(e,t){let n=dr(t);if(!n)return 0;let r=e.relative_path.toLowerCase(),i=D(e.symbol).toLowerCase(),s=n.path.toLowerCase(),o=n.leaf.toLowerCase();return r.includes(s)?i!==o?1:U(e.symbol)?Je(e.symbol)===null?5:4:Je(e.symbol)===null?3:2:0}function G(e,t){let n=ss(e,t,{allowMultiple:!1})[0]?.relativePath;return n||Fm(e,t)}function we(e,t){return ss(e,t,{allowMultiple:!0}).map(n=>n.relativePath)}function Fm(e,t){if(!t)return null;let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=Om(n)&&n.startsWith(e.config.projectRoot)?n.slice(e.config.projectRoot.length).replace(/^\/+/,""):n,i=Mm(e.config.projectRoot,r);return Pm(i)?r:null}function ss(e,t,n){let r=os(t);if(!r)return[];let s=e.all(`SELECT relative_path
|
|
309
360
|
FROM documents
|
|
310
361
|
WHERE 1 = 1
|
|
311
362
|
${e.pathExclusionsFor("documents")}
|
|
312
|
-
ORDER BY relative_path`).filter(r=>!e.isIgnored(r.relative_path)).map(r=>({relativePath:r.relative_path,score:Wl(r.relative_path,s)})).filter(r=>r.score>0).sort((r,l)=>l.score-r.score||r.relativePath.localeCompare(l.relativePath));if(o.length===0){let r=k(e,n);return!r||e.isIgnored(r.relativePath)?[]:[{relativePath:r.relativePath,score:700}]}let a=o.filter(r=>r.score>=800);return a.length>0?t.allowMultiple?a:[a[0]]:t.allowMultiple?o:[o[0]]}function Wl(e,n){let t=di(e),s=ui(t),i=ui(n),o=0;return t===n&&(o+=1200),t.endsWith(`/${n}`)&&(o+=1100),s===i&&(o+=900),t.startsWith(`${n}/`)&&(o+=850),t.includes(n)&&(o+=250),o}function di(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function pi(e,n){let t=Le(e,n);return Ke(e,t).map(({relativePath:s,...i})=>i)}import{basename as Hl}from"path";function fi(e,n){let t=k(e,n);if(!t)return[];let s=F(t.symbol),i=A(e,t.relativePath).filter(r=>Ve(r.symbol)),o=i.filter(r=>r.parentTypeName===s||r.symbol.includes(s));return(o.length>0?o:Jl(Hl(t.relativePath))===s?i.filter(r=>r.symbol.includes("<invalid-global-code>")):[]).map(r=>({startLine:r.startLine,endLine:r.endLine,name:F(r.symbol)}))}function Jl(e){return e.replace(/\.[^.]+$/,"")}var ft=new WeakMap;function yi(e,n){let t=P(n);return t==="rust"?Gl(e,n):t==="typescript"||t==="tsx"||t==="javascript"?ql(e,n):[]}var Ul=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function ql(e,n){let t=O(e,n);if(!t)return[];let s=ft.get(t);if(s)return s;let i=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(n)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(n),o=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(n),a=!1,r=t.rootNode;for(let c of r.namedChildren){if(c.type!=="expression_statement")continue;let m=c.namedChild(0);if(!m||m.type!=="call_expression")continue;let u=m.namedChild(0);if(!u)continue;let d=u.type==="member_expression"?u.namedChild(u.namedChildCount-1)?.text:u.text;if(d&&Ul.has(d)){a=!0;break}}let l=[];a&&l.push({startLine:0,endLine:r.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(i||o)&&l.push({startLine:0,endLine:r.endPosition.row,reason:i?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of r.namedChildren){let m=null,u=null;if(c.type==="function_declaration")m=c.namedChild(0)?.text??null,u=c;else if(c.type==="export_statement"){let d=c.namedChild(0);d?.type==="function_declaration"&&(m=d.namedChild(0)?.text??null,u=d)}else if(c.type==="lexical_declaration"){let d=c.namedChild(0);if(d?.type==="variable_declarator"){let g=d.namedChild(0)?.text,p=d.namedChild(1);g&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(m=g,u=d)}}m&&/^use[A-Z]/.test(m)&&u&&l.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...bi(t,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),ft.set(t,l),l}var zl=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function Vl(e){return zl.test(e)}function bi(e,n,t){let s=[],i=o=>{if(n.has(o.type)&&o.parent){let r=o.parent.children,l=-1;for(let c=0;c<r.length;c+=1)if(r[c].startIndex===o.startIndex&&r[c].type===o.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let m=r[c];if(t.has(m.type)){if(Vl(m.text)){s.push({startLine:o.startPosition.row,endLine:o.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(m.type==="attribute_item"||m.type==="inner_attribute_item"))break}}for(let a of o.namedChildren)i(a)};return i(e.rootNode),s}function Gl(e,n){let t=O(e,n);if(!t)return[];let s=ft.get(t);if(s)return s;let i=[];if(Yl(t.rootNode)){let u={startLine:0,endLine:t.rootNode.endPosition.row,reason:"generated file (@generated header)"};return ft.set(t,[u]),[u]}let o=u=>{let d=u.parent;if(!d)return[];let g=d.children,p=-1;for(let y=0;y<g.length;y+=1)if(g[y].startIndex===u.startIndex&&g[y].type===u.type){p=y;break}if(p<=0)return[];let f=[];for(let y=p-1;y>=0;y-=1){let h=g[y];if(h.type==="attribute_item"||h.type==="inner_attribute_item")f.push(h.text);else{if(h.type==="line_comment"||h.type==="block_comment")continue;break}}return f},a=u=>/#\[\s*tauri::command\b/.test(u)?"#[tauri::command]":/#\[\s*command\b/.test(u)?"#[command]":/#\[\s*test\b/.test(u)?"#[test]":/#\[\s*bench\b/.test(u)?"#[bench]":/#\[\s*tokio::test\b/.test(u)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(u)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(u)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(u)?"#[no_mangle]":/#\[\s*napi\b/.test(u)?"#[napi]":/#\[\s*pyfunction\b/.test(u)?"#[pyfunction]":/#\[\s*pymethod\b/.test(u)?"#[pymethod]":/#\[\s*pyo3\b/.test(u)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(u)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(u)?"#[doc(hidden)]":null,r=u=>/#\[\s*derive\s*\(/.test(u)?/\bSerialize\b/.test(u)||/\bDeserialize\b/.test(u)||/\bFromRow\b/.test(u)||/\bDeriveEntityModel\b/.test(u)||/\bIntoSchema\b/.test(u)||/\bToSchema\b/.test(u)||/\bDeriveValueType\b/.test(u)||/\bsqlx::FromRow\b/.test(u)||/\bError\b/.test(u)||/\bthiserror::Error\b/.test(u):!1,l=u=>/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(u),c=(u,d,g,p)=>{let f=d,y=g,h=p;if(u.type==="trait_item"&&(h=!0,i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait declaration body (dynamic dispatch)"})),u.type==="impl_item"&&u.childForFieldName("trait")&&(y=!0,i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait impl block (dynamic dispatch)"})),u.type==="function_item"||u.type==="function_signature_item"){let b=o(u),_=null;g?_="trait impl method (dynamic dispatch)":d&&(_="inside #[cfg(test)] mod");for(let S of b){let x=a(S);if(x){_=x;break}if(l(S)){_="#[allow(dead_code)]";break}}_&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:_})}else if(g&&(u.type==="const_item"||u.type==="type_item"||u.type==="static_item"||u.type==="associated_type"))i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"trait impl associated item (dynamic dispatch)"});else if(u.type==="struct_item"||u.type==="enum_item"||u.type==="union_item"){let b=o(u),_=b.some(r),S=b.some(l),x=u.namedChildren.find(L=>L.type==="type_identifier")?.text;_&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:x}),S&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"#[allow(dead_code)]",containerName:x}),d&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:x})}else u.type==="mod_item"&&o(u).some(_=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(_))&&(f=!0);for(let b of u.namedChildren)c(b,f,y,h)};c(t.rootNode,!1,!1,!1),i.push(...bi(t,new Set(["function_item","function_signature_item","struct_item","enum_item","union_item","impl_item","mod_item","static_item","const_item"]),new Set(["line_comment","block_comment"])));let m=ec(t.rootNode);if(m.size>0)for(let u of t.rootNode.descendantsOfType("mod_item")){let d=u.childForFieldName("name")?.text;d&&m.has(d)&&i.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:'serde `with = "..."` module \u2014 body invoked via reflection',containerName:d})}return ft.set(t,i),i}function Yl(e){for(let n=0;n<Math.min(e.namedChildCount,12);n+=1){let t=e.namedChild(n);if(!t||t.type!=="line_comment"&&t.type!=="block_comment")break;if(/@generated\b/.test(t.text)||/This file is .*generated\b/i.test(t.text)||/Code generated by/i.test(t.text)||/Generated by:\s*https?:\/\/openapi-generator/i.test(t.text)||/openapi-generator/i.test(t.text)&&/Generated by/i.test(t.text))return!0}return!1}var Kl=[{key:"default",re:/\bdefault\s*=\s*"([^"]+)"/g},{key:"with",re:/\bwith\s*=\s*"([^"]+)"/g},{key:"serialize_with",re:/\bserialize_with\s*=\s*"([^"]+)"/g},{key:"deserialize_with",re:/\bdeserialize_with\s*=\s*"([^"]+)"/g},{key:"skip_serializing_if",re:/\bskip_serializing_if\s*=\s*"([^"]+)"/g},{key:"getter",re:/\bgetter\s*=\s*"([^"]+)"/g},{key:"rename_all_with",re:/\brename_all_with\s*=\s*"([^"]+)"/g},{key:"schema_with",re:/\bschema_with\s*=\s*"([^"]+)"/g}],Si=/^#!?\[\s*serde\s*\(/,Ql=/^#!?\[\s*schemars\s*\(/,Xl=/^#!?\[\s*validate\s*\(/,gi=/\bwith\s*=\s*"([^"]+)"/g;function we(e,n){return Jt(e,n,Zl,()=>new Set,(t,s,i)=>{if(s==="rust"){for(let o of t.rootNode.descendantsOfType("attribute_item"))hi(o.text,i);for(let o of t.rootNode.descendantsOfType("inner_attribute_item"))hi(o.text,i)}})??new Set}var Zl=new WeakMap;function hi(e,n){let t=Si.test(e),s=Ql.test(e),i=Xl.test(e);if(!(!t&&!s&&!i))for(let{re:o}of Kl){o.lastIndex=0;let a;for(;(a=o.exec(e))!==null;){let r=a[1],l=r.split("::").pop()??r;l==="is_none"&&/\bOption\b/.test(r)||l==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(r)||l&&n.add(l)}}}function ec(e){let n=new Set;for(let t of e.descendantsOfType("attribute_item")){if(!Si.test(t.text))continue;gi.lastIndex=0;let s;for(;(s=gi.exec(t.text))!==null;){let i=s[1],o=i.split("::").pop()??i;o&&n.add(o)}}return n}var tc=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function _i(e,n){return Jt(e,n,nc,()=>new Set,(t,s,i)=>{if(!(s!=="typescript"&&s!=="tsx"&&s!=="javascript"))for(let o of t.rootNode.descendantsOfType("call_expression")){let a=o.namedChild(0);if(!a)continue;let r=ut(a);if(!r||!tc.has(r))continue;let l=o.namedChildren.find(u=>u.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let m=c.namedChildren.find(u=>u.type==="string_fragment");m&&i.add(m.text)}})??new Set}var nc=new WeakMap;function zt(e){return e.replace(/'''[\s\S]*?'''/g,De).replace(/"""[\s\S]*?"""/g,De).replace(/#.*$/gm,De).replace(/\/\/.*$/gm,De).replace(/\/\*[\s\S]*?\*\//g,De).replace(/`(?:\\[\s\S]|[^`])*`/g,De).replace(/'(?:\\.|[^'\\\r\n])*'/g,De).replace(/"(?:\\.|[^"\\\r\n])*"/g,De)}function De(e){return e.replace(/[^\r\n]/g," ")}var sc=Ot("stripped-lines");function Ii(e,n,t){return sc.get(e,n,t,()=>zt(t).split(`
|
|
313
|
-
`))}var
|
|
314
|
-
FROM documents
|
|
315
|
-
WHERE 1 = 1
|
|
316
|
-
${e.pathExclusionsFor("documents")}`).map(n=>ae(n.relative_path)).filter(n=>!e.isIgnored(n))))}function ae(e){return e.replace(/\\/g,"/")}function oe(e){let n=[],t=0,s=0;for(let i=0;i<e.length;i++){let o=e[i];(o==="{"||o==="["||o==="(")&&t++,(o==="}"||o==="]"||o===")")&&t--,o===","&&t===0&&(n.push(e.slice(s,i)),s=i+1)}return n.push(e.slice(s)),n}function le(e,n){for(let t of e.namedChildren)if(t.type===n)return t;return null}function J(e,n){let t=new Set,s=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]),i=(o,a)=>{let r=a||n.has(o.type);!r&&s.has(o.type)&&t.add(o.text);for(let l of o.children)i(l,r)};return i(e.rootNode,!1),t}function ge(e,n,t,s,i,o,a){return{importedName:i,localName:o,sourcePath:a??H(e,s,Bn(n)),kind:"named",used:te(t,o),usedMembers:[]}}function wi(e,n,t){let s=O(e,n);return s?Rc(e,n,s):Dc(t).flatMap(i=>kc(e,n,i.clause,i.specifier,i.start,i.end,t))}function Rc(e,n,t){let s=J(t,new Set(["import_statement"]));if(mt(n))for(let o of jc(e,n))s.add(o);let i=[];for(let o of t.rootNode.descendantsOfType("import_statement")){let a=Lc(o);if(!a)continue;let r=He(e,n,a),l=le(o,"import_clause");if(!l){i.push({importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]});continue}for(let c of l.namedChildren)switch(c.type){case"identifier":{let m=c.text;i.push({importedName:"default",localName:m,sourcePath:r,kind:"default",used:s.has(m),usedMembers:[]});break}case"namespace_import":{let u=le(c,"identifier")?.text??"";if(!u)break;let d=wc(t,u);i.push({importedName:"*",localName:u,sourcePath:r,kind:"namespace",used:d.length>0||s.has(u),usedMembers:d});break}case"named_imports":{for(let m of c.namedChildren){if(m.type!=="import_specifier")continue;let u=m.namedChild(0),d=m.namedChild(1);if(!u)continue;let g=u.text,p=d?.text??g;i.push({importedName:g,localName:p,sourcePath:r,kind:"named",used:s.has(p),usedMembers:[]})}break}}}return i}function Lc(e){let n=le(e,"string");if(!n)return null;let t=le(n,"string_fragment");return t?t.text:null}function wc(e,n){let t=new Set;for(let s of e.rootNode.descendantsOfType("member_expression")){let i=s.namedChild(0),o=s.namedChild(1);!i||!o||i.type!=="identifier"||i.text!==n||(o.type==="property_identifier"||o.type==="identifier")&&t.add(o.text)}return[...t]}function Dc(e){let n=[],t=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(t)){let o=i[0],a=i[1],r=i[2];!o||!r||typeof i.index!="number"||n.push({clause:a,specifier:r,start:i.index,end:i.index+o.length})}let s=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(s)){let o=i[0],a=i[1];!o||!a||typeof i.index!="number"||n.push({clause:null,specifier:a,start:i.index,end:i.index+o.length})}return n.sort((i,o)=>i.start-o.start)}function kc(e,n,t,s,i,o,a){let r=He(e,n,s),l=z(a,i,o);return t?Oc(t).map(m=>({...m,sourcePath:r})).map(m=>{if(m.kind==="namespace"){let u=Ze(l,m.localName);return{...m,used:u.length>0||te(l,m.localName),usedMembers:u}}return m.kind==="side-effect"?{...m,used:!0,usedMembers:[]}:{...m,used:m.localName?te(l,m.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:r,kind:"side-effect",used:!0,usedMembers:[]}]}function Oc(e){let n=e.trim().replace(/^type\s+/,""),[t,s]=$c(n),i=[];return t&&i.push(...Li(t)),s&&i.push(...Li(s)),i}function Li(e){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let t=n.slice(1,-1).trim();return t?oe(t).map(s=>{let i=s.trim().replace(/^type\s+/,""),[o,a]=i.split(/\s+as\s+/);return{importedName:o.trim(),localName:(a??o).trim(),kind:"named"}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace"}]:[{importedName:"default",localName:n,kind:"default"}]}function $c(e){let n=0;for(let t=0;t<e.length;t++){let s=e[t];if(s==="{"&&n++,s==="}"&&n--,s===","&&n===0)return[e.slice(0,t).trim(),e.slice(t+1).trim()]}return[e.trim(),null]}function Di(e,n){let t=O(e,n);if(t)return Mc(e,n,t);let s=M(e,n);if(!s)return[];let i=[],o=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(o)){if(typeof l.index!="number")continue;let c=l[1]??"",m=l[2]??"",u=oe(c).map(p=>Pc(p.trim())).filter(p=>!!p),d=st(s,l.index),g=st(s,l.index+l[0].length-1);i.push({kind:"named",sourcePath:He(e,n,m),names:u,startLine:d,endLine:g})}let a=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(a)){if(typeof l.index!="number")continue;let c=l[2]??"",m=st(s,l.index),u=st(s,l.index+l[0].length-1);i.push({kind:"star-as",sourcePath:He(e,n,c),names:[],startLine:m,endLine:u})}let r=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let l of s.matchAll(r)){if(typeof l.index!="number")continue;let c=l[1]??"",m=st(s,l.index),u=st(s,l.index+l[0].length-1);i.push({kind:"star",sourcePath:He(e,n,c),names:[],startLine:m,endLine:u})}return i}function Pc(e){if(!e)return null;let n=e.replace(/^type\s+/,"").trim();if(!n)return null;let t=n.match(/^(\w+)\s+as\s+(\w+)$/);if(t)return t[2]??null;let s=n.match(/^(\w+)$/);return s?s[1]??null:null}function st(e,n){let t=0;for(let s=0;s<n&&s<e.length;s++)e.charCodeAt(s)===10&&t++;return t}function Mc(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("export_statement")){let o=Fc(e,n,i);if(o===void 0)continue;let a=i.startPosition.row,r=i.endPosition.row,l=Tc(i,o,a,r);s.push(l)}return s}function Fc(e,n,t){let s=le(t,"string");if(!s)return;let i=le(s,"string_fragment");if(i)return He(e,n,i.text)}function Tc(e,n,t,s){let i=le(e,"export_clause");if(i){let a=[];for(let r of i.namedChildren){if(r.type!=="export_specifier")continue;let l=r.namedChild(0),c=r.namedChild(1);l&&a.push((c??l).text)}return{kind:"named",sourcePath:n,names:a,startLine:t,endLine:s}}return le(e,"namespace_export")?{kind:"star-as",sourcePath:n,names:[],startLine:t,endLine:s}:{kind:"star",sourcePath:n,names:[],startLine:t,endLine:s}}var Ac=W("vue-non-script-identifiers");function jc(e,n){return Ac.get(e,n,()=>{let t=new Set,s=M(e,n);if(!s)return t;let o=s.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,a=>a.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,a=>a.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,a=>a.replace(/[^\r\n]/g," "));for(let a of o.matchAll(/[A-Za-z_$][\w$]*/g))t.add(a[0]);return t})}import{basename as ki}from"path";function Oi(e,n,t){let s=O(e,n);if(s)return Bc(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length),c=ki(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:c,sourcePath:Qt(e,n,a),kind:"named",used:te(l,c),usedMembers:[]})}return i}function Bc(e,n,t){let s=J(t,new Set(["preproc_include"])),i=[];for(let o of t.rootNode.descendantsOfType("preproc_include")){let a=null;for(let l of o.namedChildren){if(l.type==="system_lib_string"){a=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){a=l.namedChildren.find(m=>m.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!a)continue;let r=ki(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:r,sourcePath:Qt(e,n,a),kind:"named",used:s.has(r),usedMembers:[]})}return i}function $i(e,n,t){let s=[];for(let i of t.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let o=i[1]?.trim(),a=i[2]?.trim()??null,r=i[0];if(!o||!r||typeof i.index!="number")continue;let l=z(t,i.index,i.index+r.length);s.push({importedName:o,localName:a,sourcePath:Xt(e,n,o),kind:a?"namespace":"side-effect",used:a?te(l,a):!0,usedMembers:a?Ze(l,a):[]})}return s}function Pi(e,n,t){let s=[];for(let i of t.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let o=i[1]?.trim();o&&s.push({specifier:o,sourcePath:Xt(e,n,o)})}return s}function Mi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="csharp")return Hc(e,n,s);if(s&&i==="vb")return Wc(e,n,s);let o=[],a=Ri(n)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;for(let r of t.matchAll(a)){let l=r[1]?.trim(),c=r[0];if(!l||!c||typeof r.index!="number")continue;let m=z(t,r.index,r.index+c.length),[u,d]=l.split(/\s*=\s*/),g=!!d,p=(g?d:u)?.trim()??l,f=p.split(".").pop()??p,y=g?u?.trim()??f:f;o.push(ge(e,n,m,p,f,y,H(e,p,tt)))}return o}function Wc(e,n,t){let s=J(t,new Set(["imports_statement"])),i=[];for(let o of t.rootNode.descendantsOfType("imports_statement")){let a=o.namedChildren.filter(d=>d.type==="namespace_name");if(a.length===0)continue;let r=a[a.length-1],l=a.length>1?a[0]:null,c=r.text,m=c.split(".").pop()??c,u=l?.text??m;i.push({importedName:m,localName:u,sourcePath:H(e,c,tt),kind:l?"namespace":"named",used:s.has(u),usedMembers:[]})}return i}function Hc(e,n,t){let s=J(t,new Set(["using_directive"])),i=[];for(let o of t.rootNode.descendantsOfType("using_directive")){let a=o.namedChildren;if(a.length===0)continue;let r=null,l=null;if(a.length>=2&&a[0].type==="identifier"&&(a[1].type==="qualified_name"||a[1].type==="identifier")?(r=a[0],l=a[1]):l=a[a.length-1],!l)continue;let c=l.text,m=c.split(".").pop()??c,u=r?.text??m;i.push({importedName:m,localName:u,sourcePath:H(e,c,tt),kind:r?"namespace":"named",used:s.has(u),usedMembers:[]})}return i}function Fi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="java")return Jc(e,n,s);if(s&&i==="kotlin")return Uc(e,n,s);if(s&&i==="scala")return qc(e,n,s);let o=[];for(let a of t.matchAll(/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm)){let r=a[1]?.trim(),l=a[0];if(!r||!l||typeof a.index!="number")continue;let c=z(t,a.index,a.index+l.length);o.push(...zc(e,n,r,c))}return o}function Jc(e,n,t){let s=J(t,new Set(["import_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.children.some(u=>u.type==="asterisk"),l=o.namedChildren.find(u=>u.type==="scoped_identifier")??o.namedChildren.find(u=>u.type==="identifier");if(!l)continue;let c=l.text;if(a){i.push({importedName:"*",localName:null,sourcePath:H(e,c,me),kind:"namespace",used:!0,usedMembers:[]});continue}let m=c.split(".").pop()??c;i.push({importedName:m,localName:m,sourcePath:H(e,c,me),kind:"named",used:s.has(m),usedMembers:[]})}return i}function Uc(e,n,t){let s=J(t,new Set(["import_header","import_list"])),i=[];for(let o of t.rootNode.descendantsOfType("import_header")){let a=o.namedChildren.find(g=>g.type==="identifier");if(!a)continue;let r=o.namedChildren.some(g=>g.type==="wildcard_import"),l=o.namedChildren.find(g=>g.type==="import_alias");if(r){i.push({importedName:"*",localName:null,sourcePath:H(e,a.text,me),kind:"namespace",used:!0,usedMembers:[]});continue}let c=a.text,m=c.split(".").pop()??c,d=l?.namedChild(0)?.text??m;i.push({importedName:m,localName:d,sourcePath:H(e,c,me),kind:"named",used:s.has(d),usedMembers:[]})}return i}function qc(e,n,t){let s=J(t,new Set(["import_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("import_declaration")){let a=o.namedChildren.find(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),r=o.namedChildren.filter(u=>u!==a&&(u.type==="identifier"||u.type==="stable_identifier")),l=r.map(u=>u.text).join(".");if(!l)continue;if(a?.type==="namespace_wildcard"){i.push({importedName:"*",localName:null,sourcePath:H(e,l,me),kind:"namespace",used:!0,usedMembers:[]});continue}if(a?.type==="namespace_selectors"){for(let u of a.namedChildren)if(u.type==="arrow_renamed_identifier"){let[d,g]=u.namedChildren;if(!d)continue;let p=d.text,f=g?.text??p;if(p==="_")continue;i.push({importedName:p,localName:f,sourcePath:H(e,`${l}.${p}`,me),kind:"named",used:s.has(f),usedMembers:[]})}else if(u.type==="identifier"){let d=u.text;i.push({importedName:d,localName:d,sourcePath:H(e,`${l}.${d}`,me),kind:"named",used:s.has(d),usedMembers:[]})}continue}let c=r[r.length-1]?.text??l,m=r.slice(0,-1).map(u=>u.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:H(e,m&&r.length>1?`${m}.${c}`:l,me),kind:"named",used:s.has(c),usedMembers:[]})}return i}function zc(e,n,t,s){if(t.includes("{")&&t.includes("}")){let i=t.slice(0,t.indexOf("{")).replace(/\.$/,"").trim(),o=t.slice(t.indexOf("{")+1,t.lastIndexOf("}")).trim();return oe(o).flatMap(a=>{let r=a.trim();if(!r)return[];let[l,c]=r.includes("=>")?r.split(/\s*=>\s*/):r.split(/\s+as\s+/),m=l?.trim();if(!m||m==="_")return[];let u=(c??m.split(".").pop()??m).trim(),d=m==="_"?i:`${i}.${m}`.replace(/\.\./g,".");return[ge(e,n,s,d,m,u)]})}return[ge(e,n,s,t,t.split(".").pop()??t,t.split(".").pop()??t)]}function Ai(e,n,t){let s=O(e,n);if(s)return Vc(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length);for(let c of oe(a)){let m=c.trim();if(!m)continue;let[u,d]=m.split(/\s+as\s+/i),g=u?.trim()??m,p=g.split("\\").pop()??g,f=(d??p).trim();i.push(ge(e,n,l,g,p,f,H(e,g.replace(/\\/g,"."),gt)))}}return i}function Vc(e,n,t){let s=J(t,new Set(["namespace_use_declaration"])),i=[],o=(a,r,l)=>{i.push({importedName:r,localName:l,sourcePath:H(e,a.replace(/\\/g,"."),gt),kind:"named",used:s.has(l),usedMembers:[]})};for(let a of t.rootNode.descendantsOfType("namespace_use_declaration")){let r=a.namedChildren.find(l=>l.type==="namespace_use_group");if(r){let l=a.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of r.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:m,localName:u,qualified:d}=Ti(c,l);m&&o(d,m,u)}continue}for(let l of a.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:m,qualified:u}=Ti(l,"");c&&o(u,c,m)}}return i}function Ti(e,n){let t=e.namedChildren.find(c=>c.type==="qualified_name"),s=e.namedChildren.filter(c=>c.type==="name"),i="";t?i=t.text:s.length>=1&&(i=s[0].text);let o=t&&s.length>0?s[s.length-1]:null,a=i.split("\\").pop()??i,r=o?.text??a,l=n?`${n}\\${i}`:i;return{importedName:a,localName:r,qualified:l}}function Wi(e,n,t){let s=O(e,n);return s?Gc(e,n,s):Kc(t).flatMap(i=>Xc(e,n,i,t))}function Gc(e,n,t){let s=J(t,new Set(["import_statement","import_from_statement"])),i=[];for(let o of t.rootNode.descendantsOfType("import_statement"))for(let a of o.namedChildren){let r=ji(a);if(!r)continue;let l=nt(e,n,r.qualifiedName);i.push({importedName:r.qualifiedName,localName:r.localName,sourcePath:l,kind:"namespace",used:s.has(r.localName),usedMembers:[]})}for(let o of t.rootNode.descendantsOfType("import_from_statement")){let a=o.namedChild(0);if(!a)continue;let r=Yc(a);if(r===null)continue;let l=nt(e,n,r);for(let c=1;c<o.namedChildCount;c+=1){let m=o.namedChild(c);if(m.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=ji(m);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:s.has(u.localName),usedMembers:[]})}}return i}function ji(e){if(e.type==="aliased_import"){let n=e.namedChild(0),t=e.namedChild(1);return!n||!t?null:{qualifiedName:n.text,localName:t.text}}if(e.type==="dotted_name"){let n=e.text;return{qualifiedName:n,localName:n.split(".")[0]??n}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function Yc(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let n=le(e,"import_prefix")?.text??"",t=le(e,"dotted_name")?.text??"";return`${n}${t}`}return null}function Kc(e){let n=e.split(`
|
|
317
|
-
`),t=[],s=0;for(let i=0;i<n.length;i++){let o=n[i],a=o.trimStart(),r=s;if(s+=o.length+1,!a.startsWith("import ")&&!a.startsWith("from "))continue;let l=o,c=r+o.length,m=Bi(o);for(;i+1<n.length&&(m>0||l.trimEnd().endsWith("\\"));){i++;let d=n[i];l+=`
|
|
318
|
-
${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,end:c})}return t}function Qc(e){let n=e.replace(/\\\s*\n/g," ").trim();if(n.startsWith("import "))return{kind:"import",module:null,clause:n.slice(7).trim()};let t=n.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!t)return null;let s=t[2].trim();return s.startsWith("(")&&s.endsWith(")")&&(s=s.slice(1,-1).trim()),{kind:"from",module:t[1],clause:s}}function Xc(e,n,t,s){let i=z(s,t.start,t.end),o=t.clause.replace(/\n/g," ").trim();if(t.kind==="import")return oe(o).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[m,u]=c.split(/\s+as\s+/),d=m.trim(),g=(u??d.split(".")[0]??d).trim(),p=nt(e,n,d),f=Ze(i,g);return[{importedName:d,localName:g,sourcePath:p,kind:"namespace",used:te(i,g)||f.length>0,usedMembers:f}]});let a=t.module?nt(e,n,t.module):null,r=[];for(let l of oe(o)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){r.push({importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]});continue}let[m,u]=c.split(/\s+as\s+/),d=(u??m).trim();r.push({importedName:m.trim(),localName:d,sourcePath:a,kind:"named",used:te(i,d),usedMembers:[]})}return r}function Bi(e){let n=0;for(let t of e)t==="("&&n++,t===")"&&n--;return n}import{basename as Zc}from"path";function Hi(e,n,t){let s=O(e,n);if(s)return eu(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm)){let a=o[1],r=o[2],l=o[0];if(!a||!r||!l||typeof o.index!="number")continue;let c=z(t,o.index,o.index+l.length),m=a==="require_relative"?Kt(e,n,r):null;if(m){let u=Ji(r);i.push({importedName:u,localName:u,sourcePath:m,kind:"named",used:te(c,u),usedMembers:[]});continue}i.push({importedName:r,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function eu(e,n,t){let s=J(t,new Set([])),i=[],o=new Set(["require","require_relative","load"]);for(let a of t.rootNode.descendantsOfType("call")){let r=a.namedChild(0);if(!r||r.type!=="identifier"||!o.has(r.text))continue;let c=a.namedChildren.find(g=>g.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(g=>g.type==="string_content")?.text;if(!u)continue;let d=r.text==="require_relative"?Kt(e,n,u):null;if(d){let g=Ji(u);i.push({importedName:g,localName:g,sourcePath:d,kind:"named",used:s.has(g),usedMembers:[]})}else i.push({importedName:u,localName:null,sourcePath:d,kind:"side-effect",used:!0,usedMembers:[]})}return i}function Ji(e){return Zc(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function Ui(e,n,t){let s=O(e,n);if(s)return tu(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim(),r=o[0];if(!a||!r||typeof o.index!="number")continue;let l=z(t,o.index,o.index+r.length);i.push(...nu(e,n,a,l))}return i}function tu(e,n,t){let s=J(t,new Set(["use_declaration"])),i=[];for(let o of t.rootNode.descendantsOfType("use_declaration")){let a=o.namedChild(0);if(a)for(let r of ht(a,"")){if(!r.importedName||r.importedName==="*")continue;let l=Ne(e,n,r.qualifiedName)??Ne(e,n,r.qualifiedName.split("::").slice(0,-1).join("::"));i.push({importedName:r.importedName,localName:r.localName,sourcePath:l,kind:"named",used:s.has(r.localName),usedMembers:[]})}}return i}function ht(e,n){switch(e.type){case"identifier":case"super":case"self":case"crate":{let t=e.text;return[{qualifiedName:Zt(n,t),importedName:t,localName:t}]}case"scoped_identifier":{let t=e.text,s=t.split("::").pop()??t;return[{qualifiedName:Zt(n,t),importedName:s,localName:s}]}case"scoped_use_list":{let t=e.namedChild(0),s=e.namedChild(1);if(!t||!s)return[];let i=Zt(n,t.text),o=[];for(let a of s.namedChildren)o.push(...ht(a,i));return o}case"use_list":{let t=[];for(let s of e.namedChildren)t.push(...ht(s,n));return t}case"use_as_clause":{let t=e.namedChild(0),s=e.namedChild(1);if(!t||!s)return[];let i=ht(t,n),o=s.text;return i.map(a=>({...a,localName:o}))}case"use_wildcard":{let t=e.namedChild(0),s=t?t.text:"";return[{qualifiedName:Zt(n,`${s}::*`),importedName:"*",localName:"*"}]}default:return[]}}function Zt(e,n){return e?n?`${e}::${n}`:e:n}function nu(e,n,t,s){let i=t.trim();if(i.includes("{")&&i.includes("}")){let m=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),u=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return oe(u).flatMap(d=>{let g=d.trim();if(!g||g==="self")return[];let[p,f]=g.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let h=(f??y.split("::").pop()??y).trim(),b=`${m}::${y}`.replace(/::::/g,"::");return[ge(e,n,s,b,y.split("::").pop()??y,h,Ne(e,n,m))]})}let[o,a]=i.split(/\s+as\s+/),r=o?.trim()??i,l=(a??r.split("::").pop()??r).trim(),c=Ne(e,n,r)??Ne(e,n,r.split("::").slice(0,-1).join("::"));return[ge(e,n,s,r,r.split("::").pop()??r,l,c)]}function qi(e,n,t){let s=O(e,n);if(s)return su(e,n,s);let i=[];for(let o of t.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let a=o[1]?.trim();a&&i.push(...ou(e,n,a))}return i}function su(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("use_declaration")){if(!iu(i))continue;let o=i.namedChildren.find(a=>a.type!=="visibility_modifier");if(o)for(let a of ht(o,""))a.importedName&&s.push(Wn(e,n,a.qualifiedName))}return s}function iu(e){for(let n of e.children)if(n.type==="visibility_modifier"&&n.text.startsWith("pub"))return!0;return!1}function ou(e,n,t){let s=t.trim();if(s.includes("{")&&s.includes("}")){let i=s.slice(0,s.indexOf("{")).replace(/::$/,"").trim(),o=s.slice(s.indexOf("{")+1,s.lastIndexOf("}")).trim();return oe(o).flatMap(a=>{let r=a.trim();if(!r||r==="self")return[];let[l]=r.split(/\s+as\s+/),c=`${i}::${l?.trim()??r}`.replace(/::::/g,"::");return[Wn(e,n,c)]})}return[Wn(e,n,s)]}function Wn(e,n,t){return{specifier:t,sourcePath:Ne(e,n,t)??Ne(e,n,t.split("::").slice(0,-1).join("::"))}}function zi(e,n){let t=n.toLowerCase();for(let s of e)for(let i of s.extensions)if(t.endsWith(i))return s;return null}var ru={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:wi},au={language:"python",extensions:[".py",".pyi"],parseImports:Wi},lu={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:Fi},cu={language:"rust",extensions:[".rs"],parseImports:Ui,parseExports:qi},uu={language:"ruby",extensions:[".rb"],parseImports:Hi},mu={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:Oi},du={language:"dotnet",extensions:[".cs",".vb"],parseImports:Mi},pu={language:"dart",extensions:[".dart"],parseImports:$i,parseExports:Pi},fu={language:"php",extensions:[".php"],parseImports:Ai},gu=[ru,au,lu,cu,uu,mu,du,pu,fu];function Hn(e){return zi(gu,e)}function Ki(e,n){return Di(e,n)}var hu=W("source-imports"),yu=W("source-exports");function de(e,n){let t=ae(n);return hu.get(e,t,()=>{let s=Hn(t);if(!s)return[];let i=Yi(e.config.projectRoot,t);if(!Vi(i))return[];let o=Gi(i,"utf-8");return s.parseImports(e,t,o)})}function Jn(e,n){let t=ae(n);return yu.get(e,t,()=>{let s=Hn(t);if(!s?.parseExports)return[];let i=Yi(e.config.projectRoot,t);if(!Vi(i))return[];let o=Gi(i,"utf-8");return s.parseExports(e,t,o)})}var bu=W("file-dep-graph");function K(e,n){return bu.get(e,n??"",()=>{let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",s=e.all(`SELECT DISTINCT
|
|
319
|
-
d1.relative_path AS from_file,
|
|
320
|
-
d2.relative_path AS to_file
|
|
321
|
-
FROM mentions m
|
|
322
|
-
JOIN chunks c ON m.chunk_id = c.id
|
|
323
|
-
JOIN documents d1 ON c.document_id = d1.id
|
|
324
|
-
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
325
|
-
JOIN (
|
|
326
|
-
SELECT m2.symbol_id, c2.document_id
|
|
327
|
-
FROM mentions m2
|
|
328
|
-
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
329
|
-
WHERE m2.role = 1
|
|
330
|
-
GROUP BY m2.symbol_id
|
|
331
|
-
) sym_def ON sym_def.symbol_id = gs.id
|
|
332
|
-
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
333
|
-
WHERE d1.id != d2.id
|
|
334
|
-
AND m.role != 1
|
|
335
|
-
${e.pathExclusionsFor("d1","d2")}
|
|
336
|
-
${t}`),i=new Map,o=new Set(e.all(`SELECT relative_path
|
|
363
|
+
ORDER BY relative_path`).filter(l=>!e.isIgnored(l.relative_path)).map(l=>({relativePath:l.relative_path,score:Tm(l.relative_path,r)})).filter(l=>l.score>0).sort((l,c)=>c.score-l.score||l.relativePath.localeCompare(c.relativePath));if(s.length===0){let l=E(e,t);return!l||e.isIgnored(l.relativePath)?[]:[{relativePath:l.relativePath,score:700}]}let o=s.filter(l=>l.score>=1100);if(o.length>0)return n.allowMultiple?o:[o[0]];let a=s.filter(l=>l.score>=800);return a.length>0?n.allowMultiple?a:[a[0]]:n.allowMultiple?s:[s[0]]}function Tm(e,t){let n=os(e),r=is(n),i=is(t),s=0;return n===t&&(s+=1200),n.endsWith(`/${t}`)&&(s+=1100),r===i&&(s+=900),n.startsWith(`${t}/`)&&(s+=850),n.includes(t)&&(s+=250),s}function os(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function as(e,t){let n=we(e,t);return nt(e,n).map(({relativePath:r,...i})=>i)}import{basename as eh}from"path";var bt=new WeakMap;function us(e,t){let n=M(t);return n==="rust"?Wm(e,t):n==="typescript"||n==="tsx"||n==="javascript"?Am(e,t):[]}var $m=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function Am(e,t){let n=P(e,t);if(!n)return[];let r=bt.get(n);if(r)return r;let i=/(^|\/)(pages|app)\/.+\.(tsx?|jsx?)$/.test(t)||/(^|\/)(layout|page|loading|error|not-found|head|template|default)\.(tsx?|jsx?)$/.test(t),s=/(^|\/)src\/(pages|views|routes)\/.+\.(tsx?|jsx?|vue)$/.test(t),o=!1,a=n.rootNode;for(let c of a.namedChildren){if(c.type!=="expression_statement")continue;let u=c.namedChild(0);if(!u||u.type!=="call_expression")continue;let d=u.namedChild(0);if(!d)continue;let m=d.type==="member_expression"?d.namedChild(d.namedChildCount-1)?.text:d.text;if(m&&$m.has(m)){o=!0;break}}let l=[];o&&l.push({startLine:0,endLine:a.endPosition.row,reason:"TS/JS test file (describe/it/test at top level)"}),(i||s)&&l.push({startLine:0,endLine:a.endPosition.row,reason:i?"Next.js / Remix route file":"Vite/Vue route component"});for(let c of a.namedChildren){let u=null,d=null;if(c.type==="function_declaration")u=c.namedChild(0)?.text??null,d=c;else if(c.type==="export_statement"){let m=c.namedChild(0);m?.type==="function_declaration"&&(u=m.namedChild(0)?.text??null,d=m)}else if(c.type==="lexical_declaration"){let m=c.namedChild(0);if(m?.type==="variable_declarator"){let g=m.namedChild(0)?.text,p=m.namedChild(1);g&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(u=g,d=m)}}u&&/^use[A-Z]/.test(u)&&d&&l.push({startLine:d.startPosition.row,endLine:d.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...ds(n,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),bt.set(n,l),l}var jm=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function Bm(e){return jm.test(e)}function ds(e,t,n){let r=[],i=s=>{if(t.has(s.type)&&s.parent){let a=s.parent.children,l=-1;for(let c=0;c<a.length;c+=1)if(a[c].startIndex===s.startIndex&&a[c].type===s.type){l=c;break}if(l>0)for(let c=l-1;c>=0;c-=1){let u=a[c];if(n.has(u.type)){if(Bm(u.text)){r.push({startLine:s.startPosition.row,endLine:s.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(u.type==="attribute_item"||u.type==="inner_attribute_item"))break}}for(let o of s.namedChildren)i(o)};return i(e.rootNode),r}function Wm(e,t){let n=P(e,t);if(!n)return[];let r=bt.get(n);if(r)return r;let i=[],s=Hm(n);return s?(bt.set(n,s),s):(ms(n.rootNode,i,!1,!1),i.push(...ds(n,new Set(["function_item","function_signature_item","struct_item","enum_item","union_item","impl_item","mod_item","static_item","const_item"]),new Set(["line_comment","block_comment"]))),i.push(...Gm(n.rootNode)),bt.set(n,i),i)}function Hm(e){return Km(e.rootNode)?[{startLine:0,endLine:e.rootNode.endPosition.row,reason:"generated file (@generated header)"}]:null}function ms(e,t,n,r){let i=n,s=r;e.type==="trait_item"&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait declaration body (dynamic dispatch)"}),e.type==="impl_item"&&e.childForFieldName("trait")&&(s=!0,t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl block (dynamic dispatch)"})),e.type==="function_item"||e.type==="function_signature_item"?Vm(e,t,n,r):r&&zm(e)?t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"trait impl associated item (dynamic dispatch)"}):e.type==="struct_item"||e.type==="enum_item"||e.type==="union_item"?Um(e,t,n):e.type==="mod_item"&&pr(e).some(o=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(o))&&(i=!0);for(let o of e.namedChildren)ms(o,t,i,s)}function Vm(e,t,n,r){let i=pr(e),s=null;r?s="trait impl method (dynamic dispatch)":n&&(s="inside #[cfg(test)] mod");for(let o of i){let a=Jm(o);if(a){s=a;break}if(ps(o)){s="#[allow(dead_code)]";break}}s&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:s})}function Um(e,t,n){let r=pr(e),i=e.namedChildren.find(s=>s.type==="type_identifier")?.text;r.some(qm)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:i}),r.some(ps)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[allow(dead_code)]",containerName:i}),n&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"inside #[cfg(test)] mod",containerName:i})}function pr(e){let t=e.parent;if(!t)return[];let n=t.children,r=-1;for(let s=0;s<n.length;s+=1)if(n[s].startIndex===e.startIndex&&n[s].type===e.type){r=s;break}if(r<=0)return[];let i=[];for(let s=r-1;s>=0;s-=1){let o=n[s];if(o.type==="attribute_item"||o.type==="inner_attribute_item")i.push(o.text);else{if(o.type==="line_comment"||o.type==="block_comment")continue;break}}return i}function Jm(e){return/#\[\s*tauri::command\b/.test(e)?"#[tauri::command]":/#\[\s*command\b/.test(e)?"#[command]":/#\[\s*test\b/.test(e)?"#[test]":/#\[\s*bench\b/.test(e)?"#[bench]":/#\[\s*tokio::test\b/.test(e)?"#[tokio::test]":/#\[\s*async_std::test\b/.test(e)?"#[async_std::test]":/#\[\s*wasm_bindgen\b/.test(e)?"#[wasm_bindgen]":/#\[\s*no_mangle\b/.test(e)?"#[no_mangle]":/#\[\s*napi\b/.test(e)?"#[napi]":/#\[\s*pyfunction\b/.test(e)?"#[pyfunction]":/#\[\s*pymethod\b/.test(e)?"#[pymethod]":/#\[\s*pyo3\b/.test(e)?"#[pyo3]":/#\[\s*cfg\s*\(\s*test\s*\)/.test(e)?"#[cfg(test)]":/#\[\s*doc\s*\(\s*hidden\s*\)/.test(e)?"#[doc(hidden)]":null}function qm(e){return/#\[\s*derive\s*\(/.test(e)?/\bSerialize\b/.test(e)||/\bDeserialize\b/.test(e)||/\bFromRow\b/.test(e)||/\bDeriveEntityModel\b/.test(e)||/\bIntoSchema\b/.test(e)||/\bToSchema\b/.test(e)||/\bDeriveValueType\b/.test(e)||/\bsqlx::FromRow\b/.test(e)||/\bError\b/.test(e)||/\bthiserror::Error\b/.test(e):!1}function ps(e){return/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(e)}function zm(e){return e.type==="const_item"||e.type==="type_item"||e.type==="static_item"||e.type==="associated_type"}function Gm(e){let t=ep(e);if(t.size===0)return[];let n=[];for(let r of e.descendantsOfType("mod_item")){let i=r.childForFieldName("name")?.text;i&&t.has(i)&&n.push({startLine:r.startPosition.row,endLine:r.endPosition.row,reason:'serde `with = "..."` module \u2014 body invoked via reflection',containerName:i})}return n}function Km(e){for(let t=0;t<Math.min(e.namedChildCount,12);t+=1){let n=e.namedChild(t);if(!n||n.type!=="line_comment"&&n.type!=="block_comment")break;if(/@generated\b/.test(n.text)||/This file is .*generated\b/i.test(n.text)||/Code generated by/i.test(n.text)||/Generated by:\s*https?:\/\/openapi-generator/i.test(n.text)||/openapi-generator/i.test(n.text)&&/Generated by/i.test(n.text))return!0}return!1}var Ym=[{key:"default",re:/\bdefault\s*=\s*"([^"]+)"/g},{key:"with",re:/\bwith\s*=\s*"([^"]+)"/g},{key:"serialize_with",re:/\bserialize_with\s*=\s*"([^"]+)"/g},{key:"deserialize_with",re:/\bdeserialize_with\s*=\s*"([^"]+)"/g},{key:"skip_serializing_if",re:/\bskip_serializing_if\s*=\s*"([^"]+)"/g},{key:"getter",re:/\bgetter\s*=\s*"([^"]+)"/g},{key:"rename_all_with",re:/\brename_all_with\s*=\s*"([^"]+)"/g},{key:"schema_with",re:/\bschema_with\s*=\s*"([^"]+)"/g}],fs=/^#!?\[\s*serde\s*\(/,Qm=/^#!?\[\s*schemars\s*\(/,Xm=/^#!?\[\s*validate\s*\(/,ls=/\bwith\s*=\s*"([^"]+)"/g;function st(e,t){return nn(e,t,Zm,()=>new Set,(n,r,i)=>{if(r==="rust"){for(let s of n.rootNode.descendantsOfType("attribute_item"))cs(s.text,i);for(let s of n.rootNode.descendantsOfType("inner_attribute_item"))cs(s.text,i)}})??new Set}var Zm=new WeakMap;function cs(e,t){let n=fs.test(e),r=Qm.test(e),i=Xm.test(e);if(!(!n&&!r&&!i))for(let{re:s}of Ym){s.lastIndex=0;let o;for(;(o=s.exec(e))!==null;){let a=o[1],l=a.split("::").pop()??a;l==="is_none"&&/\bOption\b/.test(a)||l==="is_empty"&&/\b(String|Vec|HashMap|BTreeMap|HashSet|BTreeSet)\b/.test(a)||l&&t.add(l)}}}function ep(e){let t=new Set;for(let n of e.descendantsOfType("attribute_item")){if(!fs.test(n.text))continue;ls.lastIndex=0;let r;for(;(r=ls.exec(n.text))!==null;){let i=r[1],s=i.split("::").pop()??i;s&&t.add(s)}}return t}var tp=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function gs(e,t){return nn(e,t,np,()=>new Set,(n,r,i)=>{if(!(r!=="typescript"&&r!=="tsx"&&r!=="javascript"))for(let s of n.rootNode.descendantsOfType("call_expression")){let o=s.namedChild(0);if(!o)continue;let a=ht(o);if(!a||!tp.has(a))continue;let l=s.namedChildren.find(d=>d.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(d=>d.type==="string_fragment");u&&i.add(u.text)}})??new Set}var np=new WeakMap;function an(e){return e.replace(/'''[\s\S]*?'''/g,Pe).replace(/"""[\s\S]*?"""/g,Pe).replace(/#.*$/gm,Pe).replace(/\/\/.*$/gm,Pe).replace(/\/\*[\s\S]*?\*\//g,Pe).replace(/`(?:\\[\s\S]|[^`])*`/g,Pe).replace(/'(?:\\.|[^'\\\r\n])*'/g,Pe).replace(/"(?:\\.|[^"\\\r\n])*"/g,Pe)}function Pe(e){return e.replace(/[^\r\n]/g," ")}var rp=Wt("stripped-lines");function ys(e,t,n){return rp.get(e,t,n,()=>an(n).split(`
|
|
364
|
+
`))}var hs=null,fr="";function ip(e){return hs===e||(hs=e,fr=an(e)),fr}function Oe(e,t,n){let r=ip(e);return`${r.slice(0,t)}${" ".repeat(n-t)}${r.slice(n)}`}function K(e,t){return new RegExp(`\\b${ln(t)}\\b`,"m").test(e)}function ot(e,t){let n=new Set,r=new RegExp(`\\b${ln(t)}\\s*\\.\\s*([A-Za-z_$][\\w$]*)`,"g");for(let i of e.matchAll(r)){let s=i[1];s&&n.add(s)}return[...n]}function ln(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var sp=new Set(["identifier","type_identifier","field_identifier"]),op=new Set(["identifier"]),ap=new Set(["identifier","property_identifier","type_identifier"]),lp=new Set(["rust","python"]),cp=/\{([^{}]*)\}/g,up=/\b([A-Za-z_][\w]*)\b/g;function cn(e,t,n,r={}){if(!n)return[];let i=w(e,t);if(!i)return[];if(i.indexOf(n)===-1)return[];if(M(t))return(qe(e,t).get(n)??[]).filter(u=>!bs(u,r));let s=ys(e,t,i),o=new RegExp(`\\b${ln(n)}\\b`),a=[];for(let l=0;l<s.length;l++)bs(l,r)||o.test(s[l]??"")&&a.push(l);return a}function bs(e,t){return typeof t.excludeStartLine=="number"&&typeof t.excludeEndLine=="number"&&e>=t.excludeStartLine&&e<=t.excludeEndLine}var dp=$("file-identifiers");function Ss(e,t){return dp.get(e,t,()=>new Set(qe(e,t).keys()))}var mp=$("file-ident-lines");function qe(e,t){return mp.get(e,t,()=>fp(e,t))}var pp=$("file-idents-by-line");function xs(e,t){return pp.get(e,t,()=>{let n=qe(e,t),r=0;for(let s of n.values()){let o=s[s.length-1];o!==void 0&&o>r&&(r=o)}let i=new Array(r+1);for(let s=0;s<=r;s+=1)i[s]=new Set;for(let[s,o]of n)for(let a of o)i[a].add(s);return i})}function fp(e,t){let n=new Map,r=(a,l)=>{let c=n.get(a);if(!c){n.set(a,[l]);return}c[c.length-1]!==l&&c.push(l)};if(M(t)){let a=P(e,t);if(a){let l=M(t),c=l==="rust"?sp:l==="python"?op:ap,u=d=>{if(c.has(d.type)&&r(d.text,d.startPosition.row),l&&lp.has(l)&&d.type==="string_content"){let m=d.startPosition.row;for(let g of d.text.matchAll(cp)){let p=g[1]??"";for(let f of p.matchAll(up))f[1]&&r(f[1],m)}}for(let m of d.children)u(m)};return u(a.rootNode),n}}let i=w(e,t);if(!i)return n;let s=an(i).split(/\r?\n/),o=/\b([A-Za-z_$][\w$]*)\b/g;for(let a=0;a<s.length;a+=1){let l=s[a]??"";for(let c of l.matchAll(o))c[1]&&r(c[1],a)}return n}import{existsSync as un}from"fs";import{basename as gp,dirname as Me,extname as Se,join as le,relative as St,resolve as te}from"path";var hp=Ae("indexed-paths"),xt=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],_s=[".py",".pyi"],ce=[".java",".scala",".kt",".kts"],Is=[".rs"],Rs=[".rb"],Cs=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],at=[".cs",".vb"],vs=[".dart"],_t=[".php"],yp=new Set(xt),gr=new Set(_s),Ns=new Set(ce),hr=new Set(Is),yr=new Set(Rs),Es=new Set(Cs),Ds=new Set(at),br=new Set(vs),Ls=new Set(_t),bp=[{extensions:xt,lookup:yp},{extensions:_s,lookup:gr},{extensions:ce,lookup:Ns},{extensions:Is,lookup:hr},{extensions:Rs,lookup:yr},{extensions:Cs,lookup:Es},{extensions:at,lookup:Ds},{extensions:vs,lookup:br},{extensions:_t,lookup:Ls}];function Fe(e,t){return t.has(Se(e).toLowerCase())}function Sp(e){return Fe(e,gr)}function xp(e){return Fe(e,Ns)}function _p(e){return Fe(e,hr)}function Ip(e){return Fe(e,yr)}function Rp(e){return Fe(e,Es)}function Cp(e){return Fe(e,Ds)}function ks(e){return Se(e).toLowerCase()===".vb"}function vp(e){return Fe(e,br)}function Np(e){return Fe(e,Ls)}function Sr(e){let t=Se(e).toLowerCase();for(let n of bp)if(n.lookup.has(t))return n.extensions;return xt}function Ep(e){return xp(e)||Cp(e)||Np(e)}function ge(e,t,n){return Sp(t)?lt(e,t,n):_p(t)?xe(e,t,n):Ip(t)?dn(e,t,n):Rp(t)?mn(e,t,n):Ep(t)?j(e,n.replace(/\\/g,"."),Sr(t)):vp(t)?pn(e,t,n):Dp(e,t,n)}function Dp(e,t,n){if(!n.startsWith(".")&&!n.startsWith("/"))return null;let r=Me(le(e.config.projectRoot,t)),i=te(r,n),s=It(e);for(let o of Op(i)){let a=fe(St(e.config.projectRoot,o));if(s.has(a)||un(o))return a}return fe(St(e.config.projectRoot,i))}function lt(e,t,n){let r=It(e),i;if(n.startsWith(".")){let s=n.match(/^(\.+)(.*)$/);if(!s)return null;let o=s[1].length,a=s[2].replace(/^\./,""),l=Me(le(e.config.projectRoot,t));for(let c=1;c<o;c++)l=Me(l);i=a?te(l,a.replace(/\./g,"/")):l}else i=te(e.config.projectRoot,n.replace(/\./g,"/"));for(let s of Lp(i)){let o=fe(St(e.config.projectRoot,s));if(r.has(o)||un(s))return o}return null}function xe(e,t,n){if(!n)return null;let r=n.replace(/\s+as\s+.+$/,"").trim();if(!r.startsWith("crate::")&&!r.startsWith("self::")&&!r.startsWith("super::"))return null;let i=Me(le(e.config.projectRoot,t)),s;return r.startsWith("crate::")?s=te(e.config.projectRoot,"src",r.slice(7).replace(/::/g,"/")):r.startsWith("self::")?s=te(i,r.slice(6).replace(/::/g,"/")):s=te(Me(i),r.slice(7).replace(/::/g,"/")),xr(e,kp(s))}function dn(e,t,n){let r=Me(le(e.config.projectRoot,t)),i=te(r,n);return xr(e,wp(i))}function mn(e,t,n){let r=Me(le(e.config.projectRoot,t)),i=[te(r,n),te(e.config.projectRoot,n),te(e.config.projectRoot,"include",n),te(e.config.projectRoot,"src",n)];return xr(e,i)}function j(e,t,n){let r=It(e),i=t.replace(/\\/g,".").replace(/::/g,".").replace(/^global::/,""),s=i.replace(/\./g,"/"),o=i.split(".").pop()??i;for(let l of n){let c=`${s}${l}`,u=[...r].find(d=>d.endsWith(c));if(u)return u}for(let l of n){let c=[...r].find(u=>gp(u)===`${o}${l}`);if(c)return c}let a=[...r].filter(l=>n.includes(Se(l).toLowerCase())).filter(l=>l.includes(`/${s}/`)||l.includes(`/${o}/`)).sort((l,c)=>l.localeCompare(c));return a.length===1?a[0]:null}function pn(e,t,n){let r=It(e);if(n.startsWith("package:")){let o=n.slice(8),a=o.indexOf("/");if(a<0)return null;let l=o.slice(a+1),c=fe(l.startsWith("lib/")?l:`lib/${l}`);return r.has(c)?c:null}let i=Me(le(e.config.projectRoot,t)),s=te(i,n);for(let o of Pp(s)){let a=fe(St(e.config.projectRoot,o));if(r.has(a)||un(o))return a}return null}function Lp(e){let t=Se(e);return gr.has(t)?[e]:[`${e}.py`,`${e}.pyi`,le(e,"__init__.py"),le(e,"__init__.pyi")]}function xr(e,t){let n=It(e);for(let r of t){let i=fe(St(e.config.projectRoot,r));if(n.has(i)||un(r))return i}return null}function kp(e){let t=Se(e);return hr.has(t)?[e]:[`${e}.rs`,le(e,"mod.rs")]}function wp(e){let t=Se(e);return yr.has(t)?[e]:[`${e}.rb`,le(e,"index.rb")]}function Pp(e){let t=Se(e);return br.has(t)?[e]:[`${e}.dart`,e]}function Op(e){let t=Se(e),n=new Set;if(t){n.add(e);for(let r of xt)n.add(e.slice(0,-t.length)+r)}else for(let r of xt)n.add(`${e}${r}`),n.add(le(e,`index${r}`));return[...n]}function It(e){return hp.get(e,()=>new Set(e.all(`SELECT relative_path
|
|
337
365
|
FROM documents
|
|
338
366
|
WHERE 1 = 1
|
|
339
|
-
${e.pathExclusionsFor("documents")}
|
|
340
|
-
|
|
367
|
+
${e.pathExclusionsFor("documents")}`).map(t=>fe(t.relative_path)).filter(t=>!e.isIgnored(t))))}function fe(e){return e.replace(/\\/g,"/")}var Mp=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]);function X(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let s=e[i];(s==="{"||s==="["||s==="(")&&n++,(s==="}"||s==="]"||s===")")&&n--,s===","&&n===0&&(t.push(e.slice(r,i)),r=i+1)}return t.push(e.slice(r)),t}function ne(e,t){for(let n of e.namedChildren)if(n.type===t)return n;return null}function B(e,t){let n=new Set,r=(i,s)=>{let o=s||t.has(i.type);!o&&Mp.has(i.type)&&n.add(i.text);for(let a of i.children)r(a,o)};return r(e.rootNode,!1),n}function he(e,t,n,r,i,s,o){return{importedName:i,localName:s,sourcePath:o??j(e,r,Sr(t)),kind:"named",used:K(n,s),usedMembers:[]}}function re(e,t,n){let r=[];for(let i of e.matchAll(t)){let s=i[0];if(!s||typeof i.index!="number")continue;let o=Oe(e,i.index,i.index+s.length);for(let a of n(i,o))r.push(a)}return r}function Ps(e,t,n){let r=P(e,t);return r?Fp(e,t,r):zp(n).flatMap(i=>Gp(e,t,i.clause,i.specifier,i.start,i.end,n))}function Fp(e,t,n){let r=Tp(e,t,n),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))i.push(...$p(e,t,n,s,r));return i}function Tp(e,t,n){let r=B(n,new Set(["import_statement"]));if(yt(t))for(let i of af(e,t))r.add(i);return r}function $p(e,t,n,r,i){let s=Vp(r);if(!s)return[];let o=ge(e,t,s),a=ne(r,"import_clause");return a?Ap(n,a,o,i,Up(r.text)):[jp(o)]}function Ap(e,t,n,r,i){let s=[];for(let o of t.namedChildren)if(o.type==="identifier")s.push(Bp(o.text,n,r,i));else if(o.type==="namespace_import"){let a=Wp(e,o,n,r,i);a&&s.push(a)}else o.type==="named_imports"&&s.push(...Hp(o,n,r,i));return s}function jp(e){return{importedName:"*",localName:null,sourcePath:e,kind:"side-effect",used:!0,usedMembers:[]}}function Bp(e,t,n,r){return{importedName:"default",localName:e,sourcePath:t,kind:"default",used:n.has(e),usedMembers:[],isTypeOnly:r}}function Wp(e,t,n,r,i){let o=ne(t,"identifier")?.text??"";if(!o)return null;let a=qp(e,o);return{importedName:"*",localName:o,sourcePath:n,kind:"namespace",used:a.length>0||r.has(o),usedMembers:a,isTypeOnly:i}}function Hp(e,t,n,r){let i=[];for(let s of e.namedChildren){if(s.type!=="import_specifier")continue;let o=s.namedChild(0),a=s.namedChild(1);if(!o)continue;let l=o.text,c=a?.text??l;i.push({importedName:l,localName:c,sourcePath:t,kind:"named",used:n.has(c),usedMembers:[],isTypeOnly:r||Jp(s.text)})}return i}function Vp(e){let t=ne(e,"string");if(!t)return null;let n=ne(t,"string_fragment");return n?n.text:null}function Up(e){return/^\s*import\s+type\b/.test(e)}function Jp(e){return/^\s*type\b/.test(e.trim())}function qp(e,t){let n=new Set;for(let r of e.rootNode.descendantsOfType("member_expression")){let i=r.namedChild(0),s=r.namedChild(1);!i||!s||i.type!=="identifier"||i.text!==t||(s.type==="property_identifier"||s.type==="identifier")&&n.add(s.text)}return[...n]}function zp(e){let t=[],n=/^[ \t]*import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(n)){let s=i[0],o=i[1],a=i[2];!s||!a||typeof i.index!="number"||t.push({clause:o,specifier:a,start:i.index,end:i.index+s.length})}let r=/^[ \t]*import\s+['"]([^'"]+)['"]\s*;?/gm;for(let i of e.matchAll(r)){let s=i[0],o=i[1];!s||!o||typeof i.index!="number"||t.push({clause:null,specifier:o,start:i.index,end:i.index+s.length})}return t.sort((i,s)=>i.start-s.start)}function Gp(e,t,n,r,i,s,o){let a=ge(e,t,r),l=Oe(o,i,s);return n?Kp(n).map(u=>({...u,sourcePath:a})).map(u=>{if(u.kind==="namespace"){let d=ot(l,u.localName);return{...u,used:d.length>0||K(l,u.localName),usedMembers:d}}return u.kind==="side-effect"?{...u,used:!0,usedMembers:[]}:{...u,used:u.localName?K(l,u.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]}]}function Kp(e){let t=e.trim(),n=/^type\b/.test(t),r=t.replace(/^type\s+/,""),[i,s]=Yp(r),o=[];return i&&o.push(...ws(i,n)),s&&o.push(...ws(s,n)),o}function ws(e,t){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let r=n.slice(1,-1).trim();return r?X(r).map(i=>{let s=i.trim(),o=t||/^type\b/.test(s),a=s.replace(/^type\s+/,""),[l,c]=a.split(/\s+as\s+/);return{importedName:l.trim(),localName:(c??l).trim(),kind:"named",isTypeOnly:o}}):[]}return n.startsWith("* as ")?[{importedName:"*",localName:n.slice(5).trim(),kind:"namespace",isTypeOnly:t}]:[{importedName:"default",localName:n,kind:"default",isTypeOnly:t}]}function Yp(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="{"&&t++,r==="}"&&t--,r===","&&t===0)return[e.slice(0,n).trim(),e.slice(n+1).trim()]}return[e.trim(),null]}function Os(e,t){let n=P(e,t);if(n)return nf(e,t,n);let r=w(e,t);return r?Qp(e,t,r):[]}function Qp(e,t,n){return[...Xp(e,t,n),...Zp(e,t,n),...ef(e,t,n)]}function Xp(e,t,n){let r=[],i=/^[ \t]*export\s+(?:type\s+)?\{([\s\S]*?)\}\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=s[2]??"",l=X(o).map(d=>tf(d.trim())).filter(d=>!!d),c=ct(n,s.index),u=ct(n,s.index+s[0].length-1);r.push({kind:"named",sourcePath:ge(e,t,a),names:l,startLine:c,endLine:u})}return r}function Zp(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+as\s+(\w+)\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[2]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star-as",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function ef(e,t,n){let r=[],i=/^[ \t]*export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?/gm;for(let s of n.matchAll(i)){if(typeof s.index!="number")continue;let o=s[1]??"",a=ct(n,s.index),l=ct(n,s.index+s[0].length-1);r.push({kind:"star",sourcePath:ge(e,t,o),names:[],startLine:a,endLine:l})}return r}function tf(e){if(!e)return null;let t=e.replace(/^type\s+/,"").trim();if(!t)return null;let n=t.match(/^(\w+)\s+as\s+(\w+)$/);if(n)return n[2]??null;let r=t.match(/^(\w+)$/);return r?r[1]??null:null}function ct(e,t){let n=0;for(let r=0;r<t&&r<e.length;r++)e.charCodeAt(r)===10&&n++;return n}function nf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("export_statement")){let s=rf(e,t,i);if(s===void 0)continue;let o=i.startPosition.row,a=i.endPosition.row,l=sf(i,s,o,a);r.push(l)}return r}function rf(e,t,n){let r=ne(n,"string");if(!r)return;let i=ne(r,"string_fragment");if(i)return ge(e,t,i.text)}function sf(e,t,n,r){let i=ne(e,"export_clause");if(i){let o=[];for(let a of i.namedChildren){if(a.type!=="export_specifier")continue;let l=a.namedChild(0),c=a.namedChild(1);l&&o.push((c??l).text)}return{kind:"named",sourcePath:t,names:o,startLine:n,endLine:r}}return ne(e,"namespace_export")?{kind:"star-as",sourcePath:t,names:[],startLine:n,endLine:r}:{kind:"star",sourcePath:t,names:[],startLine:n,endLine:r}}var of=$("vue-non-script-identifiers");function af(e,t){return of.get(e,t,()=>{let n=new Set,r=w(e,t);if(!r)return n;let s=r.replace(/<script\b[^>]*>[\s\S]*?<\/script>/g,o=>o.replace(/[^\r\n]/g," ")).replace(/<!--[\s\S]*?-->/g,o=>o.replace(/[^\r\n]/g," ")).replace(/\/\*[\s\S]*?\*\//g,o=>o.replace(/[^\r\n]/g," "));for(let o of s.matchAll(/[A-Za-z_$][\w$]*/g))n.add(o[0]);return n})}import{basename as Ms}from"path";function Fs(e,t,n){let r=P(e,t);return r?lf(e,t,r):re(n,/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm,(i,s)=>{let o=i[1]?.trim();if(!o)return[];let a=Ms(o).replace(/\.[^.]+$/,"");return[{importedName:o,localName:a,sourcePath:mn(e,t,o),kind:"named",used:K(s,a),usedMembers:[]}]})}function lf(e,t,n){let r=B(n,new Set(["preproc_include"])),i=[];for(let s of n.rootNode.descendantsOfType("preproc_include")){let o=null;for(let l of s.namedChildren){if(l.type==="system_lib_string"){o=l.text.replace(/^<|>$/g,"");break}if(l.type==="string_literal"){o=l.namedChildren.find(u=>u.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!o)continue;let a=Ms(o).replace(/\.[^.]+$/,"");i.push({importedName:o,localName:a,sourcePath:mn(e,t,o),kind:"named",used:r.has(a),usedMembers:[]})}return i}function Ts(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*import\s+['"]([^'"]+)['"](?:\s+as\s+([A-Za-z_]\w*))?[\s\S]*?;$/gm)){let s=i[1]?.trim(),o=i[2]?.trim()??null,a=i[0];if(!s||!a||typeof i.index!="number")continue;let l=Oe(n,i.index,i.index+a.length);r.push({importedName:s,localName:o,sourcePath:pn(e,t,s),kind:o?"namespace":"side-effect",used:o?K(l,o):!0,usedMembers:o?ot(l,o):[]})}return r}function $s(e,t,n){let r=[];for(let i of n.matchAll(/^[ \t]*export\s+['"]([^'"]+)['"][\s\S]*?;$/gm)){let s=i[1]?.trim();s&&r.push({specifier:s,sourcePath:pn(e,t,s)})}return r}function As(e,t,n){let r=P(e,t),i=M(t);if(r&&i==="csharp")return uf(e,t,r);if(r&&i==="vb")return cf(e,t,r);let s=ks(t)?/^[ \t]*Imports\s+(.+?)\s*$/gm:/^[ \t]*using\s+(.+?)\s*;$/gm;return re(n,s,(o,a)=>{let l=o[1]?.trim();if(!l)return[];let[c,u]=l.split(/\s*=\s*/),d=!!u,m=(d?u:c)?.trim()??l,g=m.split(".").pop()??m,p=d?c?.trim()??g:g;return[he(e,t,a,m,g,p,j(e,m,at))]})}function cf(e,t,n){let r=B(n,new Set(["imports_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("imports_statement")){let o=s.namedChildren.filter(m=>m.type==="namespace_name");if(o.length===0)continue;let a=o[o.length-1],l=o.length>1?o[0]:null,c=a.text,u=c.split(".").pop()??c,d=l?.text??u;i.push({importedName:u,localName:d,sourcePath:j(e,c,at),kind:l?"namespace":"named",used:r.has(d),usedMembers:[]})}return i}function uf(e,t,n){let r=B(n,new Set(["using_directive"])),i=[];for(let s of n.rootNode.descendantsOfType("using_directive")){let o=s.namedChildren;if(o.length===0)continue;let a=null,l;o.length>=2&&o[0].type==="identifier"&&(o[1].type==="qualified_name"||o[1].type==="identifier")?(a=o[0],l=o[1]):l=o[o.length-1];let c=l.text,u=c.split(".").pop()??c,d=a?.text??u;i.push({importedName:u,localName:d,sourcePath:j(e,c,at),kind:a?"namespace":"named",used:r.has(d),usedMembers:[]})}return i}function js(e,t,n){let r=P(e,t),i=M(t);return r&&i==="java"?df(e,t,r):r&&i==="kotlin"?mf(e,t,r):r&&i==="scala"?pf(e,t,r):re(n,/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm,(s,o)=>{let a=s[1]?.trim();return a?ff(e,t,a,o):[]})}function df(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.children.some(d=>d.type==="asterisk"),l=s.namedChildren.find(d=>d.type==="scoped_identifier")??s.namedChildren.find(d=>d.type==="identifier");if(!l)continue;let c=l.text;if(o){i.push({importedName:"*",localName:null,sourcePath:j(e,c,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let u=c.split(".").pop()??c;i.push({importedName:u,localName:u,sourcePath:j(e,c,ce),kind:"named",used:r.has(u),usedMembers:[]})}return i}function mf(e,t,n){let r=B(n,new Set(["import_header","import_list"])),i=[];for(let s of n.rootNode.descendantsOfType("import_header")){let o=s.namedChildren.find(g=>g.type==="identifier");if(!o)continue;let a=s.namedChildren.some(g=>g.type==="wildcard_import"),l=s.namedChildren.find(g=>g.type==="import_alias");if(a){i.push({importedName:"*",localName:null,sourcePath:j(e,o.text,ce),kind:"namespace",used:!0,usedMembers:[]});continue}let c=o.text,u=c.split(".").pop()??c,m=l?.namedChild(0)?.text??u;i.push({importedName:u,localName:m,sourcePath:j(e,c,ce),kind:"named",used:r.has(m),usedMembers:[]})}return i}function pf(e,t,n){let r=B(n,new Set(["import_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("import_declaration")){let o=s.namedChildren.find(d=>d.type==="namespace_selectors"||d.type==="namespace_wildcard"),a=s.namedChildren.filter(d=>d!==o&&(d.type==="identifier"||d.type==="stable_identifier")),l=a.map(d=>d.text).join(".");if(!l)continue;if(o?.type==="namespace_wildcard"){i.push({importedName:"*",localName:null,sourcePath:j(e,l,ce),kind:"namespace",used:!0,usedMembers:[]});continue}if(o?.type==="namespace_selectors"){for(let d of o.namedChildren)if(d.type==="arrow_renamed_identifier"){let[m,g]=d.namedChildren;if(!m)continue;let p=m.text,f=g?.text??p;if(p==="_")continue;i.push({importedName:p,localName:f,sourcePath:j(e,`${l}.${p}`,ce),kind:"named",used:r.has(f),usedMembers:[]})}else if(d.type==="identifier"){let m=d.text;i.push({importedName:m,localName:m,sourcePath:j(e,`${l}.${m}`,ce),kind:"named",used:r.has(m),usedMembers:[]})}continue}let c=a[a.length-1]?.text??l,u=a.slice(0,-1).map(d=>d.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:j(e,u&&a.length>1?`${u}.${c}`:l,ce),kind:"named",used:r.has(c),usedMembers:[]})}return i}function ff(e,t,n,r){if(n.includes("{")&&n.includes("}")){let i=n.slice(0,n.indexOf("{")).replace(/\.$/,"").trim(),s=n.slice(n.indexOf("{")+1,n.lastIndexOf("}")).trim();return X(s).flatMap(o=>{let a=o.trim();if(!a)return[];let[l,c]=a.includes("=>")?a.split(/\s*=>\s*/):a.split(/\s+as\s+/),u=l?.trim();if(!u||u==="_")return[];let d=(c??u.split(".").pop()??u).trim(),m=u==="_"?i:`${i}.${u}`.replace(/\.\./g,".");return[he(e,t,r,m,u,d)]})}return[he(e,t,r,n,n.split(".").pop()??n,n.split(".").pop()??n)]}function Ws(e,t,n){let r=P(e,t);return r?gf(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?X(o).flatMap(a=>{let l=a.trim();if(!l)return[];let[c,u]=l.split(/\s+as\s+/i),d=c?.trim()??l,m=d.split("\\").pop()??d,g=(u??m).trim();return[he(e,t,s,d,m,g,j(e,d.replace(/\\/g,"."),_t))]}):[]})}function gf(e,t,n){let r=B(n,new Set(["namespace_use_declaration"])),i=[],s=(o,a,l)=>{i.push({importedName:a,localName:l,sourcePath:j(e,o.replace(/\\/g,"."),_t),kind:"named",used:r.has(l),usedMembers:[]})};for(let o of n.rootNode.descendantsOfType("namespace_use_declaration")){let a=o.namedChildren.find(l=>l.type==="namespace_use_group");if(a){let l=o.namedChildren.find(c=>c.type==="namespace_name")?.text??"";for(let c of a.namedChildren){if(c.type!=="namespace_use_clause")continue;let{importedName:u,localName:d,qualified:m}=Bs(c,l);u&&s(m,u,d)}continue}for(let l of o.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:u,qualified:d}=Bs(l,"");c&&s(d,c,u)}}return i}function Bs(e,t){let n=e.namedChildren.find(c=>c.type==="qualified_name"),r=e.namedChildren.filter(c=>c.type==="name"),i="";n?i=n.text:r.length>=1&&(i=r[0].text);let s=n&&r.length>0?r[r.length-1]:null,o=i.split("\\").pop()??i,a=s?.text??o,l=t?`${t}\\${i}`:i;return{importedName:o,localName:a,qualified:l}}function Us(e,t,n){let r=P(e,t);return r?hf(e,t,r):bf(n).flatMap(i=>xf(e,t,i,n))}function hf(e,t,n){let r=B(n,new Set(["import_statement","import_from_statement"])),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))for(let o of s.namedChildren){let a=Hs(o);if(!a)continue;let l=lt(e,t,a.qualifiedName);i.push({importedName:a.qualifiedName,localName:a.localName,sourcePath:l,kind:"namespace",used:r.has(a.localName),usedMembers:[]})}for(let s of n.rootNode.descendantsOfType("import_from_statement")){let o=s.namedChild(0);if(!o)continue;let a=yf(o);if(a===null)continue;let l=lt(e,t,a);for(let c=1;c<s.namedChildCount;c+=1){let u=s.namedChild(c);if(u.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let d=Hs(u);d&&i.push({importedName:d.qualifiedName,localName:d.localName,sourcePath:l,kind:"named",used:r.has(d.localName),usedMembers:[]})}}return i}function Hs(e){if(e.type==="aliased_import"){let t=e.namedChild(0),n=e.namedChild(1);return!t||!n?null:{qualifiedName:t.text,localName:n.text}}if(e.type==="dotted_name"){let t=e.text;return{qualifiedName:t,localName:t.split(".")[0]??t}}return e.type==="identifier"?{qualifiedName:e.text,localName:e.text}:null}function yf(e){if(e.type==="dotted_name")return e.text;if(e.type==="relative_import"){let t=ne(e,"import_prefix")?.text??"",n=ne(e,"dotted_name")?.text??"";return`${t}${n}`}return null}function bf(e){let t=e.split(`
|
|
368
|
+
`),n=[],r=0;for(let i=0;i<t.length;i++){let s=t[i],o=s.trimStart(),a=r;if(r+=s.length+1,!o.startsWith("import ")&&!o.startsWith("from "))continue;let l=s,c=a+s.length,u=Vs(s);for(;i+1<t.length&&(u>0||l.trimEnd().endsWith("\\"));){i++;let m=t[i];l+=`
|
|
369
|
+
${m}`,c+=1+m.length,u+=Vs(m),r+=m.length+1}let d=Sf(l);d&&n.push({...d,start:a,end:c})}return n}function Sf(e){let t=e.replace(/\\\s*\n/g," ").trim();if(t.startsWith("import "))return{kind:"import",module:null,clause:t.slice(7).trim()};let n=t.match(/^from\s+([.\w]+)\s+import\s+([\s\S]+)$/);if(!n)return null;let r=n[2].trim();return r.startsWith("(")&&r.endsWith(")")&&(r=r.slice(1,-1).trim()),{kind:"from",module:n[1],clause:r}}function xf(e,t,n,r){let i=Oe(r,n.start,n.end),s=n.clause.replace(/\n/g," ").trim();if(n.kind==="import")return X(s).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[u,d]=c.split(/\s+as\s+/),m=u.trim(),g=(d??m.split(".")[0]??m).trim(),p=lt(e,t,m),f=ot(i,g);return[{importedName:m,localName:g,sourcePath:p,kind:"namespace",used:K(i,g)||f.length>0,usedMembers:f}]});let o=n.module?lt(e,t,n.module):null,a=[];for(let l of X(s)){let c=l.trim().replace(/,$/,"");if(!c)continue;if(c==="*"){a.push({importedName:"*",localName:null,sourcePath:o,kind:"side-effect",used:!0,usedMembers:[]});continue}let[u,d]=c.split(/\s+as\s+/),m=(d??u).trim();a.push({importedName:u.trim(),localName:m,sourcePath:o,kind:"named",used:K(i,m),usedMembers:[]})}return a}function Vs(e){let t=0;for(let n of e)n==="("&&t++,n===")"&&t--;return t}import{basename as _f}from"path";function Js(e,t,n){let r=P(e,t);return r?If(e,t,r):re(n,/^[ \t]*(require_relative|require)\s+["']([^"']+)["']\s*$/gm,(i,s)=>{let o=i[1],a=i[2];if(!o||!a)return[];let l=o==="require_relative"?dn(e,t,a):null;if(l){let c=qs(a);return[{importedName:c,localName:c,sourcePath:l,kind:"named",used:K(s,c),usedMembers:[]}]}return[{importedName:a,localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]}]})}function If(e,t,n){let r=B(n,new Set([])),i=[],s=new Set(["require","require_relative","load"]);for(let o of n.rootNode.descendantsOfType("call")){let a=o.namedChild(0);if(!a||a.type!=="identifier"||!s.has(a.text))continue;let c=o.namedChildren.find(g=>g.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let d=c.namedChildren.find(g=>g.type==="string_content")?.text;if(!d)continue;let m=a.text==="require_relative"?dn(e,t,d):null;if(m){let g=qs(d);i.push({importedName:g,localName:g,sourcePath:m,kind:"named",used:r.has(g),usedMembers:[]})}else i.push({importedName:d,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function qs(e){return _f(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function zs(e,t,n){let r=P(e,t);return r?Rf(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?Cf(e,t,o,s):[]})}function Rf(e,t,n){let r=B(n,new Set(["use_declaration"])),i=[];for(let s of n.rootNode.descendantsOfType("use_declaration")){let o=s.namedChild(0);if(o)for(let a of Rt(o,"")){if(!a.importedName||a.importedName==="*")continue;let l=xe(e,t,a.qualifiedName)??xe(e,t,a.qualifiedName.split("::").slice(0,-1).join("::"));i.push({importedName:a.importedName,localName:a.localName,sourcePath:l,kind:"named",used:r.has(a.localName),usedMembers:[]})}}return i}function Rt(e,t){switch(e.type){case"identifier":case"super":case"self":case"crate":{let n=e.text;return[{qualifiedName:fn(t,n),importedName:n,localName:n}]}case"scoped_identifier":{let n=e.text,r=n.split("::").pop()??n;return[{qualifiedName:fn(t,n),importedName:r,localName:r}]}case"scoped_use_list":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=fn(t,n.text),s=[];for(let o of r.namedChildren)s.push(...Rt(o,i));return s}case"use_list":{let n=[];for(let r of e.namedChildren)n.push(...Rt(r,t));return n}case"use_as_clause":{let n=e.namedChild(0),r=e.namedChild(1);if(!n||!r)return[];let i=Rt(n,t),s=r.text;return i.map(o=>({...o,localName:s}))}case"use_wildcard":{let n=e.namedChild(0),r=n?n.text:"";return[{qualifiedName:fn(t,`${r}::*`),importedName:"*",localName:"*"}]}default:return[]}}function fn(e,t){return e?t?`${e}::${t}`:e:t}function Cf(e,t,n,r){let i=n.trim();if(i.includes("{")&&i.includes("}")){let u=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),d=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return X(d).flatMap(m=>{let g=m.trim();if(!g||g==="self")return[];let[p,f]=g.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let L=(f??y.split("::").pop()??y).trim(),k=`${u}::${y}`.replace(/::::/g,"::");return[he(e,t,r,k,y.split("::").pop()??y,L,xe(e,t,u))]})}let[s,o]=i.split(/\s+as\s+/),a=s?.trim()??i,l=(o??a.split("::").pop()??a).trim(),c=xe(e,t,a)??xe(e,t,a.split("::").slice(0,-1).join("::"));return[he(e,t,r,a,a.split("::").pop()??a,l,c)]}function Gs(e,t,n){let r=P(e,t);if(r)return vf(e,t,r);let i=[];for(let s of n.matchAll(/^[ \t]*pub\s+use\s+(.+?)\s*;$/gm)){let o=s[1]?.trim();o&&i.push(...Ef(e,t,o))}return i}function vf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("use_declaration")){if(!Nf(i))continue;let s=i.namedChildren.find(o=>o.type!=="visibility_modifier");if(s)for(let o of Rt(s,""))o.importedName&&r.push(_r(e,t,o.qualifiedName))}return r}function Nf(e){for(let t of e.children)if(t.type==="visibility_modifier"&&t.text.startsWith("pub"))return!0;return!1}function Ef(e,t,n){let r=n.trim();if(r.includes("{")&&r.includes("}")){let i=r.slice(0,r.indexOf("{")).replace(/::$/,"").trim(),s=r.slice(r.indexOf("{")+1,r.lastIndexOf("}")).trim();return X(s).flatMap(o=>{let a=o.trim();if(!a||a==="self")return[];let[l]=a.split(/\s+as\s+/),c=`${i}::${l?.trim()??a}`.replace(/::::/g,"::");return[_r(e,t,c)]})}return[_r(e,t,r)]}function _r(e,t,n){return{specifier:n,sourcePath:xe(e,t,n)??xe(e,t,n.split("::").slice(0,-1).join("::"))}}function Ks(e,t){let n=t.toLowerCase();for(let r of e)for(let i of r.extensions)if(n.endsWith(i))return r;return null}var Df={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Ps},Lf={language:"python",extensions:[".py",".pyi"],parseImports:Us},kf={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:js},wf={language:"rust",extensions:[".rs"],parseImports:zs,parseExports:Gs},Pf={language:"ruby",extensions:[".rb"],parseImports:Js},Of={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:Fs},Mf={language:"dotnet",extensions:[".cs",".vb"],parseImports:As},Ff={language:"dart",extensions:[".dart"],parseImports:Ts,parseExports:$s},Tf={language:"php",extensions:[".php"],parseImports:Ws},$f=[Df,Lf,kf,wf,Pf,Of,Mf,Ff,Tf];function Ir(e){return Ks($f,e)}function Ys(e,t){return Os(e,t)}var Af=$("source-imports"),jf=$("source-exports");function J(e,t){let n=fe(t);return Af.get(e,n,()=>{let r=Ir(n);if(!r)return[];let i=w(e,n);return i?r.parseImports(e,n,i):[]})}function Rr(e,t){let n=fe(t);return jf.get(e,n,()=>{let r=Ir(n);if(!r?.parseExports)return[];let i=w(e,n);return i?r.parseExports(e,n,i):[]})}import ue from"path";import{createRequire as Bf}from"module";import{existsSync as gn,readdirSync as Wf,readFileSync as eo}from"fs";var Hf=Bf(import.meta.url),Ct;function to(e,t){let n=Vf();if(!n)return Cr("ts-morph is not installed");let r=wi(e);if(r.length===0)return Cr("no tsconfig found");try{let i=r.map(s=>({tsconfigPath:s,project:new n.Project({tsConfigFilePath:s,skipFileDependencyResolution:!1})}));return new vr(e,n,i)}catch(i){return Cr(i instanceof Error?i.message:String(i),r[0],r)}}function Vf(){if(Ct!==void 0)return Ct;try{Ct=Hf("ts-morph")}catch{Ct=null}return Ct}function Cr(e,t,n){return{language:"typescript",availability:()=>({available:!1,reason:e,tsconfigPath:t,tsconfigPaths:n}),importUsage:()=>[],referencesFor:()=>[],calleesFor:()=>[],signatureFor:()=>null}}var vr=class{constructor(t,n,r){this.db=t;this.tsMorph=n;this.projects=r;this.workspacePackages=Gf(t.config.projectRoot)}db;tsMorph;projects;language="typescript";importUsageCache=new Map;referencesCache=new Map;calleesCache=new Map;fileCalleesCache=new Map;signatureCache=new Map;sourceFileCache=new Map;definitionNodeCache=new Map;fileDefinitionNodeCache=new Map;indexedDefinitionLeafCache=new Map;packageImportReferenceIndex=null;packageExportIndex=null;workspacePackages;availability(){return{available:!0,tsconfigPath:this.projects[0]?.tsconfigPath,tsconfigPaths:this.projects.map(t=>t.tsconfigPath)}}importUsage(t){return _e(this.importUsageCache,t,()=>{let n=this.sourceFile(t);if(!n)return[];let r=[];for(let i of n.getImportDeclarations())for(let s of this.importUsageForDeclaration(t,i))r.push(s);return r})}referencesFor(t){return _e(this.referencesCache,t.symbolId,()=>{let n=this.nodeForDefinition(t),r=this.packageImportReferencesForDefinition(t);return n?tg(n,t,r,this.db.config.projectRoot):r})}calleesFor(t){return _e(this.calleesCache,t.symbolId,()=>_e(this.fileCalleesCache,t.relativePath,()=>this.calleeMapForFile(t.relativePath)).get(t.symbolId)??[])}signatureFor(t){return _e(this.signatureCache,t.symbolId,()=>{let n=this.nodeForDefinition(t);if(!n||!this.tsMorph.Node.isFunctionDeclaration(n)&&!this.tsMorph.Node.isMethodDeclaration(n)&&!this.tsMorph.Node.isArrowFunction(n)&&!this.tsMorph.Node.isFunctionExpression(n)&&!this.tsMorph.Node.isConstructorDeclaration(n))return null;let r=n.getType().getCallSignatures()[0];if(!r)return null;let i=r.getParameters().map(o=>{let a=o.getDeclarations()[0],l=a?o.getTypeAtLocation(a).getText(a):o.getValueDeclaration()?.getType().getText()??"unknown";return Zs(l)}),s=r.getReturnType().getText(n);return`(${i.join(",")})=>${Zs(s)}`})}importUsageForDeclaration(t,n){let r=ge(this.db,t,n.getModuleSpecifierValue()),i=Qs(n);return n.getImportClause()?.isTypeOnly()?i.map(s=>qf(t,r,s)):i.map(s=>this.valueImportUsageForEntry(t,r,s))}valueImportUsageForEntry(t,n,r){let i=r.identifier?r.identifier.findReferences():[],s=[];for(let c of i)for(let u of ng(c,t,r.identifier,this.db.config.projectRoot))s.push(u);let o=s.some(c=>!Xs(c.node)),a=s.some(c=>Xs(c.node)),l=r.isTypeOnly;return{importer:t,sourcePath:n,importedName:r.importedName,localName:r.localName,kind:r.kind,isTypeOnly:l,isUsed:l||s.length>0,isTypeUsed:l||a,isValueUsed:o,references:s.map(c=>c.location)}}sourceFile(t){return this.sourceFileMatch(t)?.sourceFile??null}sourceFileMatch(t){return ug(t)?_e(this.sourceFileCache,t,()=>{let n=ue.join(this.db.config.projectRoot,t);for(let{project:r}of this.projects){let i=r.getSourceFile(n)??r.addSourceFileAtPathIfExists(n)??null;if(i)return{project:r,sourceFile:i}}return null}):null}packageImportReferencesForDefinition(t){return this.packageImportReferences().get(t.symbolId)??[]}packageImportReferences(){if(this.packageImportReferenceIndex)return this.packageImportReferenceIndex;let t=new Map,n=this.packageExports();for(let r of this.indexedTypeScriptLikeDocuments())this.addPackageImportReferencesForDocument(t,n,r);for(let[r,i]of t)t.set(r,Nr(i));return this.packageImportReferenceIndex=t,t}indexedTypeScriptLikeDocuments(){return this.db.all(`SELECT relative_path
|
|
370
|
+
FROM documents
|
|
371
|
+
WHERE (
|
|
372
|
+
relative_path LIKE '%.ts'
|
|
373
|
+
OR relative_path LIKE '%.tsx'
|
|
374
|
+
OR relative_path LIKE '%.mts'
|
|
375
|
+
OR relative_path LIKE '%.cts'
|
|
376
|
+
OR relative_path LIKE '%.js'
|
|
377
|
+
OR relative_path LIKE '%.jsx'
|
|
378
|
+
OR relative_path LIKE '%.mjs'
|
|
379
|
+
OR relative_path LIKE '%.cjs'
|
|
380
|
+
)
|
|
381
|
+
${this.db.pathExclusionsFor("documents")}`).map(t=>t.relative_path)}addPackageImportReferencesForDocument(t,n,r){if(this.db.isIgnored(r))return;let i=this.sourceFileMatch(r);if(i)for(let s of i.sourceFile.getImportDeclarations())this.addPackageImportReferencesForDeclaration(t,n,r,s)}addPackageImportReferencesForDeclaration(t,n,r,i){let s=Qf(this.workspacePackages,i.getModuleSpecifierValue());if(!s)return;let o=n.get(s);if(o)for(let a of Qs(i)){if(a.kind!=="named"||!a.identifier)continue;let l=o.get(a.importedName);if(!l||l.size===0)continue;let c=rg(a.identifier,r,this.db.config.projectRoot);c.length>0&&lg(t,l,c)}}packageExports(){if(this.packageExportIndex)return this.packageExportIndex;let t=new Map;for(let n of this.workspacePackages){let r=new Map;for(let i of Xf(n))this.collectPackageExports(n,i,r,new Set);r.size>0&&t.set(n.name,r)}return this.packageExportIndex=t,t}collectPackageExports(t,n,r,i){if(i.has(n))return;i.add(n);let s=this.sourceFile(n);if(s)for(let o of s.getExportDeclarations()){let a=o.getModuleSpecifierValue(),l=a?ge(this.db,n,a):n;if(!l||!l.startsWith(`${t.sourceRootRelative}/`))continue;let c=o.getNamedExports();if(c.length===0){if(o.isNamespaceExport())continue;this.collectPackageExports(t,l,r,i);continue}for(let u of c){let d=u.getNameNode().getText(),m=u.getAliasNode()?.getText()??d,g=this.indexedDefinitionByLeaf(l,d);if(!g)continue;let p=r.get(m);p||(p=new Set,r.set(m,p)),p.add(g.symbolId)}}}indexedDefinitionByLeaf(t,n){return _e(this.indexedDefinitionLeafCache,t,()=>og(this.db,t)).get(n)??null}nodeForDefinition(t){return _e(this.definitionNodeCache,t.symbolId,()=>this.definitionNodesForFile(t.relativePath).get(t.symbolId)??null)}definitionNodesForFile(t){return _e(this.fileDefinitionNodeCache,t,()=>{let n=this.sourceFile(t);if(!n)return new Map;let r=Uf(this.db,t);return r.size===0?new Map:Jf(this.tsMorph,n,r)})}definitionFromSymbol(t){let n=t.getDeclarations();for(let r of n){let i=r.getSourceFile(),s=yn(this.db.config.projectRoot,i.getFilePath());if(!s||this.db.isIgnored(s))continue;let o=hn(i,r),a=sg(this.db,s,o,t.getName());if(a)return{symbol:a.symbol,file:a.relativePath,line:a.startLine}}return null}calleeMapForFile(t){let n=this.sourceFile(t);if(!n)return new Map;let r=Q(this.db,t).sort((s,o)=>s.startLine-o.startLine||o.endLine-s.endLine);if(r.length===0)return new Map;let i=new Map;n.forEachDescendant(s=>{if(!this.tsMorph.Node.isCallExpression(s)&&!this.tsMorph.Node.isNewExpression(s))return;let o=this.semanticCalleeForCallNode(n,r,s);o&&zf(i,o.callerId,o.target)});for(let[s,o]of i)i.set(s,cg(o));return i}semanticCalleeForCallNode(t,n,r){let i=ag(n,hn(t,r));if(!i)return null;let s=r.getExpression(),o=s.getSymbol()??s.getType().getSymbol(),a=o?this.definitionFromSymbol(o):null;return a?{callerId:i.symbolId,target:{symbol:a.symbol,file:a.file,line:a.line}}:null}};function Qs(e){let t=[],n=e.getDefaultImport();n&&t.push({identifier:n,importedName:"default",localName:n.getText(),kind:"default",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});let r=e.getNamespaceImport();r&&t.push({identifier:r,importedName:"*",localName:r.getText(),kind:"namespace",isTypeOnly:e.getImportClause()?.isTypeOnly()??!1});for(let i of e.getNamedImports()){let s=i.getNameNode(),a=i.getAliasNode()??(s.getKindName()==="Identifier"?s:null);t.push({identifier:a,importedName:s.getText(),localName:a?.getText()??s.getText(),kind:"named",isTypeOnly:i.isTypeOnly()||(e.getImportClause()?.isTypeOnly()??!1)})}return t.length===0&&t.push({identifier:null,importedName:"*",localName:null,kind:"side-effect",isTypeOnly:!1}),t}function Uf(e,t){let n=new Map;for(let r of Q(e,t)){let i=D(r.symbol)??r.leaf;if(!i)continue;let s=n.get(i);s||(s=[],n.set(i,s)),s.push(r)}return n}function Jf(e,t,n){let r=new Map,i=new Map;return t.forEachDescendant(s=>{for(let o of ig(e,s)){let a=n.get(o);if(!a)continue;let l=hn(t,s);for(let c of a){if(l<c.startLine-1||l>c.endLine+1)continue;let u=Math.abs(l-c.startLine),d=i.get(c.symbolId);d!==void 0&&d<=u||(i.set(c.symbolId,u),r.set(c.symbolId,s))}}}),r}function qf(e,t,n){return{importer:e,sourcePath:t,importedName:n.importedName,localName:n.localName,kind:n.kind,isTypeOnly:!0,isUsed:!0,isTypeUsed:!0,isValueUsed:!1,references:[]}}function zf(e,t,n){let r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}function Gf(e){let t=ue.join(e,"package.json");if(!gn(t))return[];let n;try{n=JSON.parse(eo(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>Kf(e,i)).flatMap(i=>Yf(e,i))}function Kf(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=ue.join(e,t);return gn(ue.join(o,"package.json"))?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=ue.join(e,r||".");if(!gn(s))return[];try{return Wf(s).map(o=>ue.join(s,o,i)).filter(o=>gn(ue.join(o,"package.json")))}catch{return[]}}function Yf(e,t){try{let n=JSON.parse(eo(ue.join(t,"package.json"),"utf8"));if(!n.name)return[];let r=ue.relative(e,t).replace(/\\/g,"/");return[{name:n.name,rootRelative:r,sourceRootRelative:`${r}/src`}]}catch{return[]}}function Qf(e,t){for(let n of e)if(t===n.name||t.startsWith(`${n.name}/`))return n.name;return null}function Xf(e){return[`${e.sourceRootRelative}/index.ts`,`${e.sourceRootRelative}/index.tsx`,`${e.sourceRootRelative}/index.mts`,`${e.sourceRootRelative}/index.cts`]}function Zf(e,t){return e.getReferences().map(n=>{let r=n.getNode();return no(r,t)})}function eg(e){let t=e;return typeof t.findReferences=="function"?t.findReferences():[]}function tg(e,t,n,r){let i=[];for(let s of eg(e))for(let o of Zf(s,r))o.file===t.relativePath&&o.line>=t.startLine&&o.line<=t.endLine||i.push(o);for(let s of n)i.push(s);return Nr(i)}function ng(e,t,n,r){let i=[],s=n?.getStart();for(let o of e.getReferences()){let a=o.getNode();yn(r,a.getSourceFile().getFilePath())===t&&(s!==void 0&&a.getStart()===s||i.push({location:no(a,r),node:a}))}return i}function no(e,t){let n=e.getSourceFile(),r=n.getLineAndColumnAtPos(e.getStart());return{file:yn(t,n.getFilePath())??n.getBaseName(),line:r.line-1,column:r.column-1}}function rg(e,t,n){let r=e.getSourceFile(),i=hn(r,e),s=e.getText(),o=new RegExp(`\\b${dg(s)}\\b`,"g"),a=r.getFullText().split(`
|
|
382
|
+
`),l=[];for(let c=0;c<a.length;c++){if(c===i)continue;let u=a[c]??"";o.lastIndex=0;let d;for(;(d=o.exec(u))!==null;)l.push({file:t,line:c,column:d.index})}return Nr(l.filter(c=>yn(n,ue.join(n,c.file))===t))}function Xs(e){for(let t=e;t;t=t.getParent()){let n=t.getKindName();if(n.includes("Type")||n==="InterfaceDeclaration"||n==="TypeAliasDeclaration")return!0;if(n==="CallExpression"||n==="NewExpression"||n==="ExpressionStatement")return!1}return!1}function ig(e,t){let n=[],r=i=>{i&&!n.includes(i)&&n.push(i)};if("getNameNode"in t&&typeof t.getNameNode=="function"){let i=t.getNameNode();r(i?.getText())}if("getName"in t&&typeof t.getName=="function"){let i=t.getName();r(i)}return e.Node.isIdentifier(t)&&r(t.getText()),n}function sg(e,t,n,r){return e.all(`SELECT
|
|
383
|
+
gs.id AS symbolId,
|
|
384
|
+
gs.symbol,
|
|
385
|
+
d.relative_path AS relativePath,
|
|
386
|
+
COALESCE(der.start_line, c.start_line) AS startLine,
|
|
387
|
+
COALESCE(der.end_line, c.end_line) AS endLine,
|
|
388
|
+
COALESCE(gs.display_name, '') AS leaf,
|
|
389
|
+
NULL AS parentTypeName,
|
|
390
|
+
CASE WHEN gs.kind IN (6, 12, 13) OR gs.symbol LIKE '%().' THEN 1 ELSE 0 END AS isFunctionLike,
|
|
391
|
+
CASE WHEN gs.kind IN (5, 8, 11) THEN 1 ELSE 0 END AS isTypeLike,
|
|
392
|
+
gs.kind AS kind,
|
|
393
|
+
gs.documentation AS documentation,
|
|
394
|
+
gs.enclosing_symbol AS enclosingSymbol
|
|
395
|
+
FROM global_symbols gs
|
|
396
|
+
LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
|
|
397
|
+
LEFT JOIN chunks c ON c.document_id = der.document_id
|
|
398
|
+
JOIN documents d ON d.id = der.document_id
|
|
399
|
+
WHERE d.relative_path = ?
|
|
400
|
+
AND COALESCE(gs.display_name, gs.symbol) LIKE ?
|
|
401
|
+
ORDER BY ABS(COALESCE(der.start_line, c.start_line) - ?)
|
|
402
|
+
LIMIT 5`,t,`%${r}%`,n)[0]??null}function og(e,t){let n=e.all(`SELECT
|
|
403
|
+
d.id AS documentId,
|
|
404
|
+
gs.id AS symbolId,
|
|
405
|
+
gs.symbol,
|
|
406
|
+
d.relative_path AS relativePath,
|
|
407
|
+
der.start_line AS startLine,
|
|
408
|
+
der.end_line AS endLine,
|
|
409
|
+
COALESCE(gs.display_name, '') AS leaf,
|
|
410
|
+
NULL AS parentTypeName,
|
|
411
|
+
CASE WHEN gs.kind IN (6, 12, 13) OR gs.symbol LIKE '%().' THEN 1 ELSE 0 END AS isFunctionLike,
|
|
412
|
+
CASE WHEN gs.kind IN (5, 8, 11) THEN 1 ELSE 0 END AS isTypeLike,
|
|
413
|
+
gs.kind AS kind,
|
|
414
|
+
gs.documentation AS documentation,
|
|
415
|
+
gs.enclosing_symbol AS enclosingSymbol
|
|
416
|
+
FROM global_symbols gs
|
|
417
|
+
JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
|
|
418
|
+
JOIN documents d ON d.id = der.document_id
|
|
419
|
+
WHERE d.relative_path = ?
|
|
420
|
+
UNION ALL
|
|
421
|
+
SELECT
|
|
422
|
+
d.id AS documentId,
|
|
423
|
+
gs.id AS symbolId,
|
|
424
|
+
gs.symbol,
|
|
425
|
+
d.relative_path AS relativePath,
|
|
426
|
+
MIN(c.start_line) AS startLine,
|
|
427
|
+
MAX(c.end_line) AS endLine,
|
|
428
|
+
COALESCE(gs.display_name, '') AS leaf,
|
|
429
|
+
NULL AS parentTypeName,
|
|
430
|
+
CASE WHEN gs.kind IN (6, 12, 13) OR gs.symbol LIKE '%().' THEN 1 ELSE 0 END AS isFunctionLike,
|
|
431
|
+
CASE WHEN gs.kind IN (5, 8, 11) THEN 1 ELSE 0 END AS isTypeLike,
|
|
432
|
+
gs.kind AS kind,
|
|
433
|
+
gs.documentation AS documentation,
|
|
434
|
+
gs.enclosing_symbol AS enclosingSymbol
|
|
435
|
+
FROM global_symbols gs
|
|
436
|
+
JOIN mentions m ON m.symbol_id = gs.id
|
|
437
|
+
JOIN chunks c ON c.id = m.chunk_id
|
|
438
|
+
JOIN documents d ON d.id = c.document_id
|
|
439
|
+
WHERE d.relative_path = ?
|
|
440
|
+
AND m.role = 1
|
|
441
|
+
GROUP BY gs.id, gs.symbol, d.id, d.relative_path, gs.display_name, gs.kind, gs.documentation, gs.enclosing_symbol
|
|
442
|
+
ORDER BY startLine, endLine`,t,t),r=new Set,i=new Map;for(let s of n){if(r.has(s.symbolId))continue;r.add(s.symbolId);let o=s.leaf||D(s.symbol);!o||i.has(o)||i.set(o,{...s,leaf:o})}return i}function ag(e,t){let n=null;for(let r of e)t<r.startLine||t>r.endLine||(!n||r.startLine>=n.startLine)&&(n=r);return n}function hn(e,t){return e.getLineAndColumnAtPos(t.getStart()).line-1}function Nr(e){let t=new Set,n=[];for(let r of e){let i=`${r.file}:${r.line}:${r.column}`;t.has(i)||(t.add(i),n.push(r))}return n}function lg(e,t,n){for(let r of t){let i=e.get(r)??[];i.push(...n),e.set(r,i)}}function cg(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}|${r.line}`;t.has(i)||(t.add(i),n.push(r))}return n}function _e(e,t,n){if(e.has(t))return e.get(t);let r=n();return e.set(t,r),r}function yn(e,t){let n=ue.relative(e||process.cwd(),t).replace(/\\/g,"/");return!n||n.startsWith("..")?null:n}function ug(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}function Zs(e){return e.replace(/\s+/g," ").replace(/\bimport\("[^"]+"\)\./g,"").trim()}function dg(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ro=new WeakMap;function io(e,t){let n=`${e.config.projectRoot}:typescript-workspace`,r=ro.get(e);r||(r=new Map,ro.set(e,r));let i=r.get(n);if(i)return i;let s=to(e,t);return r.set(n,s),s}function vt(e,t){let n=bn(e,t);return n?n.importUsage(t):[]}function Nt(e,t){let n=bn(e,t.relativePath);return n?n.referencesFor(t):[]}function ut(e,t){let n=new Map;for(let r of t)for(let i of Nt(e,r)){if(i.file===r.relativePath||e.isIgnored(i.file))continue;let s=n.get(r.symbolId);s||(s=new Set,n.set(r.symbolId,s)),s.add(i.file)}return n}function so(e,t){let n=new Map;for(let r of t){let i=bn(e,r.relativePath);if(!i)continue;let s=i.calleesFor(r);s.length>0&&n.set(r.symbolId,s)}return n}function oo(e,t){let n=bn(e,t.relativePath);return n?n.signatureFor(t):null}function bn(e,t){if(!mg(t))return null;let n=io(e,t);return n.availability().available?n:null}function mg(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}var pg=$("file-dep-graph");function Y(e,t){return pg.get(e,t??"",()=>{let n=new Map,r=gg(e),i=(s,o)=>hg(e,n,r,s,o);for(let s of fg(e,t))i(s.from_file,s.to_file);for(let s of r)if(!(t&&!s.includes(t)))for(let o of J(e,s))o.sourcePath&&i(s,o.sourcePath);return n})}function fg(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
|
|
443
|
+
d1.relative_path AS from_file,
|
|
444
|
+
d2.relative_path AS to_file
|
|
445
|
+
FROM mentions m
|
|
446
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
447
|
+
JOIN documents d1 ON c.document_id = d1.id
|
|
448
|
+
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
449
|
+
JOIN (
|
|
450
|
+
SELECT m2.symbol_id, c2.document_id
|
|
451
|
+
FROM mentions m2
|
|
452
|
+
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
453
|
+
WHERE m2.role = 1
|
|
454
|
+
GROUP BY m2.symbol_id
|
|
455
|
+
) sym_def ON sym_def.symbol_id = gs.id
|
|
456
|
+
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
457
|
+
WHERE d1.id != d2.id
|
|
458
|
+
AND m.role != 1
|
|
459
|
+
${e.pathExclusionsFor("d1","d2")}
|
|
460
|
+
${n}`)}function gg(e){return new Set(e.all(`SELECT relative_path
|
|
461
|
+
FROM documents
|
|
462
|
+
WHERE 1 = 1
|
|
463
|
+
${e.pathExclusionsFor("documents")}
|
|
464
|
+
ORDER BY relative_path`).map(t=>t.relative_path).filter(t=>!e.isIgnored(t)))}function hg(e,t,n,r,i){if(r===i||e.isIgnored(r)||e.isIgnored(i)||!n.has(i))return;let s=t.get(r);s||(s=new Set,t.set(r,s)),s.add(i)}function Z(e,t,n={}){let r=Sn(e,[t],{additive:n.additive}),i=n.callableOnly?(r.get(t.symbolId)??[]).filter(s=>U(s.symbol)):r.get(t.symbolId)??[];return typeof n.limit=="number"?i.slice(0,n.limit):i}function ie(e,t,n={}){let r=Sg(e)?_g(e,t):xg(e).get(t.symbolId)??[];return typeof n.limit=="number"?r.slice(0,n.limit):r}var yg=Ae("caller-rows"),bg=2e4;function Sg(e){return(e.get("SELECT COUNT(*) AS count FROM global_symbols")?.count??0)>bg}function xg(e){return yg.get(e,()=>{let t=oe(e),n=Sn(e,t),r=new Map;for(let o of t)r.set(o.symbol,o.symbolId);let i=new Map,s=new Map;for(let o of t){let a=n.get(o.symbolId);if(!(!a||a.length===0))for(let l of a){let c=r.get(l.symbol);if(c===void 0||c===o.symbolId)continue;let u=i.get(c);u||(u=[],i.set(c,u),s.set(c,new Set));let d=`${o.symbol}|${o.relativePath}`;s.get(c).has(d)||(s.get(c).add(d),u.push({symbol:o.symbol,file:o.relativePath}))}}return i})}function _g(e,t){let n=[],r=new Set,i=o=>{if(o.symbol===t.symbol)return;let a=`${o.symbol}|${o.file}`;r.has(a)||(r.add(a),n.push(o))};for(let o of Ie(e,t))o.file!==t.relativePath&&i({symbol:o.enclosingSymbol??o.file,file:o.file});let s=Ig(e,t);if(s)for(let o of Nt(e,s)){if(o.file===t.relativePath||e.isIgnored(o.file))continue;let a=ae(Q(e,o.file),o.line);i({symbol:a?.symbol??o.file,file:o.file})}return n}function Ig(e,t){return e.get(`SELECT
|
|
465
|
+
d.id AS documentId,
|
|
466
|
+
gs.id AS symbolId,
|
|
467
|
+
gs.symbol,
|
|
468
|
+
d.relative_path AS relativePath,
|
|
469
|
+
COALESCE(der.start_line, c.start_line) AS startLine,
|
|
470
|
+
COALESCE(der.end_line, c.end_line) AS endLine,
|
|
471
|
+
COALESCE(gs.display_name, '') AS leaf,
|
|
472
|
+
NULL AS parentTypeName,
|
|
473
|
+
CASE WHEN gs.kind IN (6, 12, 13) OR gs.symbol LIKE '%().' THEN 1 ELSE 0 END AS isFunctionLike,
|
|
474
|
+
CASE WHEN gs.kind IN (5, 8, 11) THEN 1 ELSE 0 END AS isTypeLike,
|
|
475
|
+
gs.kind AS kind,
|
|
476
|
+
gs.documentation AS documentation,
|
|
477
|
+
gs.enclosing_symbol AS enclosingSymbol
|
|
478
|
+
FROM global_symbols gs
|
|
479
|
+
LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
|
|
480
|
+
LEFT JOIN chunks c ON c.document_id = der.document_id
|
|
481
|
+
JOIN documents d ON d.id = COALESCE(der.document_id, c.document_id)
|
|
482
|
+
WHERE gs.id = ?
|
|
483
|
+
LIMIT 1`,t.symbolId)??null}function Ie(e,t){let n=Eg(e,t);return n?Dg(e,Rg(e,n.match,n.identifier)):[]}function Rg(e,t,n){let r=new Map;for(let[i,s]of Cg(e,t.symbolId))r.set(i,vg(e,i,s,t,n));return r}function Cg(e,t){let n=new Map,r=e.all(`SELECT DISTINCT d.relative_path, c.start_line, c.end_line
|
|
341
484
|
FROM mentions m
|
|
342
485
|
JOIN chunks c ON m.chunk_id = c.id
|
|
343
486
|
JOIN documents d ON c.document_id = d.id
|
|
344
487
|
WHERE m.symbol_id = ?
|
|
345
488
|
AND m.role != 1
|
|
346
489
|
${e.pathExclusionsFor("d")}
|
|
347
|
-
ORDER BY d.relative_path, c.start_line`,
|
|
490
|
+
ORDER BY d.relative_path, c.start_line`,t);for(let i of r){if(e.isIgnored(i.relative_path))continue;let s=n.get(i.relative_path);s||(s=[],n.set(i.relative_path,s)),s.push({start_line:i.start_line,end_line:i.end_line})}return n}function vg(e,t,n,r,i){let s=t===r.relativePath?{excludeStartLine:r.startLine,excludeEndLine:r.endLine}:{},o=i?cn(e,t,i,s):[];return n.flatMap(a=>Ng(o,a))}function Ng(e,t){let n=e.filter(r=>r>=t.start_line&&r<=t.end_line);return n.length>0?n:[t.start_line]}function Eg(e,t){let n=on(e,t);return n?{match:n,identifier:D(n.symbol)||null}:null}function Dg(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=Q(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function Sn(e,t,n={}){if(t.length===0)return new Map;let r=n.additive??!1,i=[],s=[];for(let u of t)M(u.relativePath)&&tn(e,u.relativePath)!==null?i.push(u):s.push(u);let o=new Map,a=new Map,l=u=>{for(let[d,m]of u){let g=o.get(d);g||(g=[],o.set(d,g));let p=a.get(d);p||(p=new Set,a.set(d,p));for(let f of m){let y=`${f.symbol}|${f.chunkId}`;p.has(y)||(p.add(y),g.push(f))}}};i.length>0&&l(Lg(e,i)),l(Vg(so(e,t)));let c=r?t:s;return c.length>0&&l(Fg(e,c)),o}function Lg(e,t){let n=new Map,r=kg(t,n),i=Et(e);for(let[s,o]of r){let a=tn(e,s);if(a)for(let l of a){let c=wg(o,l.line);if(!c)continue;let u=Pg(e,s,i,l.calleeLeaf,l.memberAccess);u&&u.symbol!==c.symbol&&n.get(c.symbolId).push({symbol:u.symbol,file:u.file,chunkId:l.line})}}return n}function kg(e,t){let n=new Map;for(let r of e){let i=n.get(r.relativePath);i?i.push(r):n.set(r.relativePath,[r]),t.set(r.symbolId,[])}for(let r of n.values())r.sort((i,s)=>i.endLine-i.startLine-(s.endLine-s.startLine));return n}function wg(e,t){return e.find(n=>t>=n.startLine&&t<=n.endLine)??null}function Pg(e,t,n,r,i){let s=lo(t,n.get(r)??[]);return s.length===0?null:co(e,t,s,i)}function lo(e,t){let n=ao(e);return n?t.filter(r=>ao(r.file)===n):t}function co(e,t,n,r){let i=n.find(s=>s.file===t);if(i)return i;if(r){let s=new Set(J(e,t).map(o=>o.sourcePath).filter(o=>!!o));for(let o of n)for(let a of s)if(Og(a,o.file))return o;return null}return n.length===1?n[0]:null}function Og(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function ao(e){let t=M(e);return t?t==="typescript"||t==="tsx"||t==="javascript"?"javascript-family":t:null}var Mg=Ae("global-leaf-index");function Et(e){return Mg.get(e,()=>{let t=e.all(`SELECT gs.id, gs.symbol,
|
|
348
491
|
COALESCE(der_doc.relative_path, mention_doc.relative_path) AS relative_path
|
|
349
492
|
FROM global_symbols gs
|
|
350
493
|
LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
|
|
@@ -358,10 +501,10 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
358
501
|
GROUP BY m.symbol_id
|
|
359
502
|
) mention_doc ON mention_doc.symbol_id = gs.id
|
|
360
503
|
WHERE 1 = 1
|
|
361
|
-
${e.symbolNoiseFor("gs")}`),
|
|
504
|
+
${e.symbolNoiseFor("gs")}`),n=new Map;for(let r of t){if(!r.relative_path||e.isIgnored(r.relative_path))continue;let i=D(r.symbol);if(!i)continue;let s=n.get(i);s||(s=[],n.set(i,s)),s.some(o=>o.symbolId===r.id)||s.push({symbol:r.symbol,symbolId:r.id,file:r.relative_path})}return n})}function Fg(e,t){if(t.length===0)return new Map;let n=e.all(`SELECT c.document_id, c.id AS chunk_id, c.start_line, c.end_line, m.symbol_id
|
|
362
505
|
FROM mentions m
|
|
363
506
|
JOIN chunks c ON m.chunk_id = c.id
|
|
364
|
-
WHERE m.role != 1`),
|
|
507
|
+
WHERE m.role != 1`),r=new Map;for(let c of n)r.has(c.document_id)||r.set(c.document_id,[]),r.get(c.document_id).push(c);let i=new Map(e.all("SELECT id, relative_path FROM documents").map(c=>[c.id,c.relative_path])),s=new Map,o=e.all(`SELECT gs.id AS symbol_id, gs.symbol,
|
|
365
508
|
COALESCE(der.document_id, def_chunk.document_id) AS document_id
|
|
366
509
|
FROM global_symbols gs
|
|
367
510
|
LEFT JOIN defn_enclosing_ranges der ON der.symbol_id = gs.id
|
|
@@ -371,21 +514,21 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
371
514
|
JOIN chunks c ON m.chunk_id = c.id
|
|
372
515
|
WHERE m.role = 1
|
|
373
516
|
GROUP BY m.symbol_id
|
|
374
|
-
) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of
|
|
375
|
-
WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=
|
|
517
|
+
) def_chunk ON def_chunk.symbol_id = gs.id`);for(let c of o)s.has(c.symbol_id)||s.set(c.symbol_id,{symbol:c.symbol,file:c.document_id!==null?i.get(c.document_id)??"":""});let a=new Map,l=i;for(let c of t){let u=r.get(c.documentId)??[],d=new Set,m=[],g=null,p=()=>{if(g)return g;let f=l.get(c.documentId)??"",y=new Set;if(f){let L=xs(e,f),k=Math.max(0,c.startLine),F=Math.min(L.length-1,c.endLine);for(let T=k;T<=F;T+=1)for(let R of L[T])y.add(R)}return g=y,y};for(let f of u){if(f.symbol_id===c.symbolId)continue;let y=s.get(f.symbol_id);if(!y)continue;if(!(f.start_line>=c.startLine&&f.end_line<=c.endLine)){if(!(f.start_line<=c.endLine&&f.end_line>=c.startLine))continue;let T=D(y.symbol);if(!T||!p().has(T))continue}let k=`${y.symbol}|${f.chunk_id}`;d.has(k)||(d.add(k),m.push({...y,chunkId:f.chunk_id}))}a.set(c.symbolId,m)}return a}function uo(e,t){let n=new Map,r=e.all(`SELECT relative_path FROM documents
|
|
518
|
+
WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`),i=Et(e),s=t??oe(e);return Tg(e,n,r,i),$g(e,n,s),Wg(e,n,r,i),Ug(n,ut(e,Hg(s))),n}function Tg(e,t,n,r){for(let i of n){if(!M(i.relative_path)||e.isIgnored(i.relative_path))continue;let s=tn(e,i.relative_path);if(s)for(let o of s){let a=lo(i.relative_path,r.get(o.calleeLeaf)??[]);if(!a||a.length===0)continue;let l=co(e,i.relative_path,a,o.memberAccess);l&&l.file!==i.relative_path&&Er(t,l.symbolId,i.relative_path)}}}function $g(e,t,n){let r=jg(n);for(let i of Ag(e))e.isIgnored(i.relative_path)||Bg(i,r.get(i.symbol_id))||Er(t,i.symbol_id,i.relative_path)}function Ag(e){return e.all(`SELECT DISTINCT m.symbol_id, d.relative_path, c.document_id,
|
|
376
519
|
c.start_line AS chunk_start, c.end_line AS chunk_end
|
|
377
520
|
FROM mentions m
|
|
378
521
|
JOIN chunks c ON m.chunk_id = c.id
|
|
379
522
|
JOIN documents d ON c.document_id = d.id
|
|
380
523
|
WHERE m.role != 1
|
|
381
|
-
${e.pathExclusionsFor("d")}`)
|
|
524
|
+
${e.pathExclusionsFor("d")}`)}function jg(e){let t=new Map;for(let n of e)t.set(n.symbolId,{docId:n.documentId,startLine:n.startLine,endLine:n.endLine});return t}function Bg(e,t){return!!t&&t.docId===e.document_id&&e.chunk_start>=t.startLine&&e.chunk_end<=t.endLine}function Wg(e,t,n,r){for(let i of n){if(e.isIgnored(i.relative_path)||M(i.relative_path)!=="rust")continue;let s=st(e,i.relative_path);if(s.size!==0)for(let o of s){let a=r.get(o);if(a)for(let l of a)l.file!==i.relative_path&&Er(t,l.symbolId,i.relative_path)}}}function Er(e,t,n){let r=e.get(t);r||(r=new Set,e.set(t,r)),r.add(n)}function Hg(e){return e.filter(t=>"relativePath"in t&&"symbol"in t&&"leaf"in t)}function Vg(e){let t=new Map;for(let[n,r]of e){let i=[];for(let s of r)i.push({symbol:s.symbol,file:s.file,chunkId:-1});t.set(n,i)}return t}function Ug(e,t){for(let[n,r]of t){let i=e.get(n);i||(i=new Set,e.set(n,i));for(let s of r)i.add(s)}}function ee(e){let t=Dt(e);return qg(t)?"test":zg(t)?"worker":Gg(t)?"entry":Kg(t)?"barrel":"source"}function xn(e){return ee(e)==="barrel"}function po(e){return Jg.get(e,()=>{let t=Y(e),n=Ee(e).filter(s=>{let o=ee(s);return o==="entry"||o==="worker"}),r=new Set,i=new Set;for(;n.length>0;){let s=n.shift();if(!r.has(s)){r.add(s),ee(s)==="barrel"&&i.add(s);for(let o of t.get(s)??[])r.has(o)||n.push(o)}}return i})}var Jg=Ae("live-barrels");function Dr(e,t){return po(e).has(Dt(t))}function fo(e){let t=po(e);return Ee(e).filter(n=>xn(n)&&!t.has(n))}function ze(e,t){let n=ee(t);return n==="entry"||n==="worker"||Dr(e,t)}function Lt(e,t,n){let r=e.config.entryRoots;if(!r)return!1;let i=Dt(n);return!!(r.files?.some(s=>Dt(s)===i)||r.pathPrefixes?.some(s=>i.startsWith(Dt(s)))||r.qualifiedVars?.some(s=>Yg(t,s))||r.symbolPatterns?.some(s=>{try{return new RegExp(s).test(t)}catch{return!1}}))}var go=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],ho=["%/test-utils/%"];function qg(e){return!!(/\.(?:test|spec)\.[a-z0-9]+$/i.test(e)||/(?:^|\/)(?:_)?test_[^/]+$/i.test(e)||/(?:^|\/)spec_[^/]+$/i.test(e)||/(?:^|\/)[^/]+_test\.[a-z0-9]+$/i.test(e)||/(?:^|\/)[^/]+_tests\.rs$/i.test(e)||/(?:^|\/)tests\.rs$/i.test(e)||/(?:^|\/)[^/]+_spec\.[a-z0-9]+$/i.test(e)||/(?:^|\/)__tests__\//i.test(e)||/(?:^|\/)test\//i.test(e)||/(?:^|\/)tests\//i.test(e)||/(?:^|\/)__fixtures__\//i.test(e)||/(?:^|\/)__mocks__\//i.test(e)||/(?:^|\/)test-support\//i.test(e)||/(?:^|\/)test-utils\//i.test(e)||/(?:^|\/)testing\//i.test(e))}function zg(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function Gg(e){let t=e.split("/"),n=t[t.length-1]??e;return n==="cli.ts"||n==="cli.js"||n==="postinstall.ts"||n==="postinstall.js"||n==="main.ts"||n==="main.js"||n==="main.rs"||n==="main.go"||n==="main.py"||n==="build.rs"||n==="lib.rs"||/\bsrc\/bin\/[^/]+\.rs$/.test(e)||/(?:^|\/)examples\/[^/]+\.rs$/.test(e)||/(?:^|\/)tests\/[^/]+\.rs$/.test(e)||/(?:^|\/)benches\/[^/]+\.rs$/.test(e)?!0:n==="index.ts"||n==="index.js"?/(?:^|\/)(?:apps|services)\/[^/]+\/src\/index\.(?:ts|js)$/.test(e)?!0:t.length<=2:!1}function Kg(e){return e==="index.ts"||e==="index.js"||e.endsWith("/index.ts")||e.endsWith("/index.js")||e.endsWith("/mod.rs")||e.endsWith("/__init__.py")}function Dt(e){return e.replace(/\\/g,"/")}function Yg(e,t){let n=t.lastIndexOf("/");if(n<0)return!1;let r=t.slice(0,n),i=t.slice(n+1);return e.includes(mo(r)+"/")&&e.includes(mo(i)+".")}function mo(e){return/^[A-Za-z0-9_$+-]+$/.test(e)?e:"`"+e.replace(/`/g,"``")+"`"}function dt(e,t,n){let r=Et(e).get(n);if(!r||r.length===0)return[];if(r.length===1)return[kt(r[0])];let i=r.filter(l=>l.file===t);if(i.length>0)return i.map(kt);let s=Qg(e,t),o=s.get(n);if(o)for(let l of o){let c=r.filter(u=>yo(l,u.file));if(c.length>0)return c.map(kt)}let a=new Set;for(let l of s.values())for(let c of l)a.add(c);for(let l of a){let c=r.filter(u=>yo(l,u.file));if(c.length>0&&c.length===r.length)return c.map(kt)}return[]}function So(e,t,n){let r=dt(e,t,n);if(r.length>0)return r;let i=Et(e).get(n);return!i||i.length===0?[]:i.map(kt)}function Te(e,t){let n=on(e,t);if(!n)return[];let r=D(n.symbol);if(!r)return[];let i=Nt(e,{...n,leaf:r,parentTypeName:null,isFunctionLike:!1,isTypeLike:!1,kind:null,documentation:null,enclosingSymbol:null});if(i.length>0){let o=new Map;for(let a of i){let l=o.get(a.file)??[];l.push(a.line),o.set(a.file,l)}return bo(e,o)}let s=new Map;for(let o of Ee(e)){let a=w(e,o);if(!a||a.indexOf(r)===-1||o!==n.relativePath&&!dt(e,o,r).some(u=>u.symbolId===n.symbolId))continue;let l=cn(e,o,r,o===n.relativePath?{excludeStartLine:n.startLine,excludeEndLine:n.endLine}:{});l.length>0&&s.set(o,l)}return bo(e,s)}function xo(e,t){let n=new Map;for(let s of t){if(!s.leaf)continue;let o=n.get(s.leaf)??[];o.push(s),n.set(s.leaf,o)}if(n.size===0)return new Map;let r=new Set(t.map(s=>s.symbolId)),i=new Map;for(let s of Ee(e)){let o=Ss(e,s);if(o.size!==0){for(let a of o)if(n.has(a))for(let l of dt(e,s,a)){if(!r.has(l.symbolId)||s===l.relativePath)continue;let c=i.get(l.symbolId);c||(c=new Set,i.set(l.symbolId,c)),c.add(s)}}}return i}function Qg(e,t){let n=new Map;for(let r of J(e,t)){if(!r.sourcePath)continue;let i=r.localName??r.importedName;if(i){let s=n.get(i);s||(s=new Set,n.set(i,s)),s.add(r.sourcePath)}if(r.kind==="namespace")for(let s of r.usedMembers){let o=n.get(s);o||(o=new Set,n.set(s,o)),o.add(r.sourcePath)}}return n}function yo(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function kt(e){return{symbolId:e.symbolId,symbol:e.symbol,relativePath:e.file}}function bo(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=Q(e,i);for(let a of s){let l=ae(o,a),c=`${i}|${a}|${l?.symbol??""}`;r.has(c)||(r.add(c),n.push({file:i,line:a,enclosingSymbol:l?.symbol??null}))}}return n}function _o(e,t,n){let r=t.identifierResolution==="strict"?dt:So;for(let i of t.paths){let s=M(i);if(!s&&!(t.includeVueSfc&&yt(i))||e.isIgnored(i)||t.skipPath?.(i))continue;let o=qe(e,i);for(let[a,l]of o)for(let c of r(e,i,a))n({sourceFile:i,name:a,target:c,occurrences:l.length,kind:"identifier"});if(t.includeCrossLanguageDispatchNames)for(let a of gs(e,i))for(let l of dt(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"cross-language-dispatch"});if(t.includeRustAttributeNames&&s==="rust")for(let a of st(e,i))for(let l of r(e,i,a))n({sourceFile:i,name:a,target:l,occurrences:1,kind:"rust-attribute"})}}var C=class{constructor(t){this.db=t}db;scopedDefinitions(t){return lr(this.db,t)}definitionsForFile(t){return Q(this.db,t)}productionCallableDefinitions(t={}){let{scope:n,minLoc:r=1,maxLoc:i=Number.POSITIVE_INFINITY,excludeSymbol:s,excludeEntrySurfaces:o=!1,excludeTypesFiles:a=!1,requireFunctionLikeSymbol:l=!1,requireCallableSymbol:c=!1,excludeRustTraitImplMembers:u=!1,includeSuppressed:d=!1,sortByLocDesc:m=!1}=t,g=[];for(let p of this.scopedDefinitions(n)){let f=p.relativePath;if(this.db.isIgnored(f)||o&&ze(this.db,f)||!Xg(p,{requireFunctionLikeSymbol:l,requireCallableSymbol:c})||s!==void 0&&p.symbol===s)continue;let y=Lr(p);y<r||y>i||a&&Zg(f)||u&&rn(p.symbol)||ee(f)!=="test"&&(ke(p.symbol)||!d&&or(this.db,f,p.startLine)||g.push(p))}return m?g.sort((p,f)=>Lr(f)-Lr(p)):g}calleeMap(t,n={}){return Sn(this.db,t,n)}crossFileCallerMap(t){return uo(this.db,t)}sourceFallbackCallerFiles(t){return xo(this.db,t)}fileDependencyGraph(t){return Y(this.db,t)}fileKind(t){return ee(t)}hasSuppressionComment(t){return or(this.db,t.relativePath,t.startLine)}sourceFiles(){return Ee(this.db)}scanSourceReferences(t,n){_o(this.db,t,n)}callableSignature(t){return Xi(this.db,t.relativePath,t.startLine,t.endLine)}};function Lr(e){return e.endLine-e.startLine+1}function Xg(e,t){return t.requireCallableSymbol?U(e.symbol):t.requireFunctionLikeSymbol?W(e.symbol):e.isFunctionLike}function Zg(e){return(e.split("/").pop()??"").includes("types")}function Io(e,t){let n=E(e,t);if(!n)return[];let r=D(n.symbol),s=new C(e).definitionsForFile(n.relativePath).filter(l=>U(l.symbol)),o=s.filter(l=>l.parentTypeName===r||l.symbol.includes(r));return(o.length>0?o:th(eh(n.relativePath))===r?s.filter(l=>l.symbol.includes("<invalid-global-code>")):[]).map(l=>({startLine:l.startLine,endLine:l.endLine,name:D(l.symbol)}))}function th(e){return e.replace(/\.[^.]+$/,"")}function Ro(e,t){let n=E(e,t);if(!n)return[];let i=!W(n.symbol)&&!e.isIgnored(n.relativePath)?[{relativePath:n.relativePath,line:n.startLine}]:[],s=Te(e,n),o=(s.length>0?s:Ie(e,n)).filter(u=>!e.isIgnored(u.file)).map(u=>({relativePath:u.file,line:u.line})),a=nh(e,n),l=new Set,c=[];for(let u of[...i,...o,...a]){let d=`${u.relativePath}:${u.line}`;l.has(d)||(l.add(d),c.push(u))}return c}function nh(e,t){if(!t.relativePath.endsWith(".rb"))return[];let n=rh(t.symbol);if(n.length===0)return[];let r=e.all(`SELECT relative_path
|
|
382
525
|
FROM documents
|
|
383
526
|
WHERE relative_path LIKE '%.rb'
|
|
384
527
|
${e.pathExclusionsFor("documents")}
|
|
385
|
-
ORDER BY relative_path`),i=[];for(let
|
|
386
|
-
`);for(let l=0;l<
|
|
387
|
-
`).slice(
|
|
388
|
-
`).trimEnd();return
|
|
528
|
+
ORDER BY relative_path`),i=[];for(let s of r){if(e.isIgnored(s.relative_path))continue;let o=w(e,s.relative_path);if(!o)continue;let a=o.split(`
|
|
529
|
+
`);for(let l=0;l<a.length;l++){let c=a[l]??"";n.some(u=>new RegExp(`@${u}\\b|\\b${u}:`).test(c))&&i.push({relativePath:s.relative_path,line:l})}}return i}function rh(e){let n=(e.split(":").pop()??e).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9_]+/g,"_").toLowerCase().replace(/^_+|_+$/g,""),r=n.split("_").filter(Boolean),i=new Set;return n&&i.add(n),r.length>=1&&i.add(r[r.length-1]),r.length>=2&&i.add(r.slice(-2).join("_")),[...i]}function Co(e,t){let n=E(e,t);if(!n)return{definitions:[],referencedBy:[]};let r=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",n.symbolId),i=Ve(r?.documentation??null),s=e.isIgnored(n.relativePath)?[]:[{relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,signature:sh(i,r?.display_name??null,n.symbol),source:ih(e,n.relativePath,n.startLine,n.endLine)}],o=Te(e,n),l=(o.length>0?o:Ie(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({relativePath:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol,enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"}));return{definitions:s,referencedBy:l}}function ih(e,t,n,r){let i=w(e,t);if(!i)return null;let o=i.split(`
|
|
530
|
+
`).slice(n,r+1).join(`
|
|
531
|
+
`).trimEnd();return o.length>0?o:null}function sh(e,t,n){let r=He(e);if(r&&!oh(r))return r;let i=(t??"").trim();return i?W(n)&&!i.endsWith("()")?`${i}()`:i:h(n)}function oh(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function vo(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d2.relative_path
|
|
389
532
|
FROM mentions m
|
|
390
533
|
JOIN chunks c ON m.chunk_id = c.id
|
|
391
534
|
JOIN documents d1 ON c.document_id = d1.id
|
|
@@ -401,7 +544,7 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
401
544
|
WHERE d1.relative_path = ?
|
|
402
545
|
AND d2.relative_path <> d1.relative_path
|
|
403
546
|
AND ${e.localSymbolPredicate}
|
|
404
|
-
ORDER BY d2.relative_path`,
|
|
547
|
+
ORDER BY d2.relative_path`,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function No(e,t){let n=G(e,t);return n?e.all(`SELECT DISTINCT d1.relative_path
|
|
405
548
|
FROM mentions m
|
|
406
549
|
JOIN chunks c ON m.chunk_id = c.id
|
|
407
550
|
JOIN documents d1 ON c.document_id = d1.id
|
|
@@ -416,9 +559,9 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
416
559
|
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
417
560
|
WHERE d2.relative_path = ?
|
|
418
561
|
AND d1.relative_path != ?
|
|
419
|
-
ORDER BY d1.relative_path`,
|
|
420
|
-
WHERE relative_path IN (${
|
|
421
|
-
ORDER BY relative_path`,...
|
|
562
|
+
ORDER BY d1.relative_path`,n,n).filter(i=>!e.isIgnored(i.relative_path)).map(i=>({relativePath:i.relative_path})):[]}function Eo(e,t){let n=we(e,t);if(n.length===0)return{files:[],symbols:[],dependsOn:[],dependedOnBy:[]};let r=n.map(()=>"?").join(", "),s=e.all(`SELECT relative_path FROM documents
|
|
563
|
+
WHERE relative_path IN (${r})
|
|
564
|
+
ORDER BY relative_path`,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d)),o=nt(e,s,{onlyDocumented:!0,sort:!0}).map(({relativePath:d,...m})=>m),l=e.all(`SELECT DISTINCT d2.relative_path
|
|
422
565
|
FROM mentions m
|
|
423
566
|
JOIN chunks c ON m.chunk_id = c.id
|
|
424
567
|
JOIN documents d1 ON c.document_id = d1.id
|
|
@@ -431,10 +574,10 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
431
574
|
GROUP BY m2.symbol_id
|
|
432
575
|
) sym_def ON sym_def.symbol_id = gs.id
|
|
433
576
|
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
434
|
-
WHERE d1.relative_path IN (${
|
|
435
|
-
AND d2.relative_path NOT IN (${
|
|
577
|
+
WHERE d1.relative_path IN (${r})
|
|
578
|
+
AND d2.relative_path NOT IN (${r})
|
|
436
579
|
AND ${e.localSymbolPredicate}
|
|
437
|
-
ORDER BY d2.relative_path`,...
|
|
580
|
+
ORDER BY d2.relative_path`,...n,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d)),u=e.all(`SELECT DISTINCT d1.relative_path
|
|
438
581
|
FROM mentions m
|
|
439
582
|
JOIN chunks c ON m.chunk_id = c.id
|
|
440
583
|
JOIN documents d1 ON c.document_id = d1.id
|
|
@@ -447,21 +590,21 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
447
590
|
GROUP BY m2.symbol_id
|
|
448
591
|
) sym_def ON sym_def.symbol_id = gs.id
|
|
449
592
|
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
450
|
-
WHERE d2.relative_path IN (${
|
|
451
|
-
AND d1.relative_path NOT IN (${
|
|
452
|
-
ORDER BY d1.relative_path`,...
|
|
593
|
+
WHERE d2.relative_path IN (${r})
|
|
594
|
+
AND d1.relative_path NOT IN (${r})
|
|
595
|
+
ORDER BY d1.relative_path`,...n,...n).map(d=>d.relative_path).filter(d=>!e.isIgnored(d));return{files:s,symbols:o,dependsOn:l,dependedOnBy:u}}function Do(e,t){let n=we(e,t);return n.length===0?[]:ch([...ah(e,n),...lh(e,n)]).filter(r=>!e.isIgnored(r.relative_path)).map(uh)}function ah(e,t){let n=t.map(()=>"?").join(", ");return e.all(`SELECT DISTINCT d1.relative_path, gs.symbol
|
|
453
596
|
FROM mentions m
|
|
454
597
|
JOIN chunks c ON m.chunk_id = c.id
|
|
455
598
|
JOIN documents d1 ON c.document_id = d1.id
|
|
456
599
|
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
457
|
-
WHERE d1.relative_path NOT IN (${
|
|
600
|
+
WHERE d1.relative_path NOT IN (${n})
|
|
458
601
|
AND (
|
|
459
602
|
EXISTS (
|
|
460
603
|
SELECT 1
|
|
461
604
|
FROM defn_enclosing_ranges der
|
|
462
605
|
JOIN documents d2 ON der.document_id = d2.id
|
|
463
606
|
WHERE der.symbol_id = gs.id
|
|
464
|
-
AND d2.relative_path IN (${
|
|
607
|
+
AND d2.relative_path IN (${n})
|
|
465
608
|
)
|
|
466
609
|
OR EXISTS (
|
|
467
610
|
SELECT 1
|
|
@@ -470,13 +613,13 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
470
613
|
JOIN documents d2 ON def_c.document_id = d2.id
|
|
471
614
|
WHERE def_m.symbol_id = gs.id
|
|
472
615
|
AND def_m.role = 1
|
|
473
|
-
AND d2.relative_path IN (${
|
|
616
|
+
AND d2.relative_path IN (${n})
|
|
474
617
|
)
|
|
475
618
|
)
|
|
476
619
|
AND m.role != 1
|
|
477
620
|
AND ${e.localSymbolPredicate}
|
|
478
621
|
${e.pathExclusionsFor("d1")}
|
|
479
|
-
ORDER BY d1.relative_path`,...t,...t,...t),
|
|
622
|
+
ORDER BY d1.relative_path`,...t,...t,...t)}function lh(e,t){let n=new C(e);return t.flatMap(r=>n.definitionsForFile(r).filter(i=>U(i.symbol)).map(i=>({relative_path:r,symbol:i.symbol})))}function ch(e){let t=new Set;return e.filter(n=>{let r=`${n.relative_path}|${n.symbol}`;return t.has(r)?!1:(t.add(r),!0)})}function uh(e){return{consumer:e.relative_path,symbol:e.symbol,shortName:h(e.symbol)}}function _n(e,t={}){let{scope:n,minLoc:r=1,includeTests:i=!1,skipBarrels:s=!1,includeMembers:o=!1}=t,a=s?new Set(fo(e)):new Set,l=dh(e,a);hh(e,l,a);let c=mh(e,{scope:n,minLoc:r,includeTests:i,includeMembers:o});return Ih(e,c,l,{includeTests:i,inactiveBarrelPaths:a}),gh(e,ph(c,l))}function dh(e,t){let n=e.all(`SELECT
|
|
480
623
|
m.symbol_id,
|
|
481
624
|
d.relative_path,
|
|
482
625
|
COUNT(*) AS ref_count
|
|
@@ -485,8 +628,8 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
485
628
|
JOIN documents d ON c.document_id = d.id
|
|
486
629
|
WHERE m.role != 1
|
|
487
630
|
${e.pathExclusionsFor("d")}
|
|
488
|
-
GROUP BY m.symbol_id, d.relative_path`),
|
|
489
|
-
WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`)
|
|
631
|
+
GROUP BY m.symbol_id, d.relative_path`),r=new Map;for(let i of n){if(e.isIgnored(i.relative_path)||t.has(i.relative_path))continue;let s=r.get(i.symbol_id);s||(s=new Map,r.set(i.symbol_id,s)),s.set(i.relative_path,i.ref_count)}return r}function mh(e,t){let n=Rh(e);return oe(e,{scope:t.scope}).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>!Le(r.symbol)).filter(r=>Lo(r.symbol)).filter(r=>r.isFunctionLike||!r.enclosingSymbol||!Lo(r.enclosingSymbol)).filter(r=>t.includeTests||ko(r.relativePath)).filter(r=>t.includeTests||!n(r.relativePath,r.startLine,r.symbol,r.parentTypeName)).filter(r=>!rn(r.symbol)).filter(r=>!ke(r.symbol)).filter(r=>t.includeMembers||vh(r)).filter(r=>r.endLine-r.startLine+1>=t.minLoc)}function ph(e,t){return e.map(n=>fh(n,t)).filter(n=>n.cross_file_refs===0).sort((n,r)=>r.loc-n.loc||n.relative_path.localeCompare(r.relative_path)||n.start_line-r.start_line)}function fh(e,t){let n=t.get(e.symbolId)??new Map,r=n.get(e.relativePath)??0,i=0;for(let[s,o]of n)s!==e.relativePath&&(i+=o);return{relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine,loc:e.endLine-e.startLine+1,symbol:e.symbol,same_file_refs:r,cross_file_refs:i}}function gh(e,t){let n=[],r=0,i=0,s=0;for(let o of t){if(e.isIgnored(o.relative_path)||ze(e,o.relative_path)||Lt(e,o.symbol,o.relative_path))continue;let a=o.same_file_refs===0?"dead-code":"file-internal";a==="dead-code"?r++:i++,s+=o.loc,n.push({relativePath:o.relative_path,startLine:o.start_line,endLine:o.end_line,loc:o.loc,symbol:o.symbol,shortName:h(o.symbol),sameFileRefs:o.same_file_refs,kind:a})}return{symbols:n,totalCount:n.length,deadCodeCount:r,fileInternalCount:i,totalLoc:s}}function hh(e,t,n){let r=new C(e),i=new Set(r.sourceFiles());for(let s of yh(e))i.add(s);r.scanSourceReferences({paths:i,includeVueSfc:!0,includeCrossLanguageDispatchNames:!0,includeRustAttributeNames:!0,identifierResolution:"permissive",skipPath:s=>n.has(s)},s=>{bh(e,s)||xh(t,s.target.symbolId,s.sourceFile,Sh(s))})}function yh(e){let t=e.all(`SELECT relative_path FROM documents
|
|
632
|
+
WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);return new Set(t.map(n=>n.relative_path))}function bh(e,t){return t.kind==="cross-language-dispatch"&&t.target.relativePath===t.sourceFile?!0:t.kind==="identifier"&&_h(e,t)}function Sh(e){return e.kind==="identifier"&&e.target.relativePath===e.sourceFile?Math.max(0,e.occurrences-1):e.occurrences}function xh(e,t,n,r){if(r<=0)return;let i=e.get(t);i||(i=new Map,e.set(t,i)),i.set(n,(i.get(n)??0)+r)}function _h(e,t){return t.occurrences>1?!1:J(e,t.sourceFile).some(n=>n.used||n.sourcePath!==t.target.relativePath?!1:n.importedName===t.name||n.localName===t.name)}function Ih(e,t,n,r){for(let i of t){let s=ie(e,i);if(s.length===0)continue;let o=n.get(i.symbolId);o||(o=new Map,n.set(i.symbolId,o));for(let a of s){let l=a.file;l===i.relativePath||e.isIgnored(l)||r.inactiveBarrelPaths.has(l)||!r.includeTests&&!ko(l)||o.set(l,Math.max(1,o.get(l)??0))}}}function Rh(e){let t=new Map,n=r=>{let i=t.get(r);if(i)return i;let s=us(e,r);return i={ranges:s.map(o=>({startLine:o.startLine,endLine:o.endLine})),containers:new Set(s.map(o=>o.containerName).filter(o=>!!o))},t.set(r,i),i};return(r,i,s,o)=>{let a=n(r);for(let l of a.ranges)if(i>=l.startLine&&i<=l.endLine)return!0;if(o&&a.containers.has(o))return!0;for(let l of cr(s))if(a.containers.has(l))return!0;return!1}}function ko(e){return[...new Set([...go,...ho])].every(n=>!Ch(e,n))}function Ch(e,t){return new RegExp(`^${t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function Lo(e){return W(e)||e.endsWith("().")||e.endsWith(".")}function vh(e){return U(e.symbol)||cr(e.symbol).length===0}function wo(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"",o=e.all(`SELECT
|
|
490
633
|
gs.symbol,
|
|
491
634
|
COUNT(*) AS ref_count,
|
|
492
635
|
COUNT(DISTINCT ref_d.id) AS file_count,
|
|
@@ -509,18 +652,18 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
509
652
|
${i}
|
|
510
653
|
GROUP BY gs.id
|
|
511
654
|
ORDER BY ref_count DESC
|
|
512
|
-
LIMIT ?`,
|
|
655
|
+
LIMIT ?`,n).filter(a=>!e.isIgnored(a.defined_in)).map(a=>({symbol:a.symbol,shortName:h(a.symbol),refCount:a.ref_count,fileCount:a.file_count,definedIn:a.defined_in}));return o.length>0?o:Nh(e,r,n)}function Nh(e,t,n){return oe(e,{scope:t}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>Eh(e,r)).filter(r=>r.refCount>0).sort((r,i)=>i.refCount-r.refCount||i.fileCount-r.fileCount).slice(0,n)}function Eh(e,t){let n=ie(e,t,{limit:500});return{symbol:t.symbol,shortName:h(t.symbol),refCount:n.length,fileCount:new Set(n.map(r=>r.file)).size,definedIn:t.relativePath}}function Oo(e,t){return To(e,t)?.map(n=>({symbol:n.symbol,shortName:n.shortName,fromFile:n.fromFile}))??[]}function Mo(e,t){let n=Dh(e,t);return n.length>0?n:Lh(e,t)}function Fo(e,t){return To(e,t)?.filter(n=>!n.used).map(n=>({symbol:n.symbol,shortName:n.shortName,importedIn:n.importer}))??[]}function Dh(e,t){return e.all(`SELECT DISTINCT gs.symbol, d.relative_path AS importer
|
|
513
656
|
FROM mentions m
|
|
514
657
|
JOIN chunks c ON m.chunk_id = c.id
|
|
515
658
|
JOIN documents d ON c.document_id = d.id
|
|
516
659
|
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
517
660
|
WHERE gs.symbol LIKE ?
|
|
518
661
|
AND m.role = 2
|
|
519
|
-
ORDER BY d.relative_path`,`%${
|
|
662
|
+
ORDER BY d.relative_path`,`%${t}%`).filter(r=>!e.isIgnored(r.importer)).map(r=>({symbol:r.symbol,shortName:h(r.symbol),fromFile:r.importer}))}function Lh(e,t){let n=E(e,t),r=n?.relativePath??null,i=n?D(n.symbol):t.replace(/\(\)$/,""),s=n?Le(n.symbol):!1,o=e.all(`SELECT relative_path
|
|
520
663
|
FROM documents
|
|
521
664
|
WHERE 1 = 1
|
|
522
665
|
${e.pathExclusionsFor("documents")}
|
|
523
|
-
ORDER BY relative_path`),
|
|
666
|
+
ORDER BY relative_path`),a=new Set;for(let l of o)if(!e.isIgnored(l.relative_path))for(let c of J(e,l.relative_path))kh(c,l.relative_path,{targetFile:r,targetLeaf:i,targetIsModule:s})&&a.add(l.relative_path);return[...a].sort().map(l=>({symbol:n?.symbol??i,shortName:n?h(n.symbol):i,fromFile:l}))}function kh(e,t,n){return!e.sourcePath||n.targetFile&&Po(e.sourcePath)!==Po(n.targetFile)?!1:e.kind==="side-effect"||n.targetFile&&Mh(t)||n.targetIsModule||e.kind==="named"&&e.importedName===n.targetLeaf?!0:e.kind==="namespace"&&e.usedMembers.includes(n.targetLeaf)}function To(e,t){let n=G(e,t);return n?wh(e,n)??Ph(e,n)??Oh(e,n):null}function wh(e,t){let r=e.all(`SELECT DISTINCT
|
|
524
667
|
gs.symbol,
|
|
525
668
|
def_d.relative_path AS from_file,
|
|
526
669
|
imp_d.relative_path AS importer,
|
|
@@ -546,11 +689,11 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
546
689
|
LEFT JOIN documents def_d ON sym_def.document_id = def_d.id
|
|
547
690
|
WHERE imp_d.relative_path = ?
|
|
548
691
|
AND m.role = 2
|
|
549
|
-
ORDER BY def_d.relative_path, gs.symbol`,t).filter(
|
|
692
|
+
ORDER BY def_d.relative_path, gs.symbol`,t).filter(i=>!e.isIgnored(i.importer));if(r.length>0){let i=vt(e,t);return r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),fromFile:s.from_file??"(external)",importer:s.importer,used:s.used!==0||i.some(o=>o.isUsed&&o.sourcePath===s.from_file)}))}return null}function Ph(e,t){let n=vt(e,t);return n.length>0?n.map(r=>{let i=$o(r.importedName,r.localName,r.kind);return{symbol:i,shortName:i,fromFile:r.sourcePath??"(external)",importer:t,used:r.kind==="side-effect"?!0:r.isUsed}}):null}function Oh(e,t){return J(e,t).map(n=>{let r=$o(n.importedName,n.localName,n.kind),i=n.kind==="side-effect"?!0:n.used;return{symbol:r,shortName:r,fromFile:n.sourcePath??"(external)",importer:t,used:i}})}function $o(e,t,n){return n==="namespace"&&e==="*"&&t?`* as ${t}`:n==="default"&&t?`default as ${t}`:n==="side-effect"?"(side effect import)":t&&t!==e?`${e} as ${t}`:e}function Po(e){return e.replace(/\\/g,"/")}function Mh(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function Ao(e,t){let n=we(e,t),r=nt(e,n,{sort:!0});if(r.length===0)return[];let i=r.map(a=>({symbol:a.symbol,shortName:a.shortName,startLine:a.startLine,endLine:a.endLine,children:[]})),s=new Map;for(let a of i)s.set(a.symbol,a);let o=[];for(let a=0;a<r.length;a++){let l=r[a],c=i[a];if(l.enclosingSymbol&&s.has(l.enclosingSymbol)){s.get(l.enclosingSymbol).children.push(c);continue}let u=null,d=1/0;for(let m of i)if(m!==c&&m.startLine<=c.startLine&&m.endLine>=c.endLine){if(m.startLine===c.startLine&&m.endLine===c.endLine&&!ts(m.symbol,c.symbol))continue;let p=m.endLine-m.startLine;p<d&&(d=p,u=m)}u?u.children.push(c):o.push(c)}return o}function jo(e,t){let n=E(e,t);return n?new C(e).definitionsForFile(n.relativePath).filter(i=>i.symbol!==n.symbol).filter(i=>es(n.symbol,i.symbol)).sort((i,s)=>i.startLine-s.startLine||i.endLine-s.endLine).map(i=>({symbol:i.symbol,shortName:h(i.symbol),startLine:i.startLine,endLine:i.endLine,kind:V(i.symbol)??"unknown"})):[]}function Bo(e,t){let n=E(e,t);if(!n)return[];let r=e.get(`SELECT COUNT(DISTINCT c.document_id) AS file_count
|
|
550
693
|
FROM mentions m
|
|
551
694
|
JOIN chunks c ON m.chunk_id = c.id
|
|
552
695
|
WHERE m.symbol_id = ?
|
|
553
|
-
AND m.role != 1`,
|
|
696
|
+
AND m.role != 1`,n.symbolId);return[{name:h(n.symbol),count:r?.file_count??0}]}function Wo(e,t){let n=G(e,t);if(!n)return[];let i=e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
|
|
554
697
|
FROM mentions m
|
|
555
698
|
JOIN chunks c ON m.chunk_id = c.id
|
|
556
699
|
JOIN documents d ON c.document_id = d.id
|
|
@@ -567,7 +710,7 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
567
710
|
AND m.role != 1
|
|
568
711
|
AND def_d.id != d.id
|
|
569
712
|
GROUP BY d.id
|
|
570
|
-
ORDER BY symbol_count DESC`,
|
|
713
|
+
ORDER BY symbol_count DESC`,n).filter(a=>!e.isIgnored(a.relative_path)).map(a=>({name:a.relative_path,count:a.symbol_count}));if(i.length>0)return i;let o=Y(e).get(n);return!o||o.size===0?[]:[{name:n,count:o.size}]}function Ho(e,t={}){return Fh(e,t).map(n=>({name:h(n.symbol),count:n.file_count}))}function Fh(e,t){let{limit:n=30,scope:r}=t,i=r?`AND def_d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT gs.symbol, COUNT(DISTINCT c.document_id) AS file_count
|
|
571
714
|
FROM mentions m
|
|
572
715
|
JOIN chunks c ON m.chunk_id = c.id
|
|
573
716
|
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
@@ -586,7 +729,7 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
586
729
|
GROUP BY gs.id
|
|
587
730
|
HAVING file_count > 1
|
|
588
731
|
ORDER BY file_count DESC
|
|
589
|
-
LIMIT ?`,
|
|
732
|
+
LIMIT ?`,n)}function Vo(e,t={}){let{limit:n=30,scope:r}=t,i=r?`AND d.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT d.relative_path, COUNT(DISTINCT gs.id) AS symbol_count
|
|
590
733
|
FROM mentions m
|
|
591
734
|
JOIN chunks c ON m.chunk_id = c.id
|
|
592
735
|
JOIN documents d ON c.document_id = d.id
|
|
@@ -606,7 +749,7 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
606
749
|
${i}
|
|
607
750
|
GROUP BY d.id
|
|
608
751
|
ORDER BY symbol_count DESC
|
|
609
|
-
LIMIT ?`,
|
|
752
|
+
LIMIT ?`,n).filter(o=>!e.isIgnored(o.relative_path)).map(o=>({name:o.relative_path,count:o.symbol_count}))}function Uo(e,t,n){let r=G(e,t)??t,i=G(e,n)??n,s=e.get(`SELECT COUNT(DISTINCT gs.id) AS shared
|
|
610
753
|
FROM global_symbols gs
|
|
611
754
|
WHERE (
|
|
612
755
|
-- Defined in file1, referenced in file2
|
|
@@ -638,7 +781,7 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
638
781
|
JOIN documents d ON c.document_id = d.id
|
|
639
782
|
WHERE m.symbol_id = gs.id AND m.role != 1 AND d.relative_path = ?
|
|
640
783
|
)
|
|
641
|
-
)`,
|
|
784
|
+
)`,r,i,i,r);return{file1:r,file2:i,sharedSymbols:s?.shared??0}}function Jo(e,t={}){let{limit:n=20,scope:r}=t,i=r?`AND d1.relative_path LIKE '%${r}%' AND d2.relative_path LIKE '%${r}%'`:"";return e.all(`SELECT
|
|
642
785
|
def_d.relative_path AS file1,
|
|
643
786
|
ref_d.relative_path AS file2,
|
|
644
787
|
COUNT(DISTINCT gs.id) AS shared
|
|
@@ -660,115 +803,69 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
660
803
|
${i}
|
|
661
804
|
GROUP BY def_d.id, ref_d.id
|
|
662
805
|
ORDER BY shared DESC
|
|
663
|
-
LIMIT ?`,
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
JOIN chunks ref_c ON ref_m.chunk_id = ref_c.id
|
|
670
|
-
WHERE ref_m.symbol_id = gs.id AND ref_m.role != 1
|
|
671
|
-
) AS fan_in,
|
|
672
|
-
(SELECT COUNT(DISTINCT ref_gs.id)
|
|
673
|
-
FROM mentions ref_m
|
|
674
|
-
JOIN chunks ref_c ON ref_m.chunk_id = ref_c.id
|
|
675
|
-
JOIN global_symbols ref_gs ON ref_m.symbol_id = ref_gs.id
|
|
676
|
-
JOIN (
|
|
677
|
-
SELECT m3.symbol_id, c3.document_id
|
|
678
|
-
FROM mentions m3
|
|
679
|
-
JOIN chunks c3 ON m3.chunk_id = c3.id
|
|
680
|
-
WHERE m3.role = 1
|
|
681
|
-
GROUP BY m3.symbol_id
|
|
682
|
-
) ref_sym_def ON ref_sym_def.symbol_id = ref_gs.id
|
|
683
|
-
WHERE ref_c.document_id = def_d.id
|
|
684
|
-
AND ref_m.role != 1
|
|
685
|
-
AND ref_sym_def.document_id != def_d.id
|
|
686
|
-
) AS fan_out
|
|
687
|
-
FROM global_symbols gs
|
|
688
|
-
JOIN (
|
|
689
|
-
SELECT m2.symbol_id, c2.document_id
|
|
690
|
-
FROM mentions m2
|
|
691
|
-
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
692
|
-
WHERE m2.role = 1
|
|
693
|
-
GROUP BY m2.symbol_id
|
|
694
|
-
) sym_def ON sym_def.symbol_id = gs.id
|
|
695
|
-
JOIN documents def_d ON sym_def.document_id = def_d.id
|
|
696
|
-
WHERE 1 = 1
|
|
697
|
-
${e.pathExclusionsFor("def_d")}
|
|
698
|
-
${e.symbolNoiseFor("gs")}
|
|
699
|
-
${a}
|
|
700
|
-
) WHERE fan_in >= ? AND fan_out >= ?
|
|
701
|
-
ORDER BY (fan_in * fan_out) DESC
|
|
702
|
-
LIMIT ?`,i,o,t).filter(c=>!e.isIgnored(c.defined_in)).map(c=>({symbol:c.symbol,shortName:I(c.symbol),fanIn:c.fan_in,fanOut:c.fan_out,score:c.fan_in*c.fan_out,definedIn:c.defined_in}));return l.length>0?l:Ku(e,s,{minFanIn:i,minFanOut:o,limit:t})}function Ku(e,n,t){let{minFanIn:s,minFanOut:i,limit:o}=t;return Z(e,{scope:n}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>Qu(e,r)).filter(r=>r.fanIn>=s&&r.fanOut>=i).sort((r,l)=>l.score-r.score||l.fanIn-r.fanIn).slice(0,o)}function Qu(e,n){let t=new Set(he(e,n,{limit:500}).map(i=>i.file)).size,s=new Set(ne(e,n,{limit:500}).filter(i=>i.file!==n.relativePath).map(i=>`${i.symbol}|${i.file}`)).size;return{symbol:n.symbol,shortName:I(n.symbol),fanIn:t,fanOut:s,score:t*s,definedIn:n.relativePath}}function sn(e,n={}){let{scope:t,minLoc:s=3}=n,o=Y(e,t).filter(p=>!e.isIgnored(p.relativePath)).filter(p=>!ve(e,p.relativePath)).filter(p=>p.isFunctionLike).filter(p=>!Ye(p.symbol)).filter(p=>!G(p.symbol)).filter(p=>p.endLine-p.startLine+1>=s),a=ye(e,o),r=ot(e,o),l=new Set([...a.keys(),...r.keys()]),c=new Map;for(let p of o){let f=F(p.symbol);if(!f)continue;let y=c.get(f)??[];y.push(p.symbolId),c.set(f,y)}let m=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of m){if(e.isIgnored(p.relative_path)||P(p.relative_path)!=="rust")continue;let f=we(e,p.relative_path);for(let y of f){let h=c.get(y);if(h)for(let b of h)l.add(b)}}let u=new Map(o.map(p=>[p.symbolId,p.symbol])),d=se(e,o,{additive:!0}),g=new Set([...d.entries()].filter(([p,f])=>{let y=u.get(p);return f.some(h=>h.symbol!==y)}).map(([p])=>p));return o.filter(p=>!l.has(p.symbolId)).filter(p=>!g.has(p.symbolId)).sort((p,f)=>f.endLine-f.startLine-(p.endLine-p.startLine)||p.relativePath.localeCompare(f.relativePath)||p.startLine-f.startLine).map(p=>({symbol:p.symbol,shortName:I(p.symbol),relativePath:p.relativePath,startLine:p.startLine,endLine:p.endLine,loc:p.endLine-p.startLine+1}))}var Vn={0:"UnspecifiedKind",1:"AbstractMethod",2:"Accessor",3:"Array",4:"Assertion",5:"AssociatedType",6:"Attribute",7:"Axiom",8:"Boolean",9:"Class",10:"Constant",11:"Constructor",12:"Contract",13:"DataFamily",14:"DefinitionMacro",15:"Delegate",16:"Enum",17:"EnumMember",18:"Error",19:"Event",20:"Fact",21:"Field",22:"File",23:"Function",24:"Getter",25:"Grammar",26:"Instance",27:"Interface",28:"Key",29:"Lang",30:"Lemma",31:"Library",32:"Macro",33:"Method",34:"MethodAlias",35:"MethodReceiver",36:"MethodSpecification",37:"Message",38:"Modifier",39:"Module",40:"Namespace",41:"Null",42:"Number",43:"Object",44:"Operator",45:"Package",46:"PackageObject",47:"Parameter",48:"ParameterLabel",49:"Pattern",50:"Predicate",51:"Property",52:"Protocol",53:"ProtocolMethod",54:"PureVirtualMethod",55:"Quasiquoter",56:"SelfParameter",57:"Setter",58:"Signature",59:"SingletonClass",60:"SingletonMethod",61:"StaticDataMember",62:"StaticEvent",63:"StaticField",64:"StaticMethod",65:"StaticProperty",66:"StaticVariable",67:"String",68:"Struct",69:"Subscript",70:"Tactic",71:"Theorem",72:"ThisParameter",73:"Trait",74:"TraitMethod",75:"Type",76:"TypeAlias",77:"TypeClass",78:"TypeClassMethod",79:"TypeFamily",80:"TypeParameter",81:"Union",82:"Value",83:"Variable"},zn=new Map;for(let[e,n]of Object.entries(Vn))zn.set(n.toLowerCase(),Number(e));function Xu(e){let n=parseInt(e,10);if(!isNaN(n))return n;let t=e.toLowerCase(),s=zn.get(t);if(s!==void 0)return s;for(let[i,o]of zn)if(i.includes(t))return o;return null}function Ro(e,n,t={}){let{scope:s,limit:i=100}=t,o=Xu(n);return o===null?[]:wo(e,s).map(r=>({row:r,resolvedKind:Do(r)})).filter(r=>r.resolvedKind===o).slice(0,i).map(({row:r,resolvedKind:l})=>({symbol:r.symbol,shortName:I(r.symbol),kind:l,kindName:Vn[l]??"Unknown",relativePath:r.relative_path,startLine:r.start_line,endLine:r.end_line}))}function Lo(e,n={}){let t=new Map;for(let s of wo(e,n.scope)){let i=Do(s);i===null||i===0||t.set(i,(t.get(i)??0)+1)}return[...t.entries()].sort((s,i)=>i[1]-s[1]||s[0]-i[0]).map(([s,i])=>({kind:s,kindName:Vn[s]??"Unknown",count:i}))}function wo(e,n){return Z(e,{scope:n}).map(Zu)}function Zu(e){return{symbol:e.symbol,kind:e.kind,documentation:e.documentation,enclosing_symbol:e.enclosingSymbol,relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine}}function Do(e){return e.kind!==null&&e.kind!==0?em(e.kind,e.symbol,e.documentation):tm(e.symbol,e.documentation,e.enclosing_symbol)}function em(e,n,t){let s=(t??"").toLowerCase();if(ie(n)==="type"){if(s.includes("type "))return 76;if(s.includes("interface "))return 27;if(s.includes("struct "))return 68;if(s.includes("trait "))return 73;if(s.includes("class "))return 9}return e}function tm(e,n,t){let s=V(e);if("kind"in s)return null;let i=s.descriptors,o=i[i.length-2]??null,a=ie(e),r=(n??"").toLowerCase();return a==="type"?r.includes("type ")?76:r.includes("interface ")?27:r.includes("struct ")?68:r.includes("trait ")?73:(r.includes("class "),9):a==="method"?o?.suffix==="type"?33:23:a==="namespace"?39:a!=="term"?null:r.includes("async def ")||r.includes("def ")?23:(t?ie(t):o?.suffix??null)==="type"?21:83}function ko(e,n={}){let{limit:t=10,scope:s,minDepth:i=3}=n,o=K(e,s),a=new Map,r=[],l=new Map,c=new Map,m=new Set,u=[],d=0;for(let x of o.keys()){if(l.has(x))continue;let L=[],w=(o.get(x)??new Set).values();for(l.set(x,d),c.set(x,d),d+=1,u.push(x),m.add(x),L.push({node:x,iter:w,pendingChild:null});L.length>0;){let $=L[L.length-1];if($.pendingChild!==null){let T=$.pendingChild;$.pendingChild=null,c.set($.node,Math.min(c.get($.node),c.get(T)))}let q=$.iter.next();if(q.done){if(c.get($.node)===l.get($.node)){let T=[];for(;;){let _e=u.pop();if(m.delete(_e),T.push(_e),a.set(_e,r.length),_e===$.node)break}r.push(T)}L.pop();continue}let B=q.value;if(l.has(B))m.has(B)&&c.set($.node,Math.min(c.get($.node),l.get(B)));else{l.set(B,d),c.set(B,d),d+=1,u.push(B),m.add(B);let T=(o.get(B)??new Set).values();$.pendingChild=B,L.push({node:B,iter:T,pendingChild:null})}}}let g=new Map,p=new Array(r.length);for(let x=0;x<r.length;x++)p[x]=r[x].length,g.set(x,new Set);for(let[x,L]of o){let w=a.get(x);for(let $ of L){let q=a.get($);q!==w&&g.get(w).add(q)}}let f=new Array(r.length),y=new Array(r.length);for(let x=0;x<r.length;x++){let L=[],w=0;for(let $ of g.get(x)){let q=y[$];q>w&&(w=q,L=f[$])}f[x]=[x,...L],y[x]=p[x]+w}function h(x){return f[x]}let b=r.map(x=>[...x].sort()),_=new Set,S=[];for(let x=0;x<r.length;x++){let L=h(x),w=[];for(let q of L)w.push(...b[q]);if(w.length<i)continue;let $=w.join(" ");_.has($)||(_.add($),S.push({chain:w,depth:w.length}))}return S.sort((x,L)=>L.depth-x.depth),S.slice(0,t)}function Oo(e,n){let t=k(e,n);if(!t)return[];let s=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
|
|
703
|
-
WHERE id = ? LIMIT 1`,t.symbolId);if(!s)return[];let i=[{symbol:s.symbol,shortName:I(s.symbol),depth:0}],o=s.enclosing_symbol,a=1,r=new Set([s.symbol]);for(;o&&!r.has(o)&&a<20;){r.add(o);let u=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",o);if(!u)break;i.push({symbol:u.symbol,shortName:I(u.symbol),depth:a}),o=u.enclosing_symbol,a++}if(i.length>1)return i;let l=V(s.symbol);if("kind"in l)return i;let c=l.descriptors;if(c.length<=1)return i;let m=[i[0]];for(let u=c.length-2,d=1;u>=0;u--,d++){let p=c.slice(0,u+1).map(f=>f.suffix==="method"?`${f.name}()`:f.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)$/,"")).join(":");m.push({symbol:p,shortName:p,depth:d})}return m}function $o(e,n){let t=k(e,n);if(!t)return null;let s=he(e,t,{limit:50}),i=nm(ne(e,t,{limit:50}));return{symbol:t.symbol,shortName:I(t.symbol),callers:s.map(o=>({symbol:o.symbol,shortName:I(o.symbol),file:o.file})),callees:i.map(o=>({symbol:o.symbol,shortName:I(o.symbol),file:o.file}))}}function nm(e){let n=new Set,t=[];for(let s of e){let i=`${s.symbol}|${s.file}`;n.has(i)||(n.add(i),t.push(s))}return t}function xt(e,n){let t=new Set;for(let s of e)n.has(s)&&t.add(s);return t}function It(e,n){let t=new Set;for(let s of e)n.has(s)||t.add(s);return t}function Po(e,n){if(e.size===0&&n.size===0)return 0;let t=0;for(let i of e)n.has(i)&&(t+=1);let s=e.size+n.size-t;return s===0?0:t/s}function Gn(e){let n=e.length;if(n===0)return new Map;let t=new Map;for(let i of e)for(let o of i)t.set(o,(t.get(o)??0)+1);let s=new Map;for(let[i,o]of t)s.set(i,Math.log(n/o));return s}function sm(e){let n=[...e.values()].sort((s,i)=>s-i);if(n.length===0)return 0;let t=Math.floor(n.length/2);return n.length%2===0?(n[t-1]+n[t])/2:n[t]}function Mo(e,n,t){let s=xt(e,n);if(s.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let i=0,o=0,a=0,r=new Set([...e,...n]);for(let g of r){let p=t.get(g)??0,f=e.has(g)?p:0,y=n.has(g)?p:0;i+=f*y,o+=f*f,a+=y*y}let l=Math.sqrt(o)*Math.sqrt(a),c=l>0?i/l:0,m=sm(t),u=[],d=[];for(let g of s)(t.get(g)??0)>=m?u.push(g):d.push(g);return u.sort((g,p)=>(t.get(p)??0)-(t.get(g)??0)),{similarity:c,significantShared:u,trivialShared:d}}function Fo(e,n,t={}){let{minSimilarity:s=.4,limit:i=20}=t,o=om(e,n);if(!o)return[];if(!j(o.symbol))return[];let a=im(e,o,s);return a.length>0?a.slice(0,i):rm(e,n,{minSimilarity:s,limit:i})}function im(e,n,t){let s=Ao(e,{minCallees:3,excludeSymbol:n.symbol}),i=Gn([n,...s].map(a=>a.callees)),o=[];for(let a of s){if(a.callees.size<3)continue;let r=To(n,a,i,{minSimilarity:t,requireSignificantShared:1,requireSharedCount:0});r&&o.push(r)}return o.sort((a,r)=>r.similarity-a.similarity),o}function To(e,n,t,s){let{similarity:i,significantShared:o}=Mo(e.callees,n.callees,t);if(i<s.minSimilarity)return null;let a=xt(e.callees,n.callees).size;if(o.length<s.requireSignificantShared&&a<s.requireSharedCount)return null;let r=o.length>0?o:[...xt(e.callees,n.callees)];return{symbolA:e.symbol,shortNameA:I(e.symbol),fileA:e.file,symbolB:n.symbol,shortNameB:I(n.symbol),fileB:n.file,similarity:i,sharedCallees:r.map(I),uniqueToA:[...It(e.callees,n.callees)].map(I),uniqueToB:[...It(n.callees,e.callees)].map(I)}}function on(e,n={}){let{minSimilarity:t=.5,limit:s=20,scope:i,minCallees:o=4,crossFileOnly:a=!1}=n,r=Ao(e,{minCallees:o,scope:i}),l=Gn(r.map(p=>p.callees)),c=new Map;for(let p of r)for(let f of p.callees)c.set(f,(c.get(f)??0)+1);let m=Math.max(8,Math.ceil(Math.sqrt(r.length))),u=new Map;for(let p=0;p<r.length;p+=1)for(let f of r[p].callees){if((c.get(f)??0)>m)continue;let y=u.get(f);y||(y=[],u.set(f,y)),y.push(p)}let d=[],g=new Set;e:for(let p=0;p<r.length;p+=1){let f=r[p],y=new Set;for(let h of f.callees){let b=u.get(h);if(b)for(let _ of b)_>p&&y.add(_)}for(let h of y){let b=`${p}|${h}`;if(g.has(b))continue;g.add(b);let _=r[h];if(a&&f.file===_.file)continue;if(f.paramCount>=0&&_.paramCount>=0){let x=Math.abs(f.paramCount-_.paramCount),L=Math.max(2,Math.ceil(Math.max(f.paramCount,_.paramCount)*.5));if(x>L)continue}let S=To(f,_,l,{minSimilarity:t,requireSignificantShared:2,requireSharedCount:4});if(S&&(d.push(S),d.length>s*5))break e}}return d.sort((p,f)=>f.similarity-p.similarity),d.slice(0,s)}function om(e,n){let t=k(e,n);if(!t)return null;let s=ne(e,t);return{symbol:t.symbol,file:t.relativePath,callees:new Set(s.map(i=>i.symbol)),paramCount:Pn(e,t.relativePath,t.startLine,t.endLine)?.paramCount??-1}}function Ao(e,n){let{minCallees:t,scope:s,excludeSymbol:i}=n,o=Y(e,s).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>r.isFunctionLike).filter(r=>i===void 0||r.symbol!==i).filter(r=>r.endLine-r.startLine+1>=5).filter(r=>U(r.relativePath)!=="test").filter(r=>!G(r.symbol)).filter(r=>!pe(e,r.relativePath,r.startLine)),a=se(e,o);return o.map(r=>({symbol:r.symbol,file:r.relativePath,callees:new Set((a.get(r.symbolId)??[]).map(l=>l.symbol)),paramCount:Pn(e,r.relativePath,r.startLine,r.endLine)?.paramCount??-1})).filter(r=>r.callees.size>=t)}function rm(e,n,t){let s=am(e,n);if(!s||s.tokens.size<3)return[];let i=t.minSimilarity>=.5?t.minSimilarity:.3,o=[];for(let a of cm(e)){if(a.symbol===s.symbol||a.tokens.size<3)continue;let r=xt(s.tokens,a.tokens);if(r.size<2)continue;let l=new Set([...s.tokens,...a.tokens]),c=l.size>0?r.size/l.size:0;c<i||o.push({symbolA:s.symbol,shortNameA:I(s.symbol),fileA:s.file,symbolB:a.symbol,shortNameB:I(a.symbol),fileB:a.file,similarity:c,sharedCallees:[...r].sort(),uniqueToA:[...It(s.tokens,a.tokens)].sort(),uniqueToB:[...It(a.tokens,s.tokens)].sort()})}return o.sort((a,r)=>r.similarity-a.similarity||a.shortNameB.localeCompare(r.shortNameB)),o.slice(0,t.limit)}function am(e,n){let t=k(e,n);if(!t||!j(t.symbol))return null;let s=lm(e,t);return s?{symbol:t.symbol,file:t.relativePath,tokens:s}:null}function lm(e,n){let t=F(n.symbol),s=jo(e,n.relativePath,n.startLine,n.endLine,t),i=Bo(s,t);return i.size>0?i:null}function cm(e){return Z(e).filter(n=>n.isFunctionLike).filter(n=>U(n.relativePath)!=="test").filter(n=>!G(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:Bo(jo(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function jo(e,n,t,s,i){let o=M(e,n);if(!o)return"";let a=o.split(`
|
|
704
|
-
`);if(s>=t&&s-t<=12)return a.slice(t,s+1).join(`
|
|
705
|
-
`);let r=[new RegExp(`\\bdef\\s+${Nt(i)}\\b`),new RegExp(`\\bfun\\s+${Nt(i)}\\b`),new RegExp(`\\bfn\\s+${Nt(i)}\\b`),new RegExp(`\\bfunction\\s+${Nt(i)}\\b`),new RegExp(`\\b${Nt(i)}\\s*\\(`)],l=a.findIndex(c=>r.some(m=>m.test(c)));if(l>=0){let c=l;for(let m=l+1;m<a.length&&m<=l+8;m++){let u=a[m]??"";if(m>l&&mm(u)||(c=m,u.trim()===""&&m>l+1))break}return a.slice(l,c+1).join(`
|
|
706
|
-
`)}return a.slice(t,Math.min(a.length,t+8)).join(`
|
|
707
|
-
`)}function Bo(e,n){if(!e)return new Set;let t=new Set(["public","private","protected","final","static","class","def","fun","fn","function","return","string","bool","boolean","void","unit","self","this","new","const","let","var","end","pub"]),s=um(n),o=e.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().split(/\s+/).map(a=>a.trim()).filter(a=>a.length>1).filter(a=>!t.has(a)).filter(a=>!s.has(a));return new Set(o)}function um(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(n=>n.toLowerCase()).filter(n=>n.length>1))}function mm(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function Nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ho(e,n={}){let{minSimilarity:t=.5,limit:s=20,scope:i,filePattern:o}=n,a=n.minDeps??(o?1:3),r=dm(e,{scope:i,minDeps:a}),l=[];if(o){let c=r.find(m=>m.file.includes(o));if(!c)return[];for(let m of r){if(m.file===c.file)continue;let u=Wo(c,m,t);u&&l.push(u)}}else for(let c=0;c<r.length;c++){for(let m=c+1;m<r.length;m++){let u=Wo(r[c],r[m],t);u&&l.push(u)}if(l.length>s*5)break}return l.sort((c,m)=>m.similarity-c.similarity),l.slice(0,s)}function dm(e,n){let{scope:t,minDeps:s}=n,i=K(e,t),o=pm(i),a=[];for(let[r,l]of i)l.size>=s&&a.push({file:r,deps:new Set([...l].filter(c=>!o.has(c)))});return a}function pm(e){let n=new Set,t=e.size;if(t===0)return n;let s=new Map;for(let i of e.values())for(let o of i)s.set(o,(s.get(o)??0)+1);for(let[i,o]of s)o>=5&&o/t>.3&&n.add(i);return n}function Wo(e,n,t){let s=new Set;for(let r of e.deps)n.deps.has(r)&&s.add(r);if(s.size<3||e.deps.size<4||n.deps.size<4)return null;let i=Po(e.deps,n.deps);if(i<t)return null;let o=[];for(let r of e.deps)n.deps.has(r)||o.push(r);let a=[];for(let r of n.deps)e.deps.has(r)||a.push(r);return{fileA:e.file,fileB:n.file,similarity:i,sharedDeps:[...s],uniqueToA:o,uniqueToB:a}}function Uo(e,n={}){let{minSimilarity:t=.5,limit:s=15,scope:i,minChainLength:o=3,maxChainLength:a=8}=n,r=K(e,i),l=fm(r,o,a);if(l.length===0)return[];let c=new Map,m=new Map;for(let b of l){let _=new Set;for(let S of b)_.has(S)||(c.set(S,(c.get(S)??0)+1),_.add(S));for(let S=Math.max(0,b.length-2);S<b.length;S++)m.set(b[S],(m.get(b[S])??0)+1)}let u=l.length*.9,d=l.length*.8,g=new Set;for(let[b,_]of c)_>u&&g.add(b);for(let[b,_]of m)_>d&&g.add(b);let p=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let b of c.keys()){let _=b.split("/").pop()??"";p.includes(_)&&g.add(b)}let f=[];for(let b of l){let _=b.filter(S=>!g.has(S));_.length>=2&&f.push({original:b,filtered:_})}if(f.length<2)return[];let y=[];for(let b=0;b<f.length;b++){for(let _=b+1;_<f.length;_++){let S=f[b],x=f[_],L=new Set(S.filtered),w=!1;for(let ce of x.filtered)if(L.has(ce)){w=!0;break}if(!w)continue;let{distance:$,ops:q}=gm(S.filtered,x.filtered),B=Math.max(S.filtered.length,x.filtered.length);if(B===0)continue;let T=1-$/B;if(T<t||$===0)continue;let _e=q.filter(ce=>ce.type==="substitute").map(ce=>({index:ce.indexA,nodeA:S.filtered[ce.indexA],nodeB:x.filtered[ce.indexB]}));if(_e.length===0||q.filter(ce=>ce.type==="match").length<2)continue;let Et=hm(S.original,x.original),bn=ym(S.original,x.original);y.push({chainA:S.original,chainB:x.original,similarity:T,editDistance:$,divergencePoints:_e,commonPrefix:Et,commonSuffix:bn})}if(y.length>s*10)break}y.sort((b,_)=>Math.abs(_.similarity-b.similarity)>.01?_.similarity-b.similarity:b.divergencePoints.length-_.divergencePoints.length);let h=[];for(let b of y)if(h.some(S=>Jo(b.chainA,S.chainA)&&Jo(b.chainB,S.chainB))||h.push(b),h.length>=s)break;return h}function fm(e,n,t){let s=[];for(let o of e.keys()){if(s.length>=500)break;qo(e,o,[o],new Set([o]),n,t,s,500)}return s}function qo(e,n,t,s,i,o,a,r){if(a.length>=r)return;if(t.length>=o){t.length>=i&&a.push([...t]);return}let l=e.get(n);if(!l||l.size===0){t.length>=i&&a.push([...t]);return}let c=!1;for(let m of l)if(!s.has(m)&&(s.add(m),t.push(m),qo(e,m,t,s,i,o,a,r),t.pop(),s.delete(m),c=!0,a.length>=r))return;!c&&t.length>=i&&a.push([...t])}function gm(e,n){let t=e.length,s=n.length,i=Array.from({length:t+1},()=>Array(s+1).fill(0));for(let l=0;l<=t;l++)i[l][0]=l;for(let l=0;l<=s;l++)i[0][l]=l;for(let l=1;l<=t;l++)for(let c=1;c<=s;c++)e[l-1]===n[c-1]?i[l][c]=i[l-1][c-1]:i[l][c]=1+Math.min(i[l-1][c],i[l][c-1],i[l-1][c-1]);let o=[],a=t,r=s;for(;a>0||r>0;)a>0&&r>0&&e[a-1]===n[r-1]?(o.unshift({type:"match",indexA:a-1,indexB:r-1}),a--,r--):a>0&&r>0&&i[a][r]===i[a-1][r-1]+1?(o.unshift({type:"substitute",indexA:a-1,indexB:r-1}),a--,r--):r>0&&i[a][r]===i[a][r-1]+1?(o.unshift({type:"insert",indexA:a,indexB:r-1}),r--):(o.unshift({type:"delete",indexA:a-1,indexB:r}),a--);return{distance:i[t][s],ops:o}}function hm(e,n){let t=[];for(let s=0;s<Math.min(e.length,n.length)&&e[s]===n[s];s++)t.push(e[s]);return t}function ym(e,n){let t=[],s=e.length-1,i=n.length-1;for(;s>=0&&i>=0&&e[s]===n[i];)t.unshift(e[s]),s--,i--;return t}function Jo(e,n){if(e.length>n.length)return!1;let t=n.join("\u2192"),s=e.join("\u2192");return t.includes(s)}function an(e,n={}){let{scope:t,minLoc:s=10,minCallees:i=6,limit:o=20}=n,a=Y(e,t).filter(c=>!e.isIgnored(c.relativePath)).filter(c=>rn(c)>=s&&j(c.symbol)).filter(c=>!(c.relativePath.split("/").pop()??"").includes("types")).filter(c=>U(c.relativePath)!=="test").filter(c=>!G(c.symbol)).filter(c=>!pe(e,c.relativePath,c.startLine)).sort((c,m)=>rn(m)-rn(c)),r=se(e,a),l=[];for(let c of a){let m=r.get(c.symbolId)??[],u=new Set(m.map(h=>h.symbol));if(u.size<i)continue;let d=new Map;for(let h of u)d.set(h,new Set);let g=new Map;for(let h of m)g.has(h.chunkId)||g.set(h.chunkId,new Set),g.get(h.chunkId).add(h.symbol);for(let h of g.values()){let b=[...h];for(let _=0;_<b.length;_++)for(let S=_+1;S<b.length;S++)d.get(b[_]).add(b[S]),d.get(b[S]).add(b[_])}let p=new Set,f=[];for(let h of u){if(p.has(h))continue;let b=new Set,_=[h];for(;_.length>0;){let S=_.pop();if(!p.has(S)){p.add(S),b.add(S);for(let x of d.get(S)??[])p.has(x)||_.push(x)}}f.push(b)}if(f.length<2)continue;let y=f.filter(h=>h.size>=3).map(h=>{let b=new Set;for(let L of f)if(L!==h)for(let w of L)b.add(w);let _=0;for(let L of h)for(let w of d.get(L)??[])b.has(w)&&_++;let S=h.size*b.size,x=S>0?1-_/S:1;return{callees:[...h].map(I),isolation:x}}).filter(h=>h.isolation>.5).sort((h,b)=>b.isolation-h.isolation);y.length>0&&l.push({symbol:c.symbol,shortName:I(c.symbol),relativePath:c.relativePath,startLine:c.startLine,endLine:c.endLine,loc:rn(c),totalCallees:u.size,clusters:y})}return l.sort((c,m)=>m.clusters.length-c.clusters.length||m.loc-c.loc),l.slice(0,o)}function rn(e){return e.endLine-e.startLine+1}function zo(e,n,t={}){let{maxDepth:s=5,scope:i}=t,o=k(e,n);if(!o)return[];let a=[],r=new Set([o.symbolId]),l=new Set,c=[o];for(let m=1;m<=s&&c.length!==0;m++){let u=[];for(let d of c)for(let g of bm(e,d,i)){let p=`${g.file}|${g.shortName}`;if(g.symbolId!==null){if(r.has(g.symbolId))continue;r.add(g.symbolId)}else if(l.has(p))continue;l.add(p),a.push({symbol:g.symbol,shortName:g.shortName,file:g.file,depth:m}),g.symbolId!==null&&g.symbolMatch&&u.push(g.symbolMatch)}c=u}return a.sort((m,u)=>m.depth-u.depth||m.file.localeCompare(u.file)),a}function bm(e,n,t){let s=he(e,n,{limit:500}).filter(m=>!e.isIgnored(m.file)).filter(m=>!t||m.file.includes(t)),i=new Set(s.map(m=>m.file)),o=ye(e).get(n.symbolId)??new Set,a=[];for(let m of o){if(i.has(m)||e.isIgnored(m)||t&&!m.includes(t))continue;let u=A(e,m),d=u.length>0?fe(u,u[0].startLine):null;a.push({symbol:d?.symbol??m,file:m})}let r=[...s,...a],l=[],c=new Set;for(let m of r){let u=Xe(e,m.symbol);if(!u){let g=`${m.file}|${m.symbol}`;if(c.has(g))continue;c.add(g),l.push({symbolId:null,symbol:m.symbol,shortName:I(m.symbol),file:m.file,symbolMatch:null});continue}if(u.symbolId===n.symbolId||e.isIgnored(u.relativePath))continue;let d=`${u.symbolId}|${u.relativePath}`;c.has(d)||(c.add(d),l.push({symbolId:u.symbolId,symbol:u.symbol,shortName:I(u.symbol),file:u.relativePath,symbolMatch:u}))}return l}function Vo(e,n){let t=ee(e,n);if(!t)return null;let s=e.get(`SELECT id, relative_path FROM documents
|
|
806
|
+
LIMIT ?`,n).filter(o=>!e.isIgnored(o.file1)&&!e.isIgnored(o.file2)).map(o=>({file1:o.file1,file2:o.file2,sharedSymbols:o.shared}))}function In(e,t={}){let{scope:n,maxDepth:r=10}=t,i=Y(e,n),s=[],o=new Set,a=new Set,l=[];function c(d,m){if(m>r)return;if(a.has(d)){let p=l.indexOf(d);if(p!==-1){let f=l.slice(p).concat(d),y=f.indexOf(f.reduce((F,T)=>F<T?F:T)),L=[...f.slice(y,-1),...f.slice(0,y),f[y]],k=L.join(" -> ");u.has(k)||(u.add(k),s.push({path:L,kind:Th(L)}))}return}if(o.has(d))return;o.add(d),a.add(d),l.push(d);let g=i.get(d);if(g)for(let p of g)c(p,m+1);l.pop(),a.delete(d)}let u=new Set;for(let d of i.keys())o.has(d)||c(d,0);return s.sort((d,m)=>d.kind!==m.kind?d.kind==="real"?-1:1:d.path.length-m.path.length),s}function Th(e){for(let r of e){let i=ee(r);if(i==="test"||i==="barrel"||i==="entry")return"module-hierarchy"}if(e.length!==3)return"real";let[t,n]=e;return!t||!n?"real":xn(t)||xn(n)||qo(t,n)||qo(n,t)||zo(t,n)||zo(n,t)||ee(t)==="entry"||ee(n)==="entry"?"module-hierarchy":"real"}function qo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=t.replace(/\.rs$/,"/");return e.startsWith(n)?!e.slice(n.length).includes("/"):!1}function zo(e,t){if(!/\.rs$/.test(e)||!/\.rs$/.test(t))return!1;let n=e.replace(/\.rs$/,""),r=t.replace(/\.rs$/,"");if(n===r+"_tests"||n===r+"/tests")return!0;let i=e.split("/"),s=t.split("/");if(i.length===s.length&&i.includes("tests")&&s.includes("src")){let o=i[i.length-1],a=s[s.length-1];if(o&&o===a)return!0}return!1}function Go(e,t={}){let{limit:n=20,scope:r,minFanIn:i=2,minFanOut:s=2}=t;return new C(e).productionCallableDefinitions({scope:r,requireCallableSymbol:!0,includeSuppressed:!0}).map(l=>$h(e,l)).filter(l=>l.fanIn>=i&&l.fanOut>=s).sort((l,c)=>c.score-l.score||c.fanIn-l.fanIn).slice(0,n)}function $h(e,t){let n=new Set(ie(e,t,{limit:500}).map(i=>i.file)).size,r=new Set(Z(e,t,{limit:500}).filter(i=>i.file!==t.relativePath).map(i=>`${i.symbol}|${i.file}`)).size;return{symbol:t.symbol,shortName:h(t.symbol),fanIn:n,fanOut:r,score:n*r,definedIn:t.relativePath}}function Rn(e,t={}){let{scope:n,minLoc:r=3}=t,i=new C(e),s=i.productionCallableDefinitions({scope:n,minLoc:r,excludeEntrySurfaces:!0,excludeRustTraitImplMembers:!0,includeSuppressed:!0}),o=i.crossFileCallerMap(s),a=i.sourceFallbackCallerFiles(s),l=new Set([...o.keys(),...a.keys()]),c=new Map;for(let p of s){let f=D(p.symbol);if(!f)continue;let y=c.get(f)??[];y.push(p.symbolId),c.set(f,y)}let u=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of u){if(e.isIgnored(p.relative_path)||M(p.relative_path)!=="rust")continue;let f=st(e,p.relative_path);for(let y of f){let L=c.get(y);if(L)for(let k of L)l.add(k)}}let d=new Map(s.map(p=>[p.symbolId,p.symbol])),m=i.calleeMap(s,{additive:!0}),g=new Set([...m.entries()].filter(([p,f])=>{let y=d.get(p);return f.some(L=>L.symbol!==y)}).map(([p])=>p));return s.filter(p=>!l.has(p.symbolId)).filter(p=>!g.has(p.symbolId)).sort((p,f)=>f.endLine-f.startLine-(p.endLine-p.startLine)||p.relativePath.localeCompare(f.relativePath)||p.startLine-f.startLine).map(p=>({symbol:p.symbol,shortName:h(p.symbol),relativePath:p.relativePath,startLine:p.startLine,endLine:p.endLine,loc:p.endLine-p.startLine+1}))}var wr={0:"UnspecifiedKind",1:"AbstractMethod",2:"Accessor",3:"Array",4:"Assertion",5:"AssociatedType",6:"Attribute",7:"Axiom",8:"Boolean",9:"Class",10:"Constant",11:"Constructor",12:"Contract",13:"DataFamily",14:"DefinitionMacro",15:"Delegate",16:"Enum",17:"EnumMember",18:"Error",19:"Event",20:"Fact",21:"Field",22:"File",23:"Function",24:"Getter",25:"Grammar",26:"Instance",27:"Interface",28:"Key",29:"Lang",30:"Lemma",31:"Library",32:"Macro",33:"Method",34:"MethodAlias",35:"MethodReceiver",36:"MethodSpecification",37:"Message",38:"Modifier",39:"Module",40:"Namespace",41:"Null",42:"Number",43:"Object",44:"Operator",45:"Package",46:"PackageObject",47:"Parameter",48:"ParameterLabel",49:"Pattern",50:"Predicate",51:"Property",52:"Protocol",53:"ProtocolMethod",54:"PureVirtualMethod",55:"Quasiquoter",56:"SelfParameter",57:"Setter",58:"Signature",59:"SingletonClass",60:"SingletonMethod",61:"StaticDataMember",62:"StaticEvent",63:"StaticField",64:"StaticMethod",65:"StaticProperty",66:"StaticVariable",67:"String",68:"Struct",69:"Subscript",70:"Tactic",71:"Theorem",72:"ThisParameter",73:"Trait",74:"TraitMethod",75:"Type",76:"TypeAlias",77:"TypeClass",78:"TypeClassMethod",79:"TypeFamily",80:"TypeParameter",81:"Union",82:"Value",83:"Variable"},kr=new Map;for(let[e,t]of Object.entries(wr))kr.set(t.toLowerCase(),Number(e));function Ah(e){let t=parseInt(e,10);if(!isNaN(t))return t;let n=e.toLowerCase(),r=kr.get(n);if(r!==void 0)return r;for(let[i,s]of kr)if(i.includes(n))return s;return null}function Ko(e,t,n={}){let{scope:r,limit:i=100}=n,s=Ah(t);return s===null?[]:Qo(e,r).map(a=>({row:a,resolvedKind:Xo(a)})).filter(a=>a.resolvedKind===s).slice(0,i).map(({row:a,resolvedKind:l})=>({symbol:a.symbol,shortName:h(a.symbol),kind:l,kindName:wr[l]??"Unknown",relativePath:a.relative_path,startLine:a.start_line,endLine:a.end_line}))}function Yo(e,t={}){let n=new Map;for(let r of Qo(e,t.scope)){let i=Xo(r);i===null||i===0||n.set(i,(n.get(i)??0)+1)}return[...n.entries()].sort((r,i)=>i[1]-r[1]||r[0]-i[0]).map(([r,i])=>({kind:r,kindName:wr[r]??"Unknown",count:i}))}function Qo(e,t){return oe(e,{scope:t}).map(jh)}function jh(e){return{symbol:e.symbol,kind:e.kind,documentation:e.documentation,enclosing_symbol:e.enclosingSymbol,relative_path:e.relativePath,start_line:e.startLine,end_line:e.endLine}}function Xo(e){return e.kind!==null&&e.kind!==0?Bh(e.kind,e.symbol,e.documentation):Wh(e.symbol,e.documentation,e.enclosing_symbol)}function Bh(e,t,n){let r=(n??"").toLowerCase();if(V(t)==="type"){if(r.includes("type "))return 76;if(r.includes("interface "))return 27;if(r.includes("struct "))return 68;if(r.includes("trait "))return 73;if(r.includes("class "))return 9}return e}function Wh(e,t,n){let r=H(e);if("kind"in r)return null;let i=r.descriptors,s=i[i.length-2]??null,o=V(e),a=(t??"").toLowerCase();return o==="type"?a.includes("type ")?76:a.includes("interface ")?27:a.includes("struct ")?68:a.includes("trait ")?73:(a.includes("class "),9):o==="method"?s?.suffix==="type"?33:23:o==="namespace"?39:o!=="term"?null:a.includes("async def ")||a.includes("def ")?23:(n?V(n):s?.suffix??null)==="type"?21:83}function Zo(e,t={}){let{limit:n=10,scope:r,minDepth:i=3}=t,s=Y(e,r),o=new Map,a=[],l=new Map,c=new Map,u=new Set,d=[],m=0;for(let R of s.keys()){if(l.has(R))continue;let _=[],O=(s.get(R)??new Set).values();for(l.set(R,m),c.set(R,m),m+=1,d.push(R),u.add(R),_.push({node:R,iter:O,pendingChild:null});_.length>0;){let N=_[_.length-1];if(N.pendingChild!==null){let Ke=N.pendingChild;N.pendingChild=null,c.set(N.node,Math.min(c.get(N.node),c.get(Ke)))}let z=N.iter.next();if(z.done){if(c.get(N.node)===l.get(N.node)){let Ke=[];for(;;){let $t=d.pop();if(u.delete($t),Ke.push($t),o.set($t,a.length),$t===N.node)break}a.push(Ke)}_.pop();continue}let de=z.value;if(l.has(de))u.has(de)&&c.set(N.node,Math.min(c.get(N.node),l.get(de)));else{l.set(de,m),c.set(de,m),m+=1,d.push(de),u.add(de);let Ke=(s.get(de)??new Set).values();N.pendingChild=de,_.push({node:de,iter:Ke,pendingChild:null})}}}let g=new Map,p=new Array(a.length);for(let R=0;R<a.length;R++)p[R]=a[R].length,g.set(R,new Set);for(let[R,_]of s){let O=o.get(R);for(let N of _){let z=o.get(N);z!==O&&g.get(O).add(z)}}let f=new Array(a.length),y=new Array(a.length);for(let R=0;R<a.length;R++){let _=[],O=0;for(let N of g.get(R)){let z=y[N];z>O&&(O=z,_=f[N])}f[R]=[R,..._],y[R]=p[R]+O}function L(R){return f[R]}let k=a.map(R=>[...R].sort()),F=new Set,T=[];for(let R=0;R<a.length;R++){let _=L(R),O=[];for(let z of _)O.push(...k[z]);if(O.length<i)continue;let N=O.join(" ");F.has(N)||(F.add(N),T.push({chain:O,depth:O.length}))}return T.sort((R,_)=>_.depth-R.depth),T.slice(0,n)}function ea(e,t){let n=E(e,t);if(!n)return[];let r=e.get(`SELECT symbol, enclosing_symbol FROM global_symbols
|
|
807
|
+
WHERE id = ? LIMIT 1`,n.symbolId);if(!r)return[];let i=[{symbol:r.symbol,shortName:h(r.symbol),depth:0}],s=r.enclosing_symbol,o=1,a=new Set([r.symbol]);for(;s&&!a.has(s)&&o<20;){a.add(s);let d=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",s);if(!d)break;i.push({symbol:d.symbol,shortName:h(d.symbol),depth:o}),s=d.enclosing_symbol,o++}if(i.length>1)return i;let l=H(r.symbol);if("kind"in l)return i;let c=l.descriptors;if(c.length<=1)return i;let u=[i[0]];for(let d=c.length-2,m=1;d>=0;d--,m++){let p=c.slice(0,d+1).map(f=>f.suffix==="method"?`${f.name}()`:f.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)$/,"")).join(":");u.push({symbol:p,shortName:p,depth:m})}return u}function ta(e,t){let n=E(e,t);if(!n)return null;let r=ie(e,n,{limit:50}),i=Hh(Z(e,n,{limit:50,additive:!0,callableOnly:!0}));return{symbol:n.symbol,shortName:h(n.symbol),callers:r.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file})),callees:i.map(s=>({symbol:s.symbol,shortName:h(s.symbol),file:s.file}))}}function Hh(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function wt(e,t){let n=new Set;for(let r of e)t.has(r)&&n.add(r);return n}function Pt(e,t){let n=new Set;for(let r of e)t.has(r)||n.add(r);return n}function na(e,t){if(e.size===0&&t.size===0)return 0;let n=0;for(let i of e)t.has(i)&&(n+=1);let r=e.size+t.size-n;return r===0?0:n/r}function Pr(e){let t=e.length;if(t===0)return new Map;let n=new Map;for(let i of e)for(let s of i)n.set(s,(n.get(s)??0)+1);let r=new Map;for(let[i,s]of n)r.set(i,Math.log(t/s));return r}function Vh(e){let t=[...e.values()].sort((r,i)=>r-i);if(t.length===0)return 0;let n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function ra(e,t,n){let r=wt(e,t);if(r.size===0)return{similarity:0,significantShared:[],trivialShared:[]};let i=0,s=0,o=0,a=new Set([...e,...t]);for(let g of a){let p=n.get(g)??0,f=e.has(g)?p:0,y=t.has(g)?p:0;i+=f*y,s+=f*f,o+=y*y}let l=Math.sqrt(s)*Math.sqrt(o),c=l>0?i/l:0,u=Vh(n),d=[],m=[];for(let g of r)(n.get(g)??0)>=u?d.push(g):m.push(g);return d.sort((g,p)=>(n.get(p)??0)-(n.get(g)??0)),{similarity:c,significantShared:d,trivialShared:m}}function ia(e,t,n={}){let{minSimilarity:r=.4,limit:i=20}=n,s=qh(e,t);if(!s)return[];if(!W(s.symbol))return[];let o=Uh(e,s,r);return o.length>0?o.slice(0,i):Gh(e,t,{minSimilarity:r,limit:i})}function Uh(e,t,n){let r=oa(e,{minCallees:3,excludeSymbol:t.symbol}),i=Pr([t,...r].map(o=>o.callees)),s=[];for(let o of r){if(o.callees.size<3)continue;let a=sa(t,o,i,{minSimilarity:n,requireSignificantShared:1,requireSharedCount:0});a&&s.push(a)}return s.sort((o,a)=>a.similarity-o.similarity),s}function sa(e,t,n,r){let{similarity:i,significantShared:s}=ra(e.callees,t.callees,n);if(i<r.minSimilarity)return null;let o=wt(e.callees,t.callees).size;if(s.length<r.requireSignificantShared&&o<r.requireSharedCount)return null;let a=s.length>0?s:[...wt(e.callees,t.callees)];return{symbolA:e.symbol,shortNameA:h(e.symbol),fileA:e.file,symbolB:t.symbol,shortNameB:h(t.symbol),fileB:t.file,similarity:i,similarityBasis:"callees",sharedCallees:a.map(h),uniqueToA:[...Pt(e.callees,t.callees)].map(h),uniqueToB:[...Pt(t.callees,e.callees)].map(h)}}function Cn(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,minCallees:s=4,crossFileOnly:o=!1}=t,a=oa(e,{minCallees:s,scope:i}),l=Pr(a.map(p=>p.callees)),c=new Map;for(let p of a)for(let f of p.callees)c.set(f,(c.get(f)??0)+1);let u=Math.max(8,Math.ceil(Math.sqrt(a.length))),d=new Map;for(let p=0;p<a.length;p+=1)for(let f of a[p].callees){if((c.get(f)??0)>u)continue;let y=d.get(f);y||(y=[],d.set(f,y)),y.push(p)}let m=[],g=new Set;e:for(let p=0;p<a.length;p+=1){let f=a[p],y=new Set;for(let L of f.callees){let k=d.get(L);if(k)for(let F of k)F>p&&y.add(F)}for(let L of y){let k=`${p}|${L}`;if(g.has(k))continue;g.add(k);let F=a[L];if(o&&f.file===F.file)continue;if(f.paramCount>=0&&F.paramCount>=0){let R=Math.abs(f.paramCount-F.paramCount),_=Math.max(2,Math.ceil(Math.max(f.paramCount,F.paramCount)*.5));if(R>_)continue}let T=sa(f,F,l,{minSimilarity:n,requireSignificantShared:2,requireSharedCount:4});if(T&&(m.push(T),m.length>r*5))break e}}return m.sort((p,f)=>f.similarity-p.similarity),m.slice(0,r)}var Jh=["ScipDatabase#all","ScipDatabase#get","ScipDatabase#prepare","ScipDatabase#pathExclusionsFor","ScipDatabase#isIgnored","ScipDatabase#symbolNoiseFor","PerDbValue#get","PerDbValue#has",":storage:db:ScipDatabase:all",":storage:db:ScipDatabase:get",":storage:db:ScipDatabase:prepare",":storage:db:ScipDatabase:pathExclusionsFor",":storage:db:ScipDatabase:isIgnored",":storage:db:ScipDatabase:symbolNoiseFor",":storage:per-db-cache:PerDbValue:get",":storage:per-db-cache:PerDbValue:has"];function qh(e,t){let n=E(e,t),r=new C(e);if(!n)return null;let i=Z(e,n);return{symbol:n.symbol,file:n.relativePath,callees:aa(i.map(s=>s.symbol)),paramCount:r.callableSignature(n)?.paramCount??-1}}function oa(e,t){let{minCallees:n,scope:r,excludeSymbol:i}=t,s=new C(e),o=s.productionCallableDefinitions({scope:r,minLoc:5,excludeSymbol:i}),a=s.calleeMap(o);return o.map(l=>({symbol:l.symbol,file:l.relativePath,callees:aa((a.get(l.symbolId)??[]).map(c=>c.symbol)),paramCount:s.callableSignature(l)?.paramCount??-1})).filter(l=>l.callees.size>=n)}function aa(e){return new Set([...e].filter(t=>!zh(t)))}function zh(e){return Jh.some(t=>e.includes(t))}function Gh(e,t,n){let r=Kh(e,t);if(!r||r.tokens.size<3)return[];let i=n.minSimilarity>=.5?n.minSimilarity:.3,s=[];for(let o of Qh(e)){if(o.symbol===r.symbol||o.tokens.size<3)continue;let a=wt(r.tokens,o.tokens);if(a.size<2)continue;let l=new Set([...r.tokens,...o.tokens]),c=l.size>0?a.size/l.size:0;c<i||s.push({symbolA:r.symbol,shortNameA:h(r.symbol),fileA:r.file,symbolB:o.symbol,shortNameB:h(o.symbol),fileB:o.file,similarity:c,similarityBasis:"source-tokens",sharedCallees:[...a].sort(),uniqueToA:[...Pt(r.tokens,o.tokens)].sort(),uniqueToB:[...Pt(o.tokens,r.tokens)].sort()})}return s.sort((o,a)=>a.similarity-o.similarity||o.shortNameB.localeCompare(a.shortNameB)),s.slice(0,n.limit)}function Kh(e,t){let n=E(e,t);if(!n||!W(n.symbol))return null;let r=Yh(e,n);return r?{symbol:n.symbol,file:n.relativePath,tokens:r}:null}function Yh(e,t){let n=D(t.symbol),r=la(e,t.relativePath,t.startLine,t.endLine,n),i=ca(r,n);return i.size>0?i:null}function Qh(e){let t=new C(e);return t.scopedDefinitions().filter(n=>n.isFunctionLike).filter(n=>t.fileKind(n.relativePath)!=="test").filter(n=>!ke(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:ca(la(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function la(e,t,n,r,i){let s=w(e,t);if(!s)return"";let o=s.split(`
|
|
808
|
+
`);if(r>=n&&r-n<=12)return o.slice(n,r+1).join(`
|
|
809
|
+
`);let a=[new RegExp(`\\bdef\\s+${Ot(i)}\\b`),new RegExp(`\\bfun\\s+${Ot(i)}\\b`),new RegExp(`\\bfn\\s+${Ot(i)}\\b`),new RegExp(`\\bfunction\\s+${Ot(i)}\\b`),new RegExp(`\\b${Ot(i)}\\s*\\(`)],l=o.findIndex(c=>a.some(u=>u.test(c)));if(l>=0){let c=l;for(let u=l+1;u<o.length&&u<=l+8;u++){let d=o[u]??"";if(u>l&&Zh(d)||(c=u,d.trim()===""&&u>l+1))break}return o.slice(l,c+1).join(`
|
|
810
|
+
`)}return o.slice(n,Math.min(o.length,n+8)).join(`
|
|
811
|
+
`)}function ca(e,t){if(!e)return new Set;let n=new Set(["public","private","protected","final","static","class","def","fun","fn","function","return","string","bool","boolean","void","unit","self","this","new","const","let","var","end","pub"]),r=Xh(t),s=e.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().split(/\s+/).map(o=>o.trim()).filter(o=>o.length>1).filter(o=>!n.has(o)).filter(o=>!r.has(o));return new Set(s)}function Xh(e){return new Set(e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9_]+|_/).map(t=>t.toLowerCase()).filter(t=>t.length>1))}function Zh(e){return/^\s*(?:def|fun|fn|function|class|trait|module|object|enum|interface|public|private|protected)\b/.test(e)}function Ot(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function da(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,filePattern:s}=t,o=t.minDeps??(s?1:3),a=ey(e,{scope:i,minDeps:o}),l=[];if(s){let c=a.find(u=>u.file.includes(s));if(!c)return[];for(let u of a){if(u.file===c.file)continue;let d=ua(c,u,n);d&&l.push(d)}}else for(let c=0;c<a.length;c++){for(let u=c+1;u<a.length;u++){let d=ua(a[c],a[u],n);d&&l.push(d)}if(l.length>r*5)break}return l.sort((c,u)=>u.similarity-c.similarity),l.slice(0,r)}function ey(e,t){let{scope:n,minDeps:r}=t,i=Y(e,n),s=ty(i),o=[];for(let[a,l]of i)l.size>=r&&o.push({file:a,deps:new Set([...l].filter(c=>!s.has(c)))});return o}function ty(e){let t=new Set,n=e.size;if(n===0)return t;let r=new Map;for(let i of e.values())for(let s of i)r.set(s,(r.get(s)??0)+1);for(let[i,s]of r)s>=5&&s/n>.3&&t.add(i);return t}function ua(e,t,n){let r=new Set;for(let a of e.deps)t.deps.has(a)&&r.add(a);if(r.size<3||e.deps.size<4||t.deps.size<4)return null;let i=na(e.deps,t.deps);if(i<n)return null;let s=[];for(let a of e.deps)t.deps.has(a)||s.push(a);let o=[];for(let a of t.deps)e.deps.has(a)||o.push(a);return{fileA:e.file,fileB:t.file,similarity:i,sharedDeps:[...r],uniqueToA:s,uniqueToB:o}}function pa(e,t={}){let{minSimilarity:n=.5,limit:r=15,scope:i,minChainLength:s=3,maxChainLength:o=8}=t,a=Y(e,i),l=cy(a,s,o);if(l.length===0)return[];let c=ny(l);return c.length<2?[]:ly(sy(c,n,r),r)}function ny(e){let t=ry(e),n=[];for(let r of e){let i=r.filter(s=>!t.has(s));i.length>=2&&n.push({original:r,filtered:i})}return n}function ry(e){let{nodeFreq:t,tailFreq:n}=iy(e),r=e.length*.9,i=e.length*.8,s=new Set;for(let[a,l]of t)l>r&&s.add(a);for(let[a,l]of n)l>i&&s.add(a);let o=["index.ts","index.js","cli.ts","main.ts","health.ts","health.js"];for(let a of t.keys()){let l=a.split("/").pop()??"";o.includes(l)&&s.add(a)}return s}function iy(e){let t=new Map,n=new Map;for(let r of e){let i=new Set;for(let s of r)i.has(s)||(t.set(s,(t.get(s)??0)+1),i.add(s));for(let s=Math.max(0,r.length-2);s<r.length;s++)n.set(r[s],(n.get(r[s])??0)+1)}return{nodeFreq:t,tailFreq:n}}function sy(e,t,n){let r=[];for(let i=0;i<e.length;i++){for(let s=i+1;s<e.length;s++){let o=oy(e[i],e[s],t);o&&r.push(o)}if(r.length>n*10)break}return r.sort((i,s)=>Math.abs(s.similarity-i.similarity)>.01?s.similarity-i.similarity:i.divergencePoints.length-s.divergencePoints.length),r}function oy(e,t,n){if(!ay(e.filtered,t.filtered))return null;let{distance:r,ops:i}=uy(e.filtered,t.filtered),s=Math.max(e.filtered.length,t.filtered.length);if(s===0)return null;let o=1-r/s;if(o<n||r===0)return null;let a=i.filter(c=>c.type==="substitute").map(c=>({index:c.indexA,nodeA:e.filtered[c.indexA],nodeB:t.filtered[c.indexB]}));return a.length===0||i.filter(c=>c.type==="match").length<2?null:{chainA:e.original,chainB:t.original,similarity:o,editDistance:r,divergencePoints:a,commonPrefix:dy(e.original,t.original),commonSuffix:my(e.original,t.original)}}function ay(e,t){let n=new Set(e);return t.some(r=>n.has(r))}function ly(e,t){let n=[];for(let r of e)if(n.some(s=>ma(r.chainA,s.chainA)&&ma(r.chainB,s.chainB))||n.push(r),n.length>=t)break;return n}function cy(e,t,n){let r=[];for(let s of e.keys()){if(r.length>=500)break;fa(e,s,[s],new Set([s]),t,n,r,500)}return r}function fa(e,t,n,r,i,s,o,a){if(o.length>=a)return;if(n.length>=s){n.length>=i&&o.push([...n]);return}let l=e.get(t);if(!l||l.size===0){n.length>=i&&o.push([...n]);return}let c=!1;for(let u of l)if(!r.has(u)&&(r.add(u),n.push(u),fa(e,u,n,r,i,s,o,a),n.pop(),r.delete(u),c=!0,o.length>=a))return;!c&&n.length>=i&&o.push([...n])}function uy(e,t){let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let l=0;l<=n;l++)i[l][0]=l;for(let l=0;l<=r;l++)i[0][l]=l;for(let l=1;l<=n;l++)for(let c=1;c<=r;c++)e[l-1]===t[c-1]?i[l][c]=i[l-1][c-1]:i[l][c]=1+Math.min(i[l-1][c],i[l][c-1],i[l-1][c-1]);let s=[],o=n,a=r;for(;o>0||a>0;)o>0&&a>0&&e[o-1]===t[a-1]?(s.unshift({type:"match",indexA:o-1,indexB:a-1}),o--,a--):o>0&&a>0&&i[o][a]===i[o-1][a-1]+1?(s.unshift({type:"substitute",indexA:o-1,indexB:a-1}),o--,a--):a>0&&i[o][a]===i[o][a-1]+1?(s.unshift({type:"insert",indexA:o,indexB:a-1}),a--):(s.unshift({type:"delete",indexA:o-1,indexB:a}),o--);return{distance:i[n][r],ops:s}}function dy(e,t){let n=[];for(let r=0;r<Math.min(e.length,t.length)&&e[r]===t[r];r++)n.push(e[r]);return n}function my(e,t){let n=[],r=e.length-1,i=t.length-1;for(;r>=0&&i>=0&&e[r]===t[i];)n.unshift(e[r]),r--,i--;return n}function ma(e,t){if(e.length>t.length)return!1;let n=t.join("\u2192"),r=e.join("\u2192");return n.includes(r)}function vn(e,t={}){let{scope:n,minLoc:r=10,minCallees:i=6,limit:s=20}=t,o=new C(e),a=o.productionCallableDefinitions({scope:n,minLoc:r,excludeTypesFiles:!0,requireFunctionLikeSymbol:!0,sortByLocDesc:!0}),l=o.calleeMap(a),c=[];for(let u of a){let d=py(u,l.get(u.symbolId)??[],i);d&&c.push(d)}return c.sort((u,d)=>d.clusters.length-u.clusters.length||d.loc-u.loc),c.slice(0,s)}function py(e,t,n){let r=new Set(t.map(a=>a.symbol));if(r.size<n)return null;let i=fy(r,t),s=gy(r,i);if(s.length<2)return null;let o=hy(s,i);return o.length===0?null:{symbol:e.symbol,shortName:h(e.symbol),relativePath:e.relativePath,startLine:e.startLine,endLine:e.endLine,loc:by(e),totalCallees:r.size,clusters:o}}function fy(e,t){let n=new Map;for(let i of e)n.set(i,new Set);let r=new Map;for(let i of t){let s=r.get(i.chunkId);s||(s=new Set,r.set(i.chunkId,s)),s.add(i.symbol)}for(let i of r.values()){let s=[...i];for(let o=0;o<s.length;o++)for(let a=o+1;a<s.length;a++)n.get(s[o]).add(s[a]),n.get(s[a]).add(s[o])}return n}function gy(e,t){let n=new Set,r=[];for(let i of e){if(n.has(i))continue;let s=new Set,o=[i];for(;o.length>0;){let a=o.pop();if(!n.has(a)){n.add(a),s.add(a);for(let l of t.get(a)??[])n.has(l)||o.push(l)}}r.push(s)}return r}function hy(e,t){return e.filter(n=>n.size>=3).map(n=>yy(n,e,t)).filter(n=>n.isolation>.5).sort((n,r)=>r.isolation-n.isolation)}function yy(e,t,n){let r=new Set;for(let a of t)if(a!==e)for(let l of a)r.add(l);let i=0;for(let a of e)for(let l of n.get(a)??[])r.has(l)&&i++;let s=e.size*r.size,o=s>0?1-i/s:1;return{callees:[...e].map(h),isolation:o}}function by(e){return e.endLine-e.startLine+1}function ga(e,t,n={}){let{maxDepth:r=5,scope:i}=n,s=E(e,t);if(!s)return[];let o=[],a=new Set([s.symbolId]),l=new Set,c=[s];for(let u=1;u<=r&&c.length!==0;u++){let d=[];for(let m of c)for(let g of Sy(e,m,i)){let p=`${g.file}|${g.shortName}`;if(g.symbolId!==null){if(a.has(g.symbolId))continue;a.add(g.symbolId)}else if(l.has(p))continue;l.add(p),o.push({symbol:g.symbol,shortName:g.shortName,file:g.file,depth:u}),g.symbolId!==null&&g.symbolMatch&&d.push(g.symbolMatch)}c=d}return o.sort((u,d)=>u.depth-d.depth||u.file.localeCompare(d.file)),o}function Sy(e,t,n){let r=new C(e),i=ie(e,t,{limit:500}).filter(d=>!e.isIgnored(d.file)).filter(d=>!n||d.file.includes(n)),s=new Set(i.map(d=>d.file)),o=r.crossFileCallerMap().get(t.symbolId)??new Set,a=[];for(let d of o){if(s.has(d)||e.isIgnored(d)||n&&!d.includes(n))continue;let m=r.definitionsForFile(d),g=m.length>0?ae(m,m[0].startLine):null;a.push({symbol:g?.symbol??d,file:d})}let l=[...i,...a],c=[],u=new Set;for(let d of l){let m=it(e,d.symbol);if(!m){let p=`${d.file}|${d.symbol}`;if(u.has(p))continue;u.add(p),c.push({symbolId:null,symbol:d.symbol,shortName:h(d.symbol),file:d.file,symbolMatch:null});continue}if(m.symbolId===t.symbolId||e.isIgnored(m.relativePath)||!xy(m.symbol))continue;let g=`${m.symbolId}|${m.relativePath}`;u.has(g)||(u.add(g),c.push({symbolId:m.symbolId,symbol:m.symbol,shortName:h(m.symbol),file:m.relativePath,symbolMatch:m}))}return c}function xy(e){let t=V(e);return t==="method"||t==="type"||e.endsWith("().")}function ha(e,t){let n=G(e,t);if(!n)return null;let r=_y(e,n);if(!r||e.isIgnored(r.relative_path))return null;let i=[],s=0;for(let o of Iy(e,r.relative_path)){let a=Ry(e,r,o);s+=a,i.push({symbol:o.symbol,shortName:h(o.symbol),startLine:o.startLine,endLine:o.endLine,externalConsumers:a,riskLevel:Cy(a)})}return{file:r.relative_path,symbols:i,totalExternalConsumers:s}}function _y(e,t){return e.get(`SELECT id, relative_path FROM documents
|
|
708
812
|
WHERE relative_path = ?
|
|
709
813
|
${e.pathExclusionsFor("documents")}
|
|
710
|
-
LIMIT 1`,t)
|
|
711
|
-
FROM mentions m
|
|
712
|
-
JOIN chunks c ON m.chunk_id = c.id
|
|
713
|
-
WHERE m.symbol_id = ?
|
|
714
|
-
AND m.role != 1
|
|
715
|
-
AND c.document_id != ?`,r.symbolId,s.id)?.consumer_count??0,m;c>10?m="high":c>0?m="medium":m="low",a+=c,o.push({symbol:r.symbol,shortName:I(r.symbol),startLine:r.startLine,endLine:r.endLine,externalConsumers:c,riskLevel:m})}return{file:s.relative_path,symbols:o,totalExternalConsumers:a}}import{execFileSync as Yn}from"child_process";function Go(e,n={}){let{base:t="HEAD"}=n,s;try{s=Sm(e.config.projectRoot,t)}catch{return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"Unable to compute git diff."}}}if(s.length===0)return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:"No changed files found."}};let i=[],o=[];for(let u of s){let d=e.get(`SELECT id, relative_path FROM documents
|
|
716
|
-
WHERE relative_path LIKE ?
|
|
717
|
-
LIMIT 1`,`%${u}`);d&&!e.isIgnored(d.relative_path)&&(i.push(d.relative_path),o.push(d.id))}if(o.length===0)return{changedFiles:s,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:s.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let a=o.map(()=>"?").join(","),r=e.all(`SELECT DISTINCT gs.id AS symbol_id, gs.symbol, d.relative_path
|
|
718
|
-
FROM mentions m
|
|
719
|
-
JOIN chunks c ON m.chunk_id = c.id
|
|
720
|
-
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
721
|
-
JOIN documents d ON c.document_id = d.id
|
|
722
|
-
WHERE m.role = 1
|
|
723
|
-
AND c.document_id IN (${a})
|
|
724
|
-
${e.symbolNoiseFor("gs")}
|
|
725
|
-
ORDER BY d.relative_path`,...o),l=[],c=new Map;for(let u of r){let g=e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
|
|
726
|
-
FROM mentions m
|
|
727
|
-
JOIN chunks c ON m.chunk_id = c.id
|
|
728
|
-
WHERE m.symbol_id = ?
|
|
729
|
-
AND m.role != 1`,u.symbol_id)?.fan_in??0,p=I(u.symbol);l.push({symbol:u.symbol,shortName:p,file:u.relative_path,fanIn:g});let f=e.all(`SELECT DISTINCT ref_d.relative_path
|
|
730
|
-
FROM mentions m
|
|
731
|
-
JOIN chunks c ON m.chunk_id = c.id
|
|
732
|
-
JOIN documents ref_d ON c.document_id = ref_d.id
|
|
733
|
-
WHERE m.symbol_id = ?
|
|
734
|
-
AND m.role != 1
|
|
735
|
-
AND ref_d.relative_path NOT IN (${i.map(()=>"?").join(",")})
|
|
736
|
-
${e.pathExclusionsFor("ref_d")}`,u.symbol_id,...i);for(let y of f)e.isIgnored(y.relative_path)||(c.has(y.relative_path)||c.set(y.relative_path,new Set),c.get(y.relative_path).add(p))}let m=[...c.entries()].map(([u,d])=>({file:u,consumedSymbols:d.size})).sort((u,d)=>d.consumedSymbols-u.consumedSymbols);return{changedFiles:i,changedSymbols:l,affectedConsumers:m,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:m.length}}}function Sm(e,n){let t=Yn("git",["diff","--name-only",n],{encoding:"utf-8",cwd:e,timeout:1e4}),s=Yn("git",["diff","--name-only","--cached",n],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Yn("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([t,s,i].flatMap(o=>o.split(`
|
|
737
|
-
`)).map(o=>o.trim()).filter(o=>o.length>0))]}import vt from"path";function cn(e,n){let{scope:t}=n??{},s=K(e,t),i=_m(e,t),o=[];for(let[l,c]of s){if(Ce(l))continue;let m=i.get(l)??new Set;for(let u of c)if(!Ce(u)&&!m.has(u)){if(Im(u)||Nm(e,l,u))continue;o.push({file:l,kind:"unused-import",description:`Depends on ${u} but references none of its symbols`,dep:u})}}let a=xm(s);for(let[l,c]of s){if(Ce(l))continue;let m=ln(l);for(let u of c){if(Ce(u))continue;let d=ln(u);if(m===d)continue;a.get(`${m}->${d}`)==="violation"&&o.push({file:l,kind:"layer-violation",description:`Imports from ${d}/ (${u}) \u2014 may cross architectural boundary`,dep:u,detail:`${m}/ should not depend on ${d}/`})}}let r=new Map;for(let l of s.keys()){let c=vt.dirname(l);r.has(c)||r.set(c,[]),r.get(c).push(l)}for(let[l,c]of r){let m=c.filter(d=>!Ce(d));if(m.length<5)continue;let u=new Map;for(let d of m)for(let g of s.get(d)??[])Ce(g)||u.set(g,(u.get(g)??0)+1);for(let d of m)for(let g of s.get(d)??[])Ce(g)||(u.get(g)??0)===1&&vt.dirname(g)!==l&&vt.dirname(g)!==vt.dirname(l)&&o.push({file:d,kind:"pattern-deviation",description:`Only file in ${l}/ that depends on ${g}`,dep:g})}return{results:o,unusedImports:o.filter(l=>l.kind==="unused-import").length,layerViolations:o.filter(l=>l.kind==="layer-violation").length,patternDeviations:o.filter(l=>l.kind==="pattern-deviation").length}}function _m(e,n){let t=n?`AND d1.relative_path LIKE '%${n}%'`:"",s=e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
|
|
814
|
+
LIMIT 1`,t)??null}function Iy(e,t){return new C(e).definitionsForFile(t).sort((n,r)=>n.startLine-r.startLine||n.endLine-r.endLine)}function Ry(e,t,n){let r=e.all(`SELECT DISTINCT consumer_d.relative_path
|
|
738
815
|
FROM mentions m
|
|
739
816
|
JOIN chunks c ON m.chunk_id = c.id
|
|
740
|
-
JOIN documents
|
|
741
|
-
|
|
742
|
-
JOIN (
|
|
743
|
-
SELECT m2.symbol_id, c2.document_id
|
|
744
|
-
FROM mentions m2
|
|
745
|
-
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
746
|
-
WHERE m2.role = 1
|
|
747
|
-
GROUP BY m2.symbol_id
|
|
748
|
-
) sym_def ON sym_def.symbol_id = gs.id
|
|
749
|
-
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
750
|
-
WHERE d1.id != d2.id
|
|
817
|
+
JOIN documents consumer_d ON consumer_d.id = c.document_id
|
|
818
|
+
WHERE m.symbol_id = ?
|
|
751
819
|
AND m.role != 1
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
820
|
+
AND c.document_id != ?`,n.symbolId,t.id),i=ut(e,[n]).get(n.symbolId)??new Set;return new Set([...r.map(s=>s.relative_path),...[...i].filter(s=>s!==t.relative_path)]).size}function Cy(e){return e>10?"high":e>0?"medium":"low"}import{execFileSync as Or}from"child_process";function Sa(e,t={}){let{base:n="HEAD"}=t,r;try{r=vy(e.config.projectRoot,n)}catch{return ya("Unable to compute git diff.")}if(r.length===0)return ya("No changed files found.");let i=Ny(e,r);if(i.length===0)return{changedFiles:r,changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:r.length,totalChangedSymbols:0,totalAffectedFiles:0,note:"Changed files are not present in the current SCIP index."}};let s=new C(e),o=new Set(i),a=Ey(s,i),l=[],c=new Map;for(let d of a)Dy(e,d,i,o,l,c);let u=wy(c);return{changedFiles:i,changedSymbols:l,affectedConsumers:u,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:u.length}}}function ya(e){return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:e}}}function vy(e,t){let n=Or("git",["diff","--name-only",t],{encoding:"utf-8",cwd:e,timeout:1e4}),r=Or("git",["diff","--name-only","--cached",t],{encoding:"utf-8",cwd:e,timeout:1e4}),i=Or("git",["ls-files","--others","--exclude-standard"],{encoding:"utf-8",cwd:e,timeout:1e4});return[...new Set([n,r,i].flatMap(s=>s.split(`
|
|
821
|
+
`)).map(s=>s.trim()).filter(s=>s.length>0))]}function Ny(e,t){let n=[];for(let r of t){let i=e.get(`SELECT relative_path FROM documents
|
|
822
|
+
WHERE relative_path LIKE ?
|
|
823
|
+
LIMIT 1`,`%${r}`);i&&!e.isIgnored(i.relative_path)&&n.push(i.relative_path)}return n}function Ey(e,t){return t.flatMap(n=>e.definitionsForFile(n)).filter(Py).sort((n,r)=>n.relativePath.localeCompare(r.relativePath)||n.startLine-r.startLine)}function Dy(e,t,n,r,i,s){let o=ut(e,[t]).get(t.symbolId)??new Set,a=Math.max(Ly(e,t.symbolId),o.size);if(!Oy(t,a))return;let l=h(t.symbol);i.push({symbol:t.symbol,shortName:l,file:t.relativePath,fanIn:a});for(let c of ky(e,t.symbolId,n))ba(e,r,s,c,l);for(let c of o)ba(e,r,s,c,l)}function Ly(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS fan_in
|
|
824
|
+
FROM mentions m
|
|
825
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
826
|
+
WHERE m.symbol_id = ?
|
|
827
|
+
AND m.role != 1`,t)?.fan_in??0}function ky(e,t,n){return n.length===0?[]:e.all(`SELECT DISTINCT ref_d.relative_path
|
|
828
|
+
FROM mentions m
|
|
829
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
830
|
+
JOIN documents ref_d ON c.document_id = ref_d.id
|
|
831
|
+
WHERE m.symbol_id = ?
|
|
832
|
+
AND m.role != 1
|
|
833
|
+
AND ref_d.relative_path NOT IN (${n.map(()=>"?").join(",")})
|
|
834
|
+
${e.pathExclusionsFor("ref_d")}`,t,...n).map(i=>i.relative_path)}function ba(e,t,n,r,i){if(e.isIgnored(r)||t.has(r))return;let s=n.get(r);s||(s=new Set,n.set(r,s)),s.add(i)}function wy(e){return[...e.entries()].map(([t,n])=>({file:t,consumedSymbols:n.size})).sort((t,n)=>n.consumedSymbols-t.consumedSymbols)}function Py(e){return!(Le(e.symbol)||e.parentTypeName!==null&&!U(e.symbol))}function Oy(e,t){return U(e.symbol)||e.isTypeLike?!0:e.parentTypeName===null&&t>0}import Mt from"path";function Ge(e){let n=e.replace(/\\/g,"/").split("/").filter(Boolean);return n.length<=1?"(root)":n.length>=3&&["src","lib","app","server","client"].includes(n[0])?`${n[0]}/${n[1]}`:n[0]}function Mr(e,t){if(e===t)return"ok";let n=Nn(e),r=Nn(t);return n&&r?My(n,r)?"ok":"violation":Fy(e,t)}function xa(e,t){let n=Nn(Ge(e)),r=Nn(Ge(t));return!!n&&!!r}function Nn(e){return/^src\/([^/]+)$/.exec(e)?.[1]??null}function My(e,t){return t==="domain"?!0:e==="domain"?!1:{analysis:new Set(["domain","source","storage","symbols"]),core:new Set(["analysis","domain","resolution","source","storage","symbols"]),"language-parsers":new Set(["domain","resolution","source","storage"]),queries:new Set(["analysis","core","domain","language-parsers","resolution","semantic","source","storage","symbols"]),reindex:new Set(["domain","language-parsers","resolution","runtime","source","storage","symbols"]),resolution:new Set(["domain","source","storage","symbols"]),runtime:new Set(["domain","queries","reindex","resolution","source","storage","symbols"]),semantic:new Set(["domain","resolution","storage","symbols"]),source:new Set(["domain","storage"]),storage:new Set(["domain","source"]),symbols:new Set(["analysis","domain","language-parsers","resolution","semantic","source","storage"])}[e]?.has(t)??!1}function Fy(e,t){if(t==="shared")return"ok";let n={app:new Set(["core","shared","ui"]),core:new Set(["shared"]),infra:new Set(["core","shared"]),ui:new Set(["core","shared"])};return n[e]?n[e].has(t)?"ok":"violation":null}function En(e,t){let{scope:n,minDeviation:r=5}=t??{},s=new C(e).fileDependencyGraph(n),o=Hy(e,n);return jy([...Ty(e,s,o),...$y(s),...Ay(s,r)])}function Ty(e,t,n){let r=[];for(let[i,s]of t){if(Re(i))continue;let o=n.get(i)??new Set;for(let a of s)if(!Re(a)&&!o.has(a)){if(Gy(e,i,a)||Ky(e,i,a)||Yy(e,i,a)||zy(a)||Xy(e,i,a)||Qy(a))continue;r.push({file:i,kind:"unused-import",description:`Depends on ${a} but references none of its symbols`,dep:a})}}return r}function $y(e){let t=[],n=qy(e);for(let[r,i]of e){if(Re(r))continue;let s=Ge(r);for(let o of i){if(Re(o))continue;let a=Ge(o);if(s===a)continue;(Mr(s,a)??n.get(`${s}->${a}`))==="violation"&&t.push({file:r,kind:"layer-violation",description:`Imports from ${a}/ (${o}) \u2014 may cross architectural boundary`,dep:o,detail:`${s}/ should not depend on ${a}/`})}}return t}function Ay(e,t){let n=[];for(let[r,i]of By(e)){let s=i.filter(a=>!Re(a));if(s.length<t)continue;let o=Wy(e,s);for(let a of s)for(let l of e.get(a)??[])Re(l)||(o.get(l)??0)===1&&Mt.dirname(l)!==r&&Mt.dirname(l)!==Mt.dirname(r)&&(xa(a,l)||n.push({file:a,kind:"pattern-deviation",description:`Only file in ${r}/ that depends on ${l}`,dep:l}))}return n}function jy(e){return{results:e,unusedImports:e.filter(t=>t.kind==="unused-import").length,layerViolations:e.filter(t=>t.kind==="layer-violation").length,patternDeviations:e.filter(t=>t.kind==="pattern-deviation").length}}function By(e){let t=new Map;for(let n of e.keys()){let r=Mt.dirname(n),i=t.get(r);i||(i=[],t.set(r,i)),i.push(n)}return t}function Wy(e,t){let n=new Map;for(let r of t)for(let i of e.get(r)??[])Re(i)||n.set(i,(n.get(i)??0)+1);return n}function Hy(e,t){let n=new Map;return Vy(e,n,t),Jy(e,n),n}function Vy(e,t,n){for(let r of Uy(e,n))_a(e,t,r.from_file,r.to_file)}function Uy(e,t){let n=t?`AND d1.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT d1.relative_path AS from_file, d2.relative_path AS to_file
|
|
835
|
+
FROM mentions m
|
|
836
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
837
|
+
JOIN documents d1 ON c.document_id = d1.id
|
|
838
|
+
JOIN global_symbols gs ON m.symbol_id = gs.id
|
|
839
|
+
JOIN (
|
|
840
|
+
SELECT m2.symbol_id, c2.document_id
|
|
841
|
+
FROM mentions m2
|
|
842
|
+
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
843
|
+
WHERE m2.role = 1
|
|
844
|
+
GROUP BY m2.symbol_id
|
|
845
|
+
) sym_def ON sym_def.symbol_id = gs.id
|
|
846
|
+
JOIN documents d2 ON sym_def.document_id = d2.id
|
|
847
|
+
WHERE d1.id != d2.id
|
|
848
|
+
AND m.role != 1
|
|
849
|
+
${e.pathExclusionsFor("d1","d2")}
|
|
850
|
+
${n}`)}function Jy(e,t){let n=new C(e),r=e.all(`SELECT relative_path FROM documents
|
|
851
|
+
WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);n.scanSourceReferences({paths:r.map(i=>i.relative_path),includeRustAttributeNames:!0,identifierResolution:"permissive"},i=>{i.target.relativePath!==i.sourceFile&&(e.isIgnored(i.target.relativePath)||_a(e,t,i.sourceFile,i.target.relativePath))})}function _a(e,t,n,r){if(e.isIgnored(n)||e.isIgnored(r))return;let i=t.get(n);i||(i=new Set,t.set(n,i)),i.add(r)}function qy(e){let t=new Map;for(let[r,i]of e){if(Re(r))continue;let s=Ge(r);for(let o of i){if(Re(o))continue;let a=Ge(o);if(s===a||Mr(s,a))continue;let l=`${s}->${a}`;t.set(l,(t.get(l)??0)+1)}}let n=new Map;for(let[r,i]of t)n.set(r,i<=2?"violation":"ok");return n}function zy(e){return e.includes("types")||e.endsWith(".d.ts")}function Gy(e,t,n){let r=vt(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.isUsed)}function Ky(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.used)}function Yy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.every(i=>i.isTypeOnly===!0)}function Qy(e){return e.endsWith(".vue")}function Xy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length===0?!1:r.every(i=>i.kind==="side-effect"||i.kind==="namespace"&&i.usedMembers.length===0&&!i.used)}function Re(e){let t=ee(e);return!!(t==="entry"||t==="barrel"||t==="test"||t==="worker"||Zy(Mt.basename(e)))}function Zy(e){return!!(e==="index.ts"||e==="index.js"||e==="cli.ts"||e==="main.ts"||e==="main.rs"||e.includes("worker.")||e.includes("postinstall.")||e==="health.ts"||e==="health.js")}import{basename as Ft,extname as Dn}from"path";function Ln(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=cb(s.fileDependencyGraph(n)),a=nb(s,n,r),l=lb(s.crossFileCallerMap(a),s.sourceFallbackCallerFiles(a)),c=[];for(let u of a){let d=eb(e,s,u,{callerFileMap:l,reverseFanIn:o});d&&c.push(d)}return c.sort((u,d)=>d.callerFanIn-u.callerFanIn||d.loc-u.loc),c.slice(0,i)}function eb(e,t,n,r){let i=rb(t,n,r.callerFileMap);if(i.length!==1)return null;let s=i[0],o=ib(e,n.symbolId,s);if(!o)return null;let a=sb(t,e,s,n.symbol,o);if(a&&ke(a.symbol))return null;let l=ob(r.callerFileMap,r.reverseFanIn,s,a);return l<=3?null:{symbol:n.symbol,shortName:h(n.symbol),file:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:tb(n),singleCaller:a?.symbol??"",singleCallerShort:a?.isFunctionLike?h(a.symbol):Ft(s),callerFanIn:l}}function tb(e){return e.endLine-e.startLine+1}function nb(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:2,maxLoc:n,requireFunctionLikeSymbol:!0})}function rb(e,t,n){let r=Ft(t.relativePath,Dn(t.relativePath));return[...n.get(t.symbolId)??[]].filter(i=>i!==t.relativePath).filter(i=>Ft(i,Dn(i))!==r).filter(i=>{let s=e.fileKind(i);return s!=="barrel"&&s!=="entry"&&s!=="test"})}function ib(e,t,n){return e.get(`SELECT c.start_line, c.end_line
|
|
852
|
+
FROM mentions m
|
|
853
|
+
JOIN chunks c ON m.chunk_id = c.id
|
|
854
|
+
JOIN documents d ON c.document_id = d.id
|
|
855
|
+
WHERE m.symbol_id = ? AND m.role != 1 AND d.relative_path = ?
|
|
856
|
+
LIMIT 1`,t,n)}function sb(e,t,n,r,i){let s=e.definitionsForFile(n),o=ab(t,n,r,i.start_line,i.end_line);return ae(s,o)}function ob(e,t,n,r){if(r?.isFunctionLike){let i=[...e.get(r.symbolId)??[]].filter(s=>s!==r.relativePath);if(i.length>0)return i.length}return ub(t,n)}function ab(e,t,n,r,i){let s=D(n);if(!s)return r;let o=qe(e,t).get(s);if(!o||o.length===0)return r;for(let a of o)if(a>=r&&a<=i)return a;return r}function lb(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function cb(e){let t=new Map;for(let[n,r]of e){t.has(n)||t.set(n,t.get(n)??0);for(let i of r)t.set(i,(t.get(i)??0)+1)}return t}function ub(e,t){let n=e.get(t)??0;if(n>0)return n;let r=Ft(t,Dn(t)),i=0;for(let[s,o]of e)s!==t&&Ft(s,Dn(s))===r&&o>i&&(i=o);return i}function Ra(e,t,n,r){let i=M(t);if(!i)return!0;let s=P(e,t);if(!s)return!0;let o=Ia.get(s);return o||(o=db(s,i),Ia.set(s,o)),o.get(`${n}:${r}`)??!0}var Ia=new WeakMap;function db(e,t){let n=t==="rust"?new Set(["function_item","function_signature_item"]):t==="python"?new Set(["function_definition"]):new Set(["function_declaration","method_definition","arrow_function","function_expression"]),r=new Map,i=s=>{n.has(s.type)&&r.set(`${s.startPosition.row}:${s.endPosition.row}`,mb(s,t));for(let o of s.children)i(o)};return i(e.rootNode),r}function mb(e,t){let n=e.namedChildren.find(d=>d.type==="block"||d.type==="statement_block");if(!n)return!1;let r=n.namedChildren.filter(d=>d.type!=="comment"&&d.type!=="line_comment"&&d.type!=="block_comment");if(r.length!==1)return!1;let i=r[0],s=null;if(i.type==="return_statement"||i.type==="expression_statement"?s=i.namedChild(0)??null:t==="rust"&&(i.type==="call_expression"||i.type==="macro_invocation")&&(s=i),!s)return!1;let o=t==="python"?"call":"call_expression";if(s.type!==o)return!1;let a=s.namedChildren.find(d=>d.type==="arguments"||d.type==="argument_list");if(!a)return!1;let l=a.namedChildren.filter(d=>d.type!=="comment"),c=e.namedChildren.find(d=>d.type==="parameters"||d.type==="formal_parameters");if(!c)return!1;let u=[];for(let d of c.namedChildren)if(d.type==="identifier")u.push(d.text);else{let m=d.namedChildren.find(g=>g.type==="identifier");m&&u.push(m.text)}if(l.length!==u.length)return!1;for(let d=0;d<u.length;d+=1){let m=l[d];if(m.type!=="identifier"||m.text!==u[d])return!1}return!0}function kn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=gb(s,n,r),a=s.calleeMap(o),l=[];for(let c of o){let u=pb(e,c,a.get(c.symbolId)??[]);u&&l.push(u)}return l.sort((c,u)=>c.loc-u.loc||c.file.localeCompare(u.file)),l.slice(0,i)}function pb(e,t,n){let r=fb(n);if(r.size!==1||!Ra(e,t.relativePath,t.startLine,t.endLine))return null;let[,i]=[...r.entries()][0];return{symbol:t.symbol,shortName:h(t.symbol),file:t.relativePath,startLine:t.startLine,endLine:t.endLine,loc:hb(t),forwardsTo:i.symbol,forwardsToShort:h(i.symbol),forwardsToFile:i.file}}function fb(e){let t=e.some(r=>W(r.symbol))?e.filter(r=>W(r.symbol)):e,n=new Map;for(let r of t)n.has(r.symbol)||n.set(r.symbol,r);return n}function gb(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:3,maxLoc:n,requireFunctionLikeSymbol:!0,excludeRustTraitImplMembers:!0})}function hb(e){return e.endLine-e.startLine+1}function wn(e,t){let{scope:n,minLoc:r=3,maxLoc:i=80,limit:s=30,includeLowConfidence:o=!1}=t??{},a=new C(e),l=a.scopedDefinitions(n),c=Db(a,n),u=yb(e,a,l,{minLoc:r,maxLoc:i}),d=bb(a,u),m=Ib(e,a,l,u),g=Sb(u);return xb(e,u,d,g).filter(y=>!m.has(y.definition.symbolId)).filter(y=>!y.transitivelyReachable).filter(y=>y.realConsumers.length<=1).filter(y=>!(y.realConsumers.length===0&&y.barrelConsumers>0)).filter(y=>kb(y.definition,y.realConsumers.length,c)).map(y=>_b(e,y)).filter(y=>o||y.confidence!=="low").sort((y,L)=>{let k={high:0,medium:1,low:2};return k[y.confidence]-k[L.confidence]||L.loc-y.loc||y.file.localeCompare(L.file)||y.startLine-L.startLine}).slice(0,s)}function yb(e,t,n,r){return n.filter(i=>i.isTypeLike&&Fr(i)>=r.minLoc).filter(i=>Fr(i)<=r.maxLoc).filter(i=>!e.isIgnored(i.relativePath)).filter(i=>!Lb(i.symbol)).filter(i=>!t.hasSuppressionComment(i))}function bb(e,t){return Da(e.crossFileCallerMap(t),e.sourceFallbackCallerFiles(t))}function Sb(e){let t=new Map;for(let n of e){let r=t.get(n.relativePath);r||(r=new Map,t.set(n.relativePath,r));let i=D(n.symbol);i&&r.set(i,n)}return t}function xb(e,t,n,r){return t.map(i=>{let o=[...n.get(i.symbolId)??new Set].filter(u=>u!==i.relativePath&&!e.isIgnored(u)),{realConsumers:a,barrelConsumers:l}=wb(e,i.relativePath,i.symbol,o),c=Pb(e,i,n,r);return{definition:i,realConsumers:a,barrelConsumers:l,transitivelyReachable:c}})}function _b(e,t){let n=Ea(e,t.definition.relativePath,t.definition.startLine),r=va(t.definition.relativePath)?!0:Tb(e,t.definition),{confidence:i,reason:s}=$b(t.realConsumers.length,n,r);return{symbol:t.definition.symbol,shortName:h(t.definition.symbol),file:t.definition.relativePath,startLine:t.definition.startLine,endLine:t.definition.endLine,loc:Fr(t.definition),consumers:t.realConsumers.length,barrelConsumers:t.barrelConsumers,kind:n,definerUsesType:r,confidence:i,reason:s}}function Ib(e,t,n,r){let i=Cb(e,Rb(n),r),s=i.map(l=>l.singleton);if(i.length===0)return new Set;let o=Da(t.crossFileCallerMap(s),t.sourceFallbackCallerFiles(s)),a=new Set;for(let{singleton:l,classId:c}of i)Nb(e,l,o)&&a.add(c);return a}function Rb(e){let t=new Map;for(let n of e){let r=D(n.symbol);r&&t.set(Ca(n.relativePath,r),n)}return t}function Cb(e,t,n){let r=[];for(let i of n){let s=vb(e,t,i);s&&r.push({singleton:s,classId:i.symbolId})}return r}function vb(e,t,n){if(Ea(e,n.relativePath,n.startLine)!=="class")return null;let r=D(n.symbol);if(!r)return null;let i=Eb(e,n.relativePath,r);return i?t.get(Ca(n.relativePath,i))??null:null}function Nb(e,t,n){let r=D(t.symbol),i=n.get(t.symbolId);return!r||!i?!1:[...i].some(s=>s!==t.relativePath&&!e.isIgnored(s)&&!Na(e,s,r))}function Ca(e,t){return`${e}\0${t}`}function Eb(e,t,n){let r=w(e,t);if(!r)return null;let i=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\bexport\\s+const\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*new\\s+${i}\\s*\\(`);return r.match(s)?.[1]??null}function Db(e,t){return new Set(e.scopedDefinitions(t).filter(n=>n.isFunctionLike).map(n=>n.relativePath))}function Lb(e){let t=H(e);if("kind"in t)return!1;let n=t.descriptors;if(n.length<2)return!1;let r=n[n.length-1],i=n[n.length-2];return r?.suffix==="type"&&i?.suffix==="type"}function va(e){let n=(e.split("/").pop()??"").replace(/\.[^.]+$/,"");return!!(n==="types"||n==="models"||n==="schema"||n==="common"||n==="protocol"||n==="proto"||n==="dto"||n==="mod"||/(^|\/)types(\/|\.)/.test(e)||/(^|\/)models?(\/|\.)/.test(e)||/(^|\/)proto(?:col)?(\/|\.)/.test(e)||/(^|\/)schema(\/|\.)/.test(e))}function kb(e,t,n){return!(va(e.relativePath)&&t>0||t===0&&n.has(e.relativePath))}function wb(e,t,n,r){let i=[],s=0,o=D(n);for(let a of r)Fb(e,a,t,o)||Na(e,a,o)?s++:i.push(a);return{realConsumers:i,barrelConsumers:s}}function Pb(e,t,n,r){let i=Yi(e,t.relativePath),s=D(t.symbol);if(!s)return!1;let o=i.get(s);if(!o||o.size===0)return!1;let a=r.get(t.relativePath);if(!a)return!1;for(let l of o){let c=a.get(l);if(!c)continue;let u=n.get(c.symbolId);if(u){for(let d of u)if(d!==t.relativePath&&!e.isIgnored(d))return!0}}return!1}var Ob=$("stale-abs-file-usage");function Na(e,t,n){if(!n)return!1;let r=M(t);if(!r)return!1;let i=Ob.get(e,t,()=>Mb(e,t,r));return i.importedLeaves.has(n)&&!i.usedLeaves.has(n)}function Mb(e,t,n){let r=new Set,i=new Set,s=P(e,t);if(!s)return{importedLeaves:r,usedLeaves:i};let o=n==="rust"?new Set(["use_declaration"]):n==="python"?new Set(["import_statement","import_from_statement"]):new Set(["import_statement"]),a=(l,c)=>{let u=c||o.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(u?r.add(l.text):i.add(l.text));for(let d of l.children)a(d,u)};return a(s.rootNode,!1),{importedLeaves:r,usedLeaves:i}}function Fb(e,t,n,r){if(!r)return!1;let i=w(e,t);if(!i)return!1;let s=Ys(e,t);if(s.length===0)return!1;let o=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`\\b${o}\\b`),l=i.split(`
|
|
857
|
+
`),c=0;for(let u=0;u<l.length;u++){if(!a.test(l[u]??""))continue;if(c++,!s.find(m=>m.startLine<=u&&u<=m.endLine))return!1}return c>0}function Ea(e,t,n){let r=w(e,t);if(!r)return"other";let i=r.split(`
|
|
858
|
+
`),s=Math.max(0,n-2),o=Math.min(i.length-1,n+2);for(let a=s;a<=o;a++){let c=(i[a]??"").replace(/^\s*\/\/.*$/g,"");if(/\b(?:export\s+)?(?:abstract\s+)?class\s+\w/.test(c))return"class";if(/\b(?:export\s+)?interface\s+\w/.test(c))return"interface";if(/\b(?:export\s+)?type\s+\w/.test(c))return"type";if(/\b(?:export\s+)?(?:const\s+)?enum\s+\w/.test(c))return"enum"}return"other"}function Tb(e,t){let n=w(e,t.relativePath);if(!n)return!1;let r=D(t.symbol);if(!r)return!1;let i=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=new RegExp(`\\b${i}\\b`),o=n.split(`
|
|
859
|
+
`);for(let a=0;a<o.length;a++)if(!(a>=t.startLine&&a<=t.endLine)&&s.test(o[a]??""))return!0;return!1}function $b(e,t,n){return e===0?{confidence:"high",reason:"unused \u2014 no consumers and defining file has no real usage"}:e===1&&t==="class"?{confidence:"low",reason:"1 consumer + class kind \u2014 likely 1:1 encapsulation, not over-abstraction"}:e===1&&!n?{confidence:"high",reason:"1 consumer + defining file never uses it \u2014 type belongs with its consumer"}:{confidence:"medium",reason:"1 consumer \u2014 single-use abstraction"}}function Fr(e){return e.endLine-e.startLine+1}function Da(...e){let t=new Map;for(let n of e)for(let[r,i]of n){let s=t.get(r);s||(s=new Set,t.set(r,s));for(let o of i)s.add(o)}return t}function Pn(e,t){let{scope:n,minLoc:r=10,limit:i=30}=t??{},{definitions:s,callerMap:o,calleeMap:a}=Ab(e,n);return s.map(l=>{let c=l.endLine-l.startLine+1,u=o.get(l.symbolId)?.size??0,d=a.get(l.symbolId)??[],m=d.filter(f=>f.file!==l.relativePath),g=new Set(m.map(f=>`${f.symbol}|${f.file}`)).size,p=new Set(d.map(f=>`${f.symbol}|${f.file}`)).size;return{symbol:l.symbol,shortName:h(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:u,fanOut:g,calleeCount:p,score:Math.round(c/50*(u/5)*Math.max(g/5,1)*100)/100}}).filter(l=>l.loc>=r).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,i)}function Ab(e,t){let n=new C(e),r=n.productionCallableDefinitions({scope:t,requireCallableSymbol:!0,includeSuppressed:!0});return{definitions:r,callerMap:n.crossFileCallerMap(r),calleeMap:n.calleeMap(r)}}var jb=50;function La(e,t={}){let n=Bb(e,t.scope),r=Wb(e,n),i=Hb(n,r);return{score:Vb(n,r),overview:{documents:n.statsResult.documents,symbols:n.statsResult.symbols,indexSizeBytes:n.statsResult.indexSizeBytes},findings:{deadSymbols:r.trueDeadCount,deadLoc:r.trueDeadLoc,isolatedSymbols:r.trueIsolatedCount,isolatedLoc:r.trueIsolatedLoc,cycles:r.realCycleCount,similarPairs:r.trueSimilarCount,extractionCandidates:n.extractResult.length,wrappers:n.wrapperResult.length,passthroughs:n.passthroughResult.length,staleTypes:r.trueStaleCount,driftedFiles:r.trueDriftCount,complexityHotspotCount:ka(n)},actions:i,topComplexity:n.complexResult.slice(0,5).map(o=>({symbol:o.shortName,score:o.score}))}}function Bb(e,t){return{statsResult:Zt(e),deadResult:_n(e,{scope:t,minLoc:3,skipBarrels:!0}),isolatedResult:Rn(e,{scope:t,minLoc:3}),cycleResult:In(e,{scope:t}),similarResult:Cn(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),extractResult:vn(e,{scope:t,minLoc:15,minCallees:5,limit:50}),wrapperResult:Ln(e,{scope:t,maxLoc:15,limit:50}),passthroughResult:kn(e,{scope:t,maxLoc:15,limit:50}),staleResult:wn(e,{scope:t,minLoc:3,limit:50}),driftResult:En(e,{scope:t}),complexResult:Pn(e,{scope:t,minLoc:10,limit:10})}}function Wb(e,t){let n=t.deadResult.symbols.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath)&&i.kind==="dead-code"),r=t.isolatedResult.filter(i=>!ze(e,i.relativePath)&&!Lt(e,i.symbol,i.relativePath));return{trueDeadCount:n.length,trueDeadLoc:n.reduce((i,s)=>i+s.loc,0),trueIsolatedCount:r.length,trueIsolatedLoc:r.reduce((i,s)=>i+s.loc,0),trueStaleCount:t.staleResult.length,trueDriftCount:t.driftResult.unusedImports+t.driftResult.layerViolations,trueSimilarCount:t.similarResult.length,realCycleCount:t.cycleResult.filter(i=>i.kind==="real").length}}function Hb(e,t){let n=[];if(t.trueDeadCount>0&&n.push({category:"Dead code",description:`${t.trueDeadCount} symbols with zero references anywhere \u2014 safe to delete`,effort:"low",impact:"high",count:t.trueDeadCount,locRecoverable:t.trueDeadLoc}),t.trueIsolatedCount>0&&n.push({category:"Isolated symbols",description:`${t.trueIsolatedCount} symbols completely disconnected from the codebase graph`,effort:"low",impact:"medium",count:t.trueIsolatedCount,locRecoverable:t.trueIsolatedLoc}),t.realCycleCount>0&&n.push({category:"Circular dependencies",description:`${t.realCycleCount} cycle(s) \u2014 break with dependency inversion or module restructuring`,effort:"medium",impact:"high",count:t.realCycleCount,locRecoverable:0}),t.trueSimilarCount>0&&n.push({category:"Similar functions",description:`${t.trueSimilarCount} pairs with real logic overlap (beyond shared imports) \u2014 consolidation candidates`,effort:"medium",impact:"medium",count:t.trueSimilarCount,locRecoverable:0}),e.extractResult.length>0&&n.push({category:"Extraction candidates",description:`${e.extractResult.length} large functions with isolated callee clusters \u2014 extract method opportunities`,effort:"medium",impact:"medium",count:e.extractResult.length,locRecoverable:0}),e.wrapperResult.length>0&&n.push({category:"Wrapper functions",description:`${e.wrapperResult.length} single-consumer symbols that could be inlined`,effort:"low",impact:"low",count:e.wrapperResult.length,locRecoverable:e.wrapperResult.reduce((s,o)=>s+o.loc,0)}),e.passthroughResult.length>0&&n.push({category:"Passthrough functions",description:`${e.passthroughResult.length} functions that just forward to one callee \u2014 unnecessary indirection`,effort:"low",impact:"low",count:e.passthroughResult.length,locRecoverable:e.passthroughResult.reduce((s,o)=>s+o.loc,0)}),t.trueStaleCount>0){let s=e.staleResult.filter(l=>l.consumers===0).length,o=t.trueStaleCount-s,a=[];s>0&&a.push(`${s} unused`),o>0&&a.push(`${o} single-consumer (not in types file)`),n.push({category:"Stale abstractions",description:`${a.join(", ")} \u2014 premature abstraction`,effort:"low",impact:"medium",count:t.trueStaleCount,locRecoverable:e.staleResult.reduce((l,c)=>l+c.loc,0)})}if(t.trueDriftCount>0){let s=[];e.driftResult.unusedImports>0&&s.push(`${e.driftResult.unusedImports} unused imports`),e.driftResult.layerViolations>0&&s.push(`${e.driftResult.layerViolations} layer violations`),n.push({category:"Structural drift",description:s.join(", "),effort:e.driftResult.layerViolations>0?"medium":"low",impact:e.driftResult.layerViolations>0?"medium":"low",count:t.trueDriftCount,locRecoverable:0})}let r={high:3,medium:2,low:1},i={low:3,medium:2,high:1};return n.sort((s,o)=>{let a=r[s.impact]*i[s.effort];return r[o.impact]*i[o.effort]-a}),n}function Vb(e,t){let n=Math.max(e.statsResult.documents,1),r=Math.max(e.statsResult.symbols,1),i=100,s=t.trueDeadCount/r;i-=Math.min(20,Math.round(s*200));let o=t.trueIsolatedCount/r;i-=Math.min(10,Math.round(o*200)),i-=Math.min(15,t.realCycleCount*5);let a=t.trueSimilarCount/r*1e3;i-=Math.min(10,Math.round(a));let l=e.extractResult.length/r*1e3;i-=Math.min(5,Math.round(l/2)),i-=Math.min(3,e.wrapperResult.length),i-=Math.min(3,e.passthroughResult.length);let c=t.trueStaleCount/Math.max(r*.1,1);i-=Math.min(8,Math.round(c*10));let u=t.trueDriftCount/n;i-=Math.min(5,Math.round(u*50));let d=ka(e);return i-=Math.min(5,d*2),Math.max(0,Math.min(100,i))}function ka(e){return e.complexResult.filter(t=>t.score>jb).length}function wa(e,t,n){let r=E(e,t),i=E(e,n);if(!r||!i)return null;let s=new Set(Z(e,r).map(f=>f.symbol)),o=new Set(Z(e,i).map(f=>f.symbol)),a=[];for(let f of s)o.has(f)&&a.push(f);let l=[];for(let f of s)o.has(f)||l.push(f);let c=[];for(let f of o)s.has(f)||c.push(f);let u=new Set([...s,...o]),d=u.size>0?a.length/u.size:0,m;u.size===0?m="Neither function calls other tracked symbols. There is no callee-pattern evidence for consolidation; inspect the source bodies directly.":a.length===0?m="These functions do not share any callees. They are not a callee-based consolidation candidate.":l.length===0&&c.length===0?m="These functions have identical tracked callee sets. They are a strong structural match, but identical callees do not prove interchangeable semantics; inspect signatures, control flow, and return values before consolidating.":l.length===0?m="A's tracked callees are a subset of B's. B may subsume part of A's structure, but verify signatures, guards, and non-call logic before replacing A with B.":c.length===0?m="B's tracked callees are a subset of A's. A may subsume part of B's structure, but verify signatures, guards, and non-call logic before replacing B with A.":l.length<=2&&c.length<=2?m=`Create a shared function with the ${a.length} common callees. Pass the ${l.length+c.length} divergent callees as parameters or strategy callbacks.`:m=`Extract the ${a.length} shared callees into a common helper. Each function calls the helper plus its own unique logic (${l.length} callees in A, ${c.length} in B).`;let g=r.endLine-r.startLine+1,p=i.endLine-i.startLine+1;return{symbolA:{symbol:r.symbol,shortName:h(r.symbol),file:r.relativePath,loc:g},symbolB:{symbol:i.symbol,shortName:h(i.symbol),file:i.relativePath,loc:p},similarity:d,sharedCallees:a.map(h),uniqueToA:l.map(h),uniqueToB:c.map(h),consolidationStrategy:m}}import{readFileSync as Pa}from"fs";import{extname as Ub,join as Oa}from"path";function Ma(e,t,n={}){let{context:r=0}=n,i=Jb(t);if(i)return zb(e,i.filePath,i.startLine,i.endLine,r);let s=E(e,t);return s?qb(e,s,r):null}function Jb(e){let t=e.match(/^(.+\.\w+):(\d+)-(\d+)$/);return t?{filePath:t[1],startLine:parseInt(t[2],10),endLine:parseInt(t[3],10)}:null}function qb(e,t,n){let r=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath),i=Oa(e.config.projectRoot,t.relativePath),s;try{s=Pa(i,"utf-8")}catch{return null}let o=s.split(`
|
|
860
|
+
`),a=Math.max(0,t.startLine-n),l=Math.min(o.length-1,t.endLine+n),c=o.slice(a,l+1).join(`
|
|
861
|
+
`);return{symbol:t.symbol,shortName:h(t.symbol),relativePath:t.relativePath,startLine:a,endLine:l,language:r?.language??Fa(t.relativePath),source:c}}function zb(e,t,n,r,i){let s=G(e,t);if(!s)return null;let o=e.get("SELECT relative_path, language FROM documents WHERE relative_path = ?",s);if(!o)return null;let a=Oa(e.config.projectRoot,o.relative_path),l;try{l=Pa(a,"utf-8")}catch{return null}let c=l.split(`
|
|
862
|
+
`),u=Math.max(0,n-1-i),d=Math.min(c.length-1,r-1+i),m=c.slice(u,d+1).join(`
|
|
863
|
+
`);return{symbol:`${o.relative_path}:${n}-${r}`,shortName:`${o.relative_path}:${n}-${r}`,relativePath:o.relative_path,startLine:u,endLine:d,language:o.language??Fa(o.relative_path),source:m}}function Fa(e){switch(Ub(e).toLowerCase()){case".ts":case".tsx":case".mts":case".cts":return"typescript";case".js":case".jsx":case".mjs":case".cjs":return"javascript";case".py":case".pyi":return"python";case".rs":return"rust";case".go":return"go";case".java":return"java";case".kt":case".kts":return"kotlin";case".scala":return"scala";case".rb":return"ruby";case".php":return"php";case".cs":return"csharp";case".vb":return"vb";case".dart":return"dart";case".c":case".h":return"c";case".cc":case".cpp":case".cxx":case".hpp":case".hh":case".hxx":return"cpp";case".vue":return"vue";default:return null}}import{readFileSync as Gb}from"fs";import{join as Kb}from"path";function Ta(e,t){let n=E(e,t);if(!n)return null;let r=new C(e),i=eS(Qb(e,n.relativePath,n.startLine,n.endLine),Yb(e,n.relativePath)),s=n.endLine-n.startLine+1,a=r.calleeMap([n],{additive:!0}).get(n.symbolId)??[],l=new Set(a.map(c=>c.symbol));return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,loc:s,branches:i,cyclomaticEstimate:i+1,calleeCount:l.size,fanIn:Xb(e,n.symbolId),fanOut:Zb(a,n.relativePath)}}function Yb(e,t){return e.get("SELECT language FROM documents WHERE relative_path = ?",t)?.language??"unknown"}function Qb(e,t,n,r){try{return Gb(Kb(e.config.projectRoot,t),"utf-8").split(`
|
|
864
|
+
`).slice(n,r+1).join(`
|
|
865
|
+
`)}catch{return""}}function Xb(e,t){return e.get(`SELECT COUNT(DISTINCT c.document_id) AS c
|
|
769
866
|
FROM mentions m
|
|
770
867
|
JOIN chunks c ON m.chunk_id = c.id
|
|
771
|
-
WHERE m.symbol_id = ? AND m.role != 1`,t
|
|
868
|
+
WHERE m.symbol_id = ? AND m.role != 1`,t)?.c??0}function Zb(e,t){return new Set(e.filter(n=>n.file!==t).map(n=>n.symbol)).size}function eS(e,t){let n=tS(e),r=0,i=[/\bif\b/g,/\belse\s+if\b/g,/\belse\b/g,/\bfor\b/g,/\bwhile\b/g,/\bswitch\b/g,/\bcase\b/g,/\bcatch\b/g,/\?\s*[^?]/g,/&&/g,/\|\|/g];for(let s of i){let o=n.match(s);o&&(r+=o.length)}if(t==="python"){let s=[/\belif\b/g,/\bexcept\b/g,/\bfinally\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="rust"){let s=[/\bmatch\b/g,/=>/g,/\bloop\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="ruby"){let s=[/\belsif\b/g,/\bunless\b/g,/\brescue\b/g,/\bwhen\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}else if(t==="go"){let s=[/\bselect\b/g,/\bdefer\b/g];for(let o of s){let a=n.match(o);a&&(r+=a.length)}}return r}function tS(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function $a(e,t){let n=E(e,t);if(!n)return null;let r=[{file:n.relativePath,line:n.startLine}],i=Te(e,n),o=(i.length>0?i:Ie(e,n)).filter(c=>!e.isIgnored(c.file)).map(c=>({file:c.file,line:c.line,enclosingSymbol:c.enclosingSymbol??"(top-level)",enclosingShort:c.enclosingSymbol?h(c.enclosingSymbol):"(top-level)"})),{producers:a,consumers:l}=nS(e,n,o);return{symbol:n.symbol,shortName:h(n.symbol),relativePath:n.relativePath,definitionSites:r.filter(c=>!e.isIgnored(c.file)),usageSites:o,producers:a.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:h(c.symbol),file:c.file})),consumers:l.filter(c=>!e.isIgnored(c.file)).map(c=>({symbol:c.symbol,shortName:c.symbol===c.file?"(top-level)":h(c.symbol),file:c.file}))}}function nS(e,t,n){let r=Tr(Z(e,t,{limit:30}).map(o=>({symbol:o.symbol,file:o.file}))),i=Tr(ie(e,t,{limit:30})),s=i.length>0?i:Tr(n.map(o=>({symbol:o.enclosingSymbol==="(top-level)"?o.file:o.enclosingSymbol,file:o.file})));return{producers:r,consumers:s}}function Tr(e){let t=new Set,n=[];for(let r of e){let i=`${r.symbol}|${r.file}`;t.has(i)||(t.add(i),n.push(r))}return n}function Aa(e,t,n={}){let{direction:r="backward",maxDepth:i=3}=n,s=E(e,t);return s?r==="backward"?rS(e,s,i):iS(e,s):null}function rS(e,t,n){let r=[],i=new Set([t.symbol]),s=[t];for(let o=1;o<=n&&s.length!==0;o++){let a=[];for(let l of s){let c=Z(e,l);for(let u of c){if(i.has(u.symbol))continue;i.add(u.symbol),r.push({symbol:u.symbol,shortName:h(u.symbol),file:u.file,relationship:o===1?"referenced within definition (callee)":`depth ${o} callee`});let d=it(e,u.symbol);d&&!e.isIgnored(d.relativePath)&&a.push(d)}}s=a}return{symbol:t.symbol,shortName:h(t.symbol),direction:"backward",connectedSymbols:r}}function iS(e,t){let n=Te(e,t),r=n.length>0?n:Ie(e,t),i=new Set,s=[],o=new C(e);for(let a of r){if(s.length>=30)break;if(e.isIgnored(a.file))continue;let l=a.enclosingSymbol??ae(o.definitionsForFile(a.file),a.line)?.symbol??null;if(!l||l===t.symbol)continue;let c=it(e,l);!c||e.isIgnored(c.relativePath)||i.has(c.symbol)||(i.add(c.symbol),s.push({symbol:c.symbol,shortName:h(c.symbol),file:c.relativePath,relationship:`references target at ${a.file}:${a.line+1}`}))}return s.sort((a,l)=>a.file.localeCompare(l.file)),{symbol:t.symbol,shortName:h(t.symbol),direction:"forward",connectedSymbols:s}}function ja(e,t={}){let{scope:n,limit:r}=t,i=new C(e),s=pS([...sS(e,n),...lS(e,i,n)]);return fS(s),r?s.slice(0,r):s}function sS(e,t){let n=[];for(let r of oS(e,t)){if(e.isIgnored(r.barrel_path)||e.isIgnored(r.original_path)||Dr(e,r.barrel_path))continue;let i=aS(e,r),s=i?.barrel_consumers??0,o=i?.direct_consumers??0;s!==0||o!==0||n.push({barrelFile:r.barrel_path,symbol:r.symbol,shortName:h(r.symbol),originalFile:r.original_path,barrelConsumers:s,directConsumers:o})}return n}function oS(e,t){let n=t?`AND barrel_d.relative_path LIKE '%${t}%'`:"";return e.all(`SELECT DISTINCT
|
|
772
869
|
barrel_d.id AS barrel_doc_id,
|
|
773
870
|
barrel_d.relative_path AS barrel_path,
|
|
774
871
|
gs.id AS symbol_id,
|
|
@@ -797,121 +894,123 @@ ${d}`,c+=1+d.length,m+=Bi(d),s+=d.length+1}let u=Qc(l);u&&t.push({...u,start:r,e
|
|
|
797
894
|
${e.symbolNoiseFor("gs")}
|
|
798
895
|
-- Only function-level symbols (ending with ().), not module-level
|
|
799
896
|
AND gs.symbol LIKE '%().'
|
|
800
|
-
${
|
|
801
|
-
ORDER BY barrel_d.relative_path, gs.symbol`)
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
897
|
+
${n}
|
|
898
|
+
ORDER BY barrel_d.relative_path, gs.symbol`)}function aS(e,t){return e.get(`SELECT
|
|
899
|
+
SUM(CASE WHEN uses_barrel = 1 THEN 1 ELSE 0 END) AS barrel_consumers,
|
|
900
|
+
SUM(CASE WHEN uses_barrel = 0 THEN 1 ELSE 0 END) AS direct_consumers
|
|
901
|
+
FROM (
|
|
902
|
+
SELECT
|
|
903
|
+
consumer_d.id AS consumer_doc_id,
|
|
904
|
+
MAX(CASE WHEN EXISTS (
|
|
905
|
+
SELECT 1
|
|
906
|
+
FROM mentions barrel_m
|
|
907
|
+
JOIN chunks barrel_c ON barrel_m.chunk_id = barrel_c.id
|
|
908
|
+
WHERE barrel_c.document_id = consumer_d.id
|
|
909
|
+
AND barrel_m.role != 1
|
|
910
|
+
AND barrel_m.symbol_id IN (
|
|
911
|
+
SELECT m2.symbol_id
|
|
912
|
+
FROM mentions m2
|
|
913
|
+
JOIN chunks c2 ON m2.chunk_id = c2.id
|
|
914
|
+
WHERE c2.document_id = ?
|
|
915
|
+
AND m2.role != 1
|
|
916
|
+
)
|
|
917
|
+
) THEN 1 ELSE 0 END) AS uses_barrel
|
|
918
|
+
FROM mentions ref_m
|
|
919
|
+
JOIN chunks ref_c ON ref_m.chunk_id = ref_c.id
|
|
920
|
+
JOIN documents consumer_d ON ref_c.document_id = consumer_d.id
|
|
921
|
+
WHERE ref_m.symbol_id = ?
|
|
922
|
+
AND ref_m.role != 1
|
|
923
|
+
AND consumer_d.id != ?
|
|
924
|
+
AND consumer_d.id != ?
|
|
925
|
+
${e.pathExclusionsFor("consumer_d")}
|
|
926
|
+
GROUP BY consumer_d.id
|
|
927
|
+
)`,t.barrel_doc_id,t.symbol_id,t.barrel_doc_id,t.original_doc_id)}function lS(e,t,n){let r=[];for(let i of cS(e,n))Ba(e,i,i)>0||r.push(...uS(e,t,i));return r}function cS(e,t){return e.all(`SELECT relative_path
|
|
831
928
|
FROM documents
|
|
832
929
|
WHERE 1 = 1
|
|
833
|
-
${
|
|
930
|
+
${t?"AND relative_path LIKE ?":""}
|
|
834
931
|
${e.pathExclusionsFor("documents")}
|
|
835
|
-
ORDER BY relative_path`,...
|
|
932
|
+
ORDER BY relative_path`,...t?[`%${t}%`]:[]).map(r=>r.relative_path).filter(r=>!e.isIgnored(r)).filter(r=>Rr(e,r).length>0)}function uS(e,t,n){return Rr(e,n).filter(r=>r.sourcePath&&!e.isIgnored(r.sourcePath)).flatMap(r=>dS(e,t,n,r.sourcePath))}function dS(e,t,n,r){let i=mS(t,r);return i?[{barrelFile:n,symbol:i.symbol,shortName:h(i.symbol),originalFile:r,barrelConsumers:0,directConsumers:Ba(e,r,n)}]:[]}function Ba(e,t,n){let r=e.all(`SELECT relative_path
|
|
836
933
|
FROM documents
|
|
837
934
|
WHERE 1 = 1
|
|
838
935
|
${e.pathExclusionsFor("documents")}
|
|
839
|
-
ORDER BY relative_path`),i=new Set;for(let
|
|
840
|
-
`).
|
|
841
|
-
`)
|
|
842
|
-
|
|
936
|
+
ORDER BY relative_path`),i=new Set;for(let s of r)if(!(e.isIgnored(s.relative_path)||s.relative_path===n))for(let o of J(e,s.relative_path))o.sourcePath===t&&i.add(s.relative_path);return i.size}function mS(e,t){let n=e.definitionsForFile(t);return n.find(r=>V(r.symbol)==="method")??n[0]??null}function pS(e){let t=new Set,n=[];for(let r of e){let i=`${r.barrelFile}|${r.symbol}|${r.originalFile}`;t.has(i)||(t.add(i),n.push(r))}return n}function fS(e){e.sort((t,n)=>n.directConsumers-t.directConsumers||t.barrelFile.localeCompare(n.barrelFile)||t.shortName.localeCompare(n.shortName))}function Wa(e,t={}){let{scope:n,minLoc:r=1,limit:i}=t,s=new Map;for(let a of oe(e,{scope:n})){if(!a.isFunctionLike||e.isIgnored(a.relativePath))continue;let l=a.endLine-a.startLine+1;if(l<r)continue;let c=gS(e,a);if(!c)continue;let u={symbol:a.symbol,shortName:h(a.symbol),file:a.relativePath,startLine:a.startLine,endLine:a.endLine,loc:l},d=s.get(c);d?d.push(u):s.set(c,[u])}let o=[];for(let[a,l]of s)l.length<2||o.push({signature:a,functions:l});return o.sort((a,l)=>{let c=l.functions.length-a.functions.length;if(c!==0)return c;let u=a.functions.reduce((m,g)=>m+g.loc,0);return l.functions.reduce((m,g)=>m+g.loc,0)-u}),i?o.slice(0,i):o}function gS(e,t){let n=oo(e,t);if(n)return n;let r=hS(t.documentation),i=r?SS(r):null;return i||xS(yS(e,t.relativePath,t.startLine,t.endLine,t.leaf),t.leaf)}function hS(e){return He(Ve(e))}function yS(e,t,n,r,i){let s=w(e,t);if(!s)return null;let o=s.split(/\r?\n/),a=IS(o,n,r,i);for(let l of a){let c=Math.min(o.length-1,Math.max(l,l+4)),u="";for(let d=l;d<=c;d+=1){let m=o[d]?.trim();if(m&&(u=u?`${u} ${m}`:m,bS(u)))return u}if(u&&u.includes("("))return u}return null}function bS(e){let t=e.replace(/\s+/g," ").trim();return!t.includes("(")||RS(t)>0?!1:/[;{]$/.test(t)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(t)||/\)\s*As\s+.+$/i.test(t)}function SS(e){if(!e||!e.trim())return null;let t=e.replace(/^```\w*\s*/,"").replace(/\s*```$/,"").replace(/^\(method\)\s*/,"").replace(/^\(property\)\s*/,"").replace(/^\(function\)\s*/,"").replace(/^\(class\)\s*/,"").replace(/^\(interface\)\s*/,"").replace(/^\(enum\)\s*/,"").replace(/^\(type alias\)\s*/,"").replace(/^\(const\)\s*/,"").replace(/^\(var\)\s*/,"").trim(),n=t.indexOf("(");return n===-1||(t=t.slice(n),t=t.replace(/\s+/g,"").toLowerCase(),t.length<3)?null:t}function xS(e,t){if(!e||!e.trim())return null;let n=e.replace(/\s+/g," ").trim(),r=n.indexOf("(");if(r===-1)return null;let i=n.slice(0,r),o=new RegExp(`\\b${Ha(t)}\\b`,"i").exec(i);o&&typeof o.index=="number"&&(i=i.slice(0,o.index)),i=i.replace(/\b(public|private|protected|internal|final|static|abstract|sealed|virtual|override|async|suspend|inline|constexpr|consteval|constinit|const|pub|fn|function|def|sub|friend|shared|readonly|new|open|partial|export)\b/gi," ").replace(/\s+/g," ").trim();let a=_S(n.slice(r)).replace(/\)\s*=\s*[\s\S]*$/,")").replace(/\s+throws\s+[^={]+$/i,"").replace(/\s+where\s+.+$/i,"").replace(/\s+/g," ").trim();if(!a.startsWith("("))return null;let l=`${i?`${i} `:""}${a}`.replace(/\s+/g,"").toLowerCase();return l.length>=3?l:null}function _S(e){let t=0,n=0,r=0,i=0,s=null,o=!1;for(let a=0;a<e.length;a+=1){let l=e[a];if(s){if(o){o=!1;continue}if(l==="\\"){o=!0;continue}l===s&&(s=null);continue}if(l==='"'||l==="'"||l==="`"){s=l;continue}if(l==="(")t+=1;else if(l===")")t=Math.max(0,t-1);else if(l==="[")r+=1;else if(l==="]")r=Math.max(0,r-1);else if(l==="<")i+=1;else if(l===">")i=Math.max(0,i-1);else if(l==="{"){if(t===0&&r===0&&i===0)return e.slice(0,a);n+=1}else if(l==="}")n=Math.max(0,n-1);else if(l==="="&&e[a+1]===">"&&t===0&&n===0&&r===0&&i===0)return e.slice(0,a)}return e}function IS(e,t,n,r){let i=Ha(r),s=new RegExp(`\\b${i}\\b\\s*\\(`,"i"),o=new RegExp(`\\bdef\\s+${i}\\b`,"i"),a=[],l=new Set,c=Math.max(0,Math.min(t,e.length-1)),u=Math.max(c,Math.min(e.length-1,Math.max(n,t+4)));for(let d=c;d<=u;d+=1){let m=e[d]??"";(s.test(m)||o.test(m))&&!l.has(d)&&(l.add(d),a.push(d))}for(let d=0;d<e.length;d+=1){let m=e[d]??"";(s.test(m)||o.test(m))&&!l.has(d)&&(l.add(d),a.push(d))}return a}function RS(e){let t=0;for(let n of e)n==="("&&(t+=1),n===")"&&(t-=1);return t}function Ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ce(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function Tt(e){let t=ve(e),n=Ne(e,t);return process.env.SCIP_QUERY_INDEX_DB??(Va(n.dbPath)?n.dbPath:CS(e,"index.db"))}function vS(){let e=Ce(),t=ve(e),n=Ne(e,t),r=Tt(e);Va(r)||(console.error("error: No index.db found. Run: scip-query reindex"),process.exit(1));let i={dbPath:r,indexPath:process.env.SCIP_QUERY_INDEX_SCIP??n.indexPath,projectRoot:e,entryRoots:t.entryRoots,semantic:t.semantic},s=Ye(e);return new Xt(i,s)}function I(e){let t=vS();try{e(t)}finally{t.close()}}function Ua(e,t){return t.concat([e])}function v(e){return parseInt(e,10)}function $r(e){let t=parseInt(e,10);if(!Number.isFinite(t)||t<1)throw new Error(`Expected a positive integer, got ${e}`);return t}function On(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function Ja(e){switch(e.state){case"idle":return"Watching (idle)";case"waiting":{let t=Math.round((e.reindexAt-Date.now())/1e3);return`${e.changedFiles} file(s) changed, reindexing in ${t}s...`}case"indexing":return`Reindexing... (${Math.round((Date.now()-e.startedAt)/1e3)}s)`;case"cooldown":return`Cooldown (${Math.round((e.until-Date.now())/1e3)}s)${e.dirty?" \u2014 changes pending":""}`;default:return NS(e)}}function NS(e){throw new Error(`Unhandled watcher status: ${JSON.stringify(e)}`)}var LS=ES(import.meta.url),{version:kS}=wS();function wS(){for(let e of["../package.json","../../package.json"])try{return LS(e)}catch{}return{version:"0.0.0"}}function ye(e){console.log(`Heuristic ${e}: review before acting; these are candidates, not exact compiler facts.
|
|
937
|
+
`)}S.name("scip-query").description("Language-agnostic code intelligence CLI powered by SCIP indexes").version(kS);S.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",Ua,[]).option("--pnpm-workspaces","Enable pnpm workspace support (TypeScript)").option("--force","Rebuild even if source inputs are unchanged").option("--allow-partial","Write an incomplete index when one or more detected languages fail").option("--indexer-concurrency <n>","Number of language indexers to run at once",$r).action(async e=>{let t=Ce(),n=ve(t),r=Ne(t,n);try{let i=await ki({projectRoot:t,languages:e.language.length>0?e.language:n.languages,outputScip:r.indexPath,outputDb:r.dbPath,pnpmWorkspaces:e.pnpmWorkspaces||n.indexer?.typescript?.pnpmWorkspaces,skipIfUnchanged:!e.force,allowPartial:e.allowPartial,indexerConcurrency:e.indexerConcurrency});console.log(`${i.reused?"Reused":"Indexed"} ${i.languages.join(", ")} in ${(i.durationMs/1e3).toFixed(1)}s`)}catch(i){console.error(`error: ${i instanceof Error?i.message:i}`),process.exit(1)}});S.command("augment-sources").description("Add source files skipped by upstream SCIP indexers to the SQLite documents table").action(()=>{let e=Ce(),t=Tt(e);try{let n=De({projectRoot:e,dbPath:t,onStatus:r=>console.log(r)});console.log(`Scanned ${n.scanned} auxiliary source files; inserted ${n.inserted}.`)}catch(n){console.error(`error: ${n instanceof Error?n.message:n}`),process.exit(1)}});S.command("augment-vue").description("Add compiler-resolved Vue SFC references to the SQLite index using Volar").option("--project <tsconfig>","Vue tsconfig path","frontend/tsconfig.scip.json").action(e=>{let t=Ce(),n=Tt(t);try{let r=Kn({projectRoot:t,dbPath:n,tsconfig:e.project,onStatus:i=>console.log(i)});console.log(`Vue files: ${r.vueFiles}; resolved references: ${r.resolvedReferences}; inserted mentions: ${r.insertedMentions}.`)}catch(r){console.error(`error: ${r instanceof Error?r.message:r}`),process.exit(1)}});S.command("stats").description("Show index statistics").action(()=>I(e=>{let t=x.stats(e);console.log(`Documents: ${t.documents}`),console.log(`Symbols: ${t.symbols}`),console.log(`Definitions: ${t.definitions}`),console.log(`References: ${t.references}`),console.log(`Index size: ${On(t.indexSizeBytes)}`),t.lastBuilt&&console.log(`Last built: ${t.lastBuilt.toISOString().replace("T"," ").slice(0,19)}`)}));S.command("files <pattern>").description("Find files matching a pattern").action(e=>I(t=>{b.list(x.files(t,e),n=>n.relativePath)}));S.command("symbols <file>").description("List symbols defined in a file (with line ranges + signatures)").action(e=>I(t=>{b.list(x.symbols(t,e),n=>{let r=n.signature?` \u2014 ${n.signature}`:"";return` ${me(n.startLine,n.endLine)} ${n.shortName}${r}`})}));S.command("methods <className>").description("List methods of a class (with line ranges)").action(e=>I(t=>{b.list(x.methods(t,e),n=>` ${me(n.startLine,n.endLine)} ${n.name}`)}));S.command("refs <symbol>").description("Find all files referencing a symbol").action(e=>I(t=>{b.groupedByFile(x.refs(t,e),n=>` line ${be(n.line)}`)}));S.command("trace <symbol>").description("Trace a symbol: definition + all references").action(e=>I(t=>{let n=x.trace(t,e),r=[];for(let o of n.definitions){let a=o.signature?` \u2014 ${o.signature}`:"";r.push(` ${pe(o.relativePath,o.startLine,o.endLine)}${a}`),o.source&&r.push(o.source.split(`
|
|
938
|
+
`).map((l,c)=>` ${be(o.startLine+c)} ${l}`).join(`
|
|
939
|
+
`))}let i=[],s="";for(let o of n.referencedBy)o.relativePath!==s&&(s&&i.push(""),i.push(` ${o.relativePath}`),s=o.relativePath),i.push(` line ${be(o.line)} in ${o.enclosingShort}`);b.sectionedReport([{title:"DEFINITION",rows:r},{title:"REFERENCED BY",rows:i}])}));S.command("deps <file>").description("Files this file depends on (internal)").action(e=>I(t=>{b.list(x.deps(t,e),n=>n.relativePath)}));S.command("rdeps <file>").description("Files that depend on this file/module").action(e=>I(t=>{b.list(x.rdeps(t,e),n=>n.relativePath)}));S.command("system <module>").description("Full module map: files, symbols, deps in/out").action(e=>I(t=>{let n=x.system(t,e);b.sectionedReport([{title:"FILES",rows:n.files},{title:"EXPORTED SYMBOLS",rows:n.symbols.map(r=>` ${me(r.startLine,r.endLine)} ${r.shortName}`)},{title:"DEPENDS ON (internal)",rows:n.dependsOn.map(r=>` ${r}`)},{title:"DEPENDED ON BY",rows:n.dependedOnBy.map(r=>` ${r}`)}])}));S.command("surface <module>").description("What symbols consumers actually use from this module").action(e=>I(t=>{b.list(x.surface(t,e),n=>` ${n.consumer} \u2192 ${n.shortName}`)}));S.command("dead [scope]").description("Find dead code and file-internal symbols (no cross-file consumers)").option("--min-loc <n>","Only show symbols >= N lines",v,1).option("--include-tests","Include test files").option("--skip-barrels","Ignore refs from barrel re-export files").option("--include-members","Include class members").option("--only-dead","Show only [dead code] symbols (skip [file-internal only])").option("--only-internal","Show only [file-internal only] symbols (skip [dead code])").action((e,t)=>I(n=>{let r={scope:e||void 0,minLoc:t.minLoc,includeTests:t.includeTests,skipBarrels:t.skipBarrels,includeMembers:t.includeMembers},i=x.dead(n,r),s=i.symbols.filter(f=>f.kind==="dead-code"),o=i.symbols.filter(f=>f.kind!=="dead-code"),a=!t.onlyInternal,l=!t.onlyDead,c=a?s:[],u=l?o:[];if(c.length===0&&u.length===0)return b.empty("No matching dead-code symbols found.");let d=(f,y,L,k)=>{console.log(`\u2550\u2550\u2550 ${y} (${f.length}, ${k} LOC) \u2550\u2550\u2550`),console.log(L),console.log("");let F=new Map;for(let _ of f){let O=F.get(_.relativePath)??[];O.push(_),F.set(_.relativePath,O)}let T=[...F.entries()].map(([_,O])=>({file:_,bucket:O,totalLoc:O.reduce((N,z)=>N+z.loc,0)})).sort((_,O)=>O.totalLoc-_.totalLoc||_.file.localeCompare(O.file)),R=!0;for(let{file:_,bucket:O}of T){R||console.log(""),R=!1,console.log(` ${_}`),O.sort((N,z)=>N.startLine-z.startLine);for(let N of O)console.log(` ${me(N.startLine,N.endLine)} (${N.loc} LOC) ${N.shortName}`)}},m=c.reduce((f,y)=>f+y.loc,0),g=u.reduce((f,y)=>f+y.loc,0);c.length>0&&d(c,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
|
|
940
|
+
Safe to delete.`,m),u.length>0&&(c.length>0&&console.log(""),d(u,"FILE-INTERNAL ONLY",` Used only within the same file (no cross-file callers). Could be a
|
|
843
941
|
single-use helper, an abstraction-in-progress, or a callback registered
|
|
844
942
|
through a framework path that static analysis cannot trace (signal
|
|
845
943
|
handlers, event listeners, dependency injection). NOT necessarily dead \u2014
|
|
846
|
-
review case by case.`,u)),console.log(`
|
|
847
|
-
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`),console.log(`Total: ${
|
|
848
|
-
${
|
|
849
|
-
Cycle ${
|
|
850
|
-
${
|
|
851
|
-
${
|
|
852
|
-
${
|
|
853
|
-
Chain ${
|
|
854
|
-
`),
|
|
855
|
-
${Math.round(i.similarity*100)}% similar:`,` A: ${i.shortNameA} (${i.fileA})`,` B: ${i.shortNameB} (${i.fileB})`,`
|
|
856
|
-
`)})}else{let
|
|
944
|
+
review case by case.`,g));let p=[];a&&p.push(`${c.length} dead code (${m} LOC)`),l&&p.push(`${u.length} file-internal (${g} LOC)`),console.log(`
|
|
945
|
+
\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500`),console.log(`Total: ${c.length+u.length} symbols \u2014 ${p.join(" + ")}`)}));S.command("hotspots").description("Most-referenced symbols in the codebase (choke points)").option("-n, --limit <n>","Number of results",v,30).option("-s, --scope <path>","Limit to files matching path").action(e=>I(t=>{let n=x.hotspots(t,{limit:e.limit,scope:e.scope});b.table(["refs","files","symbol"],n.map(r=>` ${String(r.refCount).padStart(4)} ${String(r.fileCount).padStart(5)} ${r.shortName}`))}));S.command("imports <file>").description("What symbols does this file import?").action(e=>I(t=>{let n=x.imports(t,e);if(n.length===0){b.empty("No imports found (indexer may not emit role=2 for this language).");return}b.list(n,r=>` ${r.shortName} \u2190 ${r.fromFile}`)}));S.command("imported-by <symbol>").description("Which files import this symbol?").action(e=>I(t=>{b.list(x.importedBy(t,e),n=>` ${n.fromFile}`)}));S.command("unused-imports <file>").description("Find imports not referenced in the same file").action(e=>I(t=>{let n=x.unusedImports(t,e);if(n.length===0)return b.empty("No unused imports found.");b.list(n,r=>` ${r.shortName} in ${r.importedIn}`),console.log(`
|
|
946
|
+
${n.length} unused import(s)`)}));S.command("outline <file>").description("Tree view of symbols in a file (using nesting hierarchy)").action(e=>I(t=>{let n=x.outline(t,e);function r(i,s){for(let o of i){let a=" ".repeat(s);console.log(`${a}${me(o.startLine,o.endLine)} ${o.shortName}`),r(o.children,s+1)}}r(n,0)}));S.command("members <symbol>").description("All children of a symbol (methods, fields, nested types)").action(e=>I(t=>{b.list(x.members(t,e),n=>` ${me(n.startLine,n.endLine)} [${n.kind}] ${n.shortName}`)}));S.command("fan-in [symbol]").description("How many files reference a symbol (or top fan-in across codebase)").option("-n, --limit <n>","Number of results for top mode",v,30).option("-s, --scope <path>","Limit to files matching path").action((e,t)=>I(n=>{if(e){let r=x.fanIn(n,e);if(r.length===0)return b.empty(`No fan-in for ${e}.`);b.list(r,i=>` ${String(i.count).padStart(4)} files ${i.name}`)}else b.table(["files","symbol"],x.topFanIn(n,{limit:t.limit,scope:t.scope}).map(r=>` ${String(r.count).padStart(5)} ${r.name}`))}));S.command("fan-out [file]").description("How many external symbols a file uses (or top fan-out across codebase)").option("-n, --limit <n>","Number of results for top mode",v,30).option("-s, --scope <path>","Limit to files matching path").action((e,t)=>I(n=>{if(e){let r=x.fanOut(n,e);if(r.length===0)return b.empty(`No fan-out for ${e}.`);b.list(r,i=>` ${String(i.count).padStart(4)} symbols ${i.name}`)}else b.table(["symbols","file"],x.topFanOut(n,{limit:t.limit,scope:t.scope}).map(r=>` ${String(r.count).padStart(7)} ${r.name}`))}));S.command("coupling [file1] [file2]").description("Coupling between two files, or top coupled pairs in codebase").option("-n, --limit <n>","Number of results for top mode",v,20).option("-s, --scope <path>","Limit to files matching path").action((e,t,n)=>I(r=>{if(e&&t){let i=x.coupling(r,e,t);console.log(`${i.file1} \u2194 ${i.file2}: ${i.sharedSymbols} shared symbols`)}else b.table(["shared","file1 \u2192 file2"],x.topCoupling(r,{limit:n.limit,scope:n.scope}).map(i=>` ${String(i.sharedSymbols).padStart(6)} ${i.file1} \u2192 ${i.file2}`))}));S.command("cycles").description("Detect circular dependency chains between files").option("-s, --scope <path>","Limit to files matching path").option("--max-depth <n>","Maximum cycle depth",v,10).action(e=>I(t=>{let n=x.cycles(t,{scope:e.scope,maxDepth:e.maxDepth});if(n.length===0)return b.empty("No circular dependencies found.");let r=n.filter(s=>s.kind==="real"),i=n.filter(s=>s.kind==="module-hierarchy");for(let s=0;s<r.length;s++){console.log(`
|
|
947
|
+
Cycle ${s+1} (${r[s].path.length-1} files):`);for(let o=0;o<r[s].path.length;o++){let a=o<r[s].path.length-1?" \u2192":" (cycle)";console.log(` ${r[s].path[o]}${a}`)}}r.length===0?console.log("No real circular dependencies found."):console.log(`
|
|
948
|
+
${r.length} real cycle(s) found.`),i.length>0&&console.log(`(${i.length} module-hierarchy cycle(s) hidden \u2014 barrel files participating in normal parent/child re-export patterns. Pass --include-module-hierarchy to see them.)`)}));S.command("bottlenecks").description("Find coupling hubs: high fan-in AND high fan-out").option("-n, --limit <n>","Number of results",v,20).option("-s, --scope <path>","Limit to files matching path").option("--min-fan-in <n>","Minimum fan-in",v,2).option("--min-fan-out <n>","Minimum fan-out",v,2).action(e=>I(t=>{let n=x.bottlenecks(t,{limit:e.limit,scope:e.scope,minFanIn:e.minFanIn,minFanOut:e.minFanOut});if(n.length===0)return b.empty("No bottlenecks found.");b.table(["score","fan-in","fan-out","symbol"],n.map(r=>` ${String(r.score).padStart(5)} ${String(r.fanIn).padStart(6)} ${String(r.fanOut).padStart(7)} ${r.shortName}`))}));S.command("isolated").description("Find completely orphaned symbols (no references at all)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum lines of code",v,3).action(e=>I(t=>{let n=x.isolated(t,{scope:e.scope,minLoc:e.minLoc});if(n.length===0)return b.empty("No isolated symbols found.");b.groupedByFile(n,r=>` ${me(r.startLine,r.endLine)} (${r.loc} LOC) ${r.shortName}`),console.log(`
|
|
949
|
+
${n.length} isolated symbol(s)`)}));S.command("by-kind <kind>").description("Find symbols by SCIP kind (class, interface, enum, function, etc.)").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",v,100).action((e,t)=>I(n=>{let r=x.byKind(n,e,{scope:t.scope,limit:t.limit});if(r.length===0)return b.empty(`No symbols found for kind "${e}". Use "kind-counts" to see available kinds.`);b.list(r,i=>` ${pe(i.relativePath,i.startLine,i.endLine)} [${i.kindName}] ${i.shortName}`),console.log(`
|
|
950
|
+
${r.length} symbol(s)`)}));S.command("kind-counts").description("Histogram of symbol kinds in the codebase").option("-s, --scope <path>","Limit to files matching path").action(e=>I(t=>{let n=x.kindCounts(t,{scope:e.scope});b.table(["count","kind"],n.map(r=>` ${String(r.count).padStart(5)} ${r.kindName} (${r.kind})`))}));S.command("deep-chains").description("Find the longest transitive dependency chains").option("-n, --limit <n>","Number of chains to show",v,10).option("-s, --scope <path>","Limit to files matching path").option("--min-depth <n>","Minimum chain depth",v,3).action(e=>I(t=>{let n=x.deepChains(t,{limit:e.limit,scope:e.scope,minDepth:e.minDepth});if(n.length===0)return b.empty("No deep chains found.");for(let r=0;r<n.length;r++){console.log(`
|
|
951
|
+
Chain ${r+1} (depth ${n[r].depth}):`);for(let i of n[r].chain)console.log(` \u2192 ${i}`)}}));S.command("hierarchy <symbol>").description("Show a symbol's ancestry chain (method \u2192 class \u2192 module)").action(e=>I(t=>{let n=x.hierarchy(t,e);if(n.length===0)return b.empty("Symbol not found.");b.list(n,r=>`${" ".repeat(r.depth)}${r.shortName}`)}));S.command("call-graph <symbol>").description("Show incoming callers and outgoing callees for a symbol").action(e=>I(t=>{let n=x.callGraph(t,e);if(!n)return b.empty("Symbol not found.");console.log(`Symbol: ${n.shortName}
|
|
952
|
+
`),b.sectionedReport([{title:`CALLERS (${n.callers.length})`,rows:n.callers.map(r=>` ${r.file} ${r.shortName}`)},{title:`CALLEES (${n.callees.length})`,rows:n.callees.map(r=>` ${r.file} ${r.shortName}`)}])}));S.command("similar [symbol]").description("Find heuristic function similarity candidates from callee fingerprints").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.4).option("-n, --limit <n>","Number of results",v,20).option("-s, --scope <path>","Limit to files matching path").option("--min-callees <n>","Minimum callees to consider",v,4).option("--cross-file-only","Only show cross-file pairs (skip same-file matches)").action((e,t)=>I(n=>{if(e){let r=x.similar(n,e,{minSimilarity:t.minSimilarity,limit:t.limit});if(r.length===0)return b.empty("No similar symbols found.");ye("similarity candidates"),b.list(r,i=>{let s=i.similarityBasis??"callees",o=s==="source-tokens"?"Shared source tokens":"Shared callees",a=s==="source-tokens"?"Only tokens in":"Only in",l=[`
|
|
953
|
+
${Math.round(i.similarity*100)}% similar:`,` A: ${i.shortNameA} (${i.fileA})`,` B: ${i.shortNameB} (${i.fileB})`,` ${o}: ${i.sharedCallees.join(", ")}`];return i.uniqueToA.length&&l.push(` ${a} A: ${i.uniqueToA.join(", ")}`),i.uniqueToB.length&&l.push(` ${a} B: ${i.uniqueToB.join(", ")}`),l.join(`
|
|
954
|
+
`)})}else{let r=x.similarAll(n,{minSimilarity:t.minSimilarity,limit:t.limit,scope:t.scope,minCallees:t.minCallees,crossFileOnly:t.crossFileOnly});if(r.length===0)return b.empty("No similar symbol pairs found.");ye("similarity candidates"),b.list(r,i=>`
|
|
857
955
|
${Math.round(i.similarity*100)}% similar:
|
|
858
956
|
A: ${i.shortNameA} (${i.fileA})
|
|
859
957
|
B: ${i.shortNameB} (${i.fileB})
|
|
860
|
-
Shared: ${i.sharedCallees.join(", ")}`),console.log(`
|
|
861
|
-
${
|
|
862
|
-
${Math.round(i.similarity*100)}% similar:`,` ${i.fileA}`,` ${i.fileB}`,` Shared deps (${i.sharedDeps.length}): ${i.sharedDeps.join(", ")}`];return i.uniqueToA.length&&
|
|
958
|
+
Shared ${i.similarityBasis==="source-tokens"?"source tokens":"callees"}: ${i.sharedCallees.join(", ")}`),console.log(`
|
|
959
|
+
${r.length} similar pair(s) found.`)}}));S.command("similar-files [file]").description("Find heuristic similar-file candidates from dependency profiles").option("--min-similarity <n>","Minimum Jaccard similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",v,20).option("-s, --scope <path>","Limit to files matching path").option("--min-deps <n>","Minimum dependencies to consider",v).action((e,t)=>I(n=>{let r=x.similarFiles(n,{minSimilarity:t.minSimilarity,limit:t.limit,scope:t.scope,minDeps:t.minDeps,filePattern:e});if(r.length===0)return b.empty("No similar file pairs found.");ye("similar file candidates"),b.list(r,i=>{let s=[`
|
|
960
|
+
${Math.round(i.similarity*100)}% similar:`,` ${i.fileA}`,` ${i.fileB}`,` Shared deps (${i.sharedDeps.length}): ${i.sharedDeps.join(", ")}`];return i.uniqueToA.length&&s.push(` Only in first: ${i.uniqueToA.join(", ")}`),i.uniqueToB.length&&s.push(` Only in second: ${i.uniqueToB.join(", ")}`),s.join(`
|
|
863
961
|
`)}),console.log(`
|
|
864
|
-
${
|
|
865
|
-
\u2500\u2500 Chain pair ${
|
|
866
|
-
${
|
|
867
|
-
${
|
|
868
|
-
${
|
|
869
|
-
\u2500\u2500 Depth ${
|
|
870
|
-
${
|
|
871
|
-
`),
|
|
872
|
-
Affected consumer files:`),
|
|
873
|
-
${
|
|
874
|
-
${
|
|
875
|
-
Only called by: ${
|
|
876
|
-
${
|
|
877
|
-
Forwards to: ${
|
|
878
|
-
${
|
|
879
|
-
${
|
|
880
|
-
${
|
|
881
|
-
Codebase Health Score: ${
|
|
882
|
-
`),console.log(` ${
|
|
883
|
-
`),console.log(" Findings:");let
|
|
884
|
-
Prioritized Actions (highest impact + lowest effort first):`);for(let i=0;i<
|
|
885
|
-
Top Complexity Hotspots:`);for(let i of
|
|
886
|
-
No issues found. Codebase is clean.`)}));
|
|
887
|
-
${Math.round(
|
|
888
|
-
`),console.log(` A: ${
|
|
889
|
-
`),console.log(` Shared callees (${
|
|
890
|
-
Unique to A (${
|
|
891
|
-
Unique to B (${
|
|
892
|
-
Strategy: ${
|
|
893
|
-
`);let i=
|
|
894
|
-
`);for(let
|
|
895
|
-
`),console.log(` LOC: ${
|
|
896
|
-
`),
|
|
897
|
-
\u2550\u2550\u2550 USED AT \u2550\u2550\u2550`);for(let
|
|
898
|
-
\u2550\u2550\u2550 PRODUCERS (feeds into this) \u2550\u2550\u2550`);for(let
|
|
899
|
-
\u2550\u2550\u2550 CONSUMERS (this feeds into) \u2550\u2550\u2550`);for(let
|
|
900
|
-
`),i.connectedSymbols.length===0){console.log(" No connected symbols found.");return}
|
|
901
|
-
${
|
|
902
|
-
${i.connectedSymbols.length} connected symbol(s).`)}));
|
|
903
|
-
${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),
|
|
962
|
+
${r.length} similar pair(s) found.`)}));S.command("similar-chains").description("Find heuristic similar-chain candidates from dependency flows").option("--min-similarity <n>","Minimum chain similarity (0-1)",parseFloat,.5).option("-n, --limit <n>","Number of results",v,15).option("-s, --scope <path>","Limit to files matching path").option("--min-length <n>","Minimum chain length",v,3).option("--max-length <n>","Maximum chain length",v,8).action(e=>I(t=>{let n=x.similarChains(t,{minSimilarity:e.minSimilarity,limit:e.limit,scope:e.scope,minChainLength:e.minLength,maxChainLength:e.maxLength});if(n.length===0)return b.empty("No similar chains found.");ye("similar chain candidates");for(let r=0;r<n.length;r++){let i=n[r];console.log(`
|
|
963
|
+
\u2500\u2500 Chain pair ${r+1} (${Math.round(i.similarity*100)}% similar, ${i.divergencePoints.length} divergence point(s)) \u2500\u2500`),console.log(` Chain A: ${i.chainA.join(" \u2192 ")}`),console.log(` Chain B: ${i.chainB.join(" \u2192 ")}`),i.commonPrefix.length&&console.log(` Common prefix: ${i.commonPrefix.join(" \u2192 ")}`),i.commonSuffix.length&&console.log(` Common suffix: ${i.commonSuffix.join(" \u2192 ")}`),console.log(" Divergence points (consolidation targets):");for(let s of i.divergencePoints)console.log(` [${s.index}] ${s.nodeA} \u2194 ${s.nodeB}`)}console.log(`
|
|
964
|
+
${n.length} similar chain pair(s) found.`)}));S.command("extract-candidates").description("Find heuristic extraction candidates from isolated callee clusters").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum function LOC",v,10).option("--min-callees <n>","Minimum callees to analyze",v,6).option("-n, --limit <n>","Number of results",v,20).action(e=>I(t=>{let n=x.extractCandidates(t,{scope:e.scope,minLoc:e.minLoc,minCallees:e.minCallees,limit:e.limit});if(n.length===0)return b.empty("No extraction candidates found.");ye("extraction candidates");for(let r of n){console.log(`
|
|
965
|
+
${pe(r.relativePath,r.startLine,r.endLine)} ${r.shortName} (${r.loc} LOC, ${r.totalCallees} callees)`);for(let i=0;i<r.clusters.length;i++){let s=r.clusters[i];console.log(` Cluster ${i+1} (${Math.round(s.isolation*100)}% isolated, ${s.callees.length} callees):`);for(let o of s.callees)console.log(` ${o}`)}}console.log(`
|
|
966
|
+
${n.length} extraction candidate(s) found.`)}));S.command("affected <symbol>").description("Transitive closure of symbols that could break if this symbol changes").option("--max-depth <n>","Maximum traversal depth",v,5).option("-s, --scope <path>","Limit to files matching path").action((e,t)=>I(n=>{let r=x.affected(n,e,{maxDepth:t.maxDepth,scope:t.scope});if(r.length===0)return b.empty("No affected symbols found.");let i=-1;for(let s of r)s.depth!==i&&(console.log(`
|
|
967
|
+
\u2500\u2500 Depth ${s.depth} \u2500\u2500`),i=s.depth),console.log(` ${s.file} ${s.shortName}`);console.log(`
|
|
968
|
+
${r.length} affected symbol(s) across ${new Set(r.map(s=>s.file)).size} files.`)}));S.command("change-surface <file>").description("Pre-change briefing: exports, consumers, and blast-radius risk").action(e=>I(t=>{let n=x.changeSurface(t,e);if(!n)return b.empty("File not found in index.");console.log(`File: ${n.file}`),console.log(`External consumers: ${n.totalExternalConsumers}
|
|
969
|
+
`),b.list(n.symbols,r=>{let i=r.riskLevel==="high"?" *** HIGH RISK ***":r.riskLevel==="medium"?" * medium risk *":"";return` ${me(r.startLine,r.endLine)} ${r.shortName} [${r.externalConsumers} consumers]${i}`})}));S.command("diff-impact").description("Compute changed symbols and downstream consumers from current git diff").option("--base <ref>","Git ref to diff against (default: HEAD)").action(e=>I(t=>{let n=x.diffImpact(t,{base:e.base});console.log(`Changed files: ${n.summary.totalChangedFiles}`),console.log(`Changed symbols: ${n.summary.totalChangedSymbols}`),console.log(`Affected consumer files: ${n.summary.totalAffectedFiles}`),n.summary.note&&console.log(`Note: ${n.summary.note}`),console.log(""),n.changedSymbols.length>0&&(console.log("Changed symbols:"),b.list(n.changedSymbols,r=>` ${r.file} ${r.shortName} (fan-in: ${r.fanIn})`)),n.affectedConsumers.length>0&&(console.log(`
|
|
970
|
+
Affected consumer files:`),b.list(n.affectedConsumers,r=>` ${r.file} (${r.consumedSymbols} symbol(s))`))}));S.command("drift [module]").description("Detect heuristic drift candidates: unused imports, layer violations, and pattern deviations").option("--min-deviation <n>","Minimum sibling files before reporting unique dependency deviations",$r,5).action((e,t)=>I(n=>{let r=x.drift(n,{scope:e,minDeviation:t.minDeviation});if(r.results.length===0)return b.empty("No drift detected.");ye("drift candidates"),console.log(""),b.groupedByFile(r.results,i=>{let o=` [${i.kind==="unused-import"?"UNUSED":i.kind==="layer-violation"?"LAYER":"UNIQUE"}] ${i.description}`;return i.detail?`${o}
|
|
971
|
+
${i.detail}`:o},i=>i.file),console.log(`
|
|
972
|
+
${r.unusedImports} unused import(s), ${r.layerViolations} layer violation(s), ${r.patternDeviations} pattern deviation(s)`)}));S.command("wrapper-candidates").description("Find heuristic wrapper candidates only called by one consumer").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",v,15).option("-n, --limit <n>","Number of results",v,30).action(e=>I(t=>{let n=x.wrapperCandidates(t,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(n.length===0)return b.empty("No wrapper candidates found.");ye("wrapper candidates"),b.list(n,r=>` ${pe(r.file,r.startLine,r.endLine)} ${r.shortName} (${r.loc} LOC)
|
|
973
|
+
Only called by: ${r.singleCallerShort} (fan-in: ${r.callerFanIn})`),console.log(`
|
|
974
|
+
${n.length} wrapper candidate(s).`)}));S.command("passthrough-candidates").description("Find heuristic passthrough candidates that forward to one callee").option("-s, --scope <path>","Limit to files matching path").option("--max-loc <n>","Maximum LOC for candidates",v,15).option("-n, --limit <n>","Number of results",v,30).action(e=>I(t=>{let n=x.passthroughCandidates(t,{scope:e.scope,maxLoc:e.maxLoc,limit:e.limit});if(n.length===0)return b.empty("No passthrough candidates found.");ye("passthrough candidates"),b.list(n,r=>` ${pe(r.file,r.startLine,r.endLine)} ${r.shortName} (${r.loc} LOC)
|
|
975
|
+
Forwards to: ${r.forwardsToShort} (${r.forwardsToFile})`),console.log(`
|
|
976
|
+
${n.length} passthrough candidate(s).`)}));S.command("stale-abstractions").description("Find heuristic stale abstraction candidates with 0-1 consumers").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",v,3).option("-n, --limit <n>","Number of results",v,30).option("--include-low-confidence","Include 1-consumer classes (usually encapsulation, not stale)",!1).action(e=>I(t=>{let n=x.staleAbstractions(t,{scope:e.scope,minLoc:e.minLoc,limit:e.limit,includeLowConfidence:!!e.includeLowConfidence});if(n.length===0)return b.empty("No stale abstractions found.");ye("stale abstraction candidates"),b.list(n,r=>{let i=r.consumers===0?"unused":`${r.consumers} consumer`,s=r.barrelConsumers>0?`, +${r.barrelConsumers} barrel`:"";return` [${r.confidence}] ${pe(r.file,r.startLine,r.endLine)} ${r.shortName} (${r.kind}, ${r.loc} LOC, ${i}${s})
|
|
977
|
+
${r.reason}`}),console.log(`
|
|
978
|
+
${n.length} stale abstraction(s).`)}));S.command("complexity-hotspots").description("Find heuristic complexity hotspot candidates from LOC x fan-in x fan-out").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC",v,10).option("-n, --limit <n>","Number of results",v,20).action(e=>I(t=>{let n=x.complexityHotspots(t,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(n.length===0)return b.empty("No complexity hotspots found.");ye("complexity hotspot candidates"),b.table(["score"," LOC","fan-in","fan-out","callees","symbol"],n.map(r=>` ${r.score.toFixed(1).padStart(5)} ${String(r.loc).padStart(4)} ${String(r.fanIn).padStart(6)} ${String(r.fanOut).padStart(7)} ${String(r.calleeCount).padStart(7)} ${r.shortName}`),[5,4,6,7,7,6])}));S.command("health").description("Composite codebase health report with prioritized action list").option("-s, --scope <path>","Limit to files matching path").option("--json","Output as JSON for programmatic consumption").action(e=>I(t=>{let n=x.health(t,{scope:e.scope});if(e.json){console.log(JSON.stringify(n,null,2));return}console.log(`
|
|
979
|
+
Codebase Health Score: ${n.score}/100
|
|
980
|
+
`),console.log(` ${n.overview.documents} files | ${n.overview.symbols} symbols | ${On(n.overview.indexSizeBytes)}
|
|
981
|
+
`),console.log(" Findings:");let r=n.findings;if(r.deadSymbols>0&&console.log(` Dead code: ${r.deadSymbols} symbols (${r.deadLoc} LOC)`),r.isolatedSymbols>0&&console.log(` Isolated symbols: ${r.isolatedSymbols} (${r.isolatedLoc} LOC)`),r.cycles>0&&console.log(` Circular deps: ${r.cycles}`),r.similarPairs>0&&console.log(` Similar pairs: ${r.similarPairs}`),r.extractionCandidates>0&&console.log(` Extract candidates: ${r.extractionCandidates}`),r.wrappers>0&&console.log(` Wrapper functions: ${r.wrappers}`),r.passthroughs>0&&console.log(` Passthroughs: ${r.passthroughs}`),r.staleTypes>0&&console.log(` Stale abstractions: ${r.staleTypes}`),r.driftedFiles>0&&console.log(` Pattern drift: ${r.driftedFiles} files`),r.complexityHotspotCount>0&&console.log(` Complexity hotspots: ${r.complexityHotspotCount}`),n.actions.length>0){console.log(`
|
|
982
|
+
Prioritized Actions (highest impact + lowest effort first):`);for(let i=0;i<n.actions.length;i++){let s=n.actions[i],o=s.locRecoverable>0?` (~${s.locRecoverable} LOC recoverable)`:"";console.log(` ${i+1}. [${s.effort} effort / ${s.impact} impact] ${s.description}${o}`)}}if(n.topComplexity.length>0){console.log(`
|
|
983
|
+
Top Complexity Hotspots:`);for(let i of n.topComplexity)console.log(` ${i.score.toFixed(1).padStart(6)} ${i.symbol}`)}n.actions.length===0&&console.log(`
|
|
984
|
+
No issues found. Codebase is clean.`)}));S.command("convergence <symbol1> <symbol2>").description("Show what a consolidated version of two similar functions would look like").action((e,t)=>I(n=>{let r=x.convergence(n,e,t);if(!r)return b.empty("One or both symbols not found.");console.log(`
|
|
985
|
+
${Math.round(r.similarity*100)}% callee overlap
|
|
986
|
+
`),console.log(` A: ${r.symbolA.shortName} (${r.symbolA.file}, ${r.symbolA.loc} LOC)`),console.log(` B: ${r.symbolB.shortName} (${r.symbolB.file}, ${r.symbolB.loc} LOC)
|
|
987
|
+
`),console.log(` Shared callees (${r.sharedCallees.length}):`);for(let i of r.sharedCallees)console.log(` ${i}`);if(r.uniqueToA.length>0){console.log(`
|
|
988
|
+
Unique to A (${r.uniqueToA.length}):`);for(let i of r.uniqueToA)console.log(` ${i}`)}if(r.uniqueToB.length>0){console.log(`
|
|
989
|
+
Unique to B (${r.uniqueToB.length}):`);for(let i of r.uniqueToB)console.log(` ${i}`)}console.log(`
|
|
990
|
+
Strategy: ${r.consolidationStrategy}`)}));S.command("code <symbol>").description("Read the source code for a symbol (bounded to its definition range)").option("-C, --context <n>","Extra lines of context above/below",v,0).action((e,t)=>I(n=>{let r=x.code(n,e,{context:t.context});if(!r)return b.empty("Symbol not found or file unreadable.");console.log(`${pe(r.relativePath,r.startLine,r.endLine)} ${r.shortName} [${r.language??"unknown"}]
|
|
991
|
+
`);let i=r.source.split(`
|
|
992
|
+
`);for(let s=0;s<i.length;s++)console.log(` ${String(be(r.startLine+s)).padStart(4)} ${i[s]}`)}));S.command("complexity <symbol>").description("Per-symbol complexity: branches, cyclomatic estimate, fan-in/out, callees").action(e=>I(t=>{let n=x.complexity(t,e);if(!n)return b.empty("Symbol not found.");console.log(`${pe(n.relativePath,n.startLine,n.endLine)} ${n.shortName}
|
|
993
|
+
`),console.log(` LOC: ${n.loc}`),console.log(` Branches: ${n.branches}`),console.log(` Cyclomatic estimate: ${n.cyclomaticEstimate}`),console.log(` Callees: ${n.calleeCount}`),console.log(` Fan-in: ${n.fanIn}`),console.log(` Fan-out: ${n.fanOut}`)}));S.command("dataflow <symbol>").description("Reference-level dataflow: definition sites, usage sites, producers, consumers").action(e=>I(t=>{let n=x.dataflow(t,e);if(!n)return b.empty("Symbol not found.");if(console.log(`${n.shortName} (${n.relativePath})
|
|
994
|
+
`),n.definitionSites.length>0){console.log(" \u2550\u2550\u2550 DEFINED AT \u2550\u2550\u2550");for(let r of n.definitionSites)console.log(` ${r.file}:${be(r.line)}`)}if(n.usageSites.length>0){console.log(`
|
|
995
|
+
\u2550\u2550\u2550 USED AT \u2550\u2550\u2550`);for(let r of n.usageSites)console.log(` ${r.file}:${be(r.line)} in ${r.enclosingShort}`)}if(n.producers.length>0){console.log(`
|
|
996
|
+
\u2550\u2550\u2550 PRODUCERS (feeds into this) \u2550\u2550\u2550`);for(let r of n.producers)console.log(` ${r.file} ${r.shortName}`)}if(n.consumers.length>0){console.log(`
|
|
997
|
+
\u2550\u2550\u2550 CONSUMERS (this feeds into) \u2550\u2550\u2550`);for(let r of n.consumers)console.log(` ${r.file} ${r.shortName}`)}}));S.command("slice <symbol>").description("Reference-level program slice: what affects this (backward) or what this affects (forward)").option("--forward","Forward slice (what does this affect). Default is backward.").option("--depth <n>","Max transitive depth for backward slice",v,3).action((e,t)=>I(n=>{let r=t.forward?"forward":"backward",i=x.slice(n,e,{direction:r,maxDepth:t.depth});if(!i)return b.empty("Symbol not found.");if(console.log(`${i.direction} slice of ${i.shortName}
|
|
998
|
+
`),i.connectedSymbols.length===0){console.log(" No connected symbols found.");return}b.list(i.connectedSymbols,s=>` ${s.file} ${s.shortName}
|
|
999
|
+
${s.relationship}`),console.log(`
|
|
1000
|
+
${i.connectedSymbols.length} connected symbol(s).`)}));S.command("install-skills").description(`Install skills (${sr.join(", ")}) into Claude Code and Codex`).action(()=>{let e=$i(),t=e.installed.length+e.alreadyLinked.length;console.log(`
|
|
1001
|
+
${e.installed.length} installed, ${e.alreadyLinked.length} already linked, ${e.skipped.length} skipped.`),t>0&&console.log("Skills will be available in your next Claude Code / Codex session.")});S.command("check-deps").description("Check whether scip-query and the detected language indexers are actually runnable").action(()=>{let e=!1;Fn()?console.log("scip CLI: installed"):(Tn(),e=!0);let t=Ce(),n=ve(t),r=n.languages??je(t);if(r.length===0){console.log(`
|
|
904
1002
|
No supported project languages detected in the current directory.`),process.exitCode=e?1:0;return}console.log(`
|
|
905
|
-
Detected languages: ${
|
|
906
|
-
Indexer readiness:`);for(let i of
|
|
907
|
-
|
|
908
|
-
${
|
|
909
|
-
|
|
1003
|
+
Detected languages: ${r.join(", ")}`),console.log(`
|
|
1004
|
+
Indexer readiness:`);for(let i of r){let s=gi(Vt(i),t),o=s.runnable?" OK":s.installed?" WARN":" MISSING",a=s.resolvedBinary?` (${s.resolvedBinary})`:"";console.log(`${o} ${i}: ${s.binaryLabel}${a}`),s.note&&console.log(` ${s.note}`),!s.installed&&s.installUrl&&console.log(` install: ${s.installUrl}`),s.runnable||(e=!0)}if(r.includes("typescript")){let i=nr(t,n.semantic?.typescript?.tsconfigs),s=i.available?" OK":i.dependencyAvailable?" WARN":" MISSING",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`
|
|
1005
|
+
Semantic provider readiness:`),console.log(`${s} typescript: ts-morph${o}`),i.reason&&console.log(` ${i.reason}; semantic checks will fall back to SCIP/source evidence`)}process.exitCode=e?1:0});S.command("redundant-reexports").description("Find barrel re-exports that nobody imports through").option("-s, --scope <path>","Limit to files matching path").option("-n, --limit <n>","Number of results",v,30).action(e=>I(t=>{let n=x.redundantReexports(t,{scope:e.scope,limit:e.limit});if(n.length===0)return b.empty("No redundant re-exports found.");b.groupedByFile(n,r=>` ${r.shortName} (from ${r.originalFile})
|
|
1006
|
+
barrel: ${r.barrelConsumers} consumer(s) | direct: ${r.directConsumers} consumer(s)`,r=>r.barrelFile),console.log(`
|
|
1007
|
+
${n.length} redundant re-export(s).`)}));S.command("similar-signatures").description("Find functions with near-identical type signatures (same shape)").option("-s, --scope <path>","Limit to files matching path").option("--min-loc <n>","Minimum LOC per function",v,3).option("-n, --limit <n>","Number of groups",v,20).action(e=>I(t=>{let n=x.similarSignatures(t,{scope:e.scope,minLoc:e.minLoc,limit:e.limit});if(n.length===0)return b.empty("No same-shape function groups found.");b.list(n,r=>{let i=`
|
|
1008
|
+
Signature: ${r.signature} (${r.functions.length} functions)`,s=r.functions.map(o=>` ${pe(o.file,o.startLine,o.endLine)} ${o.shortName} (${o.loc} LOC)`).join(`
|
|
910
1009
|
`);return`${i}
|
|
911
|
-
${
|
|
912
|
-
${
|
|
1010
|
+
${s}`}),console.log(`
|
|
1011
|
+
${n.length} group(s) found.`)}));S.command("init").description("Create a .scipquery.json config file for this project").action(()=>{let e=Ce(),t=je(e),n=Hr(e,t);console.log(`Config written to ${n}`),console.log(`Detected languages: ${t.join(", ")||"(none)"}`)});S.command("watch").description("Watch for file changes and reindex automatically").option("--debounce <ms>","Ms to wait after last change (default: 30000)",parseInt).option("--cooldown <ms>","Min ms between reindexes (default: 60000)",parseInt).action(e=>{let t=Ce(),n=ve(t);e.debounce&&((n.watch??={}).debounceMs=e.debounce),e.cooldown&&((n.watch??={}).cooldownMs=e.cooldown);let r=new Yt({projectRoot:t,config:n,languages:n.languages,onStatus:i=>{process.stdout.write(`\r\x1B[K${Ja(i)}`)},onReindexComplete:i=>{console.log(`
|
|
913
1012
|
Reindex complete in ${(i/1e3).toFixed(1)}s`)},onError:i=>{console.error(`
|
|
914
|
-
Watch error: ${i.message}`)}});console.log(`Watching ${
|
|
915
|
-
`),
|
|
916
|
-
Stopped.`),process.exit(0)})});
|
|
1013
|
+
Watch error: ${i.message}`)}});console.log(`Watching ${t}`),console.log(`Debounce: ${n.watch?.debounceMs??3e4}ms | Cooldown: ${n.watch?.cooldownMs??6e4}ms`),console.log(`Press Ctrl+C to stop.
|
|
1014
|
+
`),r.start(),process.on("SIGINT",()=>{r.stop(),console.log(`
|
|
1015
|
+
Stopped.`),process.exit(0)})});S.command("status").description("Show index status for this project").action(()=>{let e=Ce(),t=ve(e),n=Ne(e,t),r=Tt(e);if(console.log(`Project: ${e}`),console.log(`DB path: ${r}`),r!==n.dbPath&&console.log(`Config: ${n.dbPath} (fallback to project root index.db)`),(t.languages??je(e)).includes("typescript")){let i=nr(e,t.semantic?.typescript?.tsconfigs),s=i.available?"available":"fallback",o=i.tsconfigPaths&&i.tsconfigPaths.length>1?` (${i.tsconfigPaths.length} tsconfigs)`:i.tsconfigPath?` (${i.tsconfigPath})`:"";console.log(`TS sem: ${s}${o}`),i.reason&&console.log(`TS note: ${i.reason}`)}console.log(`Exists: ${qa(r)?"yes":"no"}`),qa(r)&&I(i=>{let s=x.stats(i);if(console.log(`Symbols: ${s.symbols}`),console.log(`Files: ${s.documents}`),console.log(`Size: ${On(s.indexSizeBytes)}`),s.lastBuilt){let o=Math.round((Date.now()-s.lastBuilt.getTime())/1e3);console.log(`Built: ${o}s ago`)}})});PS()&&S.parse();function PS(){if(!process.argv[1])return!1;let e=DS(import.meta.url);try{return za(e)===za(process.argv[1])}catch{return e===process.argv[1]}}export{S as program,ye as renderHeuristicNotice};
|
|
917
1016
|
//# sourceMappingURL=cli.js.map
|