@samchon/graph 0.1.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 (391) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/lib/AsyncSamchonGraphSource.d.ts +2 -0
  4. package/lib/AsyncSamchonGraphSource.js +3 -0
  5. package/lib/AsyncSamchonGraphSource.js.map +1 -0
  6. package/lib/SamchonGraphApplication.d.ts +10 -0
  7. package/lib/SamchonGraphApplication.js +64 -0
  8. package/lib/SamchonGraphApplication.js.map +1 -0
  9. package/lib/SamchonGraphSource.d.ts +2 -0
  10. package/lib/SamchonGraphSource.js +3 -0
  11. package/lib/SamchonGraphSource.js.map +1 -0
  12. package/lib/application.d.ts +3 -0
  13. package/lib/application.js +20 -0
  14. package/lib/application.js.map +1 -0
  15. package/lib/bin.d.ts +2 -0
  16. package/lib/bin.js +8 -0
  17. package/lib/bin.js.map +1 -0
  18. package/lib/index.d.ts +13 -0
  19. package/lib/index.js +30 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/indexer/IBuildGraphOptions.d.ts +41 -0
  22. package/lib/indexer/IBuildGraphOptions.js +3 -0
  23. package/lib/indexer/IBuildGraphOptions.js.map +1 -0
  24. package/lib/indexer/IIndexerResult.d.ts +5 -0
  25. package/lib/indexer/IIndexerResult.js +3 -0
  26. package/lib/indexer/IIndexerResult.js.map +1 -0
  27. package/lib/indexer/ILanguageSpec.d.ts +10 -0
  28. package/lib/indexer/ILanguageSpec.js +3 -0
  29. package/lib/indexer/ILanguageSpec.js.map +1 -0
  30. package/lib/indexer/LANGUAGE_SPECS.d.ts +2 -0
  31. package/lib/indexer/LANGUAGE_SPECS.js +114 -0
  32. package/lib/indexer/LANGUAGE_SPECS.js.map +1 -0
  33. package/lib/indexer/allExtensions.d.ts +2 -0
  34. package/lib/indexer/allExtensions.js +16 -0
  35. package/lib/indexer/allExtensions.js.map +1 -0
  36. package/lib/indexer/buildGraph.d.ts +3 -0
  37. package/lib/indexer/buildGraph.js +10 -0
  38. package/lib/indexer/buildGraph.js.map +1 -0
  39. package/lib/indexer/buildGraphDump.d.ts +3 -0
  40. package/lib/indexer/buildGraphDump.js +394 -0
  41. package/lib/indexer/buildGraphDump.js.map +1 -0
  42. package/lib/indexer/buildLspGraph.d.ts +3 -0
  43. package/lib/indexer/buildLspGraph.js +617 -0
  44. package/lib/indexer/buildLspGraph.js.map +1 -0
  45. package/lib/indexer/buildStaticGraph.d.ts +3 -0
  46. package/lib/indexer/buildStaticGraph.js +479 -0
  47. package/lib/indexer/buildStaticGraph.js.map +1 -0
  48. package/lib/indexer/decoratorsAbove.d.ts +1 -0
  49. package/lib/indexer/decoratorsAbove.js +14 -0
  50. package/lib/indexer/decoratorsAbove.js.map +1 -0
  51. package/lib/indexer/languageOf.d.ts +2 -0
  52. package/lib/indexer/languageOf.js +19 -0
  53. package/lib/indexer/languageOf.js.map +1 -0
  54. package/lib/indexer/languages.d.ts +5 -0
  55. package/lib/indexer/languages.js +22 -0
  56. package/lib/indexer/languages.js.map +1 -0
  57. package/lib/indexer/lspIndexer.d.ts +1 -0
  58. package/lib/indexer/lspIndexer.js +18 -0
  59. package/lib/indexer/lspIndexer.js.map +1 -0
  60. package/lib/indexer/overrideEdges.d.ts +2 -0
  61. package/lib/indexer/overrideEdges.js +45 -0
  62. package/lib/indexer/overrideEdges.js.map +1 -0
  63. package/lib/indexer/resolveType.d.ts +2 -0
  64. package/lib/indexer/resolveType.js +11 -0
  65. package/lib/indexer/resolveType.js.map +1 -0
  66. package/lib/indexer/specOf.d.ts +3 -0
  67. package/lib/indexer/specOf.js +8 -0
  68. package/lib/indexer/specOf.js.map +1 -0
  69. package/lib/indexer/staticIndexer.d.ts +1 -0
  70. package/lib/indexer/staticIndexer.js +18 -0
  71. package/lib/indexer/staticIndexer.js.map +1 -0
  72. package/lib/indexer/supertypesOf.d.ts +4 -0
  73. package/lib/indexer/supertypesOf.js +48 -0
  74. package/lib/indexer/supertypesOf.js.map +1 -0
  75. package/lib/lsp/DocumentSymbolResult.d.ts +3 -0
  76. package/lib/lsp/DocumentSymbolResult.js +3 -0
  77. package/lib/lsp/DocumentSymbolResult.js.map +1 -0
  78. package/lib/lsp/IDiagnostic.d.ts +8 -0
  79. package/lib/lsp/IDiagnostic.js +3 -0
  80. package/lib/lsp/IDiagnostic.js.map +1 -0
  81. package/lib/lsp/IDocumentSymbol.d.ts +9 -0
  82. package/lib/lsp/IDocumentSymbol.js +3 -0
  83. package/lib/lsp/IDocumentSymbol.js.map +1 -0
  84. package/lib/lsp/ILocation.d.ts +5 -0
  85. package/lib/lsp/ILocation.js +3 -0
  86. package/lib/lsp/ILocation.js.map +1 -0
  87. package/lib/lsp/IPosition.d.ts +4 -0
  88. package/lib/lsp/IPosition.js +3 -0
  89. package/lib/lsp/IPosition.js.map +1 -0
  90. package/lib/lsp/IRange.d.ts +5 -0
  91. package/lib/lsp/IRange.js +3 -0
  92. package/lib/lsp/IRange.js.map +1 -0
  93. package/lib/lsp/ISymbolInformation.d.ts +7 -0
  94. package/lib/lsp/ISymbolInformation.js +3 -0
  95. package/lib/lsp/ISymbolInformation.js.map +1 -0
  96. package/lib/lsp/LspClient.d.ts +17 -0
  97. package/lib/lsp/LspClient.js +140 -0
  98. package/lib/lsp/LspClient.js.map +1 -0
  99. package/lib/lsp/isDocumentSymbol.d.ts +3 -0
  100. package/lib/lsp/isDocumentSymbol.js +7 -0
  101. package/lib/lsp/isDocumentSymbol.js.map +1 -0
  102. package/lib/lsp/types.d.ts +8 -0
  103. package/lib/lsp/types.js +25 -0
  104. package/lib/lsp/types.js.map +1 -0
  105. package/lib/mcp/createServer.d.ts +3 -0
  106. package/lib/mcp/createServer.js +1947 -0
  107. package/lib/mcp/createServer.js.map +1 -0
  108. package/lib/mcp/startServer.d.ts +5 -0
  109. package/lib/mcp/startServer.js +23 -0
  110. package/lib/mcp/startServer.js.map +1 -0
  111. package/lib/model/GraphMemory.d.ts +25 -0
  112. package/lib/model/GraphMemory.js +141 -0
  113. package/lib/model/GraphMemory.js.map +1 -0
  114. package/lib/operations/bound.d.ts +1 -0
  115. package/lib/operations/bound.js +8 -0
  116. package/lib/operations/bound.js.map +1 -0
  117. package/lib/operations/common.d.ts +15 -0
  118. package/lib/operations/common.js +32 -0
  119. package/lib/operations/common.js.map +1 -0
  120. package/lib/operations/compareEdges.d.ts +2 -0
  121. package/lib/operations/compareEdges.js +10 -0
  122. package/lib/operations/compareEdges.js.map +1 -0
  123. package/lib/operations/edgeRank.d.ts +1 -0
  124. package/lib/operations/edgeRank.js +25 -0
  125. package/lib/operations/edgeRank.js.map +1 -0
  126. package/lib/operations/isExecution.d.ts +1 -0
  127. package/lib/operations/isExecution.js +11 -0
  128. package/lib/operations/isExecution.js.map +1 -0
  129. package/lib/operations/isPublicApiNoisePath.d.ts +2 -0
  130. package/lib/operations/isPublicApiNoisePath.js +11 -0
  131. package/lib/operations/isPublicApiNoisePath.js.map +1 -0
  132. package/lib/operations/isStructural.d.ts +1 -0
  133. package/lib/operations/isStructural.js +7 -0
  134. package/lib/operations/isStructural.js.map +1 -0
  135. package/lib/operations/isSupportPath.d.ts +2 -0
  136. package/lib/operations/isSupportPath.js +16 -0
  137. package/lib/operations/isSupportPath.js.map +1 -0
  138. package/lib/operations/isTestPath.d.ts +1 -0
  139. package/lib/operations/isTestPath.js +9 -0
  140. package/lib/operations/isTestPath.js.map +1 -0
  141. package/lib/operations/isTypeEdge.d.ts +1 -0
  142. package/lib/operations/isTypeEdge.js +11 -0
  143. package/lib/operations/isTypeEdge.js.map +1 -0
  144. package/lib/operations/publicEvidence.d.ts +2 -0
  145. package/lib/operations/publicEvidence.js +13 -0
  146. package/lib/operations/publicEvidence.js.map +1 -0
  147. package/lib/operations/referencesFromEdges.d.ts +3 -0
  148. package/lib/operations/referencesFromEdges.js +38 -0
  149. package/lib/operations/referencesFromEdges.js.map +1 -0
  150. package/lib/operations/resolveHandle.d.ts +6 -0
  151. package/lib/operations/resolveHandle.js +28 -0
  152. package/lib/operations/resolveHandle.js.map +1 -0
  153. package/lib/operations/resultGuide.d.ts +1 -0
  154. package/lib/operations/resultGuide.js +7 -0
  155. package/lib/operations/resultGuide.js.map +1 -0
  156. package/lib/operations/resultNext.d.ts +2 -0
  157. package/lib/operations/resultNext.js +7 -0
  158. package/lib/operations/resultNext.js.map +1 -0
  159. package/lib/operations/runDetails.d.ts +8 -0
  160. package/lib/operations/runDetails.js +190 -0
  161. package/lib/operations/runDetails.js.map +1 -0
  162. package/lib/operations/runEntrypoints.d.ts +9 -0
  163. package/lib/operations/runEntrypoints.js +122 -0
  164. package/lib/operations/runEntrypoints.js.map +1 -0
  165. package/lib/operations/runLookup.d.ts +10 -0
  166. package/lib/operations/runLookup.js +229 -0
  167. package/lib/operations/runLookup.js.map +1 -0
  168. package/lib/operations/runOverview.d.ts +10 -0
  169. package/lib/operations/runOverview.js +142 -0
  170. package/lib/operations/runOverview.js.map +1 -0
  171. package/lib/operations/runTour.d.ts +8 -0
  172. package/lib/operations/runTour.js +539 -0
  173. package/lib/operations/runTour.js.map +1 -0
  174. package/lib/operations/runTrace.d.ts +10 -0
  175. package/lib/operations/runTrace.js +283 -0
  176. package/lib/operations/runTrace.js.map +1 -0
  177. package/lib/operations/signatureOf.d.ts +2 -0
  178. package/lib/operations/signatureOf.js +45 -0
  179. package/lib/operations/signatureOf.js.map +1 -0
  180. package/lib/operations/subwords.d.ts +1 -0
  181. package/lib/operations/subwords.js +12 -0
  182. package/lib/operations/subwords.js.map +1 -0
  183. package/lib/operations/summaryOf.d.ts +2 -0
  184. package/lib/operations/summaryOf.js +24 -0
  185. package/lib/operations/summaryOf.js.map +1 -0
  186. package/lib/runGraph.d.ts +1 -0
  187. package/lib/runGraph.js +165 -0
  188. package/lib/runGraph.js.map +1 -0
  189. package/lib/structures/GraphEdgeKind.d.ts +10 -0
  190. package/lib/structures/GraphEdgeKind.js +3 -0
  191. package/lib/structures/GraphEdgeKind.js.map +1 -0
  192. package/lib/structures/GraphLanguage.d.ts +2 -0
  193. package/lib/structures/GraphLanguage.js +3 -0
  194. package/lib/structures/GraphLanguage.js.map +1 -0
  195. package/lib/structures/GraphNodeKind.d.ts +11 -0
  196. package/lib/structures/GraphNodeKind.js +3 -0
  197. package/lib/structures/GraphNodeKind.js.map +1 -0
  198. package/lib/structures/IGraphDecorator.d.ts +22 -0
  199. package/lib/structures/IGraphDecorator.js +3 -0
  200. package/lib/structures/IGraphDecorator.js.map +1 -0
  201. package/lib/structures/IGraphDetails.d.ts +126 -0
  202. package/lib/structures/IGraphDetails.js +3 -0
  203. package/lib/structures/IGraphDetails.js.map +1 -0
  204. package/lib/structures/IGraphDiagnostic.d.ts +23 -0
  205. package/lib/structures/IGraphDiagnostic.js +3 -0
  206. package/lib/structures/IGraphDiagnostic.js.map +1 -0
  207. package/lib/structures/IGraphDump.d.ts +37 -0
  208. package/lib/structures/IGraphDump.js +3 -0
  209. package/lib/structures/IGraphDump.js.map +1 -0
  210. package/lib/structures/IGraphEdge.d.ts +20 -0
  211. package/lib/structures/IGraphEdge.js +3 -0
  212. package/lib/structures/IGraphEdge.js.map +1 -0
  213. package/lib/structures/IGraphEntrypoints.d.ts +57 -0
  214. package/lib/structures/IGraphEntrypoints.js +3 -0
  215. package/lib/structures/IGraphEntrypoints.js.map +1 -0
  216. package/lib/structures/IGraphEscape.d.ts +40 -0
  217. package/lib/structures/IGraphEscape.js +3 -0
  218. package/lib/structures/IGraphEscape.js.map +1 -0
  219. package/lib/structures/IGraphEvidence.d.ts +24 -0
  220. package/lib/structures/IGraphEvidence.js +3 -0
  221. package/lib/structures/IGraphEvidence.js.map +1 -0
  222. package/lib/structures/IGraphLookup.d.ts +66 -0
  223. package/lib/structures/IGraphLookup.js +3 -0
  224. package/lib/structures/IGraphLookup.js.map +1 -0
  225. package/lib/structures/IGraphNext.d.ts +15 -0
  226. package/lib/structures/IGraphNext.js +3 -0
  227. package/lib/structures/IGraphNext.js.map +1 -0
  228. package/lib/structures/IGraphNode.d.ts +62 -0
  229. package/lib/structures/IGraphNode.js +3 -0
  230. package/lib/structures/IGraphNode.js.map +1 -0
  231. package/lib/structures/IGraphOverview.d.ts +100 -0
  232. package/lib/structures/IGraphOverview.js +3 -0
  233. package/lib/structures/IGraphOverview.js.map +1 -0
  234. package/lib/structures/IGraphTour.d.ts +54 -0
  235. package/lib/structures/IGraphTour.js +3 -0
  236. package/lib/structures/IGraphTour.js.map +1 -0
  237. package/lib/structures/IGraphTrace.d.ts +126 -0
  238. package/lib/structures/IGraphTrace.js +3 -0
  239. package/lib/structures/IGraphTrace.js.map +1 -0
  240. package/lib/structures/ISamchonGraphApplication.d.ts +162 -0
  241. package/lib/structures/ISamchonGraphApplication.js +3 -0
  242. package/lib/structures/ISamchonGraphApplication.js.map +1 -0
  243. package/lib/structures/index.d.ts +18 -0
  244. package/lib/structures/index.js +35 -0
  245. package/lib/structures/index.js.map +1 -0
  246. package/lib/structures.d.ts +1 -0
  247. package/lib/structures.js +18 -0
  248. package/lib/structures.js.map +1 -0
  249. package/lib/utils/DEFAULT_IGNORES.d.ts +1 -0
  250. package/lib/utils/DEFAULT_IGNORES.js +39 -0
  251. package/lib/utils/DEFAULT_IGNORES.js.map +1 -0
  252. package/lib/utils/IWalkOptions.d.ts +5 -0
  253. package/lib/utils/IWalkOptions.js +3 -0
  254. package/lib/utils/IWalkOptions.js.map +1 -0
  255. package/lib/utils/basename.d.ts +1 -0
  256. package/lib/utils/basename.js +10 -0
  257. package/lib/utils/basename.js.map +1 -0
  258. package/lib/utils/dirname.d.ts +1 -0
  259. package/lib/utils/dirname.js +10 -0
  260. package/lib/utils/dirname.js.map +1 -0
  261. package/lib/utils/fileFromUri.d.ts +1 -0
  262. package/lib/utils/fileFromUri.js +20 -0
  263. package/lib/utils/fileFromUri.js.map +1 -0
  264. package/lib/utils/fileUri.d.ts +1 -0
  265. package/lib/utils/fileUri.js +19 -0
  266. package/lib/utils/fileUri.js.map +1 -0
  267. package/lib/utils/fs.d.ts +6 -0
  268. package/lib/utils/fs.js +23 -0
  269. package/lib/utils/fs.js.map +1 -0
  270. package/lib/utils/isSubPath.d.ts +1 -0
  271. package/lib/utils/isSubPath.js +15 -0
  272. package/lib/utils/isSubPath.js.map +1 -0
  273. package/lib/utils/normalizePath.d.ts +1 -0
  274. package/lib/utils/normalizePath.js +7 -0
  275. package/lib/utils/normalizePath.js.map +1 -0
  276. package/lib/utils/path.d.ts +7 -0
  277. package/lib/utils/path.js +24 -0
  278. package/lib/utils/path.js.map +1 -0
  279. package/lib/utils/projectRelative.d.ts +1 -0
  280. package/lib/utils/projectRelative.js +9 -0
  281. package/lib/utils/projectRelative.js.map +1 -0
  282. package/lib/utils/readLines.d.ts +1 -0
  283. package/lib/utils/readLines.js +8 -0
  284. package/lib/utils/readLines.js.map +1 -0
  285. package/lib/utils/readText.d.ts +1 -0
  286. package/lib/utils/readText.js +17 -0
  287. package/lib/utils/readText.js.map +1 -0
  288. package/lib/utils/relativePath.d.ts +1 -0
  289. package/lib/utils/relativePath.js +12 -0
  290. package/lib/utils/relativePath.js.map +1 -0
  291. package/lib/utils/walkSourceFiles.d.ts +2 -0
  292. package/lib/utils/walkSourceFiles.js +44 -0
  293. package/lib/utils/walkSourceFiles.js.map +1 -0
  294. package/package.json +55 -0
  295. package/src/AsyncSamchonGraphSource.ts +5 -0
  296. package/src/SamchonGraphApplication.ts +74 -0
  297. package/src/SamchonGraphSource.ts +3 -0
  298. package/src/application.ts +3 -0
  299. package/src/bin.ts +6 -0
  300. package/src/index.ts +13 -0
  301. package/src/indexer/IBuildGraphOptions.ts +42 -0
  302. package/src/indexer/IIndexerResult.ts +6 -0
  303. package/src/indexer/ILanguageSpec.ts +11 -0
  304. package/src/indexer/LANGUAGE_SPECS.ts +112 -0
  305. package/src/indexer/allExtensions.ts +12 -0
  306. package/src/indexer/buildGraph.ts +10 -0
  307. package/src/indexer/buildGraphDump.ts +29 -0
  308. package/src/indexer/buildLspGraph.ts +710 -0
  309. package/src/indexer/buildStaticGraph.ts +507 -0
  310. package/src/indexer/decoratorsAbove.ts +9 -0
  311. package/src/indexer/languageOf.ts +13 -0
  312. package/src/indexer/languages.ts +5 -0
  313. package/src/indexer/lspIndexer.ts +1 -0
  314. package/src/indexer/overrideEdges.ts +42 -0
  315. package/src/indexer/resolveType.ts +14 -0
  316. package/src/indexer/specOf.ts +7 -0
  317. package/src/indexer/staticIndexer.ts +1 -0
  318. package/src/indexer/supertypesOf.ts +43 -0
  319. package/src/lsp/DocumentSymbolResult.ts +4 -0
  320. package/src/lsp/IDiagnostic.ts +9 -0
  321. package/src/lsp/IDocumentSymbol.ts +10 -0
  322. package/src/lsp/ILocation.ts +6 -0
  323. package/src/lsp/IPosition.ts +4 -0
  324. package/src/lsp/IRange.ts +6 -0
  325. package/src/lsp/ISymbolInformation.ts +8 -0
  326. package/src/lsp/LspClient.ts +165 -0
  327. package/src/lsp/isDocumentSymbol.ts +8 -0
  328. package/src/lsp/types.ts +8 -0
  329. package/src/mcp/createServer.ts +23 -0
  330. package/src/mcp/startServer.ts +23 -0
  331. package/src/model/GraphMemory.ts +165 -0
  332. package/src/operations/bound.ts +9 -0
  333. package/src/operations/common.ts +15 -0
  334. package/src/operations/compareEdges.ts +10 -0
  335. package/src/operations/edgeRank.ts +23 -0
  336. package/src/operations/isExecution.ts +9 -0
  337. package/src/operations/isPublicApiNoisePath.ts +10 -0
  338. package/src/operations/isStructural.ts +3 -0
  339. package/src/operations/isSupportPath.ts +16 -0
  340. package/src/operations/isTestPath.ts +7 -0
  341. package/src/operations/isTypeEdge.ts +9 -0
  342. package/src/operations/publicEvidence.ts +11 -0
  343. package/src/operations/referencesFromEdges.ts +37 -0
  344. package/src/operations/resolveHandle.ts +27 -0
  345. package/src/operations/resultGuide.ts +3 -0
  346. package/src/operations/resultNext.ts +9 -0
  347. package/src/operations/runDetails.ts +240 -0
  348. package/src/operations/runEntrypoints.ts +153 -0
  349. package/src/operations/runLookup.ts +269 -0
  350. package/src/operations/runOverview.ts +158 -0
  351. package/src/operations/runTour.ts +582 -0
  352. package/src/operations/runTrace.ts +339 -0
  353. package/src/operations/signatureOf.ts +40 -0
  354. package/src/operations/subwords.ts +8 -0
  355. package/src/operations/summaryOf.ts +21 -0
  356. package/src/runGraph.ts +144 -0
  357. package/src/structures/GraphEdgeKind.ts +24 -0
  358. package/src/structures/GraphLanguage.ts +21 -0
  359. package/src/structures/GraphNodeKind.ts +27 -0
  360. package/src/structures/IGraphDecorator.ts +25 -0
  361. package/src/structures/IGraphDetails.ts +153 -0
  362. package/src/structures/IGraphDiagnostic.ts +29 -0
  363. package/src/structures/IGraphDump.ts +45 -0
  364. package/src/structures/IGraphEdge.ts +24 -0
  365. package/src/structures/IGraphEntrypoints.ts +70 -0
  366. package/src/structures/IGraphEscape.ts +49 -0
  367. package/src/structures/IGraphEvidence.ts +29 -0
  368. package/src/structures/IGraphLookup.ts +80 -0
  369. package/src/structures/IGraphNext.ts +23 -0
  370. package/src/structures/IGraphNode.ts +76 -0
  371. package/src/structures/IGraphOverview.ts +121 -0
  372. package/src/structures/IGraphTour.ts +68 -0
  373. package/src/structures/IGraphTrace.ts +154 -0
  374. package/src/structures/ISamchonGraphApplication.ts +186 -0
  375. package/src/structures/index.ts +18 -0
  376. package/src/structures.ts +1 -0
  377. package/src/utils/DEFAULT_IGNORES.ts +35 -0
  378. package/src/utils/IWalkOptions.ts +5 -0
  379. package/src/utils/basename.ts +7 -0
  380. package/src/utils/dirname.ts +7 -0
  381. package/src/utils/fileFromUri.ts +14 -0
  382. package/src/utils/fileUri.ts +13 -0
  383. package/src/utils/fs.ts +6 -0
  384. package/src/utils/isSubPath.ts +9 -0
  385. package/src/utils/normalizePath.ts +3 -0
  386. package/src/utils/path.ts +7 -0
  387. package/src/utils/projectRelative.ts +6 -0
  388. package/src/utils/readLines.ts +5 -0
  389. package/src/utils/readText.ts +10 -0
  390. package/src/utils/relativePath.ts +7 -0
  391. package/src/utils/walkSourceFiles.ts +35 -0
@@ -0,0 +1,507 @@
1
+ import path from "node:path";
2
+
3
+ import {
4
+ GraphEdgeKind,
5
+ GraphLanguage,
6
+ GraphNodeKind,
7
+ IGraphDump,
8
+ IGraphEdge,
9
+ IGraphEvidence,
10
+ IGraphNode,
11
+ } from "../structures";
12
+ import { projectRelative, readLines, walkSourceFiles } from "../utils/fs";
13
+ import { allExtensions, languageOf } from "./languages";
14
+ import { IBuildGraphOptions } from "./IBuildGraphOptions";
15
+ import { decoratorsAbove } from "./decoratorsAbove";
16
+ import { overrideEdges } from "./overrideEdges";
17
+ import { resolveType } from "./resolveType";
18
+ import { supertypesOf } from "./supertypesOf";
19
+
20
+ interface IDeclaration {
21
+ node: IGraphNode;
22
+ startIndex: number;
23
+ endIndex: number;
24
+ ownerId?: string;
25
+ }
26
+
27
+ const EXTERNAL_MODULE_LIMIT = 1_500;
28
+
29
+ export function buildStaticGraph(options: IBuildGraphOptions = {}): IGraphDump {
30
+ const root = path.resolve(options.cwd ?? process.cwd());
31
+ const files = walkSourceFiles(root, {
32
+ extensions: allExtensions(options.languages),
33
+ maxFiles: options.maxFiles,
34
+ });
35
+ const nodes: IGraphNode[] = [];
36
+ const edges: IGraphEdge[] = [];
37
+ const declarationsByFile = new Map<string, IDeclaration[]>();
38
+ const byName = new Map<string, IGraphNode[]>();
39
+ const externalNodes = new Map<string, IGraphNode>();
40
+ const warnings: string[] = [];
41
+
42
+ for (const file of files) {
43
+ const lines = readLines(file);
44
+ /* c8 ignore next */
45
+ if (lines === undefined) continue;
46
+ const rel = projectRelative(root, file);
47
+ const language = languageOf(file);
48
+ const declarations = declarationsOf(rel, language, lines);
49
+ declarationsByFile.set(rel, declarations);
50
+ for (const declaration of declarations) {
51
+ nodes.push(declaration.node);
52
+ push(byName, declaration.node.name, declaration.node);
53
+ if (declaration.ownerId !== undefined) {
54
+ edges.push({
55
+ from: declaration.ownerId,
56
+ to: declaration.node.id,
57
+ kind: "contains",
58
+ evidence: declaration.node.evidence,
59
+ });
60
+ }
61
+ }
62
+ for (const imported of importsOf(rel, language, lines)) {
63
+ if (externalNodes.size >= EXTERNAL_MODULE_LIMIT) continue;
64
+ const external = externalNode(language, imported, externalNodes);
65
+ nodes.push(external);
66
+ edges.push({
67
+ from: rel,
68
+ to: external.id,
69
+ kind: "imports",
70
+ evidence: imported.evidence,
71
+ });
72
+ }
73
+ }
74
+
75
+ for (const [rel, declarations] of declarationsByFile) {
76
+ const abs = path.join(root, rel);
77
+ const lines = readLines(abs);
78
+ /* c8 ignore next */
79
+ if (lines === undefined) continue;
80
+ // Index children by owner once per file instead of re-filtering every
81
+ // declaration against every other (which is quadratic in a large file).
82
+ const childrenByOwner = new Map<string, typeof declarations>();
83
+ for (const child of declarations) {
84
+ if (child.ownerId === undefined) continue;
85
+ push(childrenByOwner, child.ownerId, child);
86
+ }
87
+ for (const declaration of declarations) {
88
+ // Scan only the lines that belong to this declaration itself: lines inside
89
+ // nested declarations are attributed to those declarations, and their
90
+ // signature lines are definitions, not calls. Without this exclusion a
91
+ // class "calls" every method it merely defines, and every call inside a
92
+ // method body is double-attributed to the class.
93
+ const nested = childrenByOwner.get(declaration.node.id) ?? [];
94
+ const body = lines
95
+ .slice(declaration.startIndex, Math.max(declaration.startIndex + 1, declaration.endIndex + 1))
96
+ .filter((_, offset) => {
97
+ const index = declaration.startIndex + offset;
98
+ return !nested.some((child) => index >= child.startIndex && index <= child.endIndex);
99
+ })
100
+ .join("\n");
101
+ for (const edge of dependencyEdges(declaration.node, body, byName)) {
102
+ edges.push(edge);
103
+ }
104
+ for (const edge of inheritanceEdges(declaration.node, byName)) {
105
+ edges.push(edge);
106
+ }
107
+ for (const name of decoratorsAbove(lines, declaration.startIndex)) {
108
+ const target = resolveType(name, declaration.node, byName);
109
+ if (target === undefined) continue;
110
+ edges.push({
111
+ from: declaration.node.id,
112
+ to: target.id,
113
+ kind: "decorates",
114
+ evidence: declaration.node.evidence,
115
+ });
116
+ }
117
+ }
118
+ }
119
+
120
+ edges.push(...overrideEdges(nodes, edges));
121
+
122
+ if (files.length === 0) {
123
+ warnings.push("No supported source files were found.");
124
+ }
125
+
126
+ return {
127
+ project: root,
128
+ languages: [...new Set(files.map(languageOf))],
129
+ generatedAt: new Date().toISOString(),
130
+ indexer: "static",
131
+ nodes: dedupeNodes(nodes),
132
+ edges: dedupeEdges(edges),
133
+ warnings,
134
+ };
135
+ }
136
+
137
+ function declarationsOf(
138
+ file: string,
139
+ language: GraphLanguage,
140
+ lines: readonly string[],
141
+ ): IDeclaration[] {
142
+ const declarations: IDeclaration[] = [];
143
+ const ownerStack: Array<{ name: string; endIndex: number; id: string; kind: GraphNodeKind }> = [];
144
+ for (let i = 0; i < lines.length; i++) {
145
+ const line = lines[i]!;
146
+ while (ownerStack.length > 0 && i > ownerStack[ownerStack.length - 1]!.endIndex) {
147
+ ownerStack.pop();
148
+ }
149
+ // Methods are only declared directly inside a type container. Detecting them
150
+ // inside a function/method body turns bare call statements (`doThing(x)`
151
+ // with no trailing `;`, as in Go and ASI JS/TS) into phantom method nodes.
152
+ const parsed = parseDeclaration(language, line, isTypeContainer(ownerStack[ownerStack.length - 1]?.kind));
153
+ if (parsed !== undefined) {
154
+ const endIndex = declarationEndIndex(lines, i);
155
+ const owner = ownerStack.map((entry) => entry.name).join(".");
156
+ const qualifiedName = owner === "" ? parsed.name : `${owner}.${parsed.name}`;
157
+ const node: IGraphNode = {
158
+ id: `${file}#${qualifiedName}:${parsed.kind}`,
159
+ kind: parsed.kind,
160
+ language,
161
+ name: parsed.name,
162
+ ...(qualifiedName !== parsed.name ? { qualifiedName } : {}),
163
+ file,
164
+ external: false,
165
+ exported: parsed.exported,
166
+ signature: line.trim(),
167
+ evidence: {
168
+ file,
169
+ startLine: i + 1,
170
+ startCol: Math.max(1, line.indexOf(parsed.name) + 1),
171
+ endLine: i + 1,
172
+ text: line.trim(),
173
+ },
174
+ };
175
+ declarations.push({
176
+ node,
177
+ startIndex: i,
178
+ endIndex,
179
+ ownerId: ownerStack[ownerStack.length - 1]?.id,
180
+ });
181
+ if (isContainer(parsed.kind) && endIndex > i) {
182
+ ownerStack.push({
183
+ name: parsed.name,
184
+ endIndex,
185
+ id: node.id,
186
+ kind: parsed.kind,
187
+ });
188
+ }
189
+ }
190
+ }
191
+ return declarations;
192
+ }
193
+
194
+ function parseDeclaration(
195
+ language: GraphLanguage,
196
+ line: string,
197
+ inContainer: boolean,
198
+ ): { kind: GraphNodeKind; name: string; exported?: boolean } | undefined {
199
+ const text = line.trim();
200
+ if (text === "" || text.startsWith("//") || text.startsWith("*")) return undefined;
201
+ const packageDeclaration = /^package\s+([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s*;?/.exec(text);
202
+ if (packageDeclaration !== null) {
203
+ return {
204
+ kind: "package",
205
+ name: packageDeclaration[1]!,
206
+ exported: true,
207
+ };
208
+ }
209
+ if (inContainer) {
210
+ const method =
211
+ /^(?:(?:public|private|protected|internal|static|abstract|final|open|override|async|pub|pub\(crate\))\s+)*([A-Za-z_$][\w$]*)\s*\([^;]*\)\s*(?::|->|\{|$)/.exec(
212
+ text,
213
+ );
214
+ if (method !== null && !CONTROL_WORDS.has(method[1]!)) {
215
+ return { kind: "method", name: method[1]! };
216
+ }
217
+ }
218
+ const generic = /^(?:export\s+)?(?:(?:public|private|protected|internal|static|abstract|final|open|override|async|pub|pub\(crate\))\s+)*(class|interface|struct|enum|trait|type|namespace|module|object|protocol|extension|func|fn|function|def|fun|method|const|let|var)\s+([A-Za-z_$][\w$]*)/.exec(text);
219
+ const cppFunction = /^(?:[\w:<>,~*&\s]+)\s+([A-Za-z_]\w*)\s*\([^;]*\)\s*(?:const\s*)?\{?\s*$/.exec(text);
220
+ const goFunc = /^func\s+(?:\([^)]*\)\s*)?([A-Za-z_]\w*)\s*\(/.exec(text);
221
+ const goType = /^type\s+([A-Za-z_]\w*)\s+(struct|interface|\w+)/.exec(text);
222
+ const tsVariable = /^(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::|=|\()/ .exec(text);
223
+
224
+ if (language === "go" && goFunc !== null) {
225
+ return { kind: "function", name: goFunc[1]!, exported: isCapitalized(goFunc[1]!) };
226
+ }
227
+ if (language === "go" && goType !== null) {
228
+ return {
229
+ kind: goType[2] === "interface" ? "interface" : "class",
230
+ name: goType[1]!,
231
+ exported: isCapitalized(goType[1]!),
232
+ };
233
+ }
234
+ if ((language === "typescript" || language === "javascript") && tsVariable !== null) {
235
+ return {
236
+ kind: "variable",
237
+ name: tsVariable[1]!,
238
+ exported: text.startsWith("export "),
239
+ };
240
+ }
241
+ if (generic !== null) {
242
+ const token = generic[1]!;
243
+ const name = generic[2]!;
244
+ return {
245
+ kind: kindOf(token),
246
+ name,
247
+ exported:
248
+ /\b(export|public|pub)\b/.test(text) ||
249
+ language === "go" && isCapitalized(name),
250
+ };
251
+ }
252
+ if ((language === "c" || language === "cpp") && cppFunction !== null) {
253
+ return { kind: "function", name: cppFunction[1]!, exported: true };
254
+ }
255
+ return undefined;
256
+ }
257
+
258
+ function kindOf(token: string): GraphNodeKind {
259
+ switch (token) {
260
+ case "class":
261
+ case "struct":
262
+ case "object":
263
+ case "extension":
264
+ return "class";
265
+ case "interface":
266
+ case "trait":
267
+ case "protocol":
268
+ return "interface";
269
+ case "type":
270
+ return "type";
271
+ case "enum":
272
+ return "enum";
273
+ case "namespace":
274
+ return "namespace";
275
+ case "module":
276
+ return "module";
277
+ case "func":
278
+ case "fn":
279
+ case "function":
280
+ case "def":
281
+ case "fun":
282
+ case "method":
283
+ return "function";
284
+ default:
285
+ return "variable";
286
+ }
287
+ }
288
+
289
+ function importsOf(
290
+ file: string,
291
+ language: GraphLanguage,
292
+ lines: readonly string[],
293
+ ): Array<{ name: string; evidence: IGraphEvidence }> {
294
+ const out: Array<{ name: string; evidence: IGraphEvidence }> = [];
295
+ let goImportBlock = false;
296
+ for (let i = 0; i < lines.length; i++) {
297
+ const text = lines[i]!.trim();
298
+ const names: string[] = [];
299
+ if (language === "typescript" || language === "javascript") {
300
+ for (const match of text.matchAll(/\bfrom\s+["']([^"']+)["']|import\s*\(\s*["']([^"']+)["']\s*\)|^import\s+["']([^"']+)["']/g)) {
301
+ names.push((match[1] ?? match[2] ?? match[3])!);
302
+ }
303
+ } else if (language === "go") {
304
+ if (goImportBlock) {
305
+ if (text.startsWith(")")) {
306
+ goImportBlock = false;
307
+ } else {
308
+ const match = /^(?:(?:[._]|\w+)\s+)?["`]([^"`]+)["`]/.exec(text);
309
+ if (match !== null) names.push(match[1]!);
310
+ }
311
+ } else if (/^import\s*\(/.test(text)) {
312
+ goImportBlock = true;
313
+ } else {
314
+ const match = /^import\s+(?:(?:[._]|\w+)\s+)?["`]([^"`]+)["`]/.exec(text);
315
+ if (match !== null) names.push(match[1]!);
316
+ }
317
+ } else if (language === "rust") {
318
+ const match = /^use\s+([^;]+);?/.exec(text);
319
+ if (match !== null) names.push(match[1]!);
320
+ } else if (language === "cpp" || language === "c") {
321
+ const match = /^#include\s+[<"]([^>"]+)[>"]/.exec(text);
322
+ if (match !== null) names.push(match[1]!);
323
+ } else {
324
+ const match = /^(?:import|using|package)\s+([^;]+)/.exec(text);
325
+ if (match !== null) names.push(match[1]!.trim());
326
+ }
327
+ for (const name of names.filter((value) => value !== "")) {
328
+ out.push({
329
+ name,
330
+ evidence: { file, startLine: i + 1, endLine: i + 1, text },
331
+ });
332
+ }
333
+ }
334
+ return out;
335
+ }
336
+
337
+ // Scan the body ONCE for identifier occurrences and resolve each against the
338
+ // name index — O(body length), not O(all names) with a regex per name. An
339
+ // identifier immediately followed by `(` is a call (an instantiation when it
340
+ // resolves to a class), otherwise a bare type reference; per target the call
341
+ // relation outranks a type reference, matching the previous "call-pattern
342
+ // first, else type" precedence exactly.
343
+ const IDENTIFIER = /[A-Za-z_$][A-Za-z0-9_$]*/g;
344
+
345
+ function dependencyEdges(
346
+ source: IGraphNode,
347
+ body: string,
348
+ byName: Map<string, IGraphNode[]>,
349
+ ): IGraphEdge[] {
350
+ const best = new Map<string, { target: IGraphNode; kind: GraphEdgeKind }>();
351
+ IDENTIFIER.lastIndex = 0;
352
+ for (let match = IDENTIFIER.exec(body); match !== null; match = IDENTIFIER.exec(body)) {
353
+ const name = match[0];
354
+ if (name === source.name) continue;
355
+ const targets = byName.get(name);
356
+ if (targets === undefined) continue;
357
+ // `name` differs from `source.name` (skipped above), so `source` is never
358
+ // among these targets and a non-self target always exists.
359
+ const target = targets.find((node) => node.file !== source.file || node.id !== source.id);
360
+ /* c8 ignore next */
361
+ if (target === undefined) continue;
362
+ // A `(` after any run of whitespace makes this occurrence a call site.
363
+ let cursor = match.index + name.length;
364
+ while (cursor < body.length && (body[cursor] === " " || body[cursor] === "\t")) cursor++;
365
+ const isCall = body[cursor] === "(";
366
+ const kind: GraphEdgeKind = isCall
367
+ ? target.kind === "class"
368
+ ? "instantiates"
369
+ : "calls"
370
+ : "type_ref";
371
+ const prev = best.get(target.id);
372
+ if (prev === undefined || (prev.kind === "type_ref" && kind !== "type_ref")) {
373
+ best.set(target.id, { target, kind });
374
+ }
375
+ }
376
+ const out: IGraphEdge[] = [];
377
+ for (const { target, kind } of best.values()) {
378
+ out.push({ from: source.id, to: target.id, kind, evidence: source.evidence });
379
+ }
380
+ return out;
381
+ }
382
+
383
+ function inheritanceEdges(
384
+ source: IGraphNode,
385
+ byName: Map<string, IGraphNode[]>,
386
+ ): IGraphEdge[] {
387
+ if (source.kind !== "class" && source.kind !== "interface") return [];
388
+ const out: IGraphEdge[] = [];
389
+ const seen = new Set<string>();
390
+ for (const supertype of supertypesOf(source.signature!)) {
391
+ const target = resolveType(supertype.name, source, byName);
392
+ if (target === undefined) continue;
393
+ const key = `${supertype.relation}\0${target.id}`;
394
+ if (seen.has(key)) continue;
395
+ seen.add(key);
396
+ out.push({
397
+ from: source.id,
398
+ to: target.id,
399
+ kind: supertype.relation,
400
+ evidence: source.evidence,
401
+ });
402
+ }
403
+ return out;
404
+ }
405
+
406
+ function externalNode(
407
+ language: GraphLanguage,
408
+ imported: { name: string; evidence: IGraphEvidence },
409
+ cache: Map<string, IGraphNode>,
410
+ ): IGraphNode {
411
+ const key = `external:${language}:${imported.name}`;
412
+ let node = cache.get(key);
413
+ if (node !== undefined) return node;
414
+ node = {
415
+ id: key,
416
+ kind: "external_symbol",
417
+ language,
418
+ name: imported.name,
419
+ file: "",
420
+ external: true,
421
+ };
422
+ cache.set(key, node);
423
+ return node;
424
+ }
425
+
426
+ function dedupeNodes(nodes: IGraphNode[]): IGraphNode[] {
427
+ const map = new Map<string, IGraphNode>();
428
+ for (const node of nodes) map.set(node.id, node);
429
+ return [...map.values()];
430
+ }
431
+
432
+ function dedupeEdges(edges: IGraphEdge[]): IGraphEdge[] {
433
+ const map = new Map<string, IGraphEdge>();
434
+ for (const edge of edges) map.set(`${edge.kind}\0${edge.from}\0${edge.to}`, edge);
435
+ return [...map.values()];
436
+ }
437
+
438
+ function push<K, V>(map: Map<K, V[]>, key: K, value: V): void {
439
+ const bucket = map.get(key);
440
+ if (bucket === undefined) map.set(key, [value]);
441
+ else bucket.push(value);
442
+ }
443
+
444
+ // A container whose direct children can be methods (unlike a function body).
445
+ // A method nested under a namespace/module still resolves because its direct
446
+ // owner is the class, not the namespace.
447
+ function isTypeContainer(kind: GraphNodeKind | undefined): boolean {
448
+ return kind === "class" || kind === "interface";
449
+ }
450
+
451
+ function isContainer(kind: GraphNodeKind): boolean {
452
+ return (
453
+ kind === "class" ||
454
+ kind === "interface" ||
455
+ kind === "namespace" ||
456
+ kind === "module" ||
457
+ kind === "function" ||
458
+ kind === "method" ||
459
+ kind === "constructor"
460
+ );
461
+ }
462
+
463
+ function declarationEndIndex(lines: readonly string[], start: number): number {
464
+ let depth = 0;
465
+ let parenDepth = 0;
466
+ let bracketDepth = 0;
467
+ let entered = false;
468
+ for (let i = start; i < lines.length; i++) {
469
+ const text = stripStringsAndComments(lines[i]!);
470
+ for (const char of text) {
471
+ if (char === "(") {
472
+ parenDepth++;
473
+ } else if (char === ")") {
474
+ parenDepth = Math.max(0, parenDepth - 1);
475
+ } else if (char === "[") {
476
+ bracketDepth++;
477
+ } else if (char === "]") {
478
+ bracketDepth = Math.max(0, bracketDepth - 1);
479
+ } else if (char === "{" && parenDepth === 0 && bracketDepth === 0) {
480
+ depth++;
481
+ entered = true;
482
+ } else if (char === "}" && parenDepth === 0 && bracketDepth === 0) {
483
+ depth = Math.max(0, depth - 1);
484
+ }
485
+ }
486
+ if (entered && depth === 0) return i;
487
+ if (!entered && text.trimEnd().endsWith(";")) return i;
488
+ }
489
+ return start;
490
+ }
491
+
492
+ function stripStringsAndComments(line: string): string {
493
+ return line.replace(/\/\/.*$/, "").replace(/(["'`])(?:\\.|(?!\1).)*\1/g, "");
494
+ }
495
+
496
+ function isCapitalized(name: string): boolean {
497
+ return /^[A-Z]/.test(name);
498
+ }
499
+
500
+ const CONTROL_WORDS = new Set([
501
+ "for",
502
+ "if",
503
+ "switch",
504
+ "while",
505
+ "catch",
506
+ "return",
507
+ ]);
@@ -0,0 +1,9 @@
1
+ export function decoratorsAbove(lines: readonly string[], index: number): string[] {
2
+ const names: string[] = [];
3
+ for (let i = Math.min(index, lines.length) - 1; i >= 0; i--) {
4
+ const match = /^@([A-Za-z_$][\w$.]*)/.exec(lines[i]!.trim());
5
+ if (match === null) break;
6
+ names.push(match[1]!);
7
+ }
8
+ return names;
9
+ }
@@ -0,0 +1,13 @@
1
+ import path from "node:path";
2
+
3
+ import { GraphLanguage } from "../structures";
4
+ import { LANGUAGE_SPECS } from "./LANGUAGE_SPECS";
5
+
6
+ export function languageOf(file: string): GraphLanguage {
7
+ const ext = path.extname(file).toLowerCase();
8
+ if (ext === ".h") return "c";
9
+ for (const spec of LANGUAGE_SPECS) {
10
+ if (spec.extensions.includes(ext)) return spec.language;
11
+ }
12
+ return "unknown";
13
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./allExtensions";
2
+ export * from "./ILanguageSpec";
3
+ export * from "./LANGUAGE_SPECS";
4
+ export * from "./languageOf";
5
+ export * from "./specOf";
@@ -0,0 +1 @@
1
+ export * from "./buildLspGraph";
@@ -0,0 +1,42 @@
1
+ import { IGraphEdge, IGraphNode } from "../structures";
2
+
3
+ // Given a graph that already carries `contains` (owner -> member) and
4
+ // `extends`/`implements` (subtype -> supertype) edges, link a method to the
5
+ // supertype method it overrides: a same-named method reachable on a supertype.
6
+ export function overrideEdges(
7
+ nodes: readonly IGraphNode[],
8
+ edges: readonly IGraphEdge[],
9
+ ): IGraphEdge[] {
10
+ const byId = new Map(nodes.map((node) => [node.id, node]));
11
+ const methodsByOwner = new Map<string, Map<string, IGraphNode>>();
12
+ for (const edge of edges) {
13
+ if (edge.kind !== "contains") continue;
14
+ const member = byId.get(edge.to);
15
+ if (member === undefined || member.kind !== "method") continue;
16
+ let methods = methodsByOwner.get(edge.from);
17
+ if (methods === undefined) {
18
+ methods = new Map();
19
+ methodsByOwner.set(edge.from, methods);
20
+ }
21
+ methods.set(member.name, member);
22
+ }
23
+
24
+ const out: IGraphEdge[] = [];
25
+ for (const edge of edges) {
26
+ if (edge.kind !== "extends" && edge.kind !== "implements") continue;
27
+ const subMethods = methodsByOwner.get(edge.from);
28
+ const superMethods = methodsByOwner.get(edge.to);
29
+ if (subMethods === undefined || superMethods === undefined) continue;
30
+ for (const [name, subMethod] of subMethods) {
31
+ const superMethod = superMethods.get(name);
32
+ if (superMethod === undefined) continue;
33
+ out.push({
34
+ from: subMethod.id,
35
+ to: superMethod.id,
36
+ kind: "overrides",
37
+ evidence: subMethod.evidence,
38
+ });
39
+ }
40
+ }
41
+ return out;
42
+ }
@@ -0,0 +1,14 @@
1
+ import { IGraphNode } from "../structures";
2
+
3
+ export function resolveType(
4
+ name: string,
5
+ source: IGraphNode,
6
+ byName: Map<string, IGraphNode[]>,
7
+ ): IGraphNode | undefined {
8
+ const candidates = byName.get(name.split(".").pop()!);
9
+ if (candidates === undefined) return undefined;
10
+ return (
11
+ candidates.find((node) => node.id !== source.id && node.file === source.file) ??
12
+ candidates.find((node) => node.id !== source.id)
13
+ );
14
+ }
@@ -0,0 +1,7 @@
1
+ import { GraphLanguage } from "../structures";
2
+ import { ILanguageSpec } from "./ILanguageSpec";
3
+ import { LANGUAGE_SPECS } from "./LANGUAGE_SPECS";
4
+
5
+ export function specOf(language: GraphLanguage): ILanguageSpec | undefined {
6
+ return LANGUAGE_SPECS.find((spec) => spec.language === language);
7
+ }
@@ -0,0 +1 @@
1
+ export * from "./buildStaticGraph";
@@ -0,0 +1,43 @@
1
+ export function supertypesOf(
2
+ rawDeclaration: string,
3
+ ): Array<{ name: string; relation: "extends" | "implements" }> {
4
+ const out: Array<{ name: string; relation: "extends" | "implements" }> = [];
5
+ const declaration = rawDeclaration.replace(
6
+ /^\s*(?:(?:export|public|private|protected|internal|abstract|final|open|sealed|static|data)\s+)+/,
7
+ "",
8
+ );
9
+ const extendsMatch = /\bextends\s+([^{]+?)(?:\bimplements\b|\bwith\b|\{|$)/.exec(declaration);
10
+ if (extendsMatch !== null)
11
+ for (const name of splitTypeList(extendsMatch[1]!)) out.push({ name, relation: "extends" });
12
+ const implementsMatch = /\b(?:implements|with)\s+([^{]+?)(?:\{|$)/.exec(declaration);
13
+ if (implementsMatch !== null)
14
+ for (const name of splitTypeList(implementsMatch[1]!)) out.push({ name, relation: "implements" });
15
+ const pythonMatch = /^class\s+\w+\s*\(([^)]*)\)/.exec(declaration);
16
+ if (pythonMatch !== null)
17
+ for (const name of splitTypeList(pythonMatch[1]!)) out.push({ name, relation: "extends" });
18
+ const rubyMatch = /^class\s+\w+\s*<\s*([A-Za-z_][\w.]*)/.exec(declaration);
19
+ if (rubyMatch !== null) out.push({ name: rubyMatch[1]!, relation: "extends" });
20
+ if (out.length === 0) {
21
+ const colonMatch = /^(?:class|struct|interface)\s+\w+\s*:\s*([^{]+)/.exec(declaration);
22
+ if (colonMatch !== null)
23
+ for (const name of splitTypeList(colonMatch[1]!)) out.push({ name, relation: "extends" });
24
+ }
25
+ return out;
26
+ }
27
+
28
+ function splitTypeList(text: string): string[] {
29
+ const names: string[] = [];
30
+ for (const part of text.split(",")) {
31
+ // Skip Python keyword-argument bases (`metaclass=Meta`) and `*args`/`**kw`
32
+ // unpacking, which are not supertypes.
33
+ if (part.includes("=") || part.trim().startsWith("*")) continue;
34
+ const cleaned = part
35
+ .trim()
36
+ .replace(/^(?:public|private|protected|virtual|final|open|sealed|abstract)\s+/, "")
37
+ .replace(/<[^>]*>/g, "")
38
+ .replace(/\(.*$/, "");
39
+ const match = /^[A-Za-z_][\w.]*/.exec(cleaned.trim());
40
+ if (match !== null) names.push(match[0]);
41
+ }
42
+ return names;
43
+ }
@@ -0,0 +1,4 @@
1
+ import { IDocumentSymbol } from "./IDocumentSymbol";
2
+ import { ISymbolInformation } from "./ISymbolInformation";
3
+
4
+ export type DocumentSymbolResult = Array<IDocumentSymbol | ISymbolInformation> | null;
@@ -0,0 +1,9 @@
1
+ import { IRange } from "./IRange";
2
+
3
+ export interface IDiagnostic {
4
+ range: IRange;
5
+ severity?: number;
6
+ code?: string | number;
7
+ source?: string;
8
+ message: string;
9
+ }
@@ -0,0 +1,10 @@
1
+ import { IRange } from "./IRange";
2
+
3
+ export interface IDocumentSymbol {
4
+ name: string;
5
+ detail?: string;
6
+ kind: number;
7
+ range: IRange;
8
+ selectionRange: IRange;
9
+ children?: IDocumentSymbol[];
10
+ }
@@ -0,0 +1,6 @@
1
+ import { IRange } from "./IRange";
2
+
3
+ export interface ILocation {
4
+ uri: string;
5
+ range: IRange;
6
+ }