scip-query 0.6.3 → 0.6.5
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 +31 -29
- package/dist/augment-vue-worker.js +2 -0
- package/dist/chunk-2ZGHRI2A.js +5 -0
- package/dist/chunk-32R4VYYA.js +2 -0
- package/dist/chunk-3UB2DPLP.js +2 -0
- package/dist/chunk-4X7C236P.js +84 -0
- package/dist/chunk-5LQ6CVX3.js +2 -0
- package/dist/chunk-5YYMKE3G.js +70 -0
- package/dist/chunk-7LSCW7NF.js +6 -0
- package/dist/chunk-7X7FLQC5.js +2 -0
- package/dist/chunk-A5UNS4DR.js +4 -0
- package/dist/chunk-BNCTPTVX.js +2 -0
- package/dist/{chunk-TRBNQ273.js → chunk-C5BFS23M.js} +2 -2
- package/dist/{chunk-DM56ECPZ.js → chunk-DRLWW74T.js} +2 -2
- package/dist/chunk-EB5IVUNU.js +2 -0
- package/dist/{chunk-TPOYTT6O.js → chunk-ERRUE5G4.js} +4 -4
- package/dist/chunk-F4KR22Z2.js +2 -0
- package/dist/chunk-FG6A6ZUP.js +2 -0
- package/dist/chunk-FHSD5RKF.js +19 -0
- package/dist/chunk-FVVEIGP3.js +5 -0
- package/dist/chunk-GBDZY73J.js +2 -0
- package/dist/{chunk-4TYGGOLO.js → chunk-H4DXD2FB.js} +1 -1
- package/dist/chunk-HUASU3AD.js +71 -0
- package/dist/chunk-IJWIYZO5.js +2 -0
- package/dist/chunk-K6H3XJQW.js +7 -0
- package/dist/{chunk-KYT47WU2.js → chunk-KAM4C6ZD.js} +1 -1
- package/dist/{chunk-56LPZC3S.js → chunk-KTCODJNQ.js} +3 -3
- package/dist/chunk-LJ2YWNQF.js +2 -0
- package/dist/chunk-LT2CPEQ4.js +2 -0
- package/dist/chunk-M5QTG55L.js +2 -0
- package/dist/chunk-MKFH7QJG.js +7 -0
- package/dist/chunk-MO32JMOD.js +12 -0
- package/dist/chunk-MO65UK5V.js +6 -0
- package/dist/chunk-MTK3JAJT.js +2 -0
- package/dist/{chunk-6TRXTRCW.js → chunk-MXWC53GJ.js} +4 -4
- package/dist/{chunk-HLILTI7S.js → chunk-OQZF2DQJ.js} +3 -3
- package/dist/chunk-PBFMZKXE.js +6 -0
- package/dist/{chunk-MMKNCPHB.js → chunk-PFMGJ4BR.js} +4 -4
- package/dist/{chunk-5KWWENJZ.js → chunk-PK4U6NWP.js} +2 -2
- package/dist/{chunk-CH47OLNL.js → chunk-Q2ALKKSE.js} +4 -4
- package/dist/chunk-QFCK6WV2.js +39 -0
- package/dist/chunk-QFZE73XF.js +84 -0
- package/dist/chunk-QRYEOK3M.js +2 -0
- package/dist/{chunk-LORWXBOO.js → chunk-RKTDEIHF.js} +1 -1
- package/dist/chunk-ROWAEEOD.js +2 -0
- package/dist/chunk-RT5PV5JQ.js +7 -0
- package/dist/chunk-TLRA5TR6.js +2 -0
- package/dist/chunk-U5MVUPOO.js +2 -0
- package/dist/chunk-URUVLDM7.js +29 -0
- package/dist/chunk-WHGCGENP.js +16 -0
- package/dist/chunk-WIIZF5FP.js +2 -0
- package/dist/chunk-WNMAH3P7.js +2 -0
- package/dist/chunk-XV3XUZ3X.js +11 -0
- package/dist/chunk-YDKWDTAW.js +2 -0
- package/dist/{chunk-IUNRL2AQ.js → chunk-YDNCX5PF.js} +2 -2
- package/dist/chunk-YU25IHJX.js +90 -0
- package/dist/{chunk-VZE4SOJG.js → chunk-Z5CTXSWT.js} +3 -3
- package/dist/chunk-ZFCQQ4B5.js +2 -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 +221 -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 +4 -2
- package/dist/chunk-2OXZVIED.js +0 -41
- package/dist/chunk-5IM4IQ6N.js +0 -2
- package/dist/chunk-5OV6CUTY.js +0 -2
- package/dist/chunk-6QXYWGE5.js +0 -10
- package/dist/chunk-C6PQLWHR.js +0 -7
- package/dist/chunk-DX5YEUX4.js +0 -6
- package/dist/chunk-DXXROCSQ.js +0 -19
- package/dist/chunk-EARGTC7U.js +0 -12
- package/dist/chunk-EJXPKSWV.js +0 -29
- package/dist/chunk-EUHHVFTI.js +0 -2
- package/dist/chunk-F2TGKDMW.js +0 -2
- package/dist/chunk-GSVIC6KN.js +0 -2
- package/dist/chunk-H4IWC7KJ.js +0 -89
- package/dist/chunk-H7BWAMFI.js +0 -4
- package/dist/chunk-HUEIPY4M.js +0 -5
- package/dist/chunk-ID7TO4P6.js +0 -65
- package/dist/chunk-J22I2FWD.js +0 -6
- package/dist/chunk-KOGVTPGE.js +0 -7
- package/dist/chunk-LUYN4IWJ.js +0 -2
- package/dist/chunk-MDUIJELV.js +0 -39
- package/dist/chunk-MSNW2AR2.js +0 -2
- package/dist/chunk-N3Z2SJCR.js +0 -2
- package/dist/chunk-NB3GIT4Z.js +0 -7
- package/dist/chunk-OBPP5RRE.js +0 -2
- package/dist/chunk-ORBQ3HJD.js +0 -2
- package/dist/chunk-P6IUCZA3.js +0 -24
- package/dist/chunk-Q2MCCKWZ.js +0 -2
- package/dist/chunk-QRULHDMO.js +0 -84
- package/dist/chunk-RAJHIEBM.js +0 -70
- package/dist/chunk-RKZBRDFK.js +0 -2
- package/dist/chunk-RPRIZ43D.js +0 -2
- package/dist/chunk-RXGCTLHY.js +0 -2
- package/dist/chunk-S6IGA6KK.js +0 -2
- package/dist/chunk-TVJMEDHH.js +0 -2
- package/dist/chunk-UDKLKBPQ.js +0 -2
- package/dist/chunk-UGUBEKK5.js +0 -2
- package/dist/chunk-VKYLXCV6.js +0 -2
- package/dist/chunk-VQXXSUQF.js +0 -8
- package/dist/chunk-VZHI3TUX.js +0 -6
- package/dist/chunk-YSEQFGGH.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 Sr from"ignore";import{readFileSync as _r,existsSync as Sn}from"fs";import{dirname as _n,isAbsolute as rs,join as xn,relative as xr,resolve as Ir}from"path";function Ue(e){let n=Sr(),t=!1,s=Nr(e);for(let i of s)try{let o=_r(i,"utf-8");n.add(o),t=!0}catch{}return t||n.add(vr),{isIgnored:i=>as(n,e,i),filter:i=>i.filter(o=>!as(n,e,o))}}function Nr(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 vr=`
|
|
2
|
+
var Ha=Object.defineProperty;var Va=(e,t)=>{for(var n in t)Ha(e,n,{get:t[n],enumerable:!0})};import{program as S}from"commander";import{createRequire as lS}from"module";import{existsSync as Ba,realpathSync as Wa}from"fs";import{fileURLToPath as cS}from"url";import{readFileSync as Ua,writeFileSync as Ja,existsSync as jr,mkdirSync as qa}from"fs";import{join as Te,resolve as Ar}from"path";import{createHash as za}from"crypto";import{homedir as Ga}from"os";var Br=".scipquery.json",Ka={enabled:!1,debounceMs:3e4,cooldownMs:6e4,ignore:[]};function Ce(e){let t=Te(e,Br);if(!jr(t))return{};try{let n=Ua(t,"utf-8");return JSON.parse(n)}catch{return{}}}function Wr(e){return{...Ka,...e.watch}}function Qa(e,t){let n=process.env.SCIP_QUERY_CACHE_DIR;if(n)return Fn(n);if(t?.dbPath)return Fn(Ar(e,t.dbPath));let i=process.env.XDG_CACHE_HOME||Te(Ga(),".cache"),s=za("sha256").update(Ar(e)).digest("hex").slice(0,12),o=Te(i,"scip-query","projects",s);return Fn(o)}function ve(e,t){let n=Qa(e,t);return{cacheDir:n,dbPath:Te(n,"index.db"),indexPath:Te(n,"index.scip"),metaPath:Te(n,"meta.json")}}function Hr(e,t){let n=Te(e,Br);return jr(n)||Ja(n,JSON.stringify({languages:t,watch:{enabled:!1,debounceMs:3e4,cooldownMs:6e4}},null,2)+`
|
|
3
|
+
`),n}function Fn(e){return qa(e,{recursive:!0}),e}import{execFile as Su,execFileSync as xu}from"child_process";import{closeSync as _u,existsSync as Be,mkdirSync as Ei,mkdtempSync as Iu,openSync as Ru,readFileSync as Cu,renameSync as Ze,rmSync as et,writeFileSync as Di}from"fs";import{cpus as vu}from"os";import{basename as Kt,dirname as je,extname as Nu,join as se}from"path";import{execFileSync as jt}from"child_process";import{platform as Bt,arch as Ya}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 Tn(){try{return jt(Vr?"where":"which",["scip"],{stdio:"pipe"}),!0}catch{return!1}}function Xa(){let e=Bt(),t=Ya(),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 $n(){let e=Xa();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 dl from"better-sqlite3";import{execFileSync as ml}from"child_process";import{existsSync as pl,readdirSync as fl,readFileSync as gl}from"fs";import{extname as Ht,join as Qr}from"path";import Za from"ignore";import{readFileSync as el,existsSync as An}from"fs";import{dirname as jn,isAbsolute as qr,join as Bn,relative as tl,resolve as nl}from"path";function Qe(e){let t=Za(),n=!1,r=rl(e);for(let i of r)try{let s=el(i,"utf-8");t.add(s),n=!0}catch{}return n||t.add(il),{isIgnored:i=>zr(t,e,i),filter:i=>i.filter(s=>!zr(t,e,s))}}function rl(e){let t=[],n=Bn(e,".gitignore");An(n)&&t.push(n);let r=jn(e),i=0;for(;r!==jn(r)&&i<5;){let s=Bn(r,".gitignore");if(An(s)&&t.push(s),An(Bn(r,".git")))break;r=jn(r),i++}return t}var il=`
|
|
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 Lr(e,{recursive:!0}),e}import{execFileSync as js}from"child_process";import{existsSync as Bs,renameSync as Ws,rmSync as Ja}from"fs";import{basename as Ua,dirname as qa,extname as za,join as At}from"path";import{execFileSync as Dt}from"child_process";import{platform as kt,arch as $r}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 Pr(){let e=kt(),n=$r(),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=Pr();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 Br from"better-sqlite3";import{existsSync as Wr,readdirSync as Hr,readFileSync as Jr}from"fs";import{extname as En,join as bs}from"path";import{readdirSync as Mr}from"fs";import{extname as hs,join as Fr}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 Tr=[".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(Tr.map(a=>a.toLowerCase())),o=`${t?"1":"0"}|${s?"1":"0"}|${[...i].sort().join(",")}`;return Ar.get(e,o,()=>{let a=new Set;if(t){let r=e.all(`SELECT relative_path
|
|
63
|
+
`;function zr(e,t,n){let r=sl(t,n);if(!r)return!1;try{return e.ignores(r)}catch{return!1}}function sl(e,t){if(!t||t===".")return null;if(!qr(t)&&!t.startsWith(".."))return t.replaceAll("\\","/");let n=qr(t)?t:nl(e,t),r=tl(e,n).replaceAll("\\","/");return!r||r==="."||r.startsWith("..")?null:r}import{readdirSync as ol}from"fs";import{extname as Gr,join as al}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 $e(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 ll=[".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"],Wn=new Set(["node_modules",".git","target","dist","build",".next",".nuxt",".cache",".turbo","out","coverage",".scipquery-cache","__pycache__",".venv","venv",".idea",".vscode"]);function Ne(e,t={}){let n=t.includeIndexed??!0,r=t.includeAuxiliary??!0,i=t.extensions?new Set(t.extensions.map(o=>o.toLowerCase())):new Set(ll.map(o=>o.toLowerCase())),s=`${n?"1":"0"}|${r?"1":"0"}|${[...i].sort().join(",")}`;return cl.get(e,s,()=>{let o=new Set;if(n){let a=e.all(`SELECT relative_path
|
|
82
64
|
FROM documents
|
|
83
65
|
WHERE 1 = 1
|
|
84
|
-
${e.pathExclusionsFor("documents")}`);for(let l of
|
|
85
|
-
VALUES (?, ?, NULL, ?)`),l=i.transaction(m=>{let u=0;for(let d of m){if(o.has(d))continue;let g=Jr(bs(e.projectRoot,d),"utf-8"),p=a.run(qr(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 Ur(e,n){let t=[],s=i=>{let o=i?bs(e,i):e,a=[];try{a=Hr(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 qr(e){return En(e).toLowerCase()===".vue"?"vue":En(e).replace(/^\./,"").toLowerCase()||"source"}import{existsSync as zr,readdirSync as _s}from"fs";import{extname as Vr,join as xs}from"path";var Gr=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),Yr=[{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=Kr(e),s=ea(e);for(let i of Yr){if(Qr(e,i.files)){n.push(i.language);continue}if(Xr(t,i.globs)){n.push(i.language);continue}ta(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 Kr(e){try{return _s(e)}catch{return[]}}function Qr(e,n){return n?.length?n.some(t=>zr(xs(e,t))):!1}function Xr(e,n){return n?.length?e.some(t=>n.some(s=>Zr(t,s))):!1}function Zr(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 ea(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()){Gr.has(o.name)||t.push(a);continue}let r=Vr(o.name).toLowerCase();r&&n.add(r)}}return n}function ta(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 na}from"fs";import{join as Rn}from"path";var sa={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 sa[e]}function Ns(e,n){let t;try{t=na(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 ia,writeFileSync as oa}from"fs";import{create as Ln}from"@bufbuild/protobuf";import{deserializeSCIP as ra,serializeSCIP as aa,DocumentSchema as la,IndexSchema as ca,SymbolInformationSchema as ua}from"@c4312/scip";function ma(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let n=da(e),t=pa(e.flatMap(i=>i.documents??[])),s=Cs(e.flatMap(i=>i.externalSymbols??[]));return Ln(ca,{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=>ra(ia(i))),s=ma(t);return oa(n,Buffer.from(aa(s))),{documentCount:s.documents.length,externalSymbolCount:s.externalSymbols.length,inputCount:e.length}}function da(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 pa(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(la,{language:s.language||t.language,relativePath:s.relativePath||t.relativePath,occurrences:[...s.occurrences,...t.occurrences],symbols:Cs([...s.symbols,...t.symbols]),text:ga(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(ua,{symbol:s.symbol,documentation:ha([...s.documentation,...t.documentation]),relationships:fa([...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 fa(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 ga(e,n){return e?n?e.length>=n.length?e:n:e:n}function ha(e){return[...new Set(e)]}import{execFileSync as Pt}from"child_process";import{existsSync as wn}from"fs";import{createRequire as ya}from"module";import{platform as Es}from"os";import{join as Rs}from"path";var ba=ya(import.meta.url),Sa=Es()==="win32";function lt(e){let n=Sa?"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 ba.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 _a(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?_a(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=xa(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 xa(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 Ia from"better-sqlite3";import{createRequire as Na}from"module";import{existsSync as Fs,readFileSync as Ft}from"fs";import{dirname as va,extname as Ca,join as Ts,relative as Ea,resolve as Ra}from"path";import{pathToFileURL as La}from"url";function On(e){Be({projectRoot:e.projectRoot,dbPath:e.dbPath});let n=Ra(e.projectRoot,e.tsconfig);if(!Fs(n))throw new Error(`Vue tsconfig not found at ${n}`);let t=Da(e.projectRoot,n),s=t.fileNames.filter(o=>o.endsWith(".vue")),i=new Ia(e.dbPath);try{wa(i);let o=ka(i,e.projectRoot),a=Oa(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 Ma(p)){let y=Fa(g,f.start);if(y===null)continue;let b=(t.languageService.getDefinitionAtPosition(m,y+1)??[]).find(x=>!Aa(e.projectRoot,x.fileName));if(!b){l++;continue}let _=$a(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=Pa(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 wa(e){e.transaction(()=>{e.prepare(`
|
|
66
|
+
${e.pathExclusionsFor("documents")}`);for(let l of a)e.isIgnored(l.relative_path)||i.has(Gr(l.relative_path).toLowerCase())&&o.add(l.relative_path)}if(r)for(let a of ul(e.config.projectRoot,i))e.isIgnored(a)||o.add(a);return[...o].sort()})}var cl=$("source-files");function ul(e,t){let n=new Set,r=i=>{let s=i?al(e,i):e,o;try{o=ol(s,{withFileTypes:!0})}catch{return}for(let a of o)if(!Wn.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 Ee(e){let t=new Set((e.extensions??Kr).map(s=>s.toLowerCase()));if(t.size===0)return{scanned:0,inserted:0,existing:0};if(!pl(e.dbPath))throw new Error(`SCIP SQLite database not found at ${e.dbPath}`);let n=Qe(e.projectRoot),r=hl(e.projectRoot,t).filter(s=>!n.isIgnored(s)),i=new dl(e.dbPath);try{let s=bl(i,r),o=i.prepare(`INSERT OR IGNORE INTO documents (language, relative_path, position_encoding, text)
|
|
67
|
+
VALUES (?, ?, NULL, ?)`),l=i.transaction(d=>{let u=0;for(let m of d){if(s.has(m))continue;let f=gl(Qr(e.projectRoot,m),"utf-8"),p=o.run(Sl(m),m,f);u+=Number(p.changes)}return u})(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 hl(e,t){let n=yl(e,t);if(n)return n;let r=[],i=s=>{let o=s?Qr(e,s):e,a;try{a=fl(o,{withFileTypes:!0})}catch{return}for(let l of a){if(Wn.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 yl(e,t){try{return ml("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 bl(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 Sl(e){return Ht(e).toLowerCase()===".vue"?"vue":Ht(e).replace(/^\./,"").toLowerCase()||"source"}import{execFileSync as xl}from"child_process";import{existsSync as _l,readdirSync as Xr}from"fs";import{extname as Zr,join as ei}from"path";var Il=new Set([".git",".hg",".svn",".idea",".vscode","node_modules","vendor","dist","build","target","bin","obj",".dart_tool",".gradle",".next",".venv","venv","__pycache__"]),Rl=[{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 Ae(e){let t=[],n=Cl(e),r=Dl(e);for(let i of Rl){if(vl(e,i.files)){t.push(i.language);continue}if(Nl(n,i.globs)){t.push(i.language);continue}kl(r,i.extensions)&&t.push(i.language)}return t.includes("typescript")&&Yr(t,"javascript"),t.includes("cpp")&&!r.has(".c")&&Yr(t,"c"),t}function Cl(e){try{return Xr(e)}catch{return[]}}function vl(e,t){return t?.length?t.some(n=>_l(ei(e,n))):!1}function Nl(e,t){return t?.length?e.some(n=>t.some(r=>El(n,r))):!1}function El(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 Dl(e){let t=Ll(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=Xr(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=ei(i,o.name);if(o.isDirectory()){Il.has(o.name)||r.push(a);continue}let l=Zr(o.name).toLowerCase();l&&n.add(l)}}return n}function Ll(e){try{let t=xl("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=Zr(r).toLowerCase();i&&n.add(i)}return n}catch{return null}}function kl(e,t){return t?.length?t.some(n=>e.has(n)):!1}function Yr(e,t){let n=e.indexOf(t);n!==-1&&e.splice(n,1)}import{existsSync as ti,readdirSync as wl}from"fs";import{join as Hn}from"path";var Pl={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",ni(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",ni(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=Hn(e,"vendor","bin","scip-php"),r=Hn(e,"vendor","davidrjenni","scip-php","bin","scip-php");return{binary:"php",args:["-d","error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED",ti(r)?r:ti(n)?n:t]}},defaultOutputPath:"index.scip",markerFiles:["composer.json"],installMethods:[],installUrl:"https://github.com/davidrjenni/scip-php/releases"}};function Vt(e){return Pl[e]}function ni(e,t){let n;try{n=wl(e)}catch{return null}for(let r of n)if(t.some(i=>r.endsWith(i)))return Hn(e,r);return null}import{readFileSync as Ol,writeFileSync as Ml}from"fs";import{create as Vn}from"@bufbuild/protobuf";import{deserializeSCIP as Fl,serializeSCIP as Tl,DocumentSchema as $l,IndexSchema as Al,SymbolInformationSchema as jl}from"@c4312/scip";function Bl(e){if(e.length===0)throw new Error("Cannot merge zero SCIP indexes");if(e.length===1)return e[0];let t=Wl(e),n=Hl(e.flatMap(i=>i.documents??[])),r=ii(e.flatMap(i=>i.externalSymbols??[]));return Vn(Al,{metadata:t,documents:n,externalSymbols:r})}function ri(e,t){if(e.length===0)throw new Error("Cannot merge zero SCIP files");let n=e.map(i=>Fl(Ol(i))),r=Bl(n);return Ml(t,Buffer.from(Tl(r))),{documentCount:r.documents.length,externalSymbolCount:r.externalSymbols.length,inputCount:e.length}}function Wl(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 Hl(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,Vn($l,{language:r.language||n.language,relativePath:r.relativePath||n.relativePath,occurrences:[...r.occurrences,...n.occurrences],symbols:ii([...r.symbols,...n.symbols]),text:Ul(r.text,n.text),positionEncoding:r.positionEncoding||n.positionEncoding}))}return[...t.values()]}function ii(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,Vn(jl,{symbol:r.symbol,documentation:Jl([...r.documentation,...n.documentation]),relationships:Vl([...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 Vl(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 Ul(e,t){return e?t?e.length>=t.length?e:t:e:t}function Jl(e){return[...new Set(e)]}import{execFileSync as ql}from"child_process";import{createHash as zl}from"crypto";import{readdirSync as Gl,readFileSync as Kl}from"fs";import{join as si}from"path";function Ql(e){return(Yl(e)??Xl(e)).filter(t=>t&&!oi(t)).sort()}function Ut(e){return Ql(e).map(t=>{let n=si(e,t);try{let r=Kl(n);return{path:t,size:r.byteLength,hash:zl("sha256").update(r).digest("hex")}}catch{return{path:t,size:-1,hash:"unreadable"}}})}function Yl(e){try{return ql("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 Xl(e){let t=[],n=[""];for(;n.length>0;){let r=n.pop(),i=r?si(e,r):e,s;try{s=Gl(i,{withFileTypes:!0})}catch{continue}for(let o of s){let a=r?`${r}/${o.name}`:o.name;if(o.isDirectory()){oi(a)||n.push(a);continue}t.push(a)}}return t}function oi(e){return e.split("/").some(n=>Zl.has(n))||e.endsWith(".db")||e.endsWith(".db-wal")||e.endsWith(".db-shm")||e.endsWith(".scip")}var Zl=new Set([".git","node_modules",".scipquery-cache",".stryker-tmp","dist","build","coverage",".next",".nuxt","target"]);import{readFileSync as ec,writeFileSync as tc}from"fs";import{create as ai}from"@bufbuild/protobuf";import{deserializeSCIP as nc,DocumentSchema as rc,IndexSchema as ic,serializeSCIP as sc,SymbolRole as oc}from"@c4312/scip";function li(e){let t;try{t=nc(ec(e))}catch{return{removedDefinitionOccurrences:0,touchedDocuments:0}}let n=ac(t);return n.removedDefinitionOccurrences>0&&tc(e,Buffer.from(sc(n.index))),{removedDefinitionOccurrences:n.removedDefinitionOccurrences,touchedDocuments:n.touchedDocuments}}function ac(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&oc.Definition)===0||t.has(a.symbol)?!0:(n+=1,!1));if(o.length===s.occurrences.length){i.push(s);continue}r+=1,i.push(ai(rc,{language:s.language,relativePath:s.relativePath,occurrences:o,symbols:s.symbols,text:s.text,positionEncoding:s.positionEncoding}))}return{index:n===0?e:ai(ic,{metadata:e.metadata,documents:i,externalSymbols:e.externalSymbols}),removedDefinitionOccurrences:n,touchedDocuments:r}}import{execFileSync as qt}from"child_process";import{existsSync as Un,readFileSync as lc}from"fs";import{createRequire as cc}from"module";import{platform as ui}from"os";import{dirname as ci,join as Jt}from"path";var uc=cc(import.meta.url),dc=ui()==="win32";function pt(e){let t=dc?"where":"which";try{return qt(t,[e],{stdio:"pipe"}),!0}catch{return!1}}function Jn(e){return[e.indexerBinary,...e.binaryAliases??[]]}function zt(e){let t=Jn(e);return t.length===1?t[0]:t.join(" or ")}function Ye(e){for(let t of Jn(e))if(pt(t))return t;return pc(e)}function di(e){return Ye(e)!==null||mc(e)}function mc(e){return mi(e)!==null}function pc(e){let t=mi(e);if(!t)return null;let r=JSON.parse(lc(t,"utf8")).bin;if(!r)return null;if(typeof r=="string")return Jt(ci(t),r);for(let i of Jn(e)){let s=r[i];if(s)return Jt(ci(t),s)}return null}function mi(e){if(!e.bundledNpmPackage)return null;try{return uc.resolve(`${e.bundledNpmPackage}/package.json`)}catch{return null}}function qn(e,t){for(let n of e.projectLocalBinaries??[]){let r=Jt(t,n);if(Un(r))return r}return null}function fc(e,t){return qn(e,t)??Ye(e)}function pi(e,t=process.env,n=e.indexerBinary){if(e.indexerBinary!=="scip-dotnet"||zn(n,t))return t;let r=hi(n,t);return r?{...t,DOTNET_ROOT:r}:t}function fi(e,t){let n=zt(e),r=t?fc(e,t):Ye(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=gc(r);return{language:e.language,binaryLabel:n,installed:!0,runnable:i.runnable,resolvedBinary:r,installUrl:e.installUrl,note:i.note}}function gi(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(pt(i.prerequisite)){t(`Installing ${r} via ${i.label}...`);try{qt(i.binary,i.args,{stdio:"inherit",timeout:3e5,env:process.env});let s=Ye(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 gc(e){if(zn(e,process.env))return{runnable:!0};let t=hi(e,process.env);if(t)return{runnable:!0,note:`using .NET 9 runtime from ${t}`};let n=yi(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 hi(e,t){for(let n of yi(t))if(zn(e,{...t,DOTNET_ROOT:n}))return n;return null}function yi(e){let t=[],n=e.DOTNET_ROOT;if(n&&Un(n)&&t.push(n),ui()==="darwin"&&pt("brew"))try{let r=qt("brew",["--prefix","dotnet@9"],{stdio:"pipe",env:e}).toString().trim(),i=Jt(r,"libexec");Un(i)&&!t.includes(i)&&t.push(i)}catch{}return t}function zn(e,t){try{return qt(e,["--version"],{stdio:"pipe",env:t}),!0}catch{return!1}}import hc from"better-sqlite3";import{createRequire as yc}from"module";import{existsSync as Si,mkdtempSync as bc,readFileSync as ft,rmSync as Sc,statSync as xc,writeFileSync as _c}from"fs";import{cpus as Ic,tmpdir as Rc}from"os";import{dirname as Kn,extname as Cc,join as Xe,relative as vc,resolve as xi}from"path";import{pathToFileURL as Nc}from"url";import{Worker as Ec}from"worker_threads";function Qn(e){Ee({projectRoot:e.projectRoot,dbPath:e.dbPath});let t=xi(e.projectRoot,e.tsconfig);if(!Si(t))throw new Error(`Vue tsconfig not found at ${t}`);let n=new hc(e.dbPath);try{let r=Kc(n,e.projectRoot),i=Xe(Kn(e.dbPath),"augment-vue-meta.json"),s=bi(n,e.projectRoot,e.tsconfig),o=Dc(i,s,e.onStatus);if(o)return o;let a=iu(n,e.projectRoot,r),l=Lc(n,e,t,r,a),c=lu(l.occurrences),d=kc(n,e,r,a,c);e.onStatus?.(`Resolved ${c.length} Vue references with Volar; inserted ${d} mentions.`);let u=wc(r,c,d,l,a);return Oc(i,bi(n,e.projectRoot,e.tsconfig),u),u}finally{n.close()}}function Dc(e,t,n){let r=Pc(e,t);return r&&n?.(`Vue references unchanged; reused ${r.resolvedReferences} cached resolved references.`),r}function Lc(e,t,n,r,i){if(Wc(r))return Hc({projectRoot:t.projectRoot,dbPath:t.dbPath,tsconfig:t.tsconfig,vueFiles:r});let s=fu(),o=Qc(t.projectRoot,n);return Mc({projectRoot:t.projectRoot,vueFiles:o.fileNames.filter(a=>a.endsWith(".vue")),context:o,symbolLookup:tu(e,t.projectRoot,s),vueSymbolLookup:i,sourceCache:s})}function kc(e,t,n,r,i){return su(e,t.projectRoot,n,r,i)}function wc(e,t,n,r,i){return{vueFiles:e.length,resolvedReferences:t.length,insertedMentions:n,skippedReferences:r.skippedReferences,syntheticSymbols:i.syntheticSymbols}}function Pc(e,t){try{let n=JSON.parse(ft(e,"utf-8"));return JSON.stringify(n.fingerprint)===JSON.stringify(t)?n.result:null}catch{return null}}function Oc(e,t,n){_c(e,JSON.stringify({updatedAt:new Date().toISOString(),fingerprint:t,result:n},null,2)+`
|
|
71
|
+
`)}function bi(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 Mc(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=Fc(e,i);t.push(...s.occurrences),n+=s.skippedReferences}return{occurrences:t,skippedReferences:n}}function Fc(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=gt(e.projectRoot,t.fileName),a=[...uu(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:Ac(a),processedStarts:new Set};return Tc({...e,fileName:t.fileName,sourceInfo:i,sourceFile:o,map:s,tokenContext:l})}function Tc(e){let t=[],n=0;for(let r of e.tokenContext.tokens){if(e.tokenContext.processedStarts.has(r.start))continue;let i=du(e.map,r.start);if(i===null)continue;let o=(e.context.languageService.getDefinitionAtPosition(e.fileName,i+1)??[]).find(l=>!mu(e.projectRoot,l.fileName));if(!o){n++;continue}let a=au(o,e.symbolLookup,e.vueSymbolLookup,e.context,e.projectRoot);if(a===null){n++;continue}_i(t,e.sourceInfo,e.sourceFile,r,a),e.tokenContext.processedStarts.add(r.start),$c(t,e,r,i,a)}return{occurrences:t,skippedReferences:n}}function $c(e,t,n,r,i){if(!((t.tokenContext.tokenTextCounts.get(n.text)??0)<=1))for(let s of jc(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&&(_i(e,t.sourceInfo,t.sourceFile,o,i),t.tokenContext.processedStarts.add(s))}}function _i(e,t,n,r,i){let s=Ni(t,r.start);e.push({sourceFile:n,sourceLine:s.line,sourceStartChar:s.character,sourceEndChar:s.character+r.text.length,symbolId:i})}function Ac(e){let t=new Map;for(let n of e)t.set(n.text,(t.get(n.text)??0)+1);return t}function jc(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 d=Bc(r,c.textSpan.start,s,i.text);d!==null&&a.push(d)}return a}function Bc(e,t,n,r){let i=n.get(t);if(i?.text===r)return i.start;let s=vi(e,t);if(s===null)return null;let o=n.get(s);return o?.text===r?o.start:null}function Wc(e){return e.length>=8&&Ii(e.length)>1}function Hc(e){let t=Ii(e.vueFiles.length),n=Uc(e.vueFiles),r=qc(n,t),i=new URL("./augment-vue-worker.js",import.meta.url),s=bc(Xe(Rc(),"scip-query-vue-workers-")),o=new SharedArrayBuffer(4),a=new Int32Array(o),l=Vc(),c=Date.now();try{for(let u=0;u<r.length;u++)new Ec(i,{workerData:{projectRoot:e.projectRoot,dbPath:e.dbPath,tsconfig:e.tsconfig,tasks:r[u],resultPath:Xe(s,`${u}.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 d=r.map((u,m)=>{let f=JSON.parse(ft(Xe(s,`${m}.json`),"utf-8"));if(!f.ok)throw new Error(`Vue reference worker failed: ${f.error}`);return f.result});return{occurrences:d.flatMap(u=>u.occurrences),skippedReferences:d.reduce((u,m)=>u+m.skippedReferences,0)}}finally{Sc(s,{recursive:!0,force:!0})}}function Ii(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,Ic().length-1));return Math.max(1,Math.min(e,n))}function Vc(){let e=Number(process.env.SCIP_QUERY_AUGMENT_VUE_WORKER_TIMEOUT_MS??0);return Number.isFinite(e)&&e>0?e:3e5}function Uc(e){let t=Jc(),n=[];for(let r of e){let i=Ri(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 Jc(){return Number.POSITIVE_INFINITY}function qc(e,t){let n=Array.from({length:t},()=>({tasks:[],weight:0})),r=e.map(i=>({task:i,weight:zc(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 zc(e){return Number.isFinite(e.endOffset)?Math.max(1,e.endOffset-e.startOffset):Math.max(1,Ri(e.fileName)-e.startOffset)}function Ri(e){try{return xc(e).size}catch{return 1}}function Gc(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 Kc(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=>xi(t,r.relativePath))}function Qc(e,t){let{vueCore:n,ts:r,volarTs:i}=Yc(e),{parsed:s,vueOptions:o}=Xc(n,r,t),a=Kn(t),l=n.createVueLanguagePlugin(r,s.options,o,f=>f),c=Zc(n,r,l),d=eu(a,s),{languageServiceHost:u}=i.createLanguageServiceHost(r,r.sys,c,f=>f,d),m=r.createLanguageService(u);return{ts:r,language:c,languageService:m,fileNames:s.fileNames,configDir:a}}function Yc(e){let t=yc(Nc(Xe(e,"package.json")).href);return{vueCore:Gn(t,"@vue/language-core",e),ts:Gn(t,"typescript",e),volarTs:Gn(t,"@volar/typescript",e)}}function Xc(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,Kn(n),void 0,n,void 0,e.getAllExtensions(s).map(o=>({extension:o.slice(1),isMixedContent:!0,scriptKind:t.ScriptKind.Deferred}))),vueOptions:s}}function Zc(e,t,n){let r={},i=e.createLanguage([n],new Map,s=>{if(!Si(s))return;let o=ft(s,"utf-8");r.current?.scripts.set(s,t.ScriptSnapshot.fromString(o),n.getLanguageId(s)??pu(s))});return r.current=i,i}function eu(e,t){return{getCurrentDirectory:()=>e,getCompilationSettings:()=>t.options,getScriptFileNames:()=>t.fileNames,getProjectReferences:()=>t.projectReferences,getProjectVersion:()=>"0"}}function Gn(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 tu(e,t,n){let r=nu(e);return i=>{let s=gt(t,i.fileName),o=n(i.fileName);if(!o)return null;let a=Ni(o,i.textSpan.start),l=r.get(s);if(!l)return null;let c=l.containingByLine.get(a.line);return c!==void 0?c:ru(l.starts,a.line,2)}}function nu(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=Ba(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 Oa(e,n,t){let s=Wa(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 ru(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 iu(e,t,n){let r=yu(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 d=gt(t,c),u=bu(r.name,r.version,d);s.run(u,"default",7,`Vue component|${d}`);let m=i.get(u);m&&(o++,a.set(c,m.id))}})(),{get(c){return a.get(c)??null},syntheticSymbols:o}}function su(e,t,n,r,i){return e.transaction(()=>(Gc(e),ou(e,t,n,r),cu(e,i)))()}function ou(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=gt(t,a),d=i.get(c);if(!d)continue;let u=s.run(d.id,-1,0,0);o.run(Number(u.lastInsertRowid),l)}}function au(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(vi(a,e.textSpan.start)!==null)return n.get(e.fileName)}return e.fileName.startsWith(i)?n.get(e.fileName):null}return t(e)}function lu(e){let t=new Set,n=[];for(let r of e){let i=Ci(r);t.has(i)||(t.add(i),n.push(r))}return n}function Ci(e){return[e.sourceFile,e.sourceLine,e.sourceStartChar,e.sourceEndChar,e.symbolId].join(":")}function cu(e,t){let n=hu(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}Va(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=Ci(l);if(s.has(c))continue;s.add(c);let d=n.get(l.sourceFile);if(!d)continue;let u=r.run(d,a++,l.sourceLine,l.sourceLine),m=i.run(Number(u.lastInsertRowid),l.symbolId);o+=Number(m.changes)}return o}function*uu(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 du(e,t){for(let[n]of e.toGeneratedLocation(t,r=>!!r.navigation))return n;return null}function vi(e,t){let n=e;for(let[r]of n.toSourceLocation(t,i=>!!i.navigation))return r;return null}function Ni(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 mu(e,t){return gt(e,t).startsWith("node_modules/")}function gt(e,t){return vc(e,t).replaceAll("\\","/")}function pu(e){switch(Cc(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 fu(){let e=new Map;return t=>{if(e.has(t))return e.get(t)??null;try{let n=ft(t,"utf-8"),r={text:n,lineStarts:gu(n)};return e.set(t,r),r}catch{return e.set(t,null),null}}}function gu(e){let t=[0];for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&t.push(n+1);return t}function hu(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 yu(e){try{let t=JSON.parse(ft(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 bu(e,t,n){let r=n.split("/").map(i=>`\`${i.replaceAll("`","")}\``).join("/");return`scip-vue npm ${e} ${t} ${r}/default.`}async function Li(e){let{projectRoot:t,maxHeapMb:n=8192,onStatus:r=console.log,skipAutoInstall:i=!1}=e,s=Eu(e),o=Date.now();Ei(je(s.outputScip),{recursive:!0}),Ei(je(s.outputDb),{recursive:!0});let a=e.languages??Ae(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=Qu(t,a,{pnpmWorkspaces:e.pnpmWorkspaces}),c=Uu(se(je(s.outputDb),"index.lock")),d=null;try{let u=Du({opts:e,paths:s,languages:a,fingerprint:l,start:o,onStatus:r});if(u)return u;Ou(i,r);let m=Lu(s);return d=m.runDir,await ku({opts:e,languages:a,projectRoot:t,paths:s,tempPaths:m,fingerprint:l,start:o,maxHeapMb:n,skipAutoInstall:i,onStatus:r})}finally{d&&et(d,{recursive:!0,force:!0}),c()}}function Eu(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(je(n),"meta.json")}}function Du(e){if(e.opts.skipIfUnchanged===!1||!Be(e.paths.outputScip)||!Be(e.paths.outputDb)||!Yu(e.paths.metaPath,e.fingerprint))return null;Ee({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 Lu(e){let t=Iu(se(je(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 ku(e){let t={...process.env,NODE_OPTIONS:`--max-old-space-size=${e.maxHeapMb}`},{indexedOutputs:n,skippedLanguages:r}=await wu(e,t);Pu(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 wu(e,t){let{preparedRuns:n,skippedLanguages:r}=Mu({languages:e.languages,tempOutputScip:e.tempPaths.tempOutputScip,projectRoot:e.projectRoot,env:t,skipAutoInstall:e.skipAutoInstall,pnpmWorkspaces:e.opts.pnpmWorkspaces,onStatus:e.onStatus}),i=await zu(n,e.projectRoot,e.onStatus,e.opts.indexerConcurrency),{indexedOutputs:s}=Tu(i,r);return $u(s,r,e.languages,e.opts.allowPartial,e.onStatus),{indexedOutputs:s,skippedLanguages:r}}function Pu(e,t,n,r){Au(n,e.tempPaths.tempOutputScip,e.onStatus),ju(e.tempPaths.tempOutputScip,e.tempPaths.tempOutputDb,t,e.onStatus),Ee({projectRoot:e.projectRoot,dbPath:e.tempPaths.tempOutputDb,onStatus:e.onStatus}),Xu(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]}),Ju({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 Ou(e,t){if(!pt("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 Mu(e){let t=[],n=[],r=e.languages.map((i,s)=>({language:i,scipPath:e.languages.length>1?Vu(e.tempOutputScip,i,s):e.tempOutputScip}));for(let{language:i,scipPath:s}of r){let o=Fu({...e,language:i,scipPath:s});"skipped"in o?n.push(o.skipped):t.push(o.prepared)}return{preparedRuns:t,skippedLanguages:n}}function Fu(e){let t=Vt(e.language),n=zt(t),r=qn(t,e.projectRoot);if(!r&&!di(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...`),!gi(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??Ye(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:pi(t,e.env,i)}}}function Tu(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 $u(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 Au(e,t,n){e.length>1?(n(`Merging ${e.length} language indexes...`),ri(e.map(r=>r.scipPath),t)):e[0].scipPath!==t&&Ze(e[0].scipPath,t)}function ju(e,t,n,r){if(r("Converting to SQLite..."),!Be(e))throw new Error(`SCIP index not found at ${e} after indexing`);try{let i=li(e);i.removedDefinitionOccurrences>0&&r(`Sanitized ${i.removedDefinitionOccurrences} invalid definition occurrences across ${i.touchedDocuments} documents before SQLite conversion.`),xu("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 Bu(e,t,n){if(!e.defaultOutputPath)return;let r=se(t,e.defaultOutputPath);n!==r&&Be(r)&&Ze(r,n)}function Wu(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}),Be(r)?(Ze(r,i),{defaultOutputPath:r,backupPath:i}):{defaultOutputPath:r,backupPath:null}}function Hu(e){e&&(et(e.defaultOutputPath,{force:!0}),e.backupPath&&Be(e.backupPath)&&Ze(e.backupPath,e.defaultOutputPath))}function Vu(e,t,n){let r=Nu(e)||".scip",i=Kt(e,r);return se(je(e),`${i}.${n+1}.${t}${r}`)}function Uu(e){let t;try{t=Ru(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 ${je(e)}.`,{cause:n}):n}return Di(t,JSON.stringify({pid:process.pid,startedAt:new Date().toISOString()})+`
|
|
131
|
+
`),()=>{try{_u(t)}finally{et(e,{force:!0})}}}function Ju(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 qu(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,vu().length-1));return Math.max(1,Math.min(e,Math.floor(r)))}async function zu(e,t,n,r){let i=e.filter(c=>c.config.defaultOutputPath),s=e.filter(c=>!c.config.defaultOutputPath),o=[],a=qu(s.length,r),l=await Ku(s,a,c=>Xn(c,t,n));if(a>1){let c=new Map;for(let d of l.filter(u=>u.skipped)){let u=s.find(m=>m.language===d.language);u&&(n(`Retrying ${u.language} indexer serially after parallel failure...`),c.set(u.language,await Xn(u,t,n)))}o.push(...l.map(d=>c.get(d.language)??d))}else o.push(...l);for(let c of i)o.push(await Xn(c,t,n));return o.sort((c,d)=>e.findIndex(u=>u.language===c.language)-e.findIndex(u=>u.language===d.language))}async function Xn(e,t,n){n(`Indexing ${e.language} with ${e.resolvedBinary}...`),et(e.scipPath,{force:!0});let r=Wu(e.config,t,e.scipPath);try{await Gu(e.binary,e.args,{cwd:t,env:e.env,maxBuffer:50*1024*1024}),Bu(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{Hu(r)}if(!Be(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 Gu(e,t,n){return new Promise((r,i)=>{Su(e,[...t],n,s=>{s?i(s):r()})})}async function Ku(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 Qu(e,t,n){return{version:1,languages:[...t].sort(),pnpmWorkspaces:n.pnpmWorkspaces===!0,files:Ut(e)}}function Yu(e,t){try{let n=JSON.parse(Cu(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 Xu(e,t){Di(e,`${JSON.stringify(t,null,2)}
|
|
133
|
+
`)}function Gt(e){return JSON.stringify(e)}import{createRequire as id}from"module";import{existsSync as ht,readFileSync as Zu,readdirSync as ed,statSync as td}from"fs";import A from"path";var er=["tsconfig.json","tsconfig.app.json","tsconfig.node.json","tsconfig.base.json"];function tr(e,t){let r=t?A.dirname(A.join(e,t)):e,i=A.resolve(e);for(;r.startsWith(i);){for(let o of er){let a=A.join(r,o);if(ht(a))return a}let s=A.dirname(r);if(s===r)break;r=s}for(let s of er){let o=A.join(e,s);if(ht(o))return o}return null}function ki(e){let t=e.config.projectRoot,n=new Set(nr(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=tr(t,i.relative_path);s&&n.add(A.resolve(s))}if(n.size===0){let i=tr(t);i&&n.add(A.resolve(i))}return[...n].filter(i=>!wi(t,i)).sort((i,s)=>i.localeCompare(s))}function nr(e,t=[]){let n=new Set;for(let r of t){let i=A.isAbsolute(r)?r:A.join(e,r);ht(i)&&n.add(A.resolve(i))}for(let r of nd(e))for(let i of er){let s=A.join(r,i);ht(s)&&n.add(A.resolve(s))}if(n.size===0){let r=tr(e);r&&n.add(A.resolve(r))}return[...n].filter(r=>!wi(e,r)).sort((r,i)=>r.localeCompare(i))}function nd(e){let t=A.join(e,"package.json");if(!ht(t))return[];let n;try{n=JSON.parse(Zu(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>rd(e,i))}function rd(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=A.join(e,t);return Zn(o)?[o]:[]}let n=t.indexOf("*"),r=t.slice(0,n).replace(/\/$/,""),i=t.slice(n+1).replace(/^\//,""),s=A.join(e,r||".");return Zn(s)?ed(s).map(o=>A.join(s,o,i)).filter(Zn):[]}function Zn(e){try{return td(e).isDirectory()}catch{return!1}}function wi(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 sd=id(import.meta.url);function rr(e,t=[]){let n=od(),r=nr(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 od(){try{return sd.resolve("ts-morph"),!0}catch{return!1}}import{watch as ad}from"fs";import{existsSync as Pi,renameSync as Oi}from"fs";import{join as ld,relative as cd}from"path";import{fork as ud}from"child_process";import dd from"ignore";var Qt=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=ve(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=Qe(t.projectRoot),this.extraIgnore=dd(),this.watchConfig.ignore.length>0&&this.extraIgnore.add(this.watchConfig.ignore)}start(){this.stopped=!1,this.setStatus({state:"idle"});try{let t=ad(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.debounceTimer&&clearTimeout(this.debounceTimer),this.cooldownTimer&&clearTimeout(this.cooldownTimer),this.setStatus({state:"idle"})}handleFileChange(t){let n=cd(this.projectRoot,ld(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.debounceTimer&&clearTimeout(this.debounceTimer);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=md(this.indexPaths.indexPath),o=ud(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{Pi(i)&&Oi(i,this.indexPaths.dbPath),Pi(s)&&Oi(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)}};function md(e){return e.endsWith(".scip")?e.slice(0,-5)+".tmp.scip":e+".tmp.scip"}import{existsSync as ir,mkdirSync as pd,symlinkSync as fd,readlinkSync as gd,unlinkSync as hd}from"fs";import{join as Yt,dirname as Mi,resolve as sr}from"path";import{homedir as Fi,platform as yd}from"os";import{fileURLToPath as bd}from"url";var Sd=yd()==="win32",or=["concrete-plan","scip-explore","scip-debloat","scip-verify","scip-language-playbook"];function Ti(e={}){let t=e.quiet?()=>{}:console.log,n=bd(import.meta.url),r=sr(Mi(n),"..","skills"),i=[Yt(Fi(),".claude","skills"),Yt(Fi(),".codex","skills")],s={installed:[],skipped:[],alreadyLinked:[]};for(let o of i){let a=Mi(o);if(!ir(a))continue;pd(o,{recursive:!0});let l=o.includes(".codex")?"Codex":"Claude";for(let c of or){let d=Yt(r,c),u=Yt(o,c);if(!ir(d)){s.skipped.push(`${l}/${c}`);continue}if(ir(u)){try{let m=gd(u);if(sr(m)===sr(d)){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}hd(u)}fd(d,u,Sd?"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 $a}from"fs";import{join as oS}from"path";import xd from"better-sqlite3";var Xt=class{db;config;pathFilter;constructor(t,n){this.config=t,this.pathFilter=n??null,this.db=new xd(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={};Va(x,{affected:()=>ca,bottlenecks:()=>Ho,byKind:()=>Vo,callGraph:()=>Ko,changeSurface:()=>ua,code:()=>Da,complexity:()=>ka,complexityHotspots:()=>On,convergence:()=>va,coupling:()=>Ao,cycles:()=>Rn,dataflow:()=>wa,dead:()=>In,deepChains:()=>zo,deps:()=>So,diffImpact:()=>pa,drift:()=>Dn,extractCandidates:()=>Nn,fanIn:()=>Mo,fanOut:()=>Fo,files:()=>$i,health:()=>Ra,hierarchy:()=>Go,hotspots:()=>vo,importedBy:()=>Do,imports:()=>Eo,isolated:()=>Cn,kindCounts:()=>Uo,members:()=>Oo,methods:()=>ho,outline:()=>Po,passthroughCandidates:()=>wn,rdeps:()=>xo,redundantReexports:()=>Oa,refs:()=>yo,similar:()=>Xo,similarAll:()=>vn,similarChains:()=>aa,similarFiles:()=>sa,similarSignatures:()=>Fa,slice:()=>Pa,staleAbstractions:()=>Pn,stats:()=>Zt,surface:()=>Io,symbols:()=>os,system:()=>_o,topCoupling:()=>jo,topFanIn:()=>To,topFanOut:()=>$o,trace:()=>bo,unusedImports:()=>Lo,wrapperCandidates:()=>kn});import{statSync as _d}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,...Id(e.config.dbPath)}}function Id(e){try{let t=_d(e);return{indexSizeBytes:t.size,lastBuilt:t.mtime}}catch{return{indexSizeBytes:0,lastBuilt:null}}}function Rd(e){return/[*?]/.test(e)?e.replace(/\*\*/g,"%").replace(/\*/g,"%").replace(/\?/g,"_"):`%${e}%`}function $i(e,t){let n=Rd(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 Hi}from"path";import{createRequire as Ld}from"module";import{existsSync as Cd,readFileSync as vd}from"fs";import{join as Nd}from"path";var Ed=$("source-text");function O(e,t){let n=t.replace(/\\/g,"/");return Ed.get(e,n,()=>{let r=Nd(e.config.projectRoot,n);return Cd(r)?vd(r,"utf-8"):""})}var Dd=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale|wrapper|passthrough|drift|extract)?/i;function ar(e,t,n){if(n<=0)return!1;let r=O(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(Dd.test(o))return!0;if(!o.startsWith("//")&&!o.startsWith("*")&&!o.startsWith("/*")&&!o.startsWith("@")&&!o.startsWith("#"))return!1}}return!1}var q=Ld(import.meta.url),en=null,Ai=!1;function Vi(){if(Ai)return null;if(en)return en;try{return en=q("tree-sitter"),en}catch{return Ai=!0,null}}var kd={".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"},ji=new Map,lr=new Set;function Ui(e){if(lr.has(e))return null;let t=ji.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 lr.add(e),null}return ji.set(e,n),n}var Bi=new Map;function Ji(e){let t=Bi.get(e);if(t)return t;let n=Ui(e);if(!n)return null;let r=Vi();if(!r)return null;let i=new r;try{i.setLanguage(n)}catch{return lr.add(e),null}return Bi.set(e,i),i}function M(e){return kd[Hi(e).toLowerCase()]??null}function bt(e){return Hi(e).toLowerCase()===".vue"}var qi=Wt("ast-trees");function w(e,t){if(bt(t))return wd(e,t);let n=M(t);if(!n)return null;let r=O(e,t);return r?qi.get(e,t,r,()=>{let i=Ji(n);if(!i)return null;try{return zi(i,r)}catch{return null}}):null}function wd(e,t){let n=O(e,t);return n?qi.get(e,t,n,()=>{let r=Pd(n);if(!r)return null;let i=Ji(r.language);if(!i)return null;let s=`
|
|
167
|
+
`.repeat(r.startLine)+r.body;try{return zi(i,s)}catch{return null}}):null}function zi(e,t){return e.parse(r=>r>=t.length?null:t.slice(r,Math.min(t.length,r+16384)))}function Pd(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=Od(e,r.openIdx);return{body:r.body,startLine:a,language:o}}function Od(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 Md(e,t){let n=`${e}::${t}`;if(tt.has(n))return tt.get(n)??null;let r=Ui(e);if(!r)return tt.set(n,null),null;let i=Vi();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 Fd={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
|
+
`},Td=new WeakMap;function Gi(e,t){return Qi(e,t,Td,Fd,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 $d={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
|
+
`},Ad=new WeakMap;function tn(e,t){return Qi(e,t,Ad,$d,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=yt(s);a&&r.push({calleeLeaf:a,memberAccess:jd(s),line:o.startPosition.row})}return r})}function jd(e){switch(e.type){case"field_expression":case"member_expression":case"attribute":return!0;default:return!1}}function Ki(e,t){return nn(e,t,Bd,()=>new Map,(n,r,i)=>{let s=(l,c)=>{if(l===c)return;let d=i.get(l);d||(d=new Set,i.set(l,d)),d.add(c)},o=r==="python"?new Set(["identifier"]):new Set(["type_identifier"]),a=(l,c)=>{let d=u=>{o.has(u.type)&&u.text!==c&&s(u.text,c);for(let m of u.children)d(m)};for(let u of l.children)d(u)};if(r==="rust")for(let l of n.rootNode.descendantsOfType(["struct_item","enum_item","union_item","type_item"])){let c=l.namedChildren.find(u=>u.type==="type_identifier")?.text;if(!c)continue;let d=l.namedChildren.find(u=>u.type==="field_declaration_list"||u.type==="enum_variant_list"||u.type==="ordered_field_declaration_list");d&&a(d,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(u=>u.type==="identifier")?.text;if(!c)continue;let d=l.namedChildren.find(u=>u.type==="block");if(d)for(let u of d.descendantsOfType("type"))for(let m of u.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(d=>d.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=w(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=w(e,t);if(!a)return null;let l=n.get(a);if(l)return l;let c=Md(s,o);if(!c)return null;let d=i(c.matches(a.rootNode));return n.set(a,d),d}var Bd=new WeakMap,Wi=new WeakMap;function Yi(e,t,n,r){let i=M(t);if(!i)return null;let s=w(e,t);if(!s)return null;let o=Wi.get(s);return o||(o=Wd(s,i),Wi.set(s,o)),o.get(`${n}:${r}`)??null}function Wd(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 yt(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?yt(t):null}case"scoped_identifier":{let t=e.childForFieldName("name")??e.namedChild(e.namedChildCount-1);return t?yt(t):null}case"super":case"self":case"this":return null;default:return null}}var Hd={"/":"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=Vd(i);return{scheme:n,manager:r,packageName:s,version:o,descriptors:l,raw:e}}function Vd(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||Xi(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&&!Xi(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=Hd[i];s&&t.push({name:r,suffix:s}),n+=1}}return t}function Xi(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=Ud(i);s&&r.push(s)}return r.join(":")}function Ud(e){let t=e.suffix==="namespace"?Jd(e.name):e.name;return t?e.suffix==="method"?`${t}()`:t:""}function Jd(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 k(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 De(e){return V(e)==="namespace"}var qd=/^rust-analyzer\b.*[\s/]impl#\[[^\]]+\]\[[^\]]+\]/;function rn(e){return qd.test(e)}var zd=new Set(["test","tests","_tests"]);function Le(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&&zd.has(r.name))return!0}return!1}function Zi(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 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)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 We(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 He(e){if(!e)return null;let t=ts(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(ts(r)??r).replace(/\n/g," ")}function ts(e){return/^```(?:\w+)?\s*\n?([\s\S]*?)\n?```/.exec(e.trimStart())?.[1]?.trim()||null}var Gd=$("file-definitions");function ee(e,t){return Gd.get(e,t,()=>{let n=Xd(Kd(e,t),Qd(e,t));return em(e,t,n.map(Yd))})}function Kd(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 Qd(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 Yd(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:k(e.symbol),parentTypeName:Ue(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 Xd(e,t){let n=new Map;for(let r of t)e.length>0&&!Zd(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 Zd(e){if(Ue(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 cr(e,t.scope)}function cr(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=>ee(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=>ee(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:We(He(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 Ve(e,t){let n=ee(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 em(e,t,n){let r=O(e,t),i=Gi(e,t);return i?om(n,i,r):r?tm(n,r):n}function tm(e,t){let n=t.split(/\r?\n/),r=nm(e,n),i=rm(e,r),s=im(i,n);return sm(e,s)}function nm(e,t){let n=e.some(i=>sn(i.symbol))?lm(t):null,r=new Map;for(let i of e)r.set(i.symbolId,am(t,n,i));return r}function rm(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 im(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:cm(t,i.definition,i.startLine,o)})}return n}function sm(e,t){return e.map(n=>{let r=t.get(n.symbolId);return r?{...n,startLine:r.startLine,endLine:r.endLine}:n})}function om(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 ns(i,n);let s=r.get(i.leaf);if(!s||s.length===0)return ns(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],d=Math.abs(c.startLine-i.startLine);d<a&&(o=c,a=d)}return{...i,startLine:o.startLine,endLine:o.endLine}})}function ns(e,t){if(!t||!e.leaf||V(e.symbol)!=="term"||Ue(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 am(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 lm(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 d of l.matchAll(t))d[1]&&o(d[1],a);for(let d of l.matchAll(n))d[1]&&o(d[1],a);let c=l.match(r);c?.[1]&&o(c[1],a);for(let d of l.matchAll(i))d[1]&&o(d[1],a)}return s}function cm(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 d=um(e[c]??"");for(let u of d)u==="{"?(o+=1,l=!0):u==="}"?o=Math.max(0,o-1):u==="("?a+=1:u===")"&&(a=Math.max(0,a-1));if(l&&o===0||!l&&a===0&&c>=s)return c}return s}function um(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 Ue(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 ur(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 vm}from"fs";import{basename as rs,isAbsolute as Nm,join as Em}from"path";function L(e,t){let n=it(e,t.trim());if(n)return n;let r=hm(e,t);if(r)return r;let i=dm(e,t);return i||gm(e,t)}function dm(e,t){let n=pr(t),r=mr(n);if(!r)return null;let i=`%${r.path}%`,s=r.leaf,a=mm(e,i,s,n)[0];return a?Ve(e,a):null}function mm(e,t,n,r){let i=dr([],[...pm(e,t,n),...fm(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 pm(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 fm(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 gm(e,t){let n=pr(t),r=Rm(t),i=xm(e,r),s=Cm(i,t,n);if(s&&!e.isIgnored(s.relative_path))return Ve(e,s);let o=null;for(let a of i){if(e.isIgnored(a.relative_path))continue;let l=Im(a,t,n,r);l<=0||(!o||l>o.score)&&(o={row:a,score:l})}return o?Ve(e,o.row):null}function hm(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=ym(e,r,o,a)??bm(e,r,o,a);return l&&!e.isIgnored(l.relative_path)?Ve(e,l):null}function ym(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 bm(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:Ve(e,r)}function on(e,t){if("symbol"in t&&"relativePath"in t)return t;let n=Sm(e,t.symbolId)[0];return n?Ve(e,n):null}function Sm(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 dr(n,r)}function xm(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 dr(i,s)}function dr(e,t){let n=new Map;for(let r of t)e.length>0&&!_m(r)||n.set(r.id,r);for(let r of e)n.set(r.id,r);return[...n.values()]}function _m(e){if(Ue(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 Im(e,t,n,r){let i=t.trim(),s=n,o=s.replace(/\(\)$/,""),a=t.toLowerCase(),l=n.toLowerCase(),c=l.replace(/\(\)$/,""),d=e.symbol,u=h(e.symbol),m=k(e.symbol),f=e.display_name??"",p=e.symbol.toLowerCase(),g=u.toLowerCase(),y=m.toLowerCase(),E=f.toLowerCase(),N=e.relative_path.toLowerCase(),F=/[/:.]/.test(n),T=mr(n),R=T?.leaf.toLowerCase(),_=0;return(d===i||d===s)&&(_+=1150),(u===i||u===s)&&(_+=1100),f===o&&(_+=1180),m===o&&(_+=1160),(`${m}()`===i||`${m}()`===s)&&(_+=955),(p===a||p===l)&&(_+=1e3),(g===a||g===l)&&(_+=950),(N===a||N===l)&&(_+=925),(N.endsWith(`/${l}`)||N.endsWith(`/${a}`))&&(_+=875),E===c&&(_+=850),y===c&&(_+=825),(`${y}()`===a||`${y}()`===l)&&(_+=820),(g.endsWith(`:${l}`)||g.endsWith(`:${c}`)||g.endsWith(`:${c}()`))&&(_+=800),p.includes(l)&&(_+=120),g.includes(l)&&(_+=140),N.includes(l)&&(_+=140),E.includes(l)&&(_+=110),r.every(P=>{let D=P.toLowerCase();return p.includes(D)||g.includes(D)||N.includes(D)||E.includes(D)})&&(_+=100+r.length*15),T&&N.includes(T.path.toLowerCase())&&(_+=360,R&&(y===R||`${y}()`===R||`${y}()`==`${R}()`)&&(_+=700),U(e.symbol)&&(_+=180)),W(e.symbol)&&y===c&&(_+=60),!F&&De(e.symbol)&&(_-=160),_-=Math.min(50,Math.max(0,e.end_line-e.start_line)),_}function mr(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 pr(e){return e.trim().replace(/\(\)$/,"").replace(/\(.*$/,"")}function Rm(e){let t=pr(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 Cm(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=mr(t);if(!n)return 0;let r=e.relative_path.toLowerCase(),i=k(e.symbol).toLowerCase(),s=n.path.toLowerCase(),o=n.leaf.toLowerCase();return r.includes(s)?i!==o?1:U(e.symbol)?Ue(e.symbol)===null?5:4:Ue(e.symbol)===null?3:2:0}function G(e,t){let n=is(e,t,{allowMultiple:!1})[0]?.relativePath;return n||Dm(e,t)}function ke(e,t){return is(e,t,{allowMultiple:!0}).map(n=>n.relativePath)}function Dm(e,t){if(!t)return null;let n=t.replace(/\\/g,"/").replace(/^\.\//,""),r=Nm(n)&&n.startsWith(e.config.projectRoot)?n.slice(e.config.projectRoot.length).replace(/^\/+/,""):n,i=Em(e.config.projectRoot,r);return vm(i)?r:null}function is(e,t,n){let r=ss(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:Bl(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 Bl(e,n){let t=mi(e),s=ci(t),i=ci(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 mi(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function di(e,n){let t=Le(e,n);return Ke(e,t).map(({relativePath:s,...i})=>i)}import{basename as Wl}from"path";function pi(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:Hl(Wl(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 Hl(e){return e.replace(/\.[^.]+$/,"")}var ft=new WeakMap;function hi(e,n){let t=P(n);return t==="rust"?Vl(e,n):t==="typescript"||t==="tsx"||t==="javascript"?Ul(e,n):[]}var Jl=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function Ul(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&&Jl.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(...yi(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 ql=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function zl(e){return ql.test(e)}function yi(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(zl(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 Vl(e,n){let t=O(e,n);if(!t)return[];let s=ft.get(t);if(s)return s;let i=[];if(Gl(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(...yi(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=Zl(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 Gl(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 Yl=[{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}],bi=/^#!?\[\s*serde\s*\(/,Kl=/^#!?\[\s*schemars\s*\(/,Ql=/^#!?\[\s*validate\s*\(/,fi=/\bwith\s*=\s*"([^"]+)"/g;function we(e,n){return Jt(e,n,Xl,()=>new Set,(t,s,i)=>{if(s==="rust"){for(let o of t.rootNode.descendantsOfType("attribute_item"))gi(o.text,i);for(let o of t.rootNode.descendantsOfType("inner_attribute_item"))gi(o.text,i)}})??new Set}var Xl=new WeakMap;function gi(e,n){let t=bi.test(e),s=Kl.test(e),i=Ql.test(e);if(!(!t&&!s&&!i))for(let{re:o}of Yl){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 Zl(e){let n=new Set;for(let t of e.descendantsOfType("attribute_item")){if(!bi.test(t.text))continue;fi.lastIndex=0;let s;for(;(s=fi.exec(t.text))!==null;){let i=s[1],o=i.split("::").pop()??i;o&&n.add(o)}}return n}var ec=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function Si(e,n){return Jt(e,n,tc,()=>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||!ec.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 tc=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 nc=Ot("stripped-lines");function xi(e,n,t){return nc.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 Li(e,n,t){let s=O(e,n);return s?Ec(e,n,s):wc(t).flatMap(i=>Dc(e,n,i.clause,i.specifier,i.start,i.end,t))}function Ec(e,n,t){let s=J(t,new Set(["import_statement"]));if(mt(n))for(let o of Ac(e,n))s.add(o);let i=[];for(let o of t.rootNode.descendantsOfType("import_statement")){let a=Rc(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=Lc(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 Rc(e){let n=le(e,"string");if(!n)return null;let t=le(n,"string_fragment");return t?t.text:null}function Lc(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 wc(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 Dc(e,n,t,s,i,o,a){let r=He(e,n,s),l=z(a,i,o);return t?kc(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 kc(e){let n=e.trim().replace(/^type\s+/,""),[t,s]=Oc(n),i=[];return t&&i.push(...Ri(t)),s&&i.push(...Ri(s)),i}function Ri(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 Oc(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 wi(e,n){let t=O(e,n);if(t)return Pc(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=>$c(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 $c(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 Pc(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("export_statement")){let o=Mc(e,n,i);if(o===void 0)continue;let a=i.startPosition.row,r=i.endPosition.row,l=Fc(i,o,a,r);s.push(l)}return s}function Mc(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 Fc(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 Tc=W("vue-non-script-identifiers");function Ac(e,n){return Tc.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 Di}from"path";function ki(e,n,t){let s=O(e,n);if(s)return jc(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=Di(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:c,sourcePath:Qt(e,n,a),kind:"named",used:te(l,c),usedMembers:[]})}return i}function jc(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=Di(a).replace(/\.[^.]+$/,"");i.push({importedName:a,localName:r,sourcePath:Qt(e,n,a),kind:"named",used:s.has(r),usedMembers:[]})}return i}function Oi(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 $i(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 Pi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="csharp")return Wc(e,n,s);if(s&&i==="vb")return Bc(e,n,s);let o=[],a=Ei(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 Bc(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 Wc(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 Mi(e,n,t){let s=O(e,n),i=P(n);if(s&&i==="java")return Hc(e,n,s);if(s&&i==="kotlin")return Jc(e,n,s);if(s&&i==="scala")return Uc(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(...qc(e,n,r,c))}return o}function Hc(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 Jc(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 Uc(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 qc(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 Ti(e,n,t){let s=O(e,n);if(s)return zc(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 zc(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}=Fi(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}=Fi(l,"");c&&o(u,c,m)}}return i}function Fi(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 Bi(e,n,t){let s=O(e,n);return s?Vc(e,n,s):Yc(t).flatMap(i=>Qc(e,n,i,t))}function Vc(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=Ai(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=Gc(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=Ai(m);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:s.has(u.localName),usedMembers:[]})}}return i}function Ai(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 Gc(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 Yc(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=ji(o);for(;i+1<n.length&&(m>0||l.trimEnd().endsWith("\\"));){i++;let d=n[i];l+=`
|
|
318
|
-
${d}`,c+=1+d.length,m+=ji(d),s+=d.length+1}let u=Kc(l);u&&t.push({...u,start:r,end:c})}return t}function Kc(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 Qc(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 ji(e){let n=0;for(let t of e)t==="("&&n++,t===")"&&n--;return n}import{basename as Xc}from"path";function Wi(e,n,t){let s=O(e,n);if(s)return Zc(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=Hi(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 Zc(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=Hi(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 Hi(e){return Xc(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function Ji(e,n,t){let s=O(e,n);if(s)return eu(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(...tu(e,n,a,l))}return i}function eu(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 tu(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 Ui(e,n,t){let s=O(e,n);if(s)return nu(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(...iu(e,n,a))}return i}function nu(e,n,t){let s=[];for(let i of t.rootNode.descendantsOfType("use_declaration")){if(!su(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 su(e){for(let n of e.children)if(n.type==="visibility_modifier"&&n.text.startsWith("pub"))return!0;return!1}function iu(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 qi(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 ou={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Li},ru={language:"python",extensions:[".py",".pyi"],parseImports:Bi},au={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:Mi},lu={language:"rust",extensions:[".rs"],parseImports:Ji,parseExports:Ui},cu={language:"ruby",extensions:[".rb"],parseImports:Wi},uu={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:ki},mu={language:"dotnet",extensions:[".cs",".vb"],parseImports:Pi},du={language:"dart",extensions:[".dart"],parseImports:Oi,parseExports:$i},pu={language:"php",extensions:[".php"],parseImports:Ti},fu=[ou,ru,au,lu,cu,uu,mu,du,pu];function Hn(e){return qi(fu,e)}function Yi(e,n){return wi(e,n)}var gu=W("source-imports"),hu=W("source-exports");function de(e,n){let t=ae(n);return gu.get(e,t,()=>{let s=Hn(t);if(!s)return[];let i=Gi(e.config.projectRoot,t);if(!zi(i))return[];let o=Vi(i,"utf-8");return s.parseImports(e,t,o)})}function Jn(e,n){let t=ae(n);return hu.get(e,t,()=>{let s=Hn(t);if(!s?.parseExports)return[];let i=Gi(e.config.projectRoot,t);if(!zi(i))return[];let o=Vi(i,"utf-8");return s.parseExports(e,t,o)})}var yu=W("file-dep-graph");function K(e,n){return yu.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:Lm(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=L(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 Lm(e,t){let n=ss(e),r=rs(n),i=rs(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 ss(e){return e.trim().replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"").replace(/\/+$/,"")}function os(e,t){let n=ke(e,t);return nt(e,n).map(({relativePath:r,...i})=>i)}import{basename as Tg}from"path";var St=new WeakMap;function cs(e,t){let n=M(t);return n==="rust"?Mm(e,t):n==="typescript"||n==="tsx"||n==="javascript"?wm(e,t):[]}var km=new Set(["describe","it","test","fdescribe","fit","xdescribe","xit","beforeEach","afterEach","beforeAll","afterAll","before","after","suite","bench","benchmark"]);function wm(e,t){let n=w(e,t);if(!n)return[];let r=St.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 d=c.namedChild(0);if(!d||d.type!=="call_expression")continue;let u=d.namedChild(0);if(!u)continue;let m=u.type==="member_expression"?u.namedChild(u.namedChildCount-1)?.text:u.text;if(m&&km.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 d=null,u=null;if(c.type==="function_declaration")d=c.namedChild(0)?.text??null,u=c;else if(c.type==="export_statement"){let m=c.namedChild(0);m?.type==="function_declaration"&&(d=m.namedChild(0)?.text??null,u=m)}else if(c.type==="lexical_declaration"){let m=c.namedChild(0);if(m?.type==="variable_declarator"){let f=m.namedChild(0)?.text,p=m.namedChild(1);f&&(p?.type==="arrow_function"||p?.type==="function_expression")&&(d=f,u=m)}}d&&/^use[A-Z]/.test(d)&&u&&l.push({startLine:u.startPosition.row,endLine:u.endPosition.row,reason:"React custom hook (use*)"})}return l.push(...us(n,new Set(["function_declaration","method_definition","class_declaration","interface_declaration","type_alias_declaration","enum_declaration","variable_declarator","export_statement"]),new Set(["comment"]))),St.set(n,l),l}var Pm=/scip-query[\s:-]*ignore[\s:-]*(?:dead(?:-code)?|stale)?/i;function Om(e){return Pm.test(e)}function us(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 d=a[c];if(n.has(d.type)){if(Om(d.text)){r.push({startLine:s.startPosition.row,endLine:s.endPosition.row,reason:"scip-query suppression comment"});break}continue}if(!(d.type==="attribute_item"||d.type==="inner_attribute_item"))break}}for(let o of s.namedChildren)i(o)};return i(e.rootNode),r}function Mm(e,t){let n=w(e,t);if(!n)return[];let r=St.get(n);if(r)return r;let i=[],s=Fm(n);return s?(St.set(n,s),s):(ds(n.rootNode,i,!1,!1),i.push(...us(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(...Wm(n.rootNode)),St.set(n,i),i)}function Fm(e){return Hm(e.rootNode)?[{startLine:0,endLine:e.rootNode.endPosition.row,reason:"generated file (@generated header)"}]:null}function ds(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"?Tm(e,t,n,r):r&&Bm(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"?$m(e,t,n):e.type==="mod_item"&&fr(e).some(o=>/#\[\s*cfg\s*\(\s*test\s*\)/.test(o))&&(i=!0);for(let o of e.namedChildren)ds(o,t,i,s)}function Tm(e,t,n,r){let i=fr(e),s=null;r?s="trait impl method (dynamic dispatch)":n&&(s="inside #[cfg(test)] mod");for(let o of i){let a=Am(o);if(a){s=a;break}if(ms(o)){s="#[allow(dead_code)]";break}}s&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:s})}function $m(e,t,n){let r=fr(e),i=e.namedChildren.find(s=>s.type==="type_identifier")?.text;r.some(jm)&&t.push({startLine:e.startPosition.row,endLine:e.endPosition.row,reason:"#[derive(<reflective>)] \u2014 fields accessed via macro/reflection",containerName:i}),r.some(ms)&&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 fr(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 Am(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 jm(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 ms(e){return/#\[\s*allow\s*\(\s*dead_code\s*\)/.test(e)}function Bm(e){return e.type==="const_item"||e.type==="type_item"||e.type==="static_item"||e.type==="associated_type"}function Wm(e){let t=zm(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 Hm(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 Vm=[{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}],ps=/^#!?\[\s*serde\s*\(/,Um=/^#!?\[\s*schemars\s*\(/,Jm=/^#!?\[\s*validate\s*\(/,as=/\bwith\s*=\s*"([^"]+)"/g;function st(e,t){return nn(e,t,qm,()=>new Set,(n,r,i)=>{if(r==="rust"){for(let s of n.rootNode.descendantsOfType("attribute_item"))ls(s.text,i);for(let s of n.rootNode.descendantsOfType("inner_attribute_item"))ls(s.text,i)}})??new Set}var qm=new WeakMap;function ls(e,t){let n=ps.test(e),r=Um.test(e),i=Jm.test(e);if(!(!n&&!r&&!i))for(let{re:s}of Vm){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 zm(e){let t=new Set;for(let n of e.descendantsOfType("attribute_item")){if(!ps.test(n.text))continue;as.lastIndex=0;let r;for(;(r=as.exec(n.text))!==null;){let i=r[1],s=i.split("::").pop()??i;s&&t.add(s)}}return t}var Gm=new Set(["invoke","invokeTauriCommand","listen","once","emit","subscribe","dispatch","sendCommand","callRust"]);function fs(e,t){return nn(e,t,Km,()=>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=yt(o);if(!a||!Gm.has(a))continue;let l=s.namedChildren.find(u=>u.type==="arguments");if(!l)continue;let c=l.namedChild(0);if(!c||c.type!=="string")continue;let d=c.namedChildren.find(u=>u.type==="string_fragment");d&&i.add(d.text)}})??new Set}var Km=new WeakMap;function an(e){return e.replace(/'''[\s\S]*?'''/g,we).replace(/"""[\s\S]*?"""/g,we).replace(/#.*$/gm,we).replace(/\/\/.*$/gm,we).replace(/\/\*[\s\S]*?\*\//g,we).replace(/`(?:\\[\s\S]|[^`])*`/g,we).replace(/'(?:\\.|[^'\\\r\n])*'/g,we).replace(/"(?:\\.|[^"\\\r\n])*"/g,we)}function we(e){return e.replace(/[^\r\n]/g," ")}var Qm=Wt("stripped-lines");function hs(e,t,n){return Qm.get(e,t,n,()=>an(n).split(`
|
|
364
|
+
`))}var gs=null,gr="";function Ym(e){return gs===e||(gs=e,gr=an(e)),gr}function Pe(e,t,n){let r=Ym(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,"\\$&")}function cn(e,t,n,r={}){if(!n)return[];let i=O(e,t);if(!i)return[];if(i.indexOf(n)===-1)return[];if(M(t))return(Je(e,t).get(n)??[]).filter(d=>!ys(d,r));let s=hs(e,t,i),o=new RegExp(`\\b${ln(n)}\\b`),a=[];for(let l=0;l<s.length;l++)ys(l,r)||o.test(s[l]??"")&&a.push(l);return a}function ys(e,t){return typeof t.excludeStartLine=="number"&&typeof t.excludeEndLine=="number"&&e>=t.excludeStartLine&&e<=t.excludeEndLine}var Xm=$("file-identifiers");function bs(e,t){return Xm.get(e,t,()=>new Set(Je(e,t).keys()))}var Zm=$("file-ident-lines");function Je(e,t){return Zm.get(e,t,()=>tp(e,t))}var ep=$("file-idents-by-line");function Ss(e,t){return ep.get(e,t,()=>{let n=Je(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 tp(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=w(e,t);if(a){let l=M(t),c=l==="rust"?new Set(["identifier","type_identifier","field_identifier"]):l==="python"?new Set(["identifier"]):new Set(["identifier","property_identifier","type_identifier"]),d=new Set(["rust","python"]),u=/\{([^{}]*)\}/g,m=/\b([A-Za-z_][\w]*)\b/g,f=p=>{if(c.has(p.type)&&r(p.text,p.startPosition.row),l&&d.has(l)&&p.type==="string_content"){let g=p.startPosition.row;for(let y of p.text.matchAll(u)){let E=y[1]??"";for(let N of E.matchAll(m))N[1]&&r(N[1],g)}}for(let g of p.children)f(g)};return f(a.rootNode),n}}let i=O(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 Ws,readFileSync as Hs}from"fs";import{join as Vs}from"path";import{existsSync as dn}from"fs";import{basename as np,dirname as Oe,extname as Se,join as le,relative as xt,resolve as te}from"path";var rp=$e("indexed-paths"),un=[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],hr=[".py",".pyi"],ce=[".java",".scala",".kt",".kts"],yr=[".rs"],br=[".rb"],xs=[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],at=[".cs",".vb"],Sr=[".dart"],_t=[".php"],ip=[un,hr,ce,yr,br,xs,at,Sr,_t];function Me(e,t){return t.includes(Se(e).toLowerCase())}function sp(e){return Me(e,hr)}function op(e){return Me(e,ce)}function ap(e){return Me(e,yr)}function lp(e){return Me(e,br)}function cp(e){return Me(e,xs)}function up(e){return Me(e,at)}function _s(e){return Se(e).toLowerCase()===".vb"}function dp(e){return Me(e,Sr)}function mp(e){return Me(e,_t)}function xr(e){let t=Se(e).toLowerCase();for(let n of ip)if(n.includes(t))return n;return un}function pp(e){return op(e)||up(e)||mp(e)}function ge(e,t,n){return sp(t)?lt(e,t,n):ap(t)?xe(e,t,n):lp(t)?mn(e,t,n):cp(t)?pn(e,t,n):pp(t)?j(e,n.replace(/\\/g,"."),xr(t)):dp(t)?fn(e,t,n):fp(e,t,n)}function fp(e,t,n){if(!n.startsWith(".")&&!n.startsWith("/"))return null;let r=Oe(le(e.config.projectRoot,t)),i=te(r,n),s=It(e);for(let o of Sp(i)){let a=fe(xt(e.config.projectRoot,o));if(s.has(a)||dn(o))return a}return fe(xt(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=Oe(le(e.config.projectRoot,t));for(let c=1;c<o;c++)l=Oe(l);i=a?te(l,a.replace(/\./g,"/")):l}else i=te(e.config.projectRoot,n.replace(/\./g,"/"));for(let s of gp(i)){let o=fe(xt(e.config.projectRoot,s));if(r.has(o)||dn(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=Oe(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(Oe(i),r.slice(7).replace(/::/g,"/")),_r(e,hp(s))}function mn(e,t,n){let r=Oe(le(e.config.projectRoot,t)),i=te(r,n);return _r(e,yp(i))}function pn(e,t,n){let r=Oe(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 _r(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}`,d=[...r].find(u=>u.endsWith(c));if(d)return d}for(let l of n){let c=[...r].find(d=>np(d)===`${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 fn(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=Oe(le(e.config.projectRoot,t)),s=te(i,n);for(let o of bp(s)){let a=fe(xt(e.config.projectRoot,o));if(r.has(a)||dn(o))return a}return null}function gp(e){let t=Se(e);return hr.includes(t)?[e]:[`${e}.py`,`${e}.pyi`,le(e,"__init__.py"),le(e,"__init__.pyi")]}function _r(e,t){let n=It(e);for(let r of t){let i=fe(xt(e.config.projectRoot,r));if(n.has(i)||dn(r))return i}return null}function hp(e){let t=Se(e);return yr.includes(t)?[e]:[`${e}.rs`,le(e,"mod.rs")]}function yp(e){let t=Se(e);return br.includes(t)?[e]:[`${e}.rb`,le(e,"index.rb")]}function bp(e){let t=Se(e);return Sr.includes(t)?[e]:[`${e}.dart`,e]}function Sp(e){let t=Se(e),n=new Set;if(t){n.add(e);for(let r of un)n.add(e.slice(0,-t.length)+r)}else for(let r of un)n.add(`${e}${r}`),n.add(le(e,`index${r}`));return[...n]}function It(e){return rp.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,"/")}function Y(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=new Set(["identifier","type_identifier","property_identifier","shorthand_property_identifier","field_identifier"]),i=(s,o)=>{let a=o||t.has(s.type);!a&&r.has(s.type)&&n.add(s.text);for(let l of s.children)i(l,a)};return i(e.rootNode,!1),n}function he(e,t,n,r,i,s,o){return{importedName:i,localName:s,sourcePath:o??j(e,r,xr(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=Pe(e,i.index,i.index+s.length);r.push(...n(i,o))}return r}function Rs(e,t,n){let r=w(e,t);return r?xp(e,t,r):Pp(n).flatMap(i=>Op(e,t,i.clause,i.specifier,i.start,i.end,n))}function xp(e,t,n){let r=_p(e,t,n),i=[];for(let s of n.rootNode.descendantsOfType("import_statement"))i.push(...Ip(e,t,n,s,r));return i}function _p(e,t,n){let r=B(n,new Set(["import_statement"]));if(bt(t))for(let i of Jp(e,t))r.add(i);return r}function Ip(e,t,n,r,i){let s=Dp(r);if(!s)return[];let o=ge(e,t,s),a=ne(r,"import_clause");return a?Rp(n,a,o,i,Lp(r.text)):[Cp(o)]}function Rp(e,t,n,r,i){let s=[];for(let o of t.namedChildren)if(o.type==="identifier")s.push(vp(o.text,n,r,i));else if(o.type==="namespace_import"){let a=Np(e,o,n,r,i);a&&s.push(a)}else o.type==="named_imports"&&s.push(...Ep(o,n,r,i));return s}function Cp(e){return{importedName:"*",localName:null,sourcePath:e,kind:"side-effect",used:!0,usedMembers:[]}}function vp(e,t,n,r){return{importedName:"default",localName:e,sourcePath:t,kind:"default",used:n.has(e),usedMembers:[],isTypeOnly:r}}function Np(e,t,n,r,i){let o=ne(t,"identifier")?.text??"";if(!o)return null;let a=wp(e,o);return{importedName:"*",localName:o,sourcePath:n,kind:"namespace",used:a.length>0||r.has(o),usedMembers:a,isTypeOnly:i}}function Ep(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||kp(s.text)})}return i}function Dp(e){let t=ne(e,"string");if(!t)return null;let n=ne(t,"string_fragment");return n?n.text:null}function Lp(e){return/^\s*import\s+type\b/.test(e)}function kp(e){return/^\s*type\b/.test(e.trim())}function wp(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 Pp(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 Op(e,t,n,r,i,s,o){let a=ge(e,t,r),l=Pe(o,i,s);return n?Mp(n).map(d=>({...d,sourcePath:a})).map(d=>{if(d.kind==="namespace"){let u=ot(l,d.localName);return{...d,used:u.length>0||K(l,d.localName),usedMembers:u}}return d.kind==="side-effect"?{...d,used:!0,usedMembers:[]}:{...d,used:d.localName?K(l,d.localName):!1,usedMembers:[]}}):[{importedName:"*",localName:null,sourcePath:a,kind:"side-effect",used:!0,usedMembers:[]}]}function Mp(e){let t=e.trim(),n=/^type\b/.test(t),r=t.replace(/^type\s+/,""),[i,s]=Fp(r),o=[];return i&&o.push(...Is(i,n)),s&&o.push(...Is(s,n)),o}function Is(e,t){let n=e.trim();if(!n)return[];if(n.startsWith("{")){let r=n.slice(1,-1).trim();return r?Y(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 Fp(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 Cs(e,t){let n=w(e,t);if(n)return Wp(e,t,n);let r=O(e,t);return r?Tp(e,t,r):[]}function Tp(e,t,n){return[...$p(e,t,n),...Ap(e,t,n),...jp(e,t,n)]}function $p(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=Y(o).map(u=>Bp(u.trim())).filter(u=>!!u),c=ct(n,s.index),d=ct(n,s.index+s[0].length-1);r.push({kind:"named",sourcePath:ge(e,t,a),names:l,startLine:c,endLine:d})}return r}function Ap(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 jp(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 Bp(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 Wp(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("export_statement")){let s=Hp(e,t,i);if(s===void 0)continue;let o=i.startPosition.row,a=i.endPosition.row,l=Vp(i,s,o,a);r.push(l)}return r}function Hp(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 Vp(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 Up=$("vue-non-script-identifiers");function Jp(e,t){return Up.get(e,t,()=>{let n=new Set,r=O(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 vs}from"path";function Ns(e,t,n){let r=w(e,t);return r?qp(e,t,r):re(n,/^[ \t]*#include\s+[<"]([^">]+)[">]\s*$/gm,(i,s)=>{let o=i[1]?.trim();if(!o)return[];let a=vs(o).replace(/\.[^.]+$/,"");return[{importedName:o,localName:a,sourcePath:pn(e,t,o),kind:"named",used:K(s,a),usedMembers:[]}]})}function qp(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(d=>d.type==="string_content")?.text??l.text.replace(/^"|"$/g,"");break}}if(!o)continue;let a=vs(o).replace(/\.[^.]+$/,"");i.push({importedName:o,localName:a,sourcePath:pn(e,t,o),kind:"named",used:r.has(a),usedMembers:[]})}return i}function Es(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=Pe(n,i.index,i.index+a.length);r.push({importedName:s,localName:o,sourcePath:fn(e,t,s),kind:o?"namespace":"side-effect",used:o?K(l,o):!0,usedMembers:o?ot(l,o):[]})}return r}function Ds(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:fn(e,t,s)})}return r}function Ls(e,t,n){let r=w(e,t),i=M(t);if(r&&i==="csharp")return Gp(e,t,r);if(r&&i==="vb")return zp(e,t,r);let s=_s(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,d]=l.split(/\s*=\s*/),u=!!d,m=(u?d:c)?.trim()??l,f=m.split(".").pop()??m,p=u?c?.trim()??f:f;return[he(e,t,a,m,f,p,j(e,m,at))]})}function zp(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,d=c.split(".").pop()??c,u=l?.text??d;i.push({importedName:d,localName:u,sourcePath:j(e,c,at),kind:l?"namespace":"named",used:r.has(u),usedMembers:[]})}return i}function Gp(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,d=c.split(".").pop()??c,u=a?.text??d;i.push({importedName:d,localName:u,sourcePath:j(e,c,at),kind:a?"namespace":"named",used:r.has(u),usedMembers:[]})}return i}function ks(e,t,n){let r=w(e,t),i=M(t);return r&&i==="java"?Kp(e,t,r):r&&i==="kotlin"?Qp(e,t,r):r&&i==="scala"?Yp(e,t,r):re(n,/^[ \t]*import\s+(?:static\s+)?(.+?)\s*;?$/gm,(s,o)=>{let a=s[1]?.trim();return a?Xp(e,t,a,o):[]})}function Kp(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(u=>u.type==="asterisk"),l=s.namedChildren.find(u=>u.type==="scoped_identifier")??s.namedChildren.find(u=>u.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 d=c.split(".").pop()??c;i.push({importedName:d,localName:d,sourcePath:j(e,c,ce),kind:"named",used:r.has(d),usedMembers:[]})}return i}function Qp(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(f=>f.type==="identifier");if(!o)continue;let a=s.namedChildren.some(f=>f.type==="wildcard_import"),l=s.namedChildren.find(f=>f.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,d=c.split(".").pop()??c,m=l?.namedChild(0)?.text??d;i.push({importedName:d,localName:m,sourcePath:j(e,c,ce),kind:"named",used:r.has(m),usedMembers:[]})}return i}function Yp(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(u=>u.type==="namespace_selectors"||u.type==="namespace_wildcard"),a=s.namedChildren.filter(u=>u!==o&&(u.type==="identifier"||u.type==="stable_identifier")),l=a.map(u=>u.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 u of o.namedChildren)if(u.type==="arrow_renamed_identifier"){let[m,f]=u.namedChildren;if(!m)continue;let p=m.text,g=f?.text??p;if(p==="_")continue;i.push({importedName:p,localName:g,sourcePath:j(e,`${l}.${p}`,ce),kind:"named",used:r.has(g),usedMembers:[]})}else if(u.type==="identifier"){let m=u.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,d=a.slice(0,-1).map(u=>u.text).join(".")||l;i.push({importedName:c,localName:c,sourcePath:j(e,d&&a.length>1?`${d}.${c}`:l,ce),kind:"named",used:r.has(c),usedMembers:[]})}return i}function Xp(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 Y(s).flatMap(o=>{let a=o.trim();if(!a)return[];let[l,c]=a.includes("=>")?a.split(/\s*=>\s*/):a.split(/\s+as\s+/),d=l?.trim();if(!d||d==="_")return[];let u=(c??d.split(".").pop()??d).trim(),m=d==="_"?i:`${i}.${d}`.replace(/\.\./g,".");return[he(e,t,r,m,d,u)]})}return[he(e,t,r,n,n.split(".").pop()??n,n.split(".").pop()??n)]}function Ps(e,t,n){let r=w(e,t);return r?Zp(e,t,r):re(n,/^[ \t]*use\s+(.+?)\s*;$/gm,(i,s)=>{let o=i[1]?.trim();return o?Y(o).flatMap(a=>{let l=a.trim();if(!l)return[];let[c,d]=l.split(/\s+as\s+/i),u=c?.trim()??l,m=u.split("\\").pop()??u,f=(d??m).trim();return[he(e,t,s,u,m,f,j(e,u.replace(/\\/g,"."),_t))]}):[]})}function Zp(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:d,localName:u,qualified:m}=ws(c,l);d&&s(m,d,u)}continue}for(let l of o.namedChildren){if(l.type!=="namespace_use_clause")continue;let{importedName:c,localName:d,qualified:u}=ws(l,"");c&&s(u,c,d)}}return i}function ws(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 Fs(e,t,n){let r=w(e,t);return r?ef(e,t,r):nf(n).flatMap(i=>sf(e,t,i,n))}function ef(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=Os(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=tf(o);if(a===null)continue;let l=lt(e,t,a);for(let c=1;c<s.namedChildCount;c+=1){let d=s.namedChild(c);if(d.type==="wildcard_import"){i.push({importedName:"*",localName:null,sourcePath:l,kind:"side-effect",used:!0,usedMembers:[]});continue}let u=Os(d);u&&i.push({importedName:u.qualifiedName,localName:u.localName,sourcePath:l,kind:"named",used:r.has(u.localName),usedMembers:[]})}}return i}function Os(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 tf(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 nf(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,d=Ms(s);for(;i+1<t.length&&(d>0||l.trimEnd().endsWith("\\"));){i++;let m=t[i];l+=`
|
|
369
|
+
${m}`,c+=1+m.length,d+=Ms(m),r+=m.length+1}let u=rf(l);u&&n.push({...u,start:a,end:c})}return n}function rf(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 sf(e,t,n,r){let i=Pe(r,n.start,n.end),s=n.clause.replace(/\n/g," ").trim();if(n.kind==="import")return Y(s).flatMap(l=>{let c=l.trim().replace(/,$/,"");if(!c)return[];let[d,u]=c.split(/\s+as\s+/),m=d.trim(),f=(u??m.split(".")[0]??m).trim(),p=lt(e,t,m),g=ot(i,f);return[{importedName:m,localName:f,sourcePath:p,kind:"namespace",used:K(i,f)||g.length>0,usedMembers:g}]});let o=n.module?lt(e,t,n.module):null,a=[];for(let l of Y(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[d,u]=c.split(/\s+as\s+/),m=(u??d).trim();a.push({importedName:d.trim(),localName:m,sourcePath:o,kind:"named",used:K(i,m),usedMembers:[]})}return a}function Ms(e){let t=0;for(let n of e)n==="("&&t++,n===")"&&t--;return t}import{basename as of}from"path";function Ts(e,t,n){let r=w(e,t);return r?af(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"?mn(e,t,a):null;if(l){let c=$s(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 af(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(f=>f.type==="argument_list")?.namedChild(0);if(!c||c.type!=="string")continue;let u=c.namedChildren.find(f=>f.type==="string_content")?.text;if(!u)continue;let m=a.text==="require_relative"?mn(e,t,u):null;if(m){let f=$s(u);i.push({importedName:f,localName:f,sourcePath:m,kind:"named",used:r.has(f),usedMembers:[]})}else i.push({importedName:u,localName:null,sourcePath:m,kind:"side-effect",used:!0,usedMembers:[]})}return i}function $s(e){return of(e).replace(/\.[^.]+$/,"").split("_").filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join("")}function As(e,t,n){let r=w(e,t);return r?lf(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 lf(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:gn(t,n),importedName:n,localName:n}]}case"scoped_identifier":{let n=e.text,r=n.split("::").pop()??n;return[{qualifiedName:gn(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=gn(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:gn(t,`${r}::*`),importedName:"*",localName:"*"}]}default:return[]}}function gn(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 d=i.slice(0,i.indexOf("{")).replace(/::$/,"").trim(),u=i.slice(i.indexOf("{")+1,i.lastIndexOf("}")).trim();return Y(u).flatMap(m=>{let f=m.trim();if(!f||f==="self")return[];let[p,g]=f.split(/\s+as\s+/),y=p?.trim();if(!y)return[];let E=(g??y.split("::").pop()??y).trim(),N=`${d}::${y}`.replace(/::::/g,"::");return[he(e,t,r,N,y.split("::").pop()??y,E,xe(e,t,d))]})}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 js(e,t,n){let r=w(e,t);if(r)return uf(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(...mf(e,t,o))}return i}function uf(e,t,n){let r=[];for(let i of n.rootNode.descendantsOfType("use_declaration")){if(!df(i))continue;let s=i.namedChildren.find(o=>o.type!=="visibility_modifier");if(s)for(let o of Rt(s,""))o.importedName&&r.push(Ir(e,t,o.qualifiedName))}return r}function df(e){for(let t of e.children)if(t.type==="visibility_modifier"&&t.text.startsWith("pub"))return!0;return!1}function mf(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 Y(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[Ir(e,t,c)]})}return[Ir(e,t,r)]}function Ir(e,t,n){return{specifier:n,sourcePath:xe(e,t,n)??xe(e,t,n.split("::").slice(0,-1).join("::"))}}function Bs(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 pf={language:"javascript",extensions:[".ts",".tsx",".mts",".cts",".js",".jsx",".mjs",".cjs",".vue"],parseImports:Rs},ff={language:"python",extensions:[".py",".pyi"],parseImports:Fs},gf={language:"jvm",extensions:[".java",".scala",".kt",".kts"],parseImports:ks},hf={language:"rust",extensions:[".rs"],parseImports:As,parseExports:js},yf={language:"ruby",extensions:[".rb"],parseImports:Ts},bf={language:"c/cpp",extensions:[".c",".h",".cc",".cpp",".cxx",".hpp",".hh",".hxx"],parseImports:Ns},Sf={language:"dotnet",extensions:[".cs",".vb"],parseImports:Ls},xf={language:"dart",extensions:[".dart"],parseImports:Es,parseExports:Ds},_f={language:"php",extensions:[".php"],parseImports:Ps},If=[pf,ff,gf,hf,yf,bf,Sf,xf,_f];function Rr(e){return Bs(If,e)}function Us(e,t){return Cs(e,t)}var Rf=$("source-imports"),Cf=$("source-exports");function J(e,t){let n=fe(t);return Rf.get(e,n,()=>{let r=Rr(n);if(!r)return[];let i=Vs(e.config.projectRoot,n);if(!Ws(i))return[];let s=Hs(i,"utf-8");return r.parseImports(e,n,s)})}function Cr(e,t){let n=fe(t);return Cf.get(e,n,()=>{let r=Rr(n);if(!r?.parseExports)return[];let i=Vs(e.config.projectRoot,n);if(!Ws(i))return[];let s=Hs(i,"utf-8");return r.parseExports(e,n,s)})}import ue from"path";import{createRequire as vf}from"module";import{existsSync as hn,readdirSync as Nf,readFileSync as Gs}from"fs";var Ef=vf(import.meta.url),Ct;function Ks(e,t){let n=Df();if(!n)return vr("ts-morph is not installed");let r=ki(e);if(r.length===0)return vr("no tsconfig found");try{let i=r.map(s=>({tsconfigPath:s,project:new n.Project({tsConfigFilePath:s,skipFileDependencyResolution:!1})}));return new Nr(e,n,i)}catch(i){return vr(i instanceof Error?i.message:String(i),r[0],r)}}function Df(){if(Ct!==void 0)return Ct;try{Ct=Ef("ts-morph")}catch{Ct=null}return Ct}function vr(e,t,n){return{language:"typescript",availability:()=>({available:!1,reason:e,tsconfigPath:t,tsconfigPaths:n}),importUsage:()=>[],referencesFor:()=>[],calleesFor:()=>[],signatureFor:()=>null}}var Nr=class{constructor(t,n,r){this.db=t;this.tsMorph=n;this.projects=r;this.workspacePackages=wf(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;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 qe(this.importUsageCache,t,()=>{let n=this.sourceFile(t);if(!n)return[];let r=[];for(let i of n.getImportDeclarations())r.push(...this.importUsageForDeclaration(t,i));return r})}referencesFor(t){return qe(this.referencesCache,t.symbolId,()=>{let n=this.nodeForDefinition(t),r=this.packageImportReferencesForDefinition(t);if(!n)return r;let i=$f(n);return Er([...i.flatMap(s=>Tf(s,this.db.config.projectRoot)).filter(s=>s.file!==t.relativePath||s.line<t.startLine||s.line>t.endLine),...r])})}calleesFor(t){return qe(this.calleesCache,t.symbolId,()=>qe(this.fileCalleesCache,t.relativePath,()=>this.calleeMapForFile(t.relativePath)).get(t.symbolId)??[])}signatureFor(t){return qe(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=Js(n);return n.getImportClause()?.isTypeOnly()?i.map(s=>Lf(t,r,s)):i.map(s=>this.valueImportUsageForEntry(t,r,s))}valueImportUsageForEntry(t,n,r){let s=(r.identifier?r.identifier.findReferences():[]).flatMap(c=>Af(c,t,r.identifier,this.db.config.projectRoot)),o=s.some(c=>!qs(c.node)),a=s.some(c=>qs(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 qf(t)?qe(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,Er(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=Mf(this.workspacePackages,i.getModuleSpecifierValue());if(!s)return;let o=n.get(s);if(o)for(let a of Js(i)){if(a.kind!=="named"||!a.identifier)continue;let l=o.get(a.importedName);if(!l||l.size===0)continue;let c=jf(a.identifier,r,this.db.config.projectRoot);c.length>0&&Uf(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 Ff(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 d of c){let u=d.getNameNode().getText(),m=d.getAliasNode()?.getText()??u,f=this.indexedDefinitionByLeaf(l,u);if(!f)continue;let p=r.get(m);p||(p=new Set,r.set(m,p)),p.add(f.symbolId)}}}indexedDefinitionByLeaf(t,n){return qe(this.indexedDefinitionLeafCache,t,()=>Hf(this.db,t)).get(n)??null}nodeForDefinition(t){let n=this.sourceFile(t.relativePath);if(!n)return null;let r=k(t.symbol)??t.leaf,i=[];return n.forEachDescendant(s=>{if(!Bf(this.tsMorph,s,r))return;let o=ut(n,s);o<t.startLine-1||o>t.endLine+1||i.push(s)}),i.sort((s,o)=>Math.abs(ut(n,s)-t.startLine)-Math.abs(ut(n,o)-t.startLine))[0]??null}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=ut(i,r),a=Wf(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=ee(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&&kf(i,o.callerId,o.target)});for(let[s,o]of i)i.set(s,Jf(o));return i}semanticCalleeForCallNode(t,n,r){let i=Vf(n,ut(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 Js(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 Lf(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 kf(e,t,n){let r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}function wf(e){let t=ue.join(e,"package.json");if(!hn(t))return[];let n;try{n=JSON.parse(Gs(t,"utf8"))}catch{return[]}return(Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages??[]).flatMap(i=>Pf(e,i)).flatMap(i=>Of(e,i))}function Pf(e,t){if(!t||t.startsWith("!")||t.includes("node_modules"))return[];if(!t.includes("*")){let o=ue.join(e,t);return hn(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(!hn(s))return[];try{return Nf(s).map(o=>ue.join(s,o,i)).filter(o=>hn(ue.join(o,"package.json")))}catch{return[]}}function Of(e,t){try{let n=JSON.parse(Gs(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 Mf(e,t){for(let n of e)if(t===n.name||t.startsWith(`${n.name}/`))return n.name;return null}function Ff(e){return[`${e.sourceRootRelative}/index.ts`,`${e.sourceRootRelative}/index.tsx`,`${e.sourceRootRelative}/index.mts`,`${e.sourceRootRelative}/index.cts`]}function Tf(e,t){return e.getReferences().map(n=>{let r=n.getNode();return Qs(r,t)})}function $f(e){let t=e;return typeof t.findReferences=="function"?t.findReferences():[]}function Af(e,t,n,r){return e.getReferences().map(i=>i.getNode()).filter(i=>yn(r,i.getSourceFile().getFilePath())===t).filter(i=>!n||i.getStart()!==n.getStart()).map(i=>({location:Qs(i,r),node:i}))}function Qs(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 jf(e,t,n){let r=e.getSourceFile(),i=ut(r,e),s=e.getText(),o=new RegExp(`\\b${zf(s)}\\b`,"g"),a=r.getFullText().split(`
|
|
382
|
+
`),l=[];for(let c=0;c<a.length;c++){if(c===i)continue;let d=a[c]??"";o.lastIndex=0;let u;for(;(u=o.exec(d))!==null;)l.push({file:t,line:c,column:u.index})}return Er(l.filter(c=>yn(n,ue.join(n,c.file))===t))}function qs(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 Bf(e,t,n){return"getNameNode"in t&&typeof t.getNameNode=="function"&&t.getNameNode()?.getText()===n||"getName"in t&&typeof t.getName=="function"&&t.getName()===n?!0:e.Node.isIdentifier(t)&&t.getText()===n}function Wf(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 Hf(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||k(s.symbol);!o||i.has(o)||i.set(o,{...s,leaf:o})}return i}function Vf(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 ut(e,t){return e.getLineAndColumnAtPos(t.getStart()).line-1}function Er(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 Uf(e,t,n){for(let r of t){let i=e.get(r)??[];i.push(...n),e.set(r,i)}}function Jf(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 qe(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 qf(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 zf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ys=new WeakMap;function Xs(e,t){let n=`${e.config.projectRoot}:typescript-workspace`,r=Ys.get(e);r||(r=new Map,Ys.set(e,r));let i=r.get(n);if(i)return i;let s=Ks(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 dt(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 Zs(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 eo(e,t){let n=bn(e,t.relativePath);return n?n.signatureFor(t):null}function bn(e,t){if(!Gf(t))return null;let n=Xs(e,t);return n.availability().available?n:null}function Gf(e){return/\.(?:ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(e)}var Kf=$("file-dep-graph");function Q(e,t){return Kf.get(e,t??"",()=>{let n=new Map,r=Yf(e),i=(s,o)=>Xf(e,n,r,s,o);for(let s of Qf(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 Qf(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 Yf(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 Xf(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 X(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=tg(e)?rg(e,t):ng(e).get(t.symbolId)??[];return typeof n.limit=="number"?r.slice(0,n.limit):r}var Zf=$e("caller-rows"),eg=2e4;function tg(e){return(e.get("SELECT COUNT(*) AS count FROM global_symbols")?.count??0)>eg}function ng(e){return Zf.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 d=i.get(c);d||(d=[],i.set(c,d),s.set(c,new Set));let u=`${o.symbol}|${o.relativePath}`;s.get(c).has(u)||(s.get(c).add(u),d.push({symbol:o.symbol,file:o.relativePath}))}}return i})}function rg(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 _e(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(ee(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 _e(e,t){let n=cg(e,t);return n?ug(e,sg(e,n.match,n.identifier)):[]}function sg(e,t,n){let r=new Map;for(let[i,s]of og(e,t.symbolId))r.set(i,ag(e,i,s,t,n));return r}function og(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 ag(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=>lg(o,a))}function lg(e,t){let n=e.filter(r=>r>=t.start_line&&r<=t.end_line);return n.length>0?n:[t.start_line]}function cg(e,t){let n=on(e,t);return n?{match:n,identifier:k(n.symbol)||null}:null}function ug(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=ee(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 c of t)M(c.relativePath)&&tn(e,c.relativePath)!==null?i.push(c):s.push(c);let o=new Map,a=c=>{for(let[d,u]of c){let m=o.get(d);m||(m=[],o.set(d,m));let f=new Set(m.map(p=>`${p.symbol}|${p.chunkId}`));for(let p of u){let g=`${p.symbol}|${p.chunkId}`;f.has(g)||(f.add(g),m.push(p))}}};i.length>0&&a(dg(e,i)),a(vg(Zs(e,t)));let l=r?t:s;return l.length>0&&a(yg(e,l)),o}function dg(e,t){let n=new Map,r=mg(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=pg(o,l.line);if(!c)continue;let d=fg(e,s,i,l.calleeLeaf,l.memberAccess);d&&d.symbol!==c.symbol&&n.get(c.symbolId).push({symbol:d.symbol,file:d.file,chunkId:l.line})}}return n}function mg(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 pg(e,t){return e.find(n=>t>=n.startLine&&t<=n.endLine)??null}function fg(e,t,n,r,i){let s=no(t,n.get(r)??[]);return s.length===0?null:ro(e,t,s,i)}function no(e,t){let n=to(e);return n?t.filter(r=>to(r.file)===n):t}function ro(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));return n.find(o=>[...s].some(a=>gg(a,o.file)))??null}return n.length===1?n[0]:null}function gg(e,t){let n=r=>r.replace(/\\/g,"/").replace(/^\.\//,"");return n(e)===n(t)}function to(e){let t=M(e);return t?t==="typescript"||t==="tsx"||t==="javascript"?"javascript-family":t:null}var hg=$e("global-leaf-index");function Et(e){return hg.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+=ji(d),s+=d.length+1}let u=Kc(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=k(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 yg(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+=ji(d),s+=d.length+1}let u=Kc(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 d=r.get(c.documentId)??[],u=new Set,m=[],f=null,p=()=>{if(f)return f;let g=l.get(c.documentId)??"",y=new Set;if(g){let E=Ss(e,g),N=Math.max(0,c.startLine),F=Math.min(E.length-1,c.endLine);for(let T=N;T<=F;T+=1)for(let R of E[T])y.add(R)}return f=y,y};for(let g of d){if(g.symbol_id===c.symbolId)continue;let y=s.get(g.symbol_id);if(!y)continue;if(!(g.start_line>=c.startLine&&g.end_line<=c.endLine)){if(!(g.start_line<=c.endLine&&g.end_line>=c.startLine))continue;let T=k(y.symbol);if(!T||!p().has(T))continue}let N=`${y.symbol}|${g.chunk_id}`;u.has(N)||(u.add(N),m.push({...y,chunkId:g.chunk_id}))}a.set(c.symbolId,m)}return a}function io(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 bg(e,n,r,i),Sg(e,n,s),Rg(e,n,r,i),Ng(n,dt(e,Cg(s))),n}function bg(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=no(i.relative_path,r.get(o.calleeLeaf)??[]);if(!a||a.length===0)continue;let l=ro(e,i.relative_path,a,o.memberAccess);l&&l.file!==i.relative_path&&Dr(t,l.symbolId,i.relative_path)}}}function Sg(e,t,n){let r=_g(n);for(let i of xg(e))e.isIgnored(i.relative_path)||Ig(i,r.get(i.symbol_id))||Dr(t,i.symbol_id,i.relative_path)}function xg(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 _g(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 Ig(e,t){return!!t&&t.docId===e.document_id&&e.chunk_start>=t.startLine&&e.chunk_end<=t.endLine}function Rg(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&&Dr(t,l.symbolId,i.relative_path)}}}function Dr(e,t,n){let r=e.get(t);r||(r=new Set,e.set(t,r)),r.add(n)}function Cg(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)t.set(n,r.map(i=>({...i,chunkId:-1})));return t}function Ng(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 Z(e){let t=Dt(e);return Dg(t)?"test":Lg(t)?"worker":kg(t)?"entry":wg(t)?"barrel":"source"}function xn(e){return Z(e)==="barrel"}function oo(e){return Eg.get(e,()=>{let t=Q(e),n=Ne(e).filter(s=>{let o=Z(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),Z(s)==="barrel"&&i.add(s);for(let o of t.get(s)??[])r.has(o)||n.push(o)}}return i})}var Eg=$e("live-barrels");function Lr(e,t){return oo(e).has(Dt(t))}function ao(e){let t=oo(e);return Ne(e).filter(n=>xn(n)&&!t.has(n))}function ze(e,t){let n=Z(t);return n==="entry"||n==="worker"||Lr(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=>Pg(t,s))||r.symbolPatterns?.some(s=>{try{return new RegExp(s).test(t)}catch{return!1}}))}var lo=["%/__tests__/%","%.test.%","%.spec.%","%/test/%","%/tests/%","%_test.%","%_spec.%","%/test_%.%","%/spec_%.%"],co=["%/test-utils/%"];function Dg(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 Lg(e){return/(?:^|\/)[^/]*worker\.(?:ts|tsx|js|mjs|cjs|rs|py|go)$/.test(e)}function kg(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 wg(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 Pg(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(so(r)+"/")&&e.includes(so(i)+".")}function so(e){return/^[A-Za-z0-9_$+-]+$/.test(e)?e:"`"+e.replace(/`/g,"``")+"`"}function mt(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=Og(e,t),o=s.get(n);if(o)for(let l of o){let c=r.filter(d=>uo(l,d.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(d=>uo(l,d.file));if(c.length>0&&c.length===r.length)return c.map(kt)}return[]}function po(e,t,n){let r=mt(e,t,n);if(r.length>0)return r;let i=Et(e).get(n);return!i||i.length===0?[]:i.map(kt)}function Fe(e,t){let n=on(e,t);if(!n)return[];let r=k(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 mo(e,o)}let s=new Map;for(let o of Ne(e)){let a=O(e,o);if(!a||a.indexOf(r)===-1||o!==n.relativePath&&!mt(e,o,r).some(d=>d.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 mo(e,s)}function fo(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 Ne(e)){let o=bs(e,s);if(o.size!==0){for(let a of o)if(n.has(a))for(let l of mt(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 Og(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 uo(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 mo(e,t){let n=[],r=new Set;for(let[i,s]of t){let o=ee(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 go(e,t,n){let r=t.identifierResolution==="strict"?mt:po;for(let i of t.paths){let s=M(i);if(!s&&!(t.includeVueSfc&&bt(i))||e.isIgnored(i)||t.skipPath?.(i))continue;let o=Je(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 fs(e,i))for(let l of mt(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 cr(this.db,t)}definitionsForFile(t){return ee(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:d=!1,includeSuppressed:u=!1,sortByLocDesc:m=!1}=t,f=this.scopedDefinitions(n).filter(p=>!this.db.isIgnored(p.relativePath)).filter(p=>!o||!ze(this.db,p.relativePath)).filter(p=>Mg(p,{requireFunctionLikeSymbol:l,requireCallableSymbol:c})).filter(p=>s===void 0||p.symbol!==s).filter(p=>_n(p)>=r&&_n(p)<=i).filter(p=>!a||!Fg(p.relativePath)).filter(p=>!d||!rn(p.symbol)).filter(p=>Z(p.relativePath)!=="test").filter(p=>!Le(p.symbol)).filter(p=>u||!ar(this.db,p.relativePath,p.startLine));return m?[...f].sort((p,g)=>_n(g)-_n(p)):f}calleeMap(t,n={}){return Sn(this.db,t,n)}crossFileCallerMap(t){return io(this.db,t)}sourceFallbackCallerFiles(t){return fo(this.db,t)}fileDependencyGraph(t){return Q(this.db,t)}fileKind(t){return Z(t)}hasSuppressionComment(t){return ar(this.db,t.relativePath,t.startLine)}sourceFiles(){return Ne(this.db)}scanSourceReferences(t,n){go(this.db,t,n)}callableSignature(t){return Yi(this.db,t.relativePath,t.startLine,t.endLine)}};function _n(e){return e.endLine-e.startLine+1}function Mg(e,t){return t.requireCallableSymbol?U(e.symbol):t.requireFunctionLikeSymbol?W(e.symbol):e.isFunctionLike}function Fg(e){return(e.split("/").pop()??"").includes("types")}function ho(e,t){let n=L(e,t);if(!n)return[];let r=k(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:$g(Tg(n.relativePath))===r?s.filter(l=>l.symbol.includes("<invalid-global-code>")):[]).map(l=>({startLine:l.startLine,endLine:l.endLine,name:k(l.symbol)}))}function $g(e){return e.replace(/\.[^.]+$/,"")}function yo(e,t){let n=L(e,t);if(!n)return[];let i=!W(n.symbol)&&!e.isIgnored(n.relativePath)?[{relativePath:n.relativePath,line:n.startLine}]:[],s=Fe(e,n),o=(s.length>0?s:_e(e,n)).filter(d=>!e.isIgnored(d.file)).map(d=>({relativePath:d.file,line:d.line})),a=Ag(e,n),l=new Set,c=[];for(let d of[...i,...o,...a]){let u=`${d.relativePath}:${d.line}`;l.has(u)||(l.add(u),c.push(d))}return c}function Ag(e,t){if(!t.relativePath.endsWith(".rb"))return[];let n=jg(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=O(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(d=>new RegExp(`@${d}\\b|\\b${d}:`).test(c))&&i.push({relativePath:s.relative_path,line:l})}}return i}function jg(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 bo(e,t){let n=L(e,t);if(!n)return{definitions:[],referencedBy:[]};let r=e.get("SELECT display_name, documentation FROM global_symbols WHERE id = ?",n.symbolId),i=He(r?.documentation??null),s=e.isIgnored(n.relativePath)?[]:[{relativePath:n.relativePath,startLine:n.startLine,endLine:n.endLine,signature:Wg(i,r?.display_name??null,n.symbol),source:Bg(e,n.relativePath,n.startLine,n.endLine)}],o=Fe(e,n),l=(o.length>0?o:_e(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 Bg(e,t,n,r){let i=O(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 Wg(e,t,n){let r=We(e);if(r&&!Hg(r))return r;let i=(t??"").trim();return i?W(n)&&!i.endsWith("()")?`${i}()`:i:h(n)}function Hg(e){return e.startsWith("undefined")||e.includes("|")||e.includes("```")}function So(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+=ji(d),s+=d.length+1}let u=Kc(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 xo(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+=ji(d),s+=d.length+1}let u=Kc(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 _o(e,t){let n=ke(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(u=>u.relative_path).filter(u=>!e.isIgnored(u)),o=nt(e,s,{onlyDocumented:!0,sort:!0}).map(({relativePath:u,...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+=ji(d),s+=d.length+1}let u=Kc(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(u=>u.relative_path).filter(u=>!e.isIgnored(u)),d=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+=ji(d),s+=d.length+1}let u=Kc(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(u=>u.relative_path).filter(u=>!e.isIgnored(u));return{files:s,symbols:o,dependsOn:l,dependedOnBy:d}}function Io(e,t){let n=ke(e,t);return n.length===0?[]:Jg([...Vg(e,n),...Ug(e,n)]).filter(r=>!e.isIgnored(r.relative_path)).map(qg)}function Vg(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+=ji(d),s+=d.length+1}let u=Kc(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 Ug(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 Jg(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 qg(e){return{consumer:e.relative_path,symbol:e.symbol,shortName:h(e.symbol)}}function In(e,t={}){let{scope:n,minLoc:r=1,includeTests:i=!1,skipBarrels:s=!1,includeMembers:o=!1}=t,a=s?new Set(ao(e)):new Set,l=zg(e,a);Xg(e,l,a);let c=Gg(e,{scope:n,minLoc:r,includeTests:i,includeMembers:o});return ih(e,c,l,{includeTests:i,inactiveBarrelPaths:a}),Yg(e,Kg(c,l))}function zg(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+=ji(d),s+=d.length+1}let u=Kc(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 Gg(e,t){let n=sh(e);return oe(e,{scope:t.scope}).filter(r=>!e.isIgnored(r.relativePath)).filter(r=>!De(r.symbol)).filter(r=>Ro(r.symbol)).filter(r=>r.isFunctionLike||!r.enclosingSymbol||!Ro(r.enclosingSymbol)).filter(r=>t.includeTests||Co(r.relativePath)).filter(r=>t.includeTests||!n(r.relativePath,r.startLine,r.symbol,r.parentTypeName)).filter(r=>!rn(r.symbol)).filter(r=>!Le(r.symbol)).filter(r=>t.includeMembers||ah(r)).filter(r=>r.endLine-r.startLine+1>=t.minLoc)}function Kg(e,t){return e.map(n=>Qg(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 Qg(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 Yg(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 Xg(e,t,n){let r=new C(e),i=new Set(r.sourceFiles());for(let s of Zg(e))i.add(s);r.scanSourceReferences({paths:i,includeVueSfc:!0,includeCrossLanguageDispatchNames:!0,includeRustAttributeNames:!0,identifierResolution:"permissive",skipPath:s=>n.has(s)},s=>{eh(e,s)||nh(t,s.target.symbolId,s.sourceFile,th(s))})}function Zg(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 eh(e,t){return t.kind==="cross-language-dispatch"&&t.target.relativePath===t.sourceFile?!0:t.kind==="identifier"&&rh(e,t)}function th(e){return e.kind==="identifier"&&e.target.relativePath===e.sourceFile?Math.max(0,e.occurrences-1):e.occurrences}function nh(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 rh(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&&!Co(l)||o.set(l,Math.max(1,o.get(l)??0))}}}function sh(e){let t=new Map,n=r=>{let i=t.get(r);if(i)return i;let s=cs(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 ur(s))if(a.containers.has(l))return!0;return!1}}function Co(e){return[...new Set([...lo,...co])].every(n=>!oh(e,n))}function oh(e,t){return new RegExp(`^${t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/%/g,".*").replace(/_/g,".")}$`).test(e)}function Ro(e){return W(e)||e.endsWith("().")||e.endsWith(".")}function ah(e){return U(e.symbol)||ur(e.symbol).length===0}function vo(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+=ji(d),s+=d.length+1}let u=Kc(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:lh(e,r,n)}function lh(e,t,n){return oe(e,{scope:t}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>ch(e,r)).filter(r=>r.refCount>0).sort((r,i)=>i.refCount-r.refCount||i.fileCount-r.fileCount).slice(0,n)}function ch(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 Eo(e,t){return ko(e,t)?.map(n=>({symbol:n.symbol,shortName:n.shortName,fromFile:n.fromFile}))??[]}function Do(e,t){let n=uh(e,t);return n.length>0?n:dh(e,t)}function Lo(e,t){return ko(e,t)?.filter(n=>!n.used).map(n=>({symbol:n.symbol,shortName:n.shortName,importedIn:n.importer}))??[]}function uh(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 dh(e,t){let n=L(e,t),r=n?.relativePath??null,i=n?k(n.symbol):t.replace(/\(\)$/,""),s=n?De(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))mh(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 mh(e,t,n){return!e.sourcePath||n.targetFile&&No(e.sourcePath)!==No(n.targetFile)?!1:e.kind==="side-effect"||n.targetFile&&hh(t)||n.targetIsModule||e.kind==="named"&&e.importedName===n.targetLeaf?!0:e.kind==="namespace"&&e.usedMembers.includes(n.targetLeaf)}function ko(e,t){let n=G(e,t);return n?ph(e,n)??fh(e,n)??gh(e,n):null}function ph(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+=ji(d),s+=d.length+1}let u=Kc(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 fh(e,t){let n=vt(e,t);return n.length>0?n.map(r=>{let i=wo(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 gh(e,t){return J(e,t).map(n=>{let r=wo(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 wo(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 No(e){return e.replace(/\\/g,"/")}function hh(e){return/\.(?:c|h|cc|cpp|cxx|hpp|hh|hxx)$/i.test(e)}function Po(e,t){let n=ke(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 d=null,u=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&&!es(m.symbol,c.symbol))continue;let p=m.endLine-m.startLine;p<u&&(u=p,d=m)}d?d.children.push(c):o.push(c)}return o}function Oo(e,t){let n=L(e,t);return n?new C(e).definitionsForFile(n.relativePath).filter(i=>i.symbol!==n.symbol).filter(i=>Zi(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 Mo(e,t){let n=L(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 Fo(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+=ji(d),s+=d.length+1}let u=Kc(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=Q(e).get(n);return!o||o.size===0?[]:[{name:n,count:o.size}]}function To(e,t={}){return yh(e,t).map(n=>({name:h(n.symbol),count:n.file_count}))}function yh(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+=ji(d),s+=d.length+1}let u=Kc(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 $o(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+=ji(d),s+=d.length+1}let u=Kc(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 Ao(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+=ji(d),s+=d.length+1}let u=Kc(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+=ji(d),s+=d.length+1}let u=Kc(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:Yu(e,s,{minFanIn:i,minFanOut:o,limit:t})}function Yu(e,n,t){let{minFanIn:s,minFanOut:i,limit:o}=t;return Z(e,{scope:n}).filter(r=>!e.isIgnored(r.relativePath)).map(r=>Ku(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 Ku(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 Qu(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 Eo(e,n,t={}){let{scope:s,limit:i=100}=t,o=Qu(n);return o===null?[]:Lo(e,s).map(r=>({row:r,resolvedKind:wo(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 Ro(e,n={}){let t=new Map;for(let s of Lo(e,n.scope)){let i=wo(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 Lo(e,n){return Z(e,{scope:n}).map(Xu)}function Xu(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 wo(e){return e.kind!==null&&e.kind!==0?Zu(e.kind,e.symbol,e.documentation):em(e.symbol,e.documentation,e.enclosing_symbol)}function Zu(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 em(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 Do(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 ko(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 Oo(e,n){let t=k(e,n);if(!t)return null;let s=he(e,t,{limit:50}),i=tm(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 tm(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 $o(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 nm(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 Po(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=nm(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 Mo(e,n,t={}){let{minSimilarity:s=.4,limit:i=20}=t,o=im(e,n);if(!o)return[];if(!j(o.symbol))return[];let a=sm(e,o,s);return a.length>0?a.slice(0,i):om(e,n,{minSimilarity:s,limit:i})}function sm(e,n,t){let s=To(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=Fo(n,a,i,{minSimilarity:t,requireSignificantShared:1,requireSharedCount:0});r&&o.push(r)}return o.sort((a,r)=>r.similarity-a.similarity),o}function Fo(e,n,t,s){let{similarity:i,significantShared:o}=Po(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=To(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=Fo(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 im(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 To(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 om(e,n,t){let s=rm(e,n);if(!s||s.tokens.size<3)return[];let i=t.minSimilarity>=.5?t.minSimilarity:.3,o=[];for(let a of lm(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 rm(e,n){let t=k(e,n);if(!t||!j(t.symbol))return null;let s=am(e,t);return s?{symbol:t.symbol,file:t.relativePath,tokens:s}:null}function am(e,n){let t=F(n.symbol),s=Ao(e,n.relativePath,n.startLine,n.endLine,t),i=jo(s,t);return i.size>0?i:null}function lm(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:jo(Ao(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function Ao(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&&um(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 jo(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=cm(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 cm(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 um(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 Wo(e,n={}){let{minSimilarity:t=.5,limit:s=20,scope:i,filePattern:o}=n,a=n.minDeps??(o?1:3),r=mm(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=Bo(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=Bo(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 mm(e,n){let{scope:t,minDeps:s}=n,i=K(e,t),o=dm(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 dm(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 Bo(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=$o(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 Jo(e,n={}){let{minSimilarity:t=.5,limit:s=15,scope:i,minChainLength:o=3,maxChainLength:a=8}=n,r=K(e,i),l=pm(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}=fm(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=gm(S.original,x.original),bn=hm(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=>Ho(b.chainA,S.chainA)&&Ho(b.chainB,S.chainB))||h.push(b),h.length>=s)break;return h}function pm(e,n,t){let s=[];for(let o of e.keys()){if(s.length>=500)break;Uo(e,o,[o],new Set([o]),n,t,s,500)}return s}function Uo(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),Uo(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 fm(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 gm(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 hm(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 Ho(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 qo(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 ym(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 ym(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 zo(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 Rn(e,t={}){let{scope:n,maxDepth:r=10}=t,i=Q(e,n),s=[],o=new Set,a=new Set,l=[];function c(u,m){if(m>r)return;if(a.has(u)){let p=l.indexOf(u);if(p!==-1){let g=l.slice(p).concat(u),y=g.indexOf(g.reduce((F,T)=>F<T?F:T)),E=[...g.slice(y,-1),...g.slice(0,y),g[y]],N=E.join(" -> ");d.has(N)||(d.add(N),s.push({path:E,kind:bh(E)}))}return}if(o.has(u))return;o.add(u),a.add(u),l.push(u);let f=i.get(u);if(f)for(let p of f)c(p,m+1);l.pop(),a.delete(u)}let d=new Set;for(let u of i.keys())o.has(u)||c(u,0);return s.sort((u,m)=>u.kind!==m.kind?u.kind==="real"?-1:1:u.path.length-m.path.length),s}function bh(e){for(let r of e){let i=Z(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)||Bo(t,n)||Bo(n,t)||Wo(t,n)||Wo(n,t)||Z(t)==="entry"||Z(n)==="entry"?"module-hierarchy":"real"}function Bo(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 Wo(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 Ho(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=>Sh(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 Sh(e,t){let n=new Set(ie(e,t,{limit:500}).map(i=>i.file)).size,r=new Set(X(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 Cn(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 g=k(p.symbol);if(!g)continue;let y=c.get(g)??[];y.push(p.symbolId),c.set(g,y)}let d=e.all(`SELECT relative_path FROM documents WHERE 1 = 1 ${e.pathExclusionsFor("documents")}`);for(let p of d){if(e.isIgnored(p.relative_path)||M(p.relative_path)!=="rust")continue;let g=st(e,p.relative_path);for(let y of g){let E=c.get(y);if(E)for(let N of E)l.add(N)}}let u=new Map(s.map(p=>[p.symbolId,p.symbol])),m=i.calleeMap(s,{additive:!0}),f=new Set([...m.entries()].filter(([p,g])=>{let y=u.get(p);return g.some(E=>E.symbol!==y)}).map(([p])=>p));return s.filter(p=>!l.has(p.symbolId)).filter(p=>!f.has(p.symbolId)).sort((p,g)=>g.endLine-g.startLine-(p.endLine-p.startLine)||p.relativePath.localeCompare(g.relativePath)||p.startLine-g.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 xh(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 Vo(e,t,n={}){let{scope:r,limit:i=100}=n,s=xh(t);return s===null?[]:Jo(e,r).map(a=>({row:a,resolvedKind:qo(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 Uo(e,t={}){let n=new Map;for(let r of Jo(e,t.scope)){let i=qo(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 Jo(e,t){return oe(e,{scope:t}).map(_h)}function _h(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 qo(e){return e.kind!==null&&e.kind!==0?Ih(e.kind,e.symbol,e.documentation):Rh(e.symbol,e.documentation,e.enclosing_symbol)}function Ih(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 Rh(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=Q(e,r),o=new Map,a=[],l=new Map,c=new Map,d=new Set,u=[],m=0;for(let R of s.keys()){if(l.has(R))continue;let _=[],P=(s.get(R)??new Set).values();for(l.set(R,m),c.set(R,m),m+=1,u.push(R),d.add(R),_.push({node:R,iter:P,pendingChild:null});_.length>0;){let D=_[_.length-1];if(D.pendingChild!==null){let Ke=D.pendingChild;D.pendingChild=null,c.set(D.node,Math.min(c.get(D.node),c.get(Ke)))}let z=D.iter.next();if(z.done){if(c.get(D.node)===l.get(D.node)){let Ke=[];for(;;){let $t=u.pop();if(d.delete($t),Ke.push($t),o.set($t,a.length),$t===D.node)break}a.push(Ke)}_.pop();continue}let de=z.value;if(l.has(de))d.has(de)&&c.set(D.node,Math.min(c.get(D.node),l.get(de)));else{l.set(de,m),c.set(de,m),m+=1,u.push(de),d.add(de);let Ke=(s.get(de)??new Set).values();D.pendingChild=de,_.push({node:de,iter:Ke,pendingChild:null})}}}let f=new Map,p=new Array(a.length);for(let R=0;R<a.length;R++)p[R]=a[R].length,f.set(R,new Set);for(let[R,_]of s){let P=o.get(R);for(let D of _){let z=o.get(D);z!==P&&f.get(P).add(z)}}let g=new Array(a.length),y=new Array(a.length);for(let R=0;R<a.length;R++){let _=[],P=0;for(let D of f.get(R)){let z=y[D];z>P&&(P=z,_=g[D])}g[R]=[R,..._],y[R]=p[R]+P}function E(R){return g[R]}let N=a.map(R=>[...R].sort()),F=new Set,T=[];for(let R=0;R<a.length;R++){let _=E(R),P=[];for(let z of _)P.push(...N[z]);if(P.length<i)continue;let D=P.join(" ");F.has(D)||(F.add(D),T.push({chain:P,depth:P.length}))}return T.sort((R,_)=>_.depth-R.depth),T.slice(0,n)}function Go(e,t){let n=L(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 u=e.get("SELECT symbol, enclosing_symbol FROM global_symbols WHERE symbol = ?",s);if(!u)break;i.push({symbol:u.symbol,shortName:h(u.symbol),depth:o}),s=u.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 d=[i[0]];for(let u=c.length-2,m=1;u>=0;u--,m++){let p=c.slice(0,u+1).map(g=>g.suffix==="method"?`${g.name}()`:g.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(":");d.push({symbol:p,shortName:p,depth:m})}return d}function Ko(e,t){let n=L(e,t);if(!n)return null;let r=ie(e,n,{limit:50}),i=Ch(X(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 Ch(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 Qo(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 Yo(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 f of a){let p=n.get(f)??0,g=e.has(f)?p:0,y=t.has(f)?p:0;i+=g*y,s+=g*g,o+=y*y}let l=Math.sqrt(s)*Math.sqrt(o),c=l>0?i/l:0,d=vh(n),u=[],m=[];for(let f of r)(n.get(f)??0)>=d?u.push(f):m.push(f);return u.sort((f,p)=>(n.get(p)??0)-(n.get(f)??0)),{similarity:c,significantShared:u,trivialShared:m}}function Xo(e,t,n={}){let{minSimilarity:r=.4,limit:i=20}=n,s=Dh(e,t);if(!s)return[];if(!W(s.symbol))return[];let o=Nh(e,s,r);return o.length>0?o.slice(0,i):kh(e,t,{minSimilarity:r,limit:i})}function Nh(e,t,n){let r=ea(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=Zo(t,o,i,{minSimilarity:n,requireSignificantShared:1,requireSharedCount:0});a&&s.push(a)}return s.sort((o,a)=>a.similarity-o.similarity),s}function Zo(e,t,n,r){let{similarity:i,significantShared:s}=Yo(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 vn(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,minCallees:s=4,crossFileOnly:o=!1}=t,a=ea(e,{minCallees:s,scope:i}),l=Pr(a.map(p=>p.callees)),c=new Map;for(let p of a)for(let g of p.callees)c.set(g,(c.get(g)??0)+1);let d=Math.max(8,Math.ceil(Math.sqrt(a.length))),u=new Map;for(let p=0;p<a.length;p+=1)for(let g of a[p].callees){if((c.get(g)??0)>d)continue;let y=u.get(g);y||(y=[],u.set(g,y)),y.push(p)}let m=[],f=new Set;e:for(let p=0;p<a.length;p+=1){let g=a[p],y=new Set;for(let E of g.callees){let N=u.get(E);if(N)for(let F of N)F>p&&y.add(F)}for(let E of y){let N=`${p}|${E}`;if(f.has(N))continue;f.add(N);let F=a[E];if(o&&g.file===F.file)continue;if(g.paramCount>=0&&F.paramCount>=0){let R=Math.abs(g.paramCount-F.paramCount),_=Math.max(2,Math.ceil(Math.max(g.paramCount,F.paramCount)*.5));if(R>_)continue}let T=Zo(g,F,l,{minSimilarity:n,requireSignificantShared:2,requireSharedCount:4});if(T&&(m.push(T),m.length>r*5))break e}}return m.sort((p,g)=>g.similarity-p.similarity),m.slice(0,r)}var Eh=["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 Dh(e,t){let n=L(e,t),r=new C(e);if(!n)return null;let i=X(e,n);return{symbol:n.symbol,file:n.relativePath,callees:ta(i.map(s=>s.symbol)),paramCount:r.callableSignature(n)?.paramCount??-1}}function ea(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:ta((a.get(l.symbolId)??[]).map(c=>c.symbol)),paramCount:s.callableSignature(l)?.paramCount??-1})).filter(l=>l.callees.size>=n)}function ta(e){return new Set([...e].filter(t=>!Lh(t)))}function Lh(e){return Eh.some(t=>e.includes(t))}function kh(e,t,n){let r=wh(e,t);if(!r||r.tokens.size<3)return[];let i=n.minSimilarity>=.5?n.minSimilarity:.3,s=[];for(let o of Oh(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 wh(e,t){let n=L(e,t);if(!n||!W(n.symbol))return null;let r=Ph(e,n);return r?{symbol:n.symbol,file:n.relativePath,tokens:r}:null}function Ph(e,t){let n=k(t.symbol),r=na(e,t.relativePath,t.startLine,t.endLine,n),i=ra(r,n);return i.size>0?i:null}function Oh(e){let t=new C(e);return t.scopedDefinitions().filter(n=>n.isFunctionLike).filter(n=>t.fileKind(n.relativePath)!=="test").filter(n=>!Le(n.symbol)).map(n=>({symbol:n.symbol,file:n.relativePath,tokens:ra(na(e,n.relativePath,n.startLine,n.endLine,n.leaf),n.leaf)})).filter(n=>n.tokens.size>0)}function na(e,t,n,r,i){let s=O(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(d=>d.test(c)));if(l>=0){let c=l;for(let d=l+1;d<o.length&&d<=l+8;d++){let u=o[d]??"";if(d>l&&Fh(u)||(c=d,u.trim()===""&&d>l+1))break}return o.slice(l,c+1).join(`
|
|
810
|
+
`)}return o.slice(n,Math.min(o.length,n+8)).join(`
|
|
811
|
+
`)}function ra(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=Mh(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 Mh(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 Fh(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 sa(e,t={}){let{minSimilarity:n=.5,limit:r=20,scope:i,filePattern:s}=t,o=t.minDeps??(s?1:3),a=Th(e,{scope:i,minDeps:o}),l=[];if(s){let c=a.find(d=>d.file.includes(s));if(!c)return[];for(let d of a){if(d.file===c.file)continue;let u=ia(c,d,n);u&&l.push(u)}}else for(let c=0;c<a.length;c++){for(let d=c+1;d<a.length;d++){let u=ia(a[c],a[d],n);u&&l.push(u)}if(l.length>r*5)break}return l.sort((c,d)=>d.similarity-c.similarity),l.slice(0,r)}function Th(e,t){let{scope:n,minDeps:r}=t,i=Q(e,n),s=$h(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 $h(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 ia(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=Qo(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 aa(e,t={}){let{minSimilarity:n=.5,limit:r=15,scope:i,minChainLength:s=3,maxChainLength:o=8}=t,a=Q(e,i),l=Jh(a,s,o);if(l.length===0)return[];let c=Ah(l);return c.length<2?[]:Uh(Wh(c,n,r),r)}function Ah(e){let t=jh(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 jh(e){let{nodeFreq:t,tailFreq:n}=Bh(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 Bh(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 Wh(e,t,n){let r=[];for(let i=0;i<e.length;i++){for(let s=i+1;s<e.length;s++){let o=Hh(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 Hh(e,t,n){if(!Vh(e.filtered,t.filtered))return null;let{distance:r,ops:i}=qh(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:zh(e.original,t.original),commonSuffix:Gh(e.original,t.original)}}function Vh(e,t){let n=new Set(e);return t.some(r=>n.has(r))}function Uh(e,t){let n=[];for(let r of e)if(n.some(s=>oa(r.chainA,s.chainA)&&oa(r.chainB,s.chainB))||n.push(r),n.length>=t)break;return n}function Jh(e,t,n){let r=[];for(let s of e.keys()){if(r.length>=500)break;la(e,s,[s],new Set([s]),t,n,r,500)}return r}function la(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 d of l)if(!r.has(d)&&(r.add(d),n.push(d),la(e,d,n,r,i,s,o,a),n.pop(),r.delete(d),c=!0,o.length>=a))return;!c&&n.length>=i&&o.push([...n])}function qh(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 zh(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 Gh(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 oa(e,t){if(e.length>t.length)return!1;let n=t.join("\u2192"),r=e.join("\u2192");return n.includes(r)}function Nn(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 d of a){let u=Kh(d,l.get(d.symbolId)??[],i);u&&c.push(u)}return c.sort((d,u)=>u.clusters.length-d.clusters.length||u.loc-d.loc),c.slice(0,s)}function Kh(e,t,n){let r=new Set(t.map(a=>a.symbol));if(r.size<n)return null;let i=Qh(r,t),s=Yh(r,i);if(s.length<2)return null;let o=Xh(s,i);return o.length===0?null:{symbol:e.symbol,shortName:h(e.symbol),relativePath:e.relativePath,startLine:e.startLine,endLine:e.endLine,loc:ey(e),totalCallees:r.size,clusters:o}}function Qh(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 Yh(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 Xh(e,t){return e.filter(n=>n.size>=3).map(n=>Zh(n,e,t)).filter(n=>n.isolation>.5).sort((n,r)=>r.isolation-n.isolation)}function Zh(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 ey(e){return e.endLine-e.startLine+1}function ca(e,t,n={}){let{maxDepth:r=5,scope:i}=n,s=L(e,t);if(!s)return[];let o=[],a=new Set([s.symbolId]),l=new Set,c=[s];for(let d=1;d<=r&&c.length!==0;d++){let u=[];for(let m of c)for(let f of ty(e,m,i)){let p=`${f.file}|${f.shortName}`;if(f.symbolId!==null){if(a.has(f.symbolId))continue;a.add(f.symbolId)}else if(l.has(p))continue;l.add(p),o.push({symbol:f.symbol,shortName:f.shortName,file:f.file,depth:d}),f.symbolId!==null&&f.symbolMatch&&u.push(f.symbolMatch)}c=u}return o.sort((d,u)=>d.depth-u.depth||d.file.localeCompare(u.file)),o}function ty(e,t,n){let r=new C(e),i=ie(e,t,{limit:500}).filter(u=>!e.isIgnored(u.file)).filter(u=>!n||u.file.includes(n)),s=new Set(i.map(u=>u.file)),o=r.crossFileCallerMap().get(t.symbolId)??new Set,a=[];for(let u of o){if(s.has(u)||e.isIgnored(u)||n&&!u.includes(n))continue;let m=r.definitionsForFile(u),f=m.length>0?ae(m,m[0].startLine):null;a.push({symbol:f?.symbol??u,file:u})}let l=[...i,...a],c=[],d=new Set;for(let u of l){let m=it(e,u.symbol);if(!m){let p=`${u.file}|${u.symbol}`;if(d.has(p))continue;d.add(p),c.push({symbolId:null,symbol:u.symbol,shortName:h(u.symbol),file:u.file,symbolMatch:null});continue}if(m.symbolId===t.symbolId||e.isIgnored(m.relativePath)||!ny(m.symbol))continue;let f=`${m.symbolId}|${m.relativePath}`;d.has(f)||(d.add(f),c.push({symbolId:m.symbolId,symbol:m.symbol,shortName:h(m.symbol),file:m.relativePath,symbolMatch:m}))}return c}function ny(e){let t=V(e);return t==="method"||t==="type"||e.endsWith("().")}function ua(e,t){let n=G(e,t);if(!n)return null;let r=ry(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=sy(e,r,o);s+=a,i.push({symbol:o.symbol,shortName:h(o.symbol),startLine:o.startLine,endLine:o.endLine,externalConsumers:a,riskLevel:oy(a)})}return{file:r.relative_path,symbols:i,totalExternalConsumers:s}}function ry(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 Vo(e,n={}){let{base:t="HEAD"}=n,s;try{s=bm(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 bm(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=Sm(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(xm(u)||Im(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=_m(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 Sm(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 sy(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=dt(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 oy(e){return e>10?"high":e>0?"medium":"low"}import{execFileSync as Or}from"child_process";function pa(e,t={}){let{base:n="HEAD"}=t,r;try{r=ay(e.config.projectRoot,n)}catch{return da("Unable to compute git diff.")}if(r.length===0)return da("No changed files found.");let i=ly(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=cy(s,i),l=[],c=new Map;for(let u of a)uy(e,u,i,o,l,c);let d=py(c);return{changedFiles:i,changedSymbols:l,affectedConsumers:d,summary:{totalChangedFiles:i.length,totalChangedSymbols:l.length,totalAffectedFiles:d.length}}}function da(e){return{changedFiles:[],changedSymbols:[],affectedConsumers:[],summary:{totalChangedFiles:0,totalChangedSymbols:0,totalAffectedFiles:0,note:e}}}function ay(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 ly(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 cy(e,t){return t.flatMap(n=>e.definitionsForFile(n)).filter(fy).sort((n,r)=>n.relativePath.localeCompare(r.relativePath)||n.startLine-r.startLine)}function uy(e,t,n,r,i,s){let o=dt(e,[t]).get(t.symbolId)??new Set,a=Math.max(dy(e,t.symbolId),o.size);if(!gy(t,a))return;let l=h(t.symbol);i.push({symbol:t.symbol,shortName:l,file:t.relativePath,fanIn:a});for(let c of my(e,t.symbolId,n))ma(e,r,s,c,l);for(let c of o)ma(e,r,s,c,l)}function dy(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 my(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 ma(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 py(e){return[...e.entries()].map(([t,n])=>({file:t,consumedSymbols:n.size})).sort((t,n)=>n.consumedSymbols-t.consumedSymbols)}function fy(e){return!(De(e.symbol)||e.parentTypeName!==null&&!U(e.symbol))}function gy(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=En(e),r=En(t);return n&&r?hy(n,r)?"ok":"violation":yy(e,t)}function fa(e,t){let n=En(Ge(e)),r=En(Ge(t));return!!n&&!!r}function En(e){return/^src\/([^/]+)$/.exec(e)?.[1]??null}function hy(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 yy(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 Dn(e,t){let{scope:n,minDeviation:r=5}=t??{},s=new C(e).fileDependencyGraph(n),o=Cy(e,n);return _y([...by(e,s,o),...Sy(s),...xy(s,r)])}function by(e,t,n){let r=[];for(let[i,s]of t){if(Ie(i))continue;let o=n.get(i)??new Set;for(let a of s)if(!Ie(a)&&!o.has(a)){if(ky(e,i,a)||wy(e,i,a)||Py(e,i,a)||Ly(a)||My(e,i,a)||Oy(a))continue;r.push({file:i,kind:"unused-import",description:`Depends on ${a} but references none of its symbols`,dep:a})}}return r}function Sy(e){let t=[],n=Dy(e);for(let[r,i]of e){if(Ie(r))continue;let s=Ge(r);for(let o of i){if(Ie(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 xy(e,t){let n=[];for(let[r,i]of Iy(e)){let s=i.filter(a=>!Ie(a));if(s.length<t)continue;let o=Ry(e,s);for(let a of s)for(let l of e.get(a)??[])Ie(l)||(o.get(l)??0)===1&&Mt.dirname(l)!==r&&Mt.dirname(l)!==Mt.dirname(r)&&(fa(a,l)||n.push({file:a,kind:"pattern-deviation",description:`Only file in ${r}/ that depends on ${l}`,dep:l}))}return n}function _y(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 Iy(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 Ry(e,t){let n=new Map;for(let r of t)for(let i of e.get(r)??[])Ie(i)||n.set(i,(n.get(i)??0)+1);return n}function Cy(e,t){let n=new Map;return vy(e,n,t),Ey(e,n),n}function vy(e,t,n){for(let r of Ny(e,n))ga(e,t,r.from_file,r.to_file)}function Ny(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 Ey(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)||ga(e,t,i.sourceFile,i.target.relativePath))})}function ga(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 Dy(e){let t=new Map;for(let[r,i]of e){if(Ie(r))continue;let s=Ge(r);for(let o of i){if(Ie(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 Ly(e){return e.includes("types")||e.endsWith(".d.ts")}function ky(e,t,n){let r=vt(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.isUsed)}function wy(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.some(i=>i.used)}function Py(e,t,n){let r=J(e,t).filter(i=>i.sourcePath===n);return r.length>0&&r.every(i=>i.isTypeOnly===!0)}function Oy(e){return e.endsWith(".vue")}function My(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 Ie(e){let t=Z(e);return!!(t==="entry"||t==="barrel"||t==="test"||t==="worker"||Fy(Mt.basename(e)))}function Fy(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 Ln}from"path";function kn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=Jy(s.fileDependencyGraph(n)),a=Ay(s,n,r),l=Uy(s.crossFileCallerMap(a),s.sourceFallbackCallerFiles(a)),c=[];for(let d of a){let u=Ty(e,s,d,{callerFileMap:l,reverseFanIn:o});u&&c.push(u)}return c.sort((d,u)=>u.callerFanIn-d.callerFanIn||u.loc-d.loc),c.slice(0,i)}function Ty(e,t,n,r){let i=jy(t,n,r.callerFileMap);if(i.length!==1)return null;let s=i[0],o=By(e,n.symbolId,s);if(!o)return null;let a=Wy(t,e,s,n.symbol,o);if(a&&Le(a.symbol))return null;let l=Hy(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:$y(n),singleCaller:a?.symbol??"",singleCallerShort:a?.isFunctionLike?h(a.symbol):Ft(s),callerFanIn:l}}function $y(e){return e.endLine-e.startLine+1}function Ay(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:2,maxLoc:n,requireFunctionLikeSymbol:!0})}function jy(e,t,n){let r=Ft(t.relativePath,Ln(t.relativePath));return[...n.get(t.symbolId)??[]].filter(i=>i!==t.relativePath).filter(i=>Ft(i,Ln(i))!==r).filter(i=>{let s=e.fileKind(i);return s!=="barrel"&&s!=="entry"&&s!=="test"})}function By(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 Wy(e,t,n,r,i){let s=e.definitionsForFile(n),o=Vy(t,n,r,i.start_line,i.end_line);return ae(s,o)}function Hy(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 qy(t,n)}function Vy(e,t,n,r,i){let s=k(n);if(!s)return r;let o=Je(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 Uy(...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 Jy(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 qy(e,t){let n=e.get(t)??0;if(n>0)return n;let r=Ft(t,Ln(t)),i=0;for(let[s,o]of e)s!==t&&Ft(s,Ln(s))===r&&o>i&&(i=o);return i}function ya(e,t,n,r){let i=M(t);if(!i)return!0;let s=w(e,t);if(!s)return!0;let o=ha.get(s);return o||(o=zy(s,i),ha.set(s,o)),o.get(`${n}:${r}`)??!0}var ha=new WeakMap;function zy(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}`,Gy(s,t));for(let o of s.children)i(o)};return i(e.rootNode),r}function Gy(e,t){let n=e.namedChildren.find(u=>u.type==="block"||u.type==="statement_block");if(!n)return!1;let r=n.namedChildren.filter(u=>u.type!=="comment"&&u.type!=="line_comment"&&u.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(u=>u.type==="arguments"||u.type==="argument_list");if(!a)return!1;let l=a.namedChildren.filter(u=>u.type!=="comment"),c=e.namedChildren.find(u=>u.type==="parameters"||u.type==="formal_parameters");if(!c)return!1;let d=[];for(let u of c.namedChildren)if(u.type==="identifier")d.push(u.text);else{let m=u.namedChildren.find(f=>f.type==="identifier");m&&d.push(m.text)}if(l.length!==d.length)return!1;for(let u=0;u<d.length;u+=1){let m=l[u];if(m.type!=="identifier"||m.text!==d[u])return!1}return!0}function wn(e,t){let{scope:n,maxLoc:r=15,limit:i=30}=t??{},s=new C(e),o=Yy(s,n,r),a=s.calleeMap(o),l=[];for(let c of o){let d=Ky(e,c,a.get(c.symbolId)??[]);d&&l.push(d)}return l.sort((c,d)=>c.loc-d.loc||c.file.localeCompare(d.file)),l.slice(0,i)}function Ky(e,t,n){let r=Qy(n);if(r.size!==1||!ya(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:Xy(t),forwardsTo:i.symbol,forwardsToShort:h(i.symbol),forwardsToFile:i.file}}function Qy(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 Yy(e,t,n){return e.productionCallableDefinitions({scope:t,minLoc:3,maxLoc:n,requireFunctionLikeSymbol:!0,excludeRustTraitImplMembers:!0})}function Xy(e){return e.endLine-e.startLine+1}function Pn(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=ub(a,n),d=Zy(e,a,l,{minLoc:r,maxLoc:i}),u=eb(a,d),m=ib(e,a,l,d),f=tb(d);return nb(e,d,u,f).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=>mb(y.definition,y.realConsumers.length,c)).map(y=>rb(e,y)).filter(y=>o||y.confidence!=="low").sort((y,E)=>{let N={high:0,medium:1,low:2};return N[y.confidence]-N[E.confidence]||E.loc-y.loc||y.file.localeCompare(E.file)||y.startLine-E.startLine}).slice(0,s)}function Zy(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=>!db(i.symbol)).filter(i=>!t.hasSuppressionComment(i))}function eb(e,t){return Ia(e.crossFileCallerMap(t),e.sourceFallbackCallerFiles(t))}function tb(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=k(n.symbol);i&&r.set(i,n)}return t}function nb(e,t,n,r){return t.map(i=>{let o=[...n.get(i.symbolId)??new Set].filter(d=>d!==i.relativePath&&!e.isIgnored(d)),{realConsumers:a,barrelConsumers:l}=pb(e,i.relativePath,i.symbol,o),c=fb(e,i,n,r);return{definition:i,realConsumers:a,barrelConsumers:l,transitivelyReachable:c}})}function rb(e,t){let n=_a(e,t.definition.relativePath,t.definition.startLine),r=Sa(t.definition.relativePath)?!0:bb(e,t.definition),{confidence:i,reason:s}=Sb(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=ob(e,sb(n),r),s=i.map(l=>l.singleton);if(i.length===0)return new Set;let o=Ia(t.crossFileCallerMap(s),t.sourceFallbackCallerFiles(s)),a=new Set;for(let{singleton:l,classId:c}of i)lb(e,l,o)&&a.add(c);return a}function sb(e){let t=new Map;for(let n of e){let r=k(n.symbol);r&&t.set(ba(n.relativePath,r),n)}return t}function ob(e,t,n){let r=[];for(let i of n){let s=ab(e,t,i);s&&r.push({singleton:s,classId:i.symbolId})}return r}function ab(e,t,n){if(_a(e,n.relativePath,n.startLine)!=="class")return null;let r=k(n.symbol);if(!r)return null;let i=cb(e,n.relativePath,r);return i?t.get(ba(n.relativePath,i))??null:null}function lb(e,t,n){let r=k(t.symbol),i=n.get(t.symbolId);return!r||!i?!1:[...i].some(s=>s!==t.relativePath&&!e.isIgnored(s)&&!xa(e,s,r))}function ba(e,t){return`${e}\0${t}`}function cb(e,t,n){let r=O(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 ub(e,t){return new Set(e.scopedDefinitions(t).filter(n=>n.isFunctionLike).map(n=>n.relativePath))}function db(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 Sa(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 mb(e,t,n){return!(Sa(e.relativePath)&&t>0||t===0&&n.has(e.relativePath))}function pb(e,t,n,r){let i=[],s=0,o=k(n);for(let a of r)yb(e,a,t,o)||xa(e,a,o)?s++:i.push(a);return{realConsumers:i,barrelConsumers:s}}function fb(e,t,n,r){let i=Ki(e,t.relativePath),s=k(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 d=n.get(c.symbolId);if(d){for(let u of d)if(u!==t.relativePath&&!e.isIgnored(u))return!0}}return!1}var gb=$("stale-abs-file-usage");function xa(e,t,n){if(!n)return!1;let r=M(t);if(!r)return!1;let i=gb.get(e,t,()=>hb(e,t,r));return i.importedLeaves.has(n)&&!i.usedLeaves.has(n)}function hb(e,t,n){let r=new Set,i=new Set,s=w(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 d=c||o.has(l.type);(l.type==="identifier"||l.type==="type_identifier"||l.type==="property_identifier"||l.type==="field_identifier")&&(d?r.add(l.text):i.add(l.text));for(let u of l.children)a(u,d)};return a(s.rootNode,!1),{importedLeaves:r,usedLeaves:i}}function yb(e,t,n,r){if(!r)return!1;let i=O(e,t);if(!i)return!1;let s=Us(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 d=0;d<l.length;d++){if(!a.test(l[d]??""))continue;if(c++,!s.find(m=>m.startLine<=d&&d<=m.endLine))return!1}return c>0}function _a(e,t,n){let r=O(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 bb(e,t){let n=O(e,t.relativePath);if(!n)return!1;let r=k(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 Sb(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 Ia(...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 On(e,t){let{scope:n,minLoc:r=10,limit:i=30}=t??{},{definitions:s,callerMap:o,calleeMap:a}=xb(e,n);return s.map(l=>{let c=l.endLine-l.startLine+1,d=o.get(l.symbolId)?.size??0,u=a.get(l.symbolId)??[],m=u.filter(g=>g.file!==l.relativePath),f=new Set(m.map(g=>`${g.symbol}|${g.file}`)).size,p=new Set(u.map(g=>`${g.symbol}|${g.file}`)).size;return{symbol:l.symbol,shortName:h(l.symbol),file:l.relativePath,startLine:l.startLine,endLine:l.endLine,loc:c,fanIn:d,fanOut:f,calleeCount:p,score:Math.round(c/50*(d/5)*Math.max(f/5,1)*100)/100}}).filter(l=>l.loc>=r).sort((l,c)=>c.score-l.score||c.loc-l.loc).slice(0,i)}function xb(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 _b=50;function Ra(e,t={}){let n=Ib(e,t.scope),r=Rb(e,n),i=Cb(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:Ca(n)},actions:i,topComplexity:n.complexResult.slice(0,5).map(o=>({symbol:o.shortName,score:o.score}))}}function Ib(e,t){return{statsResult:Zt(e),deadResult:In(e,{scope:t,minLoc:3,skipBarrels:!0}),isolatedResult:Cn(e,{scope:t,minLoc:3}),cycleResult:Rn(e,{scope:t}),similarResult:vn(e,{scope:t,minSimilarity:.6,limit:50,minCallees:4}),extractResult:Nn(e,{scope:t,minLoc:15,minCallees:5,limit:50}),wrapperResult:kn(e,{scope:t,maxLoc:15,limit:50}),passthroughResult:wn(e,{scope:t,maxLoc:15,limit:50}),staleResult:Pn(e,{scope:t,minLoc:3,limit:50}),driftResult:Dn(e,{scope:t}),complexResult:On(e,{scope:t,minLoc:10,limit:10})}}function Rb(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 Cb(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 d=t.trueDriftCount/n;i-=Math.min(5,Math.round(d*50));let u=Ca(e);return i-=Math.min(5,u*2),Math.max(0,Math.min(100,i))}function Ca(e){return e.complexResult.filter(t=>t.score>_b).length}function va(e,t,n){let r=L(e,t),i=L(e,n);if(!r||!i)return null;let s=new Set(X(e,r).map(g=>g.symbol)),o=new Set(X(e,i).map(g=>g.symbol)),a=[];for(let g of s)o.has(g)&&a.push(g);let l=[];for(let g of s)o.has(g)||l.push(g);let c=[];for(let g of o)s.has(g)||c.push(g);let d=new Set([...s,...o]),u=d.size>0?a.length/d.size:0,m;d.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 f=r.endLine-r.startLine+1,p=i.endLine-i.startLine+1;return{symbolA:{symbol:r.symbol,shortName:h(r.symbol),file:r.relativePath,loc:f},symbolB:{symbol:i.symbol,shortName:h(i.symbol),file:i.relativePath,loc:p},similarity:u,sharedCallees:a.map(h),uniqueToA:l.map(h),uniqueToB:c.map(h),consolidationStrategy:m}}import{readFileSync as Na}from"fs";import{extname as Nb,join as Ea}from"path";function Da(e,t,n={}){let{context:r=0}=n,i=Eb(t);if(i)return Lb(e,i.filePath,i.startLine,i.endLine,r);let s=L(e,t);return s?Db(e,s,r):null}function Eb(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 Db(e,t,n){let r=e.get("SELECT language FROM documents WHERE relative_path = ?",t.relativePath),i=Ea(e.config.projectRoot,t.relativePath),s;try{s=Na(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??La(t.relativePath),source:c}}function Lb(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=Ea(e.config.projectRoot,o.relative_path),l;try{l=Na(a,"utf-8")}catch{return null}let c=l.split(`
|
|
862
|
+
`),d=Math.max(0,n-1-i),u=Math.min(c.length-1,r-1+i),m=c.slice(d,u+1).join(`
|
|
863
|
+
`);return{symbol:`${o.relative_path}:${n}-${r}`,shortName:`${o.relative_path}:${n}-${r}`,relativePath:o.relative_path,startLine:d,endLine:u,language:o.language??La(o.relative_path),source:m}}function La(e){switch(Nb(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 kb}from"fs";import{join as wb}from"path";function ka(e,t){let n=L(e,t);if(!n)return null;let r=new C(e),i=Tb(Ob(e,n.relativePath,n.startLine,n.endLine),Pb(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:Mb(e,n.symbolId),fanOut:Fb(a,n.relativePath)}}function Pb(e,t){return e.get("SELECT language FROM documents WHERE relative_path = ?",t)?.language??"unknown"}function Ob(e,t,n,r){try{return kb(wb(e.config.projectRoot,t),"utf-8").split(`
|
|
864
|
+
`).slice(n,r+1).join(`
|
|
865
|
+
`)}catch{return""}}function Mb(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 Fb(e,t){return new Set(e.filter(n=>n.file!==t).map(n=>n.symbol)).size}function Tb(e,t){let n=$b(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 $b(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*/g,"").replace(/#.*/g,"").replace(/"(?:[^"\\]|\\.)*"/g,'""').replace(/'(?:[^'\\]|\\.)*'/g,"''").replace(/`(?:[^`\\]|\\.)*`/g,"``")}function wa(e,t){let n=L(e,t);if(!n)return null;let r=[{file:n.relativePath,line:n.startLine}],i=Fe(e,n),o=(i.length>0?i:_e(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}=Ab(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 Ab(e,t,n){let r=Tr(X(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 Pa(e,t,n={}){let{direction:r="backward",maxDepth:i=3}=n,s=L(e,t);return s?r==="backward"?jb(e,s,i):Bb(e,s):null}function jb(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=X(e,l);for(let d of c){if(i.has(d.symbol))continue;i.add(d.symbol),r.push({symbol:d.symbol,shortName:h(d.symbol),file:d.file,relationship:o===1?"referenced within definition (callee)":`depth ${o} callee`});let u=it(e,d.symbol);u&&!e.isIgnored(u.relativePath)&&a.push(u)}}s=a}return{symbol:t.symbol,shortName:h(t.symbol),direction:"backward",connectedSymbols:r}}function Bb(e,t){let n=Fe(e,t),r=n.length>0?n:_e(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 Oa(e,t={}){let{scope:n,limit:r}=t,i=new C(e),s=Kb([...Wb(e,n),...Ub(e,i,n)]);return Qb(s),r?s.slice(0,r):s}function Wb(e,t){let n=[];for(let r of Hb(e,t)){if(e.isIgnored(r.barrel_path)||e.isIgnored(r.original_path)||Lr(e,r.barrel_path))continue;let i=Vb(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 Hb(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+=ji(d),s+=d.length+1}let u=Kc(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 Vb(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 Ub(e,t,n){let r=[];for(let i of Jb(e,n))Ma(e,i,i)>0||r.push(...qb(e,t,i));return r}function Jb(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=>Cr(e,r).length>0)}function qb(e,t,n){return Cr(e,n).filter(r=>r.sourcePath&&!e.isIgnored(r.sourcePath)).flatMap(r=>zb(e,t,n,r.sourcePath))}function zb(e,t,n,r){let i=Gb(t,r);return i?[{barrelFile:n,symbol:i.symbol,shortName:h(i.symbol),originalFile:r,barrelConsumers:0,directConsumers:Ma(e,r,n)}]:[]}function Ma(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 Gb(e,t){let n=e.definitionsForFile(t);return n.find(r=>V(r.symbol)==="method")??n[0]??null}function Kb(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 Qb(e){e.sort((t,n)=>n.directConsumers-t.directConsumers||t.barrelFile.localeCompare(n.barrelFile)||t.shortName.localeCompare(n.shortName))}function Fa(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=Yb(e,a);if(!c)continue;let d={symbol:a.symbol,shortName:h(a.symbol),file:a.relativePath,startLine:a.startLine,endLine:a.endLine,loc:l},u=s.get(c);u?u.push(d):s.set(c,[d])}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 d=a.functions.reduce((m,f)=>m+f.loc,0);return l.functions.reduce((m,f)=>m+f.loc,0)-d}),i?o.slice(0,i):o}function Yb(e,t){let n=eo(e,t);if(n)return n;let r=Xb(t.documentation),i=r?tS(r):null;return i||nS(Zb(e,t.relativePath,t.startLine,t.endLine,t.leaf),t.leaf)}function Xb(e){return We(He(e))}function Zb(e,t,n,r,i){let s=O(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)),d="";for(let u=l;u<=c;u+=1){let m=o[u]?.trim();if(m&&(d=d?`${d} ${m}`:m,eS(d)))return d}if(d&&d.includes("("))return d}return null}function eS(e){let t=e.replace(/\s+/g," ").trim();return!t.includes("(")||sS(t)>0?!1:/[;{]$/.test(t)||/\)\s*(?::\s*[^={]+)?\s*(?:=>|=|throws\b|where\b|$)/i.test(t)||/\)\s*As\s+.+$/i.test(t)}function tS(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 nS(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${Ta(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=rS(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 rS(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=Ta(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)),d=Math.max(c,Math.min(e.length-1,Math.max(n,t+4)));for(let u=c;u<=d;u+=1){let m=e[u]??"";(s.test(m)||o.test(m))&&!l.has(u)&&(l.add(u),a.push(u))}for(let u=0;u<e.length;u+=1){let m=e[u]??"";(s.test(m)||o.test(m))&&!l.has(u)&&(l.add(u),a.push(u))}return a}function sS(e){let t=0;for(let n of e)n==="("&&(t+=1),n===")"&&(t-=1);return t}function Ta(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Re(){return process.env.SCIP_QUERY_PROJECT_ROOT??process.cwd()}function Tt(e){let t=Ce(e),n=ve(e,t);return process.env.SCIP_QUERY_INDEX_DB??($a(n.dbPath)?n.dbPath:oS(e,"index.db"))}function aS(){let e=Re(),t=Ce(e),n=ve(e,t),r=Tt(e);$a(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=Qe(e);return new Xt(i,s)}function I(e){let t=aS();try{e(t)}finally{t.close()}}function Aa(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 Mn(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":""}`}}var uS=lS(import.meta.url),{version:dS}=mS();function mS(){for(let e of["../package.json","../../package.json"])try{return uS(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(dS);S.command("reindex").description("Index the codebase and convert to SQLite").option("-l, --language <lang>","Index only this language (can be repeated)",Aa,[]).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=Re(),n=Ce(t),r=ve(t,n);try{let i=await Li({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=Re(),t=Tt(e);try{let n=Ee({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=Re(),n=Tt(t);try{let r=Qn({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: ${Mn(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(g=>g.kind==="dead-code"),o=i.symbols.filter(g=>g.kind!=="dead-code"),a=!t.onlyInternal,l=!t.onlyDead,c=a?s:[],d=l?o:[];if(c.length===0&&d.length===0)return b.empty("No matching dead-code symbols found.");let u=(g,y,E,N)=>{console.log(`\u2550\u2550\u2550 ${y} (${g.length}, ${N} LOC) \u2550\u2550\u2550`),console.log(E),console.log("");let F=new Map;for(let _ of g){let P=F.get(_.relativePath)??[];P.push(_),F.set(_.relativePath,P)}let T=[...F.entries()].map(([_,P])=>({file:_,bucket:P,totalLoc:P.reduce((D,z)=>D+z.loc,0)})).sort((_,P)=>P.totalLoc-_.totalLoc||_.file.localeCompare(P.file)),R=!0;for(let{file:_,bucket:P}of T){R||console.log(""),R=!1,console.log(` ${_}`),P.sort((D,z)=>D.startLine-z.startLine);for(let D of P)console.log(` ${me(D.startLine,D.endLine)} (${D.loc} LOC) ${D.shortName}`)}},m=c.reduce((g,y)=>g+y.loc,0),f=d.reduce((g,y)=>g+y.loc,0);c.length>0&&u(c,"DEAD CODE",` Zero references anywhere \u2014 no cross-file callers AND no same-file uses.
|
|
940
|
+
Safe to delete.`,m),d.length>0&&(c.length>0&&console.log(""),u(d,"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.`,
|
|
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.`,f));let p=[];a&&p.push(`${c.length} dead code (${m} LOC)`),l&&p.push(`${d.length} file-internal (${f} 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+d.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 | ${Mn(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 (${or.join(", ")}) into Claude Code and Codex`).action(()=>{let e=Ti(),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;Tn()?console.log("scip CLI: installed"):($n(),e=!0);let t=Re(),n=Ce(t),r=n.languages??Ae(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=fi(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=rr(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=Re(),t=Ae(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=Re(),n=Ce(t);e.debounce&&((n.watch??={}).debounceMs=e.debounce),e.cooldown&&((n.watch??={}).cooldownMs=e.cooldown);let r=new Qt({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=Re(),t=Ce(e),n=ve(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??Ae(e)).includes("typescript")){let i=rr(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: ${Ba(r)?"yes":"no"}`),Ba(r)&&I(i=>{let s=x.stats(i);if(console.log(`Symbols: ${s.symbols}`),console.log(`Files: ${s.documents}`),console.log(`Size: ${Mn(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=cS(import.meta.url);try{return Wa(e)===Wa(process.argv[1])}catch{return e===process.argv[1]}}export{S as program,ye as renderHeuristicNotice};
|
|
917
1016
|
//# sourceMappingURL=cli.js.map
|