@colbymchenry/codegraph-darwin-x64 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (569) hide show
  1. package/bin/codegraph +3 -0
  2. package/lib/dist/bin/codegraph.d.ts +21 -0
  3. package/lib/dist/bin/codegraph.d.ts.map +1 -0
  4. package/lib/dist/bin/codegraph.js +1273 -0
  5. package/lib/dist/bin/codegraph.js.map +1 -0
  6. package/lib/dist/bin/node-version-check.d.ts +37 -0
  7. package/lib/dist/bin/node-version-check.d.ts.map +1 -0
  8. package/lib/dist/bin/node-version-check.js +79 -0
  9. package/lib/dist/bin/node-version-check.js.map +1 -0
  10. package/lib/dist/bin/uninstall.d.ts +14 -0
  11. package/lib/dist/bin/uninstall.d.ts.map +1 -0
  12. package/lib/dist/bin/uninstall.js +36 -0
  13. package/lib/dist/bin/uninstall.js.map +1 -0
  14. package/lib/dist/config.d.ts +51 -0
  15. package/lib/dist/config.d.ts.map +1 -0
  16. package/lib/dist/config.js +321 -0
  17. package/lib/dist/config.js.map +1 -0
  18. package/lib/dist/context/formatter.d.ts +30 -0
  19. package/lib/dist/context/formatter.d.ts.map +1 -0
  20. package/lib/dist/context/formatter.js +244 -0
  21. package/lib/dist/context/formatter.js.map +1 -0
  22. package/lib/dist/context/index.d.ts +97 -0
  23. package/lib/dist/context/index.d.ts.map +1 -0
  24. package/lib/dist/context/index.js +1050 -0
  25. package/lib/dist/context/index.js.map +1 -0
  26. package/lib/dist/db/index.d.ts +83 -0
  27. package/lib/dist/db/index.d.ts.map +1 -0
  28. package/lib/dist/db/index.js +219 -0
  29. package/lib/dist/db/index.js.map +1 -0
  30. package/lib/dist/db/migrations.d.ts +44 -0
  31. package/lib/dist/db/migrations.d.ts.map +1 -0
  32. package/lib/dist/db/migrations.js +131 -0
  33. package/lib/dist/db/migrations.js.map +1 -0
  34. package/lib/dist/db/queries.d.ts +253 -0
  35. package/lib/dist/db/queries.d.ts.map +1 -0
  36. package/lib/dist/db/queries.js +1207 -0
  37. package/lib/dist/db/queries.js.map +1 -0
  38. package/lib/dist/db/schema.sql +151 -0
  39. package/lib/dist/db/sqlite-adapter.d.ts +46 -0
  40. package/lib/dist/db/sqlite-adapter.d.ts.map +1 -0
  41. package/lib/dist/db/sqlite-adapter.js +114 -0
  42. package/lib/dist/db/sqlite-adapter.js.map +1 -0
  43. package/lib/dist/directory.d.ts +57 -0
  44. package/lib/dist/directory.d.ts.map +1 -0
  45. package/lib/dist/directory.js +264 -0
  46. package/lib/dist/directory.js.map +1 -0
  47. package/lib/dist/errors.d.ts +136 -0
  48. package/lib/dist/errors.d.ts.map +1 -0
  49. package/lib/dist/errors.js +219 -0
  50. package/lib/dist/errors.js.map +1 -0
  51. package/lib/dist/extraction/dfm-extractor.d.ts +31 -0
  52. package/lib/dist/extraction/dfm-extractor.d.ts.map +1 -0
  53. package/lib/dist/extraction/dfm-extractor.js +151 -0
  54. package/lib/dist/extraction/dfm-extractor.js.map +1 -0
  55. package/lib/dist/extraction/grammars.d.ts +78 -0
  56. package/lib/dist/extraction/grammars.d.ts.map +1 -0
  57. package/lib/dist/extraction/grammars.js +332 -0
  58. package/lib/dist/extraction/grammars.js.map +1 -0
  59. package/lib/dist/extraction/index.d.ts +130 -0
  60. package/lib/dist/extraction/index.d.ts.map +1 -0
  61. package/lib/dist/extraction/index.js +1305 -0
  62. package/lib/dist/extraction/index.js.map +1 -0
  63. package/lib/dist/extraction/languages/c-cpp.d.ts +4 -0
  64. package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  65. package/lib/dist/extraction/languages/c-cpp.js +126 -0
  66. package/lib/dist/extraction/languages/c-cpp.js.map +1 -0
  67. package/lib/dist/extraction/languages/csharp.d.ts +3 -0
  68. package/lib/dist/extraction/languages/csharp.d.ts.map +1 -0
  69. package/lib/dist/extraction/languages/csharp.js +72 -0
  70. package/lib/dist/extraction/languages/csharp.js.map +1 -0
  71. package/lib/dist/extraction/languages/dart.d.ts +3 -0
  72. package/lib/dist/extraction/languages/dart.d.ts.map +1 -0
  73. package/lib/dist/extraction/languages/dart.js +192 -0
  74. package/lib/dist/extraction/languages/dart.js.map +1 -0
  75. package/lib/dist/extraction/languages/go.d.ts +3 -0
  76. package/lib/dist/extraction/languages/go.d.ts.map +1 -0
  77. package/lib/dist/extraction/languages/go.js +58 -0
  78. package/lib/dist/extraction/languages/go.js.map +1 -0
  79. package/lib/dist/extraction/languages/index.d.ts +10 -0
  80. package/lib/dist/extraction/languages/index.d.ts.map +1 -0
  81. package/lib/dist/extraction/languages/index.js +49 -0
  82. package/lib/dist/extraction/languages/index.js.map +1 -0
  83. package/lib/dist/extraction/languages/java.d.ts +3 -0
  84. package/lib/dist/extraction/languages/java.d.ts.map +1 -0
  85. package/lib/dist/extraction/languages/java.js +64 -0
  86. package/lib/dist/extraction/languages/java.js.map +1 -0
  87. package/lib/dist/extraction/languages/javascript.d.ts +3 -0
  88. package/lib/dist/extraction/languages/javascript.d.ts.map +1 -0
  89. package/lib/dist/extraction/languages/javascript.js +90 -0
  90. package/lib/dist/extraction/languages/javascript.js.map +1 -0
  91. package/lib/dist/extraction/languages/kotlin.d.ts +3 -0
  92. package/lib/dist/extraction/languages/kotlin.d.ts.map +1 -0
  93. package/lib/dist/extraction/languages/kotlin.js +253 -0
  94. package/lib/dist/extraction/languages/kotlin.js.map +1 -0
  95. package/lib/dist/extraction/languages/lua.d.ts +3 -0
  96. package/lib/dist/extraction/languages/lua.d.ts.map +1 -0
  97. package/lib/dist/extraction/languages/lua.js +150 -0
  98. package/lib/dist/extraction/languages/lua.js.map +1 -0
  99. package/lib/dist/extraction/languages/luau.d.ts +3 -0
  100. package/lib/dist/extraction/languages/luau.d.ts.map +1 -0
  101. package/lib/dist/extraction/languages/luau.js +37 -0
  102. package/lib/dist/extraction/languages/luau.js.map +1 -0
  103. package/lib/dist/extraction/languages/pascal.d.ts +3 -0
  104. package/lib/dist/extraction/languages/pascal.d.ts.map +1 -0
  105. package/lib/dist/extraction/languages/pascal.js +66 -0
  106. package/lib/dist/extraction/languages/pascal.js.map +1 -0
  107. package/lib/dist/extraction/languages/php.d.ts +3 -0
  108. package/lib/dist/extraction/languages/php.d.ts.map +1 -0
  109. package/lib/dist/extraction/languages/php.js +107 -0
  110. package/lib/dist/extraction/languages/php.js.map +1 -0
  111. package/lib/dist/extraction/languages/python.d.ts +3 -0
  112. package/lib/dist/extraction/languages/python.d.ts.map +1 -0
  113. package/lib/dist/extraction/languages/python.js +56 -0
  114. package/lib/dist/extraction/languages/python.js.map +1 -0
  115. package/lib/dist/extraction/languages/ruby.d.ts +3 -0
  116. package/lib/dist/extraction/languages/ruby.d.ts.map +1 -0
  117. package/lib/dist/extraction/languages/ruby.js +114 -0
  118. package/lib/dist/extraction/languages/ruby.js.map +1 -0
  119. package/lib/dist/extraction/languages/rust.d.ts +3 -0
  120. package/lib/dist/extraction/languages/rust.d.ts.map +1 -0
  121. package/lib/dist/extraction/languages/rust.js +109 -0
  122. package/lib/dist/extraction/languages/rust.js.map +1 -0
  123. package/lib/dist/extraction/languages/scala.d.ts +3 -0
  124. package/lib/dist/extraction/languages/scala.d.ts.map +1 -0
  125. package/lib/dist/extraction/languages/scala.js +139 -0
  126. package/lib/dist/extraction/languages/scala.js.map +1 -0
  127. package/lib/dist/extraction/languages/swift.d.ts +3 -0
  128. package/lib/dist/extraction/languages/swift.d.ts.map +1 -0
  129. package/lib/dist/extraction/languages/swift.js +91 -0
  130. package/lib/dist/extraction/languages/swift.js.map +1 -0
  131. package/lib/dist/extraction/languages/typescript.d.ts +3 -0
  132. package/lib/dist/extraction/languages/typescript.d.ts.map +1 -0
  133. package/lib/dist/extraction/languages/typescript.js +129 -0
  134. package/lib/dist/extraction/languages/typescript.js.map +1 -0
  135. package/lib/dist/extraction/liquid-extractor.d.ts +52 -0
  136. package/lib/dist/extraction/liquid-extractor.d.ts.map +1 -0
  137. package/lib/dist/extraction/liquid-extractor.js +313 -0
  138. package/lib/dist/extraction/liquid-extractor.js.map +1 -0
  139. package/lib/dist/extraction/parse-worker.d.ts +8 -0
  140. package/lib/dist/extraction/parse-worker.d.ts.map +1 -0
  141. package/lib/dist/extraction/parse-worker.js +94 -0
  142. package/lib/dist/extraction/parse-worker.js.map +1 -0
  143. package/lib/dist/extraction/svelte-extractor.d.ts +56 -0
  144. package/lib/dist/extraction/svelte-extractor.d.ts.map +1 -0
  145. package/lib/dist/extraction/svelte-extractor.js +272 -0
  146. package/lib/dist/extraction/svelte-extractor.js.map +1 -0
  147. package/lib/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  148. package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  149. package/lib/dist/extraction/tree-sitter-helpers.js +103 -0
  150. package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -0
  151. package/lib/dist/extraction/tree-sitter-types.d.ts +179 -0
  152. package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  153. package/lib/dist/extraction/tree-sitter-types.js +10 -0
  154. package/lib/dist/extraction/tree-sitter-types.js.map +1 -0
  155. package/lib/dist/extraction/tree-sitter.d.ts +233 -0
  156. package/lib/dist/extraction/tree-sitter.d.ts.map +1 -0
  157. package/lib/dist/extraction/tree-sitter.js +2425 -0
  158. package/lib/dist/extraction/tree-sitter.js.map +1 -0
  159. package/lib/dist/extraction/vue-extractor.d.ts +36 -0
  160. package/lib/dist/extraction/vue-extractor.d.ts.map +1 -0
  161. package/lib/dist/extraction/vue-extractor.js +163 -0
  162. package/lib/dist/extraction/vue-extractor.js.map +1 -0
  163. package/lib/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  164. package/lib/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  165. package/lib/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  166. package/lib/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  167. package/lib/dist/graph/index.d.ts +8 -0
  168. package/lib/dist/graph/index.d.ts.map +1 -0
  169. package/lib/dist/graph/index.js +13 -0
  170. package/lib/dist/graph/index.js.map +1 -0
  171. package/lib/dist/graph/queries.d.ts +106 -0
  172. package/lib/dist/graph/queries.d.ts.map +1 -0
  173. package/lib/dist/graph/queries.js +366 -0
  174. package/lib/dist/graph/queries.js.map +1 -0
  175. package/lib/dist/graph/traversal.d.ts +127 -0
  176. package/lib/dist/graph/traversal.d.ts.map +1 -0
  177. package/lib/dist/graph/traversal.js +493 -0
  178. package/lib/dist/graph/traversal.js.map +1 -0
  179. package/lib/dist/index.d.ts +453 -0
  180. package/lib/dist/index.d.ts.map +1 -0
  181. package/lib/dist/index.js +833 -0
  182. package/lib/dist/index.js.map +1 -0
  183. package/lib/dist/installer/claude-md-template.d.ts +14 -0
  184. package/lib/dist/installer/claude-md-template.d.ts.map +1 -0
  185. package/lib/dist/installer/claude-md-template.js +21 -0
  186. package/lib/dist/installer/claude-md-template.js.map +1 -0
  187. package/lib/dist/installer/config-writer.d.ts +29 -0
  188. package/lib/dist/installer/config-writer.d.ts.map +1 -0
  189. package/lib/dist/installer/config-writer.js +111 -0
  190. package/lib/dist/installer/config-writer.js.map +1 -0
  191. package/lib/dist/installer/index.d.ts +65 -0
  192. package/lib/dist/installer/index.d.ts.map +1 -0
  193. package/lib/dist/installer/index.js +406 -0
  194. package/lib/dist/installer/index.js.map +1 -0
  195. package/lib/dist/installer/instructions-template.d.ts +28 -0
  196. package/lib/dist/installer/instructions-template.d.ts.map +1 -0
  197. package/lib/dist/installer/instructions-template.js +64 -0
  198. package/lib/dist/installer/instructions-template.js.map +1 -0
  199. package/lib/dist/installer/targets/claude.d.ts +47 -0
  200. package/lib/dist/installer/targets/claude.d.ts.map +1 -0
  201. package/lib/dist/installer/targets/claude.js +401 -0
  202. package/lib/dist/installer/targets/claude.js.map +1 -0
  203. package/lib/dist/installer/targets/codex.d.ts +18 -0
  204. package/lib/dist/installer/targets/codex.d.ts.map +1 -0
  205. package/lib/dist/installer/targets/codex.js +185 -0
  206. package/lib/dist/installer/targets/codex.js.map +1 -0
  207. package/lib/dist/installer/targets/cursor.d.ts +35 -0
  208. package/lib/dist/installer/targets/cursor.d.ts.map +1 -0
  209. package/lib/dist/installer/targets/cursor.js +229 -0
  210. package/lib/dist/installer/targets/cursor.js.map +1 -0
  211. package/lib/dist/installer/targets/opencode.d.ts +30 -0
  212. package/lib/dist/installer/targets/opencode.d.ts.map +1 -0
  213. package/lib/dist/installer/targets/opencode.js +235 -0
  214. package/lib/dist/installer/targets/opencode.js.map +1 -0
  215. package/lib/dist/installer/targets/registry.d.ts +35 -0
  216. package/lib/dist/installer/targets/registry.d.ts.map +1 -0
  217. package/lib/dist/installer/targets/registry.js +83 -0
  218. package/lib/dist/installer/targets/registry.js.map +1 -0
  219. package/lib/dist/installer/targets/shared.d.ts +77 -0
  220. package/lib/dist/installer/targets/shared.d.ts.map +1 -0
  221. package/lib/dist/installer/targets/shared.js +246 -0
  222. package/lib/dist/installer/targets/shared.js.map +1 -0
  223. package/lib/dist/installer/targets/toml.d.ts +52 -0
  224. package/lib/dist/installer/targets/toml.d.ts.map +1 -0
  225. package/lib/dist/installer/targets/toml.js +147 -0
  226. package/lib/dist/installer/targets/toml.js.map +1 -0
  227. package/lib/dist/installer/targets/types.d.ts +116 -0
  228. package/lib/dist/installer/targets/types.d.ts.map +1 -0
  229. package/lib/dist/installer/targets/types.js +16 -0
  230. package/lib/dist/installer/targets/types.js.map +1 -0
  231. package/lib/dist/mcp/index.d.ts +94 -0
  232. package/lib/dist/mcp/index.d.ts.map +1 -0
  233. package/lib/dist/mcp/index.js +453 -0
  234. package/lib/dist/mcp/index.js.map +1 -0
  235. package/lib/dist/mcp/server-instructions.d.ts +19 -0
  236. package/lib/dist/mcp/server-instructions.d.ts.map +1 -0
  237. package/lib/dist/mcp/server-instructions.js +71 -0
  238. package/lib/dist/mcp/server-instructions.js.map +1 -0
  239. package/lib/dist/mcp/tools.d.ts +257 -0
  240. package/lib/dist/mcp/tools.d.ts.map +1 -0
  241. package/lib/dist/mcp/tools.js +1646 -0
  242. package/lib/dist/mcp/tools.js.map +1 -0
  243. package/lib/dist/mcp/transport.d.ts +106 -0
  244. package/lib/dist/mcp/transport.d.ts.map +1 -0
  245. package/lib/dist/mcp/transport.js +233 -0
  246. package/lib/dist/mcp/transport.js.map +1 -0
  247. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  248. package/lib/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  249. package/lib/dist/resolution/frameworks/cargo-workspace.js +225 -0
  250. package/lib/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  251. package/lib/dist/resolution/frameworks/csharp.d.ts +8 -0
  252. package/lib/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  253. package/lib/dist/resolution/frameworks/csharp.js +213 -0
  254. package/lib/dist/resolution/frameworks/csharp.js.map +1 -0
  255. package/lib/dist/resolution/frameworks/express.d.ts +8 -0
  256. package/lib/dist/resolution/frameworks/express.d.ts.map +1 -0
  257. package/lib/dist/resolution/frameworks/express.js +225 -0
  258. package/lib/dist/resolution/frameworks/express.js.map +1 -0
  259. package/lib/dist/resolution/frameworks/go.d.ts +8 -0
  260. package/lib/dist/resolution/frameworks/go.d.ts.map +1 -0
  261. package/lib/dist/resolution/frameworks/go.js +158 -0
  262. package/lib/dist/resolution/frameworks/go.js.map +1 -0
  263. package/lib/dist/resolution/frameworks/index.d.ts +42 -0
  264. package/lib/dist/resolution/frameworks/index.d.ts.map +1 -0
  265. package/lib/dist/resolution/frameworks/index.js +133 -0
  266. package/lib/dist/resolution/frameworks/index.js.map +1 -0
  267. package/lib/dist/resolution/frameworks/java.d.ts +8 -0
  268. package/lib/dist/resolution/frameworks/java.d.ts.map +1 -0
  269. package/lib/dist/resolution/frameworks/java.js +177 -0
  270. package/lib/dist/resolution/frameworks/java.js.map +1 -0
  271. package/lib/dist/resolution/frameworks/laravel.d.ts +13 -0
  272. package/lib/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  273. package/lib/dist/resolution/frameworks/laravel.js +248 -0
  274. package/lib/dist/resolution/frameworks/laravel.js.map +1 -0
  275. package/lib/dist/resolution/frameworks/nestjs.d.ts +26 -0
  276. package/lib/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  277. package/lib/dist/resolution/frameworks/nestjs.js +374 -0
  278. package/lib/dist/resolution/frameworks/nestjs.js.map +1 -0
  279. package/lib/dist/resolution/frameworks/python.d.ts +10 -0
  280. package/lib/dist/resolution/frameworks/python.d.ts.map +1 -0
  281. package/lib/dist/resolution/frameworks/python.js +278 -0
  282. package/lib/dist/resolution/frameworks/python.js.map +1 -0
  283. package/lib/dist/resolution/frameworks/react.d.ts +8 -0
  284. package/lib/dist/resolution/frameworks/react.d.ts.map +1 -0
  285. package/lib/dist/resolution/frameworks/react.js +272 -0
  286. package/lib/dist/resolution/frameworks/react.js.map +1 -0
  287. package/lib/dist/resolution/frameworks/ruby.d.ts +8 -0
  288. package/lib/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  289. package/lib/dist/resolution/frameworks/ruby.js +198 -0
  290. package/lib/dist/resolution/frameworks/ruby.js.map +1 -0
  291. package/lib/dist/resolution/frameworks/rust.d.ts +8 -0
  292. package/lib/dist/resolution/frameworks/rust.d.ts.map +1 -0
  293. package/lib/dist/resolution/frameworks/rust.js +207 -0
  294. package/lib/dist/resolution/frameworks/rust.js.map +1 -0
  295. package/lib/dist/resolution/frameworks/svelte.d.ts +9 -0
  296. package/lib/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  297. package/lib/dist/resolution/frameworks/svelte.js +249 -0
  298. package/lib/dist/resolution/frameworks/svelte.js.map +1 -0
  299. package/lib/dist/resolution/frameworks/swift.d.ts +10 -0
  300. package/lib/dist/resolution/frameworks/swift.d.ts.map +1 -0
  301. package/lib/dist/resolution/frameworks/swift.js +376 -0
  302. package/lib/dist/resolution/frameworks/swift.js.map +1 -0
  303. package/lib/dist/resolution/frameworks/vue.d.ts +9 -0
  304. package/lib/dist/resolution/frameworks/vue.d.ts.map +1 -0
  305. package/lib/dist/resolution/frameworks/vue.js +306 -0
  306. package/lib/dist/resolution/frameworks/vue.js.map +1 -0
  307. package/lib/dist/resolution/import-resolver.d.ts +40 -0
  308. package/lib/dist/resolution/import-resolver.d.ts.map +1 -0
  309. package/lib/dist/resolution/import-resolver.js +663 -0
  310. package/lib/dist/resolution/import-resolver.js.map +1 -0
  311. package/lib/dist/resolution/index.d.ts +106 -0
  312. package/lib/dist/resolution/index.d.ts.map +1 -0
  313. package/lib/dist/resolution/index.js +709 -0
  314. package/lib/dist/resolution/index.js.map +1 -0
  315. package/lib/dist/resolution/name-matcher.d.ts +32 -0
  316. package/lib/dist/resolution/name-matcher.d.ts.map +1 -0
  317. package/lib/dist/resolution/name-matcher.js +384 -0
  318. package/lib/dist/resolution/name-matcher.js.map +1 -0
  319. package/lib/dist/resolution/path-aliases.d.ts +68 -0
  320. package/lib/dist/resolution/path-aliases.d.ts.map +1 -0
  321. package/lib/dist/resolution/path-aliases.js +238 -0
  322. package/lib/dist/resolution/path-aliases.js.map +1 -0
  323. package/lib/dist/resolution/strip-comments.d.ts +27 -0
  324. package/lib/dist/resolution/strip-comments.d.ts.map +1 -0
  325. package/lib/dist/resolution/strip-comments.js +441 -0
  326. package/lib/dist/resolution/strip-comments.js.map +1 -0
  327. package/lib/dist/resolution/types.d.ts +172 -0
  328. package/lib/dist/resolution/types.d.ts.map +1 -0
  329. package/lib/dist/resolution/types.js +8 -0
  330. package/lib/dist/resolution/types.js.map +1 -0
  331. package/lib/dist/search/query-parser.d.ts +57 -0
  332. package/lib/dist/search/query-parser.d.ts.map +1 -0
  333. package/lib/dist/search/query-parser.js +177 -0
  334. package/lib/dist/search/query-parser.js.map +1 -0
  335. package/lib/dist/search/query-utils.d.ts +53 -0
  336. package/lib/dist/search/query-utils.d.ts.map +1 -0
  337. package/lib/dist/search/query-utils.js +350 -0
  338. package/lib/dist/search/query-utils.js.map +1 -0
  339. package/lib/dist/sync/git-hooks.d.ts +45 -0
  340. package/lib/dist/sync/git-hooks.d.ts.map +1 -0
  341. package/lib/dist/sync/git-hooks.js +223 -0
  342. package/lib/dist/sync/git-hooks.js.map +1 -0
  343. package/lib/dist/sync/index.d.ts +17 -0
  344. package/lib/dist/sync/index.d.ts.map +1 -0
  345. package/lib/dist/sync/index.js +28 -0
  346. package/lib/dist/sync/index.js.map +1 -0
  347. package/lib/dist/sync/watch-policy.d.ts +48 -0
  348. package/lib/dist/sync/watch-policy.d.ts.map +1 -0
  349. package/lib/dist/sync/watch-policy.js +124 -0
  350. package/lib/dist/sync/watch-policy.js.map +1 -0
  351. package/lib/dist/sync/watcher.d.ts +81 -0
  352. package/lib/dist/sync/watcher.d.ts.map +1 -0
  353. package/lib/dist/sync/watcher.js +194 -0
  354. package/lib/dist/sync/watcher.js.map +1 -0
  355. package/lib/dist/types.d.ts +423 -0
  356. package/lib/dist/types.d.ts.map +1 -0
  357. package/lib/dist/types.js +262 -0
  358. package/lib/dist/types.js.map +1 -0
  359. package/lib/dist/ui/glyphs.d.ts +42 -0
  360. package/lib/dist/ui/glyphs.d.ts.map +1 -0
  361. package/lib/dist/ui/glyphs.js +78 -0
  362. package/lib/dist/ui/glyphs.js.map +1 -0
  363. package/lib/dist/ui/shimmer-progress.d.ts +11 -0
  364. package/lib/dist/ui/shimmer-progress.d.ts.map +1 -0
  365. package/lib/dist/ui/shimmer-progress.js +90 -0
  366. package/lib/dist/ui/shimmer-progress.js.map +1 -0
  367. package/lib/dist/ui/shimmer-worker.d.ts +2 -0
  368. package/lib/dist/ui/shimmer-worker.d.ts.map +1 -0
  369. package/lib/dist/ui/shimmer-worker.js +118 -0
  370. package/lib/dist/ui/shimmer-worker.js.map +1 -0
  371. package/lib/dist/ui/types.d.ts +17 -0
  372. package/lib/dist/ui/types.d.ts.map +1 -0
  373. package/lib/dist/ui/types.js +3 -0
  374. package/lib/dist/ui/types.js.map +1 -0
  375. package/lib/dist/utils.d.ts +205 -0
  376. package/lib/dist/utils.d.ts.map +1 -0
  377. package/lib/dist/utils.js +549 -0
  378. package/lib/dist/utils.js.map +1 -0
  379. package/lib/node_modules/.package-lock.json +116 -0
  380. package/lib/node_modules/@clack/core/CHANGELOG.md +348 -0
  381. package/lib/node_modules/@clack/core/LICENSE +9 -0
  382. package/lib/node_modules/@clack/core/README.md +22 -0
  383. package/lib/node_modules/@clack/core/dist/index.d.mts +363 -0
  384. package/lib/node_modules/@clack/core/dist/index.mjs +17 -0
  385. package/lib/node_modules/@clack/core/dist/index.mjs.map +1 -0
  386. package/lib/node_modules/@clack/core/package.json +63 -0
  387. package/lib/node_modules/@clack/prompts/CHANGELOG.md +591 -0
  388. package/lib/node_modules/@clack/prompts/LICENSE +9 -0
  389. package/lib/node_modules/@clack/prompts/README.md +375 -0
  390. package/lib/node_modules/@clack/prompts/dist/index.d.mts +396 -0
  391. package/lib/node_modules/@clack/prompts/dist/index.mjs +144 -0
  392. package/lib/node_modules/@clack/prompts/dist/index.mjs.map +1 -0
  393. package/lib/node_modules/@clack/prompts/package.json +68 -0
  394. package/lib/node_modules/commander/LICENSE +22 -0
  395. package/lib/node_modules/commander/Readme.md +1176 -0
  396. package/lib/node_modules/commander/esm.mjs +16 -0
  397. package/lib/node_modules/commander/index.js +24 -0
  398. package/lib/node_modules/commander/lib/argument.js +150 -0
  399. package/lib/node_modules/commander/lib/command.js +2777 -0
  400. package/lib/node_modules/commander/lib/error.js +39 -0
  401. package/lib/node_modules/commander/lib/help.js +747 -0
  402. package/lib/node_modules/commander/lib/option.js +380 -0
  403. package/lib/node_modules/commander/lib/suggestSimilar.js +101 -0
  404. package/lib/node_modules/commander/package-support.json +19 -0
  405. package/lib/node_modules/commander/package.json +82 -0
  406. package/lib/node_modules/commander/typings/esm.d.mts +3 -0
  407. package/lib/node_modules/commander/typings/index.d.ts +1113 -0
  408. package/lib/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  409. package/lib/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  410. package/lib/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  411. package/lib/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  412. package/lib/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  413. package/lib/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  414. package/lib/node_modules/fast-string-truncated-width/license +21 -0
  415. package/lib/node_modules/fast-string-truncated-width/package.json +35 -0
  416. package/lib/node_modules/fast-string-truncated-width/readme.md +59 -0
  417. package/lib/node_modules/fast-string-width/dist/index.d.ts +4 -0
  418. package/lib/node_modules/fast-string-width/dist/index.js +14 -0
  419. package/lib/node_modules/fast-string-width/license +21 -0
  420. package/lib/node_modules/fast-string-width/package.json +34 -0
  421. package/lib/node_modules/fast-string-width/readme.md +42 -0
  422. package/lib/node_modules/fast-wrap-ansi/LICENSE +23 -0
  423. package/lib/node_modules/fast-wrap-ansi/README.md +26 -0
  424. package/lib/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  425. package/lib/node_modules/fast-wrap-ansi/lib/main.js +219 -0
  426. package/lib/node_modules/fast-wrap-ansi/lib/main.js.map +1 -0
  427. package/lib/node_modules/fast-wrap-ansi/package.json +51 -0
  428. package/lib/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  429. package/lib/node_modules/jsonc-parser/LICENSE.md +21 -0
  430. package/lib/node_modules/jsonc-parser/README.md +364 -0
  431. package/lib/node_modules/jsonc-parser/SECURITY.md +41 -0
  432. package/lib/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  433. package/lib/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  434. package/lib/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  435. package/lib/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  436. package/lib/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  437. package/lib/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  438. package/lib/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  439. package/lib/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  440. package/lib/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  441. package/lib/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  442. package/lib/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  443. package/lib/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  444. package/lib/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  445. package/lib/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  446. package/lib/node_modules/jsonc-parser/package.json +37 -0
  447. package/lib/node_modules/picomatch/LICENSE +21 -0
  448. package/lib/node_modules/picomatch/README.md +738 -0
  449. package/lib/node_modules/picomatch/index.js +17 -0
  450. package/lib/node_modules/picomatch/lib/constants.js +180 -0
  451. package/lib/node_modules/picomatch/lib/parse.js +1085 -0
  452. package/lib/node_modules/picomatch/lib/picomatch.js +341 -0
  453. package/lib/node_modules/picomatch/lib/scan.js +391 -0
  454. package/lib/node_modules/picomatch/lib/utils.js +72 -0
  455. package/lib/node_modules/picomatch/package.json +83 -0
  456. package/lib/node_modules/picomatch/posix.js +3 -0
  457. package/lib/node_modules/sisteransi/license +21 -0
  458. package/lib/node_modules/sisteransi/package.json +34 -0
  459. package/lib/node_modules/sisteransi/readme.md +113 -0
  460. package/lib/node_modules/sisteransi/src/index.js +58 -0
  461. package/lib/node_modules/sisteransi/src/sisteransi.d.ts +35 -0
  462. package/lib/node_modules/tree-sitter-wasms/LICENSE +24 -0
  463. package/lib/node_modules/tree-sitter-wasms/README.md +23 -0
  464. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-bash.wasm +0 -0
  465. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-c.wasm +0 -0
  466. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-c_sharp.wasm +0 -0
  467. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-cpp.wasm +0 -0
  468. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-css.wasm +0 -0
  469. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-dart.wasm +0 -0
  470. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elisp.wasm +0 -0
  471. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elixir.wasm +0 -0
  472. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-elm.wasm +0 -0
  473. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-embedded_template.wasm +0 -0
  474. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-go.wasm +0 -0
  475. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-html.wasm +0 -0
  476. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-java.wasm +0 -0
  477. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-javascript.wasm +0 -0
  478. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-json.wasm +0 -0
  479. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-kotlin.wasm +0 -0
  480. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-lua.wasm +0 -0
  481. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-objc.wasm +0 -0
  482. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ocaml.wasm +0 -0
  483. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-php.wasm +0 -0
  484. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-python.wasm +0 -0
  485. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ql.wasm +0 -0
  486. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-rescript.wasm +0 -0
  487. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm +0 -0
  488. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-rust.wasm +0 -0
  489. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-scala.wasm +0 -0
  490. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-solidity.wasm +0 -0
  491. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-swift.wasm +0 -0
  492. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-systemrdl.wasm +0 -0
  493. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-tlaplus.wasm +0 -0
  494. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-toml.wasm +0 -0
  495. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-tsx.wasm +0 -0
  496. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-typescript.wasm +0 -0
  497. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-vue.wasm +0 -0
  498. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-yaml.wasm +0 -0
  499. package/lib/node_modules/tree-sitter-wasms/out/tree-sitter-zig.wasm +0 -0
  500. package/lib/node_modules/tree-sitter-wasms/package.json +64 -0
  501. package/lib/node_modules/web-tree-sitter/LICENSE +21 -0
  502. package/lib/node_modules/web-tree-sitter/README.md +269 -0
  503. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.cjs +4558 -0
  504. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.cjs.map +7 -0
  505. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.js +4516 -0
  506. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.js.map +7 -0
  507. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.wasm +0 -0
  508. package/lib/node_modules/web-tree-sitter/debug/tree-sitter.wasm.map +31 -0
  509. package/lib/node_modules/web-tree-sitter/lib/alloc.c +48 -0
  510. package/lib/node_modules/web-tree-sitter/lib/alloc.h +41 -0
  511. package/lib/node_modules/web-tree-sitter/lib/array.h +291 -0
  512. package/lib/node_modules/web-tree-sitter/lib/atomic.h +68 -0
  513. package/lib/node_modules/web-tree-sitter/lib/clock.h +146 -0
  514. package/lib/node_modules/web-tree-sitter/lib/error_costs.h +11 -0
  515. package/lib/node_modules/web-tree-sitter/lib/get_changed_ranges.c +523 -0
  516. package/lib/node_modules/web-tree-sitter/lib/get_changed_ranges.h +36 -0
  517. package/lib/node_modules/web-tree-sitter/lib/host.h +21 -0
  518. package/lib/node_modules/web-tree-sitter/lib/language.c +293 -0
  519. package/lib/node_modules/web-tree-sitter/lib/language.h +293 -0
  520. package/lib/node_modules/web-tree-sitter/lib/length.h +52 -0
  521. package/lib/node_modules/web-tree-sitter/lib/lexer.c +483 -0
  522. package/lib/node_modules/web-tree-sitter/lib/lexer.h +54 -0
  523. package/lib/node_modules/web-tree-sitter/lib/lib.c +12 -0
  524. package/lib/node_modules/web-tree-sitter/lib/node.c +875 -0
  525. package/lib/node_modules/web-tree-sitter/lib/parser.c +2297 -0
  526. package/lib/node_modules/web-tree-sitter/lib/parser.h +286 -0
  527. package/lib/node_modules/web-tree-sitter/lib/point.h +48 -0
  528. package/lib/node_modules/web-tree-sitter/lib/query.c +4347 -0
  529. package/lib/node_modules/web-tree-sitter/lib/reduce_action.h +34 -0
  530. package/lib/node_modules/web-tree-sitter/lib/reusable_node.h +95 -0
  531. package/lib/node_modules/web-tree-sitter/lib/stack.c +912 -0
  532. package/lib/node_modules/web-tree-sitter/lib/stack.h +133 -0
  533. package/lib/node_modules/web-tree-sitter/lib/subtree.c +1034 -0
  534. package/lib/node_modules/web-tree-sitter/lib/subtree.h +399 -0
  535. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.c +987 -0
  536. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.cjs +2988 -0
  537. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.wasm +0 -0
  538. package/lib/node_modules/web-tree-sitter/lib/tree-sitter.wasm.map +1 -0
  539. package/lib/node_modules/web-tree-sitter/lib/tree.c +170 -0
  540. package/lib/node_modules/web-tree-sitter/lib/tree.h +31 -0
  541. package/lib/node_modules/web-tree-sitter/lib/tree_cursor.c +716 -0
  542. package/lib/node_modules/web-tree-sitter/lib/tree_cursor.h +48 -0
  543. package/lib/node_modules/web-tree-sitter/lib/ts_assert.h +11 -0
  544. package/lib/node_modules/web-tree-sitter/lib/unicode.h +75 -0
  545. package/lib/node_modules/web-tree-sitter/lib/wasm_store.c +1937 -0
  546. package/lib/node_modules/web-tree-sitter/lib/wasm_store.h +31 -0
  547. package/lib/node_modules/web-tree-sitter/package.json +98 -0
  548. package/lib/node_modules/web-tree-sitter/src/bindings.ts +26 -0
  549. package/lib/node_modules/web-tree-sitter/src/constants.ts +133 -0
  550. package/lib/node_modules/web-tree-sitter/src/index.ts +31 -0
  551. package/lib/node_modules/web-tree-sitter/src/language.ts +291 -0
  552. package/lib/node_modules/web-tree-sitter/src/lookahead_iterator.ts +75 -0
  553. package/lib/node_modules/web-tree-sitter/src/marshal.ts +176 -0
  554. package/lib/node_modules/web-tree-sitter/src/node.ts +646 -0
  555. package/lib/node_modules/web-tree-sitter/src/parser.ts +325 -0
  556. package/lib/node_modules/web-tree-sitter/src/query.ts +973 -0
  557. package/lib/node_modules/web-tree-sitter/src/tree.ts +145 -0
  558. package/lib/node_modules/web-tree-sitter/src/tree_cursor.ts +318 -0
  559. package/lib/node_modules/web-tree-sitter/tree-sitter.cjs +4031 -0
  560. package/lib/node_modules/web-tree-sitter/tree-sitter.cjs.map +7 -0
  561. package/lib/node_modules/web-tree-sitter/tree-sitter.js +3980 -0
  562. package/lib/node_modules/web-tree-sitter/tree-sitter.js.map +7 -0
  563. package/lib/node_modules/web-tree-sitter/tree-sitter.wasm +0 -0
  564. package/lib/node_modules/web-tree-sitter/tree-sitter.wasm.map +30 -0
  565. package/lib/node_modules/web-tree-sitter/web-tree-sitter.d.ts +1030 -0
  566. package/lib/node_modules/web-tree-sitter/web-tree-sitter.d.ts.map +56 -0
  567. package/lib/package.json +55 -0
  568. package/node +0 -0
  569. package/package.json +17 -0
@@ -0,0 +1,973 @@
1
+ import { Point, ZERO_POINT, SIZE_OF_INT, C } from './constants';
2
+ import { Node } from './node';
3
+ import { marshalNode, unmarshalCaptures } from './marshal';
4
+ import { TRANSFER_BUFFER } from './parser';
5
+ import { Language } from './language';
6
+
7
+ const PREDICATE_STEP_TYPE_CAPTURE = 1;
8
+
9
+ const PREDICATE_STEP_TYPE_STRING = 2;
10
+
11
+ const QUERY_WORD_REGEX = /[\w-]+/g;
12
+
13
+ /**
14
+ * Options for query execution
15
+ */
16
+ export interface QueryOptions {
17
+ /** The start position of the range to query */
18
+ startPosition?: Point;
19
+
20
+ /** The end position of the range to query */
21
+ endPosition?: Point;
22
+
23
+ /** The start index of the range to query */
24
+ startIndex?: number;
25
+
26
+ /** The end index of the range to query */
27
+ endIndex?: number;
28
+
29
+ /**
30
+ * The maximum number of in-progress matches for this query.
31
+ * The limit must be > 0 and <= 65536.
32
+ */
33
+ matchLimit?: number;
34
+
35
+ /**
36
+ * The maximum start depth for a query cursor.
37
+ *
38
+ * This prevents cursors from exploring children nodes at a certain depth.
39
+ * Note if a pattern includes many children, then they will still be
40
+ * checked.
41
+ *
42
+ * The zero max start depth value can be used as a special behavior and
43
+ * it helps to destructure a subtree by staying on a node and using
44
+ * captures for interested parts. Note that the zero max start depth
45
+ * only limit a search depth for a pattern's root node but other nodes
46
+ * that are parts of the pattern may be searched at any depth what
47
+ * defined by the pattern structure.
48
+ *
49
+ * Set to `null` to remove the maximum start depth.
50
+ */
51
+ maxStartDepth?: number;
52
+
53
+ /**
54
+ * The maximum duration in microseconds that query execution should be allowed to
55
+ * take before halting.
56
+ *
57
+ * If query execution takes longer than this, it will halt early, returning an empty array.
58
+ */
59
+ timeoutMicros?: number;
60
+
61
+ /**
62
+ * A function that will be called periodically during the execution of the query to check
63
+ * if query execution should be cancelled. You can also use this to instrument query execution
64
+ * and check where the query is at in the document. The progress callback takes a single argument,
65
+ * which is a {@link QueryState} representing the current state of the query.
66
+ */
67
+ progressCallback?: (state: QueryState) => void;
68
+ }
69
+
70
+ /**
71
+ * A stateful object that is passed into the progress callback {@link QueryOptions#progressCallback}
72
+ * to provide the current state of the query.
73
+ */
74
+ export interface QueryState {
75
+ /** The byte offset in the document that the query is at. */
76
+ currentOffset: number;
77
+ }
78
+
79
+ /** A record of key-value pairs associated with a particular pattern in a {@link Query}. */
80
+ export type QueryProperties = Record<string, string | null>;
81
+
82
+ /**
83
+ * A predicate that contains an operator and list of operands.
84
+ */
85
+ export interface QueryPredicate {
86
+ /** The operator of the predicate, like `match?`, `eq?`, `set!`, etc. */
87
+ operator: string;
88
+
89
+ /** The operands of the predicate, which are either captures or strings. */
90
+ operands: PredicateStep[];
91
+ }
92
+
93
+ /**
94
+ * A particular {@link Node} that has been captured with a particular name within a
95
+ * {@link Query}.
96
+ */
97
+ export interface QueryCapture {
98
+ /** The index of the pattern that matched. */
99
+ patternIndex: number;
100
+
101
+ /** The name of the capture */
102
+ name: string;
103
+
104
+ /** The captured node */
105
+ node: Node;
106
+
107
+ /** The properties for predicates declared with the operator `set!`. */
108
+ setProperties?: QueryProperties;
109
+
110
+ /** The properties for predicates declared with the operator `is?`. */
111
+ assertedProperties?: QueryProperties;
112
+
113
+ /** The properties for predicates declared with the operator `is-not?`. */
114
+ refutedProperties?: QueryProperties;
115
+ }
116
+
117
+ /** A match of a {@link Query} to a particular set of {@link Node}s. */
118
+ export interface QueryMatch {
119
+ /** @deprecated since version 0.25.0, use `patternIndex` instead. */
120
+ pattern: number;
121
+
122
+ /** The index of the pattern that matched. */
123
+ patternIndex: number;
124
+
125
+ /** The captures associated with the match. */
126
+ captures: QueryCapture[];
127
+
128
+ /** The properties for predicates declared with the operator `set!`. */
129
+ setProperties?: QueryProperties;
130
+
131
+ /** The properties for predicates declared with the operator `is?`. */
132
+ assertedProperties?: QueryProperties;
133
+
134
+ /** The properties for predicates declared with the operator `is-not?`. */
135
+ refutedProperties?: QueryProperties;
136
+ }
137
+
138
+ /** A quantifier for captures */
139
+ export const CaptureQuantifier = {
140
+ Zero: 0,
141
+ ZeroOrOne: 1,
142
+ ZeroOrMore: 2,
143
+ One: 3,
144
+ OneOrMore: 4
145
+ } as const;
146
+
147
+ /** A quantifier for captures */
148
+ export type CaptureQuantifier = typeof CaptureQuantifier[keyof typeof CaptureQuantifier];
149
+
150
+ /**
151
+ * Predicates are represented as a single array of steps. There are two
152
+ * types of steps, which correspond to the two legal values for
153
+ * the `type` field:
154
+ *
155
+ * - `CapturePredicateStep` - Steps with this type represent names
156
+ * of captures.
157
+ *
158
+ * - `StringPredicateStep` - Steps with this type represent literal
159
+ * strings.
160
+ */
161
+ export type PredicateStep = CapturePredicateStep | StringPredicateStep;
162
+
163
+ /**
164
+ * A step in a predicate that refers to a capture.
165
+ *
166
+ * The `name` field is the name of the capture.
167
+ */
168
+ export interface CapturePredicateStep { type: 'capture', name: string }
169
+
170
+ /**
171
+ * A step in a predicate that refers to a string.
172
+ *
173
+ * The `value` field is the string value.
174
+ */
175
+ export interface StringPredicateStep { type: 'string', value: string }
176
+
177
+ const isCaptureStep = (step: PredicateStep): step is Extract<PredicateStep, { type: 'capture' }> =>
178
+ step.type === 'capture';
179
+
180
+ const isStringStep = (step: PredicateStep): step is Extract<PredicateStep, { type: 'string' }> =>
181
+ step.type === 'string';
182
+
183
+ /**
184
+ * @internal
185
+ *
186
+ * A function that checks if a given set of captures matches a particular
187
+ * condition. This is used in the built-in `eq?`, `match?`, and `any-of?`
188
+ * predicates.
189
+ */
190
+ export type TextPredicate = (captures: QueryCapture[]) => boolean;
191
+
192
+ /** Error codes returned from tree-sitter query parsing */
193
+ export const QueryErrorKind = {
194
+ Syntax: 1,
195
+ NodeName: 2,
196
+ FieldName: 3,
197
+ CaptureName: 4,
198
+ PatternStructure: 5,
199
+ } as const;
200
+
201
+ /** An error that occurred while parsing a query string. */
202
+ export type QueryErrorKind = typeof QueryErrorKind[keyof typeof QueryErrorKind];
203
+
204
+ /** Information about a {@link QueryError}. */
205
+ export interface QueryErrorInfo {
206
+ [QueryErrorKind.NodeName]: { word: string };
207
+ [QueryErrorKind.FieldName]: { word: string };
208
+ [QueryErrorKind.CaptureName]: { word: string };
209
+ [QueryErrorKind.PatternStructure]: { suffix: string };
210
+ [QueryErrorKind.Syntax]: { suffix: string };
211
+ }
212
+
213
+ /** Error thrown when parsing a tree-sitter query fails */
214
+ export class QueryError extends Error {
215
+ constructor(
216
+ public kind: QueryErrorKind,
217
+ public info: QueryErrorInfo[typeof kind],
218
+ public index: number,
219
+ public length: number
220
+ ) {
221
+ super(QueryError.formatMessage(kind, info));
222
+ this.name = 'QueryError';
223
+ }
224
+
225
+ /** Formats an error message based on the error kind and info */
226
+ private static formatMessage(kind: QueryErrorKind, info: QueryErrorInfo[QueryErrorKind]): string {
227
+ switch (kind) {
228
+ case QueryErrorKind.NodeName:
229
+ return `Bad node name '${(info as QueryErrorInfo[2]).word}'`;
230
+ case QueryErrorKind.FieldName:
231
+ return `Bad field name '${(info as QueryErrorInfo[3]).word}'`;
232
+ case QueryErrorKind.CaptureName:
233
+ return `Bad capture name @${(info as QueryErrorInfo[4]).word}`;
234
+ case QueryErrorKind.PatternStructure:
235
+ return `Bad pattern structure at offset ${(info as QueryErrorInfo[5]).suffix}`;
236
+ case QueryErrorKind.Syntax:
237
+ return `Bad syntax at offset ${(info as QueryErrorInfo[1]).suffix}`;
238
+ }
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Parses the `eq?` and `not-eq?` predicates in a query, and updates the text predicates.
244
+ */
245
+ function parseAnyPredicate(
246
+ steps: PredicateStep[],
247
+ index: number,
248
+ operator: string,
249
+ textPredicates: TextPredicate[][],
250
+ ) {
251
+ if (steps.length !== 3) {
252
+ throw new Error(
253
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}`
254
+ );
255
+ }
256
+
257
+ if (!isCaptureStep(steps[1])) {
258
+ throw new Error(
259
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"`
260
+ );
261
+ }
262
+
263
+ const isPositive = operator === 'eq?' || operator === 'any-eq?';
264
+ const matchAll = !operator.startsWith('any-');
265
+
266
+ if (isCaptureStep(steps[2])) {
267
+ const captureName1 = steps[1].name;
268
+ const captureName2 = steps[2].name;
269
+ textPredicates[index].push((captures) => {
270
+ const nodes1: Node[] = [];
271
+ const nodes2: Node[] = [];
272
+ for (const c of captures) {
273
+ if (c.name === captureName1) nodes1.push(c.node);
274
+ if (c.name === captureName2) nodes2.push(c.node);
275
+ }
276
+ const compare = (n1: { text: string }, n2: { text: string }, positive: boolean) => {
277
+ return positive ? n1.text === n2.text : n1.text !== n2.text;
278
+ };
279
+ return matchAll
280
+ ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)))
281
+ : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)));
282
+ });
283
+ } else {
284
+ const captureName = steps[1].name;
285
+ const stringValue = steps[2].value;
286
+ const matches = (n: Node) => n.text === stringValue;
287
+ const doesNotMatch = (n: Node) => n.text !== stringValue;
288
+ textPredicates[index].push((captures) => {
289
+ const nodes = [];
290
+ for (const c of captures) {
291
+ if (c.name === captureName) nodes.push(c.node);
292
+ }
293
+ const test = isPositive ? matches : doesNotMatch;
294
+ return matchAll ? nodes.every(test) : nodes.some(test);
295
+ });
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Parses the `match?` and `not-match?` predicates in a query, and updates the text predicates.
301
+ */
302
+ function parseMatchPredicate(
303
+ steps: PredicateStep[],
304
+ index: number,
305
+ operator: string,
306
+ textPredicates: TextPredicate[][],
307
+ ) {
308
+ if (steps.length !== 3) {
309
+ throw new Error(
310
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}.`,
311
+ );
312
+ }
313
+
314
+ if (steps[1].type !== 'capture') {
315
+ throw new Error(
316
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`,
317
+ );
318
+ }
319
+
320
+ if (steps[2].type !== 'string') {
321
+ throw new Error(
322
+ `Second argument of \`#${operator}\` predicate must be a string. Got @${steps[2].name}.`,
323
+ );
324
+ }
325
+
326
+ const isPositive = operator === 'match?' || operator === 'any-match?';
327
+ const matchAll = !operator.startsWith('any-');
328
+ const captureName = steps[1].name;
329
+ const regex = new RegExp(steps[2].value);
330
+ textPredicates[index].push((captures) => {
331
+ const nodes = [];
332
+ for (const c of captures) {
333
+ if (c.name === captureName) nodes.push(c.node.text);
334
+ }
335
+ const test = (text: string, positive: boolean) => {
336
+ return positive ?
337
+ regex.test(text) :
338
+ !regex.test(text);
339
+ };
340
+ if (nodes.length === 0) return !isPositive;
341
+ return matchAll ?
342
+ nodes.every((text) => test(text, isPositive)) :
343
+ nodes.some((text) => test(text, isPositive));
344
+ });
345
+ }
346
+
347
+ /**
348
+ * Parses the `any-of?` and `not-any-of?` predicates in a query, and updates the text predicates.
349
+ */
350
+ function parseAnyOfPredicate(
351
+ steps: PredicateStep[],
352
+ index: number,
353
+ operator: string,
354
+ textPredicates: TextPredicate[][],
355
+ ) {
356
+ if (steps.length < 2) {
357
+ throw new Error(
358
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${steps.length - 1}.`,
359
+ );
360
+ }
361
+
362
+ if (steps[1].type !== 'capture') {
363
+ throw new Error(
364
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`,
365
+ );
366
+ }
367
+
368
+ const isPositive = operator === 'any-of?';
369
+ const captureName = steps[1].name;
370
+
371
+ const stringSteps = steps.slice(2);
372
+ if (!stringSteps.every(isStringStep)) {
373
+ throw new Error(
374
+ `Arguments to \`#${operator}\` predicate must be strings.".`,
375
+ );
376
+ }
377
+ const values = stringSteps.map((s) => s.value);
378
+
379
+ textPredicates[index].push((captures) => {
380
+ const nodes = [];
381
+ for (const c of captures) {
382
+ if (c.name === captureName) nodes.push(c.node.text);
383
+ }
384
+ if (nodes.length === 0) return !isPositive;
385
+ return nodes.every((text) => values.includes(text)) === isPositive;
386
+ });
387
+ }
388
+
389
+ /**
390
+ * Parses the `is?` and `is-not?` predicates in a query, and updates the asserted or refuted properties,
391
+ * depending on if the operator is positive or negative.
392
+ */
393
+ function parseIsPredicate(
394
+ steps: PredicateStep[],
395
+ index: number,
396
+ operator: string,
397
+ assertedProperties: QueryProperties[],
398
+ refutedProperties: QueryProperties[],
399
+ ) {
400
+ if (steps.length < 2 || steps.length > 3) {
401
+ throw new Error(
402
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`,
403
+ );
404
+ }
405
+
406
+ if (!steps.every(isStringStep)) {
407
+ throw new Error(
408
+ `Arguments to \`#${operator}\` predicate must be strings.".`,
409
+ );
410
+ }
411
+
412
+ const properties = operator === 'is?' ? assertedProperties : refutedProperties;
413
+ if (!properties[index]) properties[index] = {};
414
+ properties[index][steps[1].value] = steps[2]?.value ?? null;
415
+ }
416
+
417
+ /**
418
+ * Parses the `set!` directive in a query, and updates the set properties.
419
+ */
420
+ function parseSetDirective(
421
+ steps: PredicateStep[],
422
+ index: number,
423
+ setProperties: QueryProperties[],
424
+ ) {
425
+ if (steps.length < 2 || steps.length > 3) {
426
+ throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`);
427
+ }
428
+ if (!steps.every(isStringStep)) {
429
+ throw new Error(`Arguments to \`#set!\` predicate must be strings.".`);
430
+ }
431
+ if (!setProperties[index]) setProperties[index] = {};
432
+ setProperties[index][steps[1].value] = steps[2]?.value ?? null;
433
+ }
434
+
435
+ /**
436
+ * Parses the predicate at a given step in a pattern, and updates the appropriate
437
+ * predicates or properties.
438
+ */
439
+ function parsePattern(
440
+ index: number,
441
+ stepType: number,
442
+ stepValueId: number,
443
+ captureNames: string[],
444
+ stringValues: string[],
445
+ steps: PredicateStep[],
446
+ textPredicates: TextPredicate[][],
447
+ predicates: QueryPredicate[][],
448
+ setProperties: QueryProperties[],
449
+ assertedProperties: QueryProperties[],
450
+ refutedProperties: QueryProperties[],
451
+ ) {
452
+ if (stepType === PREDICATE_STEP_TYPE_CAPTURE) {
453
+ const name = captureNames[stepValueId];
454
+ steps.push({ type: 'capture', name });
455
+ } else if (stepType === PREDICATE_STEP_TYPE_STRING) {
456
+ steps.push({ type: 'string', value: stringValues[stepValueId] });
457
+ } else if (steps.length > 0) {
458
+ if (steps[0].type !== 'string') {
459
+ throw new Error('Predicates must begin with a literal value');
460
+ }
461
+
462
+ const operator = steps[0].value;
463
+ switch (operator) {
464
+ case 'any-not-eq?':
465
+ case 'not-eq?':
466
+ case 'any-eq?':
467
+ case 'eq?':
468
+ parseAnyPredicate(steps, index, operator, textPredicates);
469
+ break;
470
+
471
+ case 'any-not-match?':
472
+ case 'not-match?':
473
+ case 'any-match?':
474
+ case 'match?':
475
+ parseMatchPredicate(steps, index, operator, textPredicates);
476
+ break;
477
+
478
+ case 'not-any-of?':
479
+ case 'any-of?':
480
+ parseAnyOfPredicate(steps, index, operator, textPredicates);
481
+ break;
482
+
483
+ case 'is?':
484
+ case 'is-not?':
485
+ parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties);
486
+ break;
487
+
488
+ case 'set!':
489
+ parseSetDirective(steps, index, setProperties);
490
+ break;
491
+
492
+ default:
493
+ predicates[index].push({ operator, operands: steps.slice(1) });
494
+ }
495
+
496
+ steps.length = 0;
497
+ }
498
+ }
499
+
500
+ export class Query {
501
+ /** @internal */
502
+ private [0] = 0; // Internal handle for WASM
503
+
504
+ /** @internal */
505
+ private exceededMatchLimit: boolean;
506
+
507
+ /** @internal */
508
+ private textPredicates: TextPredicate[][];
509
+
510
+ /** The names of the captures used in the query. */
511
+ readonly captureNames: string[];
512
+
513
+ /** The quantifiers of the captures used in the query. */
514
+ readonly captureQuantifiers: CaptureQuantifier[][];
515
+
516
+ /**
517
+ * The other user-defined predicates associated with the given index.
518
+ *
519
+ * This includes predicates with operators other than:
520
+ * - `match?`
521
+ * - `eq?` and `not-eq?`
522
+ * - `any-of?` and `not-any-of?`
523
+ * - `is?` and `is-not?`
524
+ * - `set!`
525
+ */
526
+ readonly predicates: QueryPredicate[][];
527
+
528
+ /** The properties for predicates with the operator `set!`. */
529
+ readonly setProperties: QueryProperties[];
530
+
531
+ /** The properties for predicates with the operator `is?`. */
532
+ readonly assertedProperties: QueryProperties[];
533
+
534
+ /** The properties for predicates with the operator `is-not?`. */
535
+ readonly refutedProperties: QueryProperties[];
536
+
537
+ /** The maximum number of in-progress matches for this cursor. */
538
+ matchLimit?: number;
539
+
540
+ /**
541
+ * Create a new query from a string containing one or more S-expression
542
+ * patterns.
543
+ *
544
+ * The query is associated with a particular language, and can only be run
545
+ * on syntax nodes parsed with that language. References to Queries can be
546
+ * shared between multiple threads.
547
+ *
548
+ * @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
549
+ */
550
+ constructor(language: Language, source: string) {
551
+ const sourceLength = C.lengthBytesUTF8(source);
552
+ const sourceAddress = C._malloc(sourceLength + 1);
553
+ C.stringToUTF8(source, sourceAddress, sourceLength + 1);
554
+ const address = C._ts_query_new(
555
+ language[0],
556
+ sourceAddress,
557
+ sourceLength,
558
+ TRANSFER_BUFFER,
559
+ TRANSFER_BUFFER + SIZE_OF_INT
560
+ );
561
+
562
+ if (!address) {
563
+ const errorId = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32') as QueryErrorKind;
564
+ const errorByte = C.getValue(TRANSFER_BUFFER, 'i32');
565
+ const errorIndex = C.UTF8ToString(sourceAddress, errorByte).length;
566
+ const suffix = source.slice(errorIndex, errorIndex + 100).split('\n')[0];
567
+ const word = suffix.match(QUERY_WORD_REGEX)?.[0] ?? '';
568
+ C._free(sourceAddress);
569
+
570
+ switch (errorId) {
571
+ case QueryErrorKind.Syntax:
572
+ throw new QueryError(QueryErrorKind.Syntax, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
573
+ case QueryErrorKind.NodeName:
574
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
575
+ case QueryErrorKind.FieldName:
576
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
577
+ case QueryErrorKind.CaptureName:
578
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
579
+ case QueryErrorKind.PatternStructure:
580
+ throw new QueryError(errorId, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
581
+ }
582
+ }
583
+
584
+ const stringCount = C._ts_query_string_count(address);
585
+ const captureCount = C._ts_query_capture_count(address);
586
+ const patternCount = C._ts_query_pattern_count(address);
587
+ const captureNames = new Array<string>(captureCount);
588
+ const captureQuantifiers = new Array<CaptureQuantifier[]>(patternCount);
589
+ const stringValues = new Array<string>(stringCount);
590
+
591
+ // Fill in the capture names
592
+ for (let i = 0; i < captureCount; i++) {
593
+ const nameAddress = C._ts_query_capture_name_for_id(
594
+ address,
595
+ i,
596
+ TRANSFER_BUFFER
597
+ );
598
+ const nameLength = C.getValue(TRANSFER_BUFFER, 'i32');
599
+ captureNames[i] = C.UTF8ToString(nameAddress, nameLength);
600
+ }
601
+
602
+ // Fill in the capture quantifiers
603
+ for (let i = 0; i < patternCount; i++) {
604
+ const captureQuantifiersArray = new Array<CaptureQuantifier>(captureCount);
605
+ for (let j = 0; j < captureCount; j++) {
606
+ const quantifier = C._ts_query_capture_quantifier_for_id(address, i, j);
607
+ captureQuantifiersArray[j] = quantifier as CaptureQuantifier;
608
+ }
609
+ captureQuantifiers[i] = captureQuantifiersArray;
610
+ }
611
+
612
+ // Fill in the string values
613
+ for (let i = 0; i < stringCount; i++) {
614
+ const valueAddress = C._ts_query_string_value_for_id(
615
+ address,
616
+ i,
617
+ TRANSFER_BUFFER
618
+ );
619
+ const nameLength = C.getValue(TRANSFER_BUFFER, 'i32');
620
+ stringValues[i] = C.UTF8ToString(valueAddress, nameLength);
621
+ }
622
+
623
+ const setProperties = new Array<QueryProperties>(patternCount);
624
+ const assertedProperties = new Array<QueryProperties>(patternCount);
625
+ const refutedProperties = new Array<QueryProperties>(patternCount);
626
+ const predicates = new Array<QueryPredicate[]>(patternCount);
627
+ const textPredicates = new Array<TextPredicate[]>(patternCount);
628
+
629
+ // Parse the predicates, and add the appropriate predicates or properties
630
+ for (let i = 0; i < patternCount; i++) {
631
+ const predicatesAddress = C._ts_query_predicates_for_pattern(address, i, TRANSFER_BUFFER);
632
+ const stepCount = C.getValue(TRANSFER_BUFFER, 'i32');
633
+
634
+ predicates[i] = [];
635
+ textPredicates[i] = [];
636
+
637
+ const steps = new Array<PredicateStep>();
638
+
639
+ let stepAddress = predicatesAddress;
640
+ for (let j = 0; j < stepCount; j++) {
641
+ const stepType = C.getValue(stepAddress, 'i32');
642
+ stepAddress += SIZE_OF_INT;
643
+
644
+ const stepValueId = C.getValue(stepAddress, 'i32');
645
+ stepAddress += SIZE_OF_INT;
646
+
647
+ parsePattern(
648
+ i,
649
+ stepType,
650
+ stepValueId,
651
+ captureNames,
652
+ stringValues,
653
+ steps,
654
+ textPredicates,
655
+ predicates,
656
+ setProperties,
657
+ assertedProperties,
658
+ refutedProperties,
659
+ );
660
+ }
661
+
662
+ Object.freeze(textPredicates[i]);
663
+ Object.freeze(predicates[i]);
664
+ Object.freeze(setProperties[i]);
665
+ Object.freeze(assertedProperties[i]);
666
+ Object.freeze(refutedProperties[i]);
667
+ }
668
+
669
+ C._free(sourceAddress);
670
+
671
+
672
+ this[0] = address;
673
+ this.captureNames = captureNames;
674
+ this.captureQuantifiers = captureQuantifiers;
675
+ this.textPredicates = textPredicates;
676
+ this.predicates = predicates;
677
+ this.setProperties = setProperties;
678
+ this.assertedProperties = assertedProperties;
679
+ this.refutedProperties = refutedProperties;
680
+ this.exceededMatchLimit = false;
681
+ }
682
+
683
+ /** Delete the query, freeing its resources. */
684
+ delete(): void {
685
+ C._ts_query_delete(this[0]);
686
+ this[0] = 0;
687
+ }
688
+
689
+ /**
690
+ * Iterate over all of the matches in the order that they were found.
691
+ *
692
+ * Each match contains the index of the pattern that matched, and a list of
693
+ * captures. Because multiple patterns can match the same set of nodes,
694
+ * one match may contain captures that appear *before* some of the
695
+ * captures from a previous match.
696
+ *
697
+ * @param {Node} node - The node to execute the query on.
698
+ *
699
+ * @param {QueryOptions} options - Options for query execution.
700
+ */
701
+ matches(
702
+ node: Node,
703
+ options: QueryOptions = {}
704
+ ): QueryMatch[] {
705
+ const startPosition = options.startPosition ?? ZERO_POINT;
706
+ const endPosition = options.endPosition ?? ZERO_POINT;
707
+ const startIndex = options.startIndex ?? 0;
708
+ const endIndex = options.endIndex ?? 0;
709
+ const matchLimit = options.matchLimit ?? 0xFFFFFFFF;
710
+ const maxStartDepth = options.maxStartDepth ?? 0xFFFFFFFF;
711
+ const timeoutMicros = options.timeoutMicros ?? 0;
712
+ const progressCallback = options.progressCallback;
713
+
714
+ if (typeof matchLimit !== 'number') {
715
+ throw new Error('Arguments must be numbers');
716
+ }
717
+ this.matchLimit = matchLimit;
718
+
719
+ if (endIndex !== 0 && startIndex > endIndex) {
720
+ throw new Error('`startIndex` cannot be greater than `endIndex`');
721
+ }
722
+
723
+ if (endPosition !== ZERO_POINT && (
724
+ startPosition.row > endPosition.row ||
725
+ (startPosition.row === endPosition.row && startPosition.column > endPosition.column)
726
+ )) {
727
+ throw new Error('`startPosition` cannot be greater than `endPosition`');
728
+ }
729
+
730
+ if (progressCallback) {
731
+ C.currentQueryProgressCallback = progressCallback;
732
+ }
733
+
734
+ marshalNode(node);
735
+
736
+ C._ts_query_matches_wasm(
737
+ this[0],
738
+ node.tree[0],
739
+ startPosition.row,
740
+ startPosition.column,
741
+ endPosition.row,
742
+ endPosition.column,
743
+ startIndex,
744
+ endIndex,
745
+ matchLimit,
746
+ maxStartDepth,
747
+ timeoutMicros,
748
+ );
749
+
750
+ const rawCount = C.getValue(TRANSFER_BUFFER, 'i32');
751
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
752
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
753
+ const result = new Array<QueryMatch>(rawCount);
754
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
755
+
756
+ let filteredCount = 0;
757
+ let address = startAddress;
758
+ for (let i = 0; i < rawCount; i++) {
759
+ const patternIndex = C.getValue(address, 'i32');
760
+ address += SIZE_OF_INT;
761
+ const captureCount = C.getValue(address, 'i32');
762
+ address += SIZE_OF_INT;
763
+
764
+ const captures = new Array<QueryCapture>(captureCount);
765
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
766
+
767
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
768
+ result[filteredCount] = { pattern: patternIndex, patternIndex, captures };
769
+ const setProperties = this.setProperties[patternIndex];
770
+ result[filteredCount].setProperties = setProperties;
771
+ const assertedProperties = this.assertedProperties[patternIndex];
772
+ result[filteredCount].assertedProperties = assertedProperties;
773
+ const refutedProperties = this.refutedProperties[patternIndex];
774
+ result[filteredCount].refutedProperties = refutedProperties;
775
+ filteredCount++;
776
+ }
777
+ }
778
+ result.length = filteredCount;
779
+
780
+ C._free(startAddress);
781
+ C.currentQueryProgressCallback = null;
782
+ return result;
783
+ }
784
+
785
+ /**
786
+ * Iterate over all of the individual captures in the order that they
787
+ * appear.
788
+ *
789
+ * This is useful if you don't care about which pattern matched, and just
790
+ * want a single, ordered sequence of captures.
791
+ *
792
+ * @param {Node} node - The node to execute the query on.
793
+ *
794
+ * @param {QueryOptions} options - Options for query execution.
795
+ */
796
+ captures(
797
+ node: Node,
798
+ options: QueryOptions = {}
799
+ ): QueryCapture[] {
800
+ const startPosition = options.startPosition ?? ZERO_POINT;
801
+ const endPosition = options.endPosition ?? ZERO_POINT;
802
+ const startIndex = options.startIndex ?? 0;
803
+ const endIndex = options.endIndex ?? 0;
804
+ const matchLimit = options.matchLimit ?? 0xFFFFFFFF;
805
+ const maxStartDepth = options.maxStartDepth ?? 0xFFFFFFFF;
806
+ const timeoutMicros = options.timeoutMicros ?? 0;
807
+ const progressCallback = options.progressCallback;
808
+
809
+ if (typeof matchLimit !== 'number') {
810
+ throw new Error('Arguments must be numbers');
811
+ }
812
+ this.matchLimit = matchLimit;
813
+
814
+ if (endIndex !== 0 && startIndex > endIndex) {
815
+ throw new Error('`startIndex` cannot be greater than `endIndex`');
816
+ }
817
+
818
+ if (endPosition !== ZERO_POINT && (
819
+ startPosition.row > endPosition.row ||
820
+ (startPosition.row === endPosition.row && startPosition.column > endPosition.column)
821
+ )) {
822
+ throw new Error('`startPosition` cannot be greater than `endPosition`');
823
+ }
824
+
825
+ if (progressCallback) {
826
+ C.currentQueryProgressCallback = progressCallback;
827
+ }
828
+
829
+ marshalNode(node);
830
+
831
+ C._ts_query_captures_wasm(
832
+ this[0],
833
+ node.tree[0],
834
+ startPosition.row,
835
+ startPosition.column,
836
+ endPosition.row,
837
+ endPosition.column,
838
+ startIndex,
839
+ endIndex,
840
+ matchLimit,
841
+ maxStartDepth,
842
+ timeoutMicros,
843
+ );
844
+
845
+ const count = C.getValue(TRANSFER_BUFFER, 'i32');
846
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
847
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
848
+ const result = new Array<QueryCapture>();
849
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
850
+
851
+ const captures = new Array<QueryCapture>();
852
+ let address = startAddress;
853
+ for (let i = 0; i < count; i++) {
854
+ const patternIndex = C.getValue(address, 'i32');
855
+ address += SIZE_OF_INT;
856
+ const captureCount = C.getValue(address, 'i32');
857
+ address += SIZE_OF_INT;
858
+ const captureIndex = C.getValue(address, 'i32');
859
+ address += SIZE_OF_INT;
860
+
861
+ captures.length = captureCount;
862
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
863
+
864
+ if (this.textPredicates[patternIndex].every(p => p(captures))) {
865
+ const capture = captures[captureIndex];
866
+ const setProperties = this.setProperties[patternIndex];
867
+ capture.setProperties = setProperties;
868
+ const assertedProperties = this.assertedProperties[patternIndex];
869
+ capture.assertedProperties = assertedProperties;
870
+ const refutedProperties = this.refutedProperties[patternIndex];
871
+ capture.refutedProperties = refutedProperties;
872
+ result.push(capture);
873
+ }
874
+ }
875
+
876
+ C._free(startAddress);
877
+ C.currentQueryProgressCallback = null;
878
+ return result;
879
+ }
880
+
881
+ /** Get the predicates for a given pattern. */
882
+ predicatesForPattern(patternIndex: number): QueryPredicate[] {
883
+ return this.predicates[patternIndex];
884
+ }
885
+
886
+ /**
887
+ * Disable a certain capture within a query.
888
+ *
889
+ * This prevents the capture from being returned in matches, and also
890
+ * avoids any resource usage associated with recording the capture.
891
+ */
892
+ disableCapture(captureName: string): void {
893
+ const captureNameLength = C.lengthBytesUTF8(captureName);
894
+ const captureNameAddress = C._malloc(captureNameLength + 1);
895
+ C.stringToUTF8(captureName, captureNameAddress, captureNameLength + 1);
896
+ C._ts_query_disable_capture(this[0], captureNameAddress, captureNameLength);
897
+ C._free(captureNameAddress);
898
+ }
899
+
900
+ /**
901
+ * Disable a certain pattern within a query.
902
+ *
903
+ * This prevents the pattern from matching, and also avoids any resource
904
+ * usage associated with the pattern. This throws an error if the pattern
905
+ * index is out of bounds.
906
+ */
907
+ disablePattern(patternIndex: number): void {
908
+ if (patternIndex >= this.predicates.length) {
909
+ throw new Error(
910
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
911
+ );
912
+ }
913
+ C._ts_query_disable_pattern(this[0], patternIndex);
914
+ }
915
+
916
+ /**
917
+ * Check if, on its last execution, this cursor exceeded its maximum number
918
+ * of in-progress matches.
919
+ */
920
+ didExceedMatchLimit(): boolean {
921
+ return this.exceededMatchLimit;
922
+ }
923
+
924
+ /** Get the byte offset where the given pattern starts in the query's source. */
925
+ startIndexForPattern(patternIndex: number): number {
926
+ if (patternIndex >= this.predicates.length) {
927
+ throw new Error(
928
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
929
+ );
930
+ }
931
+ return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
932
+ }
933
+
934
+ /** Get the byte offset where the given pattern ends in the query's source. */
935
+ endIndexForPattern(patternIndex: number): number {
936
+ if (patternIndex >= this.predicates.length) {
937
+ throw new Error(
938
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
939
+ );
940
+ }
941
+ return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
942
+ }
943
+
944
+ /** Get the number of patterns in the query. */
945
+ patternCount(): number {
946
+ return C._ts_query_pattern_count(this[0]);
947
+ }
948
+
949
+ /** Get the index for a given capture name. */
950
+ captureIndexForName(captureName: string): number {
951
+ return this.captureNames.indexOf(captureName);
952
+ }
953
+
954
+ /** Check if a given pattern within a query has a single root node. */
955
+ isPatternRooted(patternIndex: number): boolean {
956
+ return C._ts_query_is_pattern_rooted(this[0], patternIndex) === 1;
957
+ }
958
+
959
+ /** Check if a given pattern within a query has a single root node. */
960
+ isPatternNonLocal(patternIndex: number): boolean {
961
+ return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
962
+ }
963
+
964
+ /**
965
+ * Check if a given step in a query is 'definite'.
966
+ *
967
+ * A query step is 'definite' if its parent pattern will be guaranteed to
968
+ * match successfully once it reaches the step.
969
+ */
970
+ isPatternGuaranteedAtStep(byteIndex: number): boolean {
971
+ return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
972
+ }
973
+ }