@vscode/chat-lib 0.0.1 → 0.0.3

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 (476) hide show
  1. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.d.ts +2 -1
  2. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.d.ts.map +1 -1
  3. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js +70 -28
  4. package/dist/src/_internal/extension/inlineEdits/node/nextEditProvider.js.map +1 -1
  5. package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.d.ts +4 -3
  6. package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.d.ts.map +1 -1
  7. package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.js +85 -109
  8. package/dist/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.js.map +1 -1
  9. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.d.ts.map +1 -1
  10. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js +14 -6
  11. package/dist/src/_internal/extension/prompt/node/chatMLFetcher.js.map +1 -1
  12. package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts.map +1 -1
  13. package/dist/src/_internal/extension/xtab/common/promptCrafting.js +6 -5
  14. package/dist/src/_internal/extension/xtab/common/promptCrafting.js.map +1 -1
  15. package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts +1 -0
  16. package/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts.map +1 -1
  17. package/dist/src/_internal/extension/xtab/node/xtabProvider.js +44 -42
  18. package/dist/src/_internal/extension/xtab/node/xtabProvider.js.map +1 -1
  19. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.d.ts.map +1 -1
  20. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js +8 -4
  21. package/dist/src/_internal/platform/authentication/node/copilotTokenManager.js.map +1 -1
  22. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +8 -0
  23. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
  24. package/dist/src/_internal/platform/configuration/common/configurationService.js +11 -3
  25. package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
  26. package/dist/src/_internal/platform/endpoint/common/capiClient.d.ts +1 -1
  27. package/dist/src/_internal/platform/endpoint/common/capiClient.d.ts.map +1 -1
  28. package/dist/src/_internal/platform/endpoint/common/capiClient.js +2 -2
  29. package/dist/src/_internal/platform/endpoint/common/capiClient.js.map +1 -1
  30. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts +4 -0
  31. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.d.ts.map +1 -1
  32. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js +7 -0
  33. package/dist/src/_internal/platform/endpoint/common/chatModelCapabilities.js.map +1 -1
  34. package/dist/src/_internal/platform/endpoint/node/capiClientImpl.d.ts.map +1 -1
  35. package/dist/src/_internal/platform/endpoint/node/capiClientImpl.js +1 -1
  36. package/dist/src/_internal/platform/endpoint/node/capiClientImpl.js.map +1 -1
  37. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts +1 -1
  38. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.d.ts.map +1 -1
  39. package/dist/src/_internal/platform/endpoint/node/chatEndpoint.js.map +1 -1
  40. package/dist/src/_internal/platform/endpoint/node/responsesApi.js +10 -4
  41. package/dist/src/_internal/platform/endpoint/node/responsesApi.js.map +1 -1
  42. package/dist/src/_internal/platform/env/common/envService.d.ts +5 -0
  43. package/dist/src/_internal/platform/env/common/envService.d.ts.map +1 -1
  44. package/dist/src/_internal/platform/env/common/envService.js +2 -1
  45. package/dist/src/_internal/platform/env/common/envService.js.map +1 -1
  46. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts +3 -0
  47. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts.map +1 -1
  48. package/dist/src/_internal/platform/env/common/nullEnvService.js +8 -1
  49. package/dist/src/_internal/platform/env/common/nullEnvService.js.map +1 -1
  50. package/dist/src/_internal/platform/github/common/githubService.d.ts +3 -3
  51. package/dist/src/_internal/platform/github/common/githubService.d.ts.map +1 -1
  52. package/dist/src/_internal/platform/github/common/githubService.js.map +1 -1
  53. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts +0 -3
  54. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.d.ts.map +1 -1
  55. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.js +0 -5
  56. package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.js.map +1 -1
  57. package/dist/src/_internal/platform/networking/common/fetcherService.d.ts +2 -1
  58. package/dist/src/_internal/platform/networking/common/fetcherService.d.ts.map +1 -1
  59. package/dist/src/_internal/platform/networking/common/fetcherService.js.map +1 -1
  60. package/dist/src/_internal/platform/networking/common/networking.d.ts.map +1 -1
  61. package/dist/src/_internal/platform/networking/common/networking.js.map +1 -1
  62. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts +7 -0
  63. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts.map +1 -1
  64. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js +1 -0
  65. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js.map +1 -1
  66. package/dist/src/_internal/platform/telemetry/common/telemetry.d.ts +1 -0
  67. package/dist/src/_internal/platform/telemetry/common/telemetry.d.ts.map +1 -1
  68. package/dist/src/_internal/platform/telemetry/common/telemetry.js.map +1 -1
  69. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts +8 -0
  70. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts.map +1 -1
  71. package/dist/src/_internal/util/common/test/shims/chatTypes.js +19 -1
  72. package/dist/src/_internal/util/common/test/shims/chatTypes.js.map +1 -1
  73. package/dist/src/_internal/util/common/test/shims/enums.d.ts +6 -0
  74. package/dist/src/_internal/util/common/test/shims/enums.d.ts.map +1 -1
  75. package/dist/src/_internal/util/common/test/shims/enums.js +8 -1
  76. package/dist/src/_internal/util/common/test/shims/enums.js.map +1 -1
  77. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.d.ts.map +1 -1
  78. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js +9 -1
  79. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js.map +1 -1
  80. package/dist/src/_internal/vscodeTypes.d.ts +5 -0
  81. package/dist/src/_internal/vscodeTypes.d.ts.map +1 -1
  82. package/dist/src/_internal/vscodeTypes.js +6 -1
  83. package/dist/src/_internal/vscodeTypes.js.map +1 -1
  84. package/dist/src/main.d.ts +15 -1
  85. package/dist/src/main.d.ts.map +1 -1
  86. package/dist/src/main.js +73 -13
  87. package/dist/src/main.js.map +1 -1
  88. package/dist/src/package.json +70 -31
  89. package/package.json +7 -9
  90. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.d.ts +0 -42
  91. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.d.ts.map +0 -1
  92. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.js +0 -125
  93. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.js.map +0 -1
  94. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.d.ts +0 -60
  95. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.d.ts.map +0 -1
  96. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.js +0 -416
  97. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.js.map +0 -1
  98. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.d.ts +0 -30
  99. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.d.ts.map +0 -1
  100. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.js +0 -64
  101. package/dist/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.js.map +0 -1
  102. package/dist/src/_internal/extension/prompts/node/inline/visualization.d.ts +0 -26
  103. package/dist/src/_internal/extension/prompts/node/inline/visualization.d.ts.map +0 -1
  104. package/dist/src/_internal/extension/prompts/node/inline/visualization.js +0 -41
  105. package/dist/src/_internal/extension/prompts/node/inline/visualization.js.map +0 -1
  106. package/dist/src/_internal/platform/editing/common/abstractText.d.ts +0 -58
  107. package/dist/src/_internal/platform/editing/common/abstractText.d.ts.map +0 -1
  108. package/dist/src/_internal/platform/editing/common/abstractText.js +0 -129
  109. package/dist/src/_internal/platform/editing/common/abstractText.js.map +0 -1
  110. package/dist/src/_internal/platform/parser/node/nodes.d.ts +0 -93
  111. package/dist/src/_internal/platform/parser/node/nodes.d.ts.map +0 -1
  112. package/dist/src/_internal/platform/parser/node/nodes.js +0 -133
  113. package/dist/src/_internal/platform/parser/node/nodes.js.map +0 -1
  114. package/dist/src/_internal/platform/telemetry/common/nullTelemetryService.d.ts +0 -18
  115. package/dist/src/_internal/platform/telemetry/common/nullTelemetryService.d.ts.map +0 -1
  116. package/dist/src/_internal/platform/telemetry/common/nullTelemetryService.js +0 -50
  117. package/dist/src/_internal/platform/telemetry/common/nullTelemetryService.js.map +0 -1
  118. package/dist/src/_internal/util/common/arrays.d.ts +0 -18
  119. package/dist/src/_internal/util/common/arrays.d.ts.map +0 -1
  120. package/dist/src/_internal/util/common/arrays.js +0 -80
  121. package/dist/src/_internal/util/common/arrays.js.map +0 -1
  122. package/src/_internal/extension/byok/node/openAIEndpoint.ts +0 -171
  123. package/src/_internal/extension/common/constants.ts +0 -90
  124. package/src/_internal/extension/inlineEdits/common/delayer.ts +0 -108
  125. package/src/_internal/extension/inlineEdits/common/editRebase.ts +0 -268
  126. package/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.tsx +0 -163
  127. package/src/_internal/extension/inlineEdits/common/nearbyCursorInlineEditProvider.ts +0 -225
  128. package/src/_internal/extension/inlineEdits/common/rejectionCollector.ts +0 -164
  129. package/src/_internal/extension/inlineEdits/node/debugRecorder.ts +0 -205
  130. package/src/_internal/extension/inlineEdits/node/importFiltering.ts +0 -25
  131. package/src/_internal/extension/inlineEdits/node/nesConfigs.ts +0 -12
  132. package/src/_internal/extension/inlineEdits/node/nextEditCache.ts +0 -278
  133. package/src/_internal/extension/inlineEdits/node/nextEditProvider.ts +0 -778
  134. package/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.ts +0 -983
  135. package/src/_internal/extension/inlineEdits/node/nextEditResult.ts +0 -40
  136. package/src/_internal/extension/prompt/common/importStatement.ts +0 -25
  137. package/src/_internal/extension/prompt/node/chatMLFetcher.ts +0 -706
  138. package/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.ts +0 -146
  139. package/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.ts +0 -527
  140. package/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.ts +0 -76
  141. package/src/_internal/extension/prompts/node/inline/visualization.ts +0 -65
  142. package/src/_internal/extension/vscode.proposed.activeComment.d.ts +0 -23
  143. package/src/_internal/extension/vscode.proposed.aiRelatedInformation.d.ts +0 -49
  144. package/src/_internal/extension/vscode.proposed.aiSettingsSearch.d.ts +0 -31
  145. package/src/_internal/extension/vscode.proposed.aiTextSearchProvider.d.ts +0 -41
  146. package/src/_internal/extension/vscode.proposed.authLearnMore.d.ts +0 -16
  147. package/src/_internal/extension/vscode.proposed.chatBinaryReferenceData.d.ts +0 -41
  148. package/src/_internal/extension/vscode.proposed.chatEditing.d.ts +0 -29
  149. package/src/_internal/extension/vscode.proposed.chatParticipantAdditions.d.ts +0 -636
  150. package/src/_internal/extension/vscode.proposed.chatParticipantPrivate.d.ts +0 -276
  151. package/src/_internal/extension/vscode.proposed.chatProvider.d.ts +0 -62
  152. package/src/_internal/extension/vscode.proposed.chatReadonlyPromptReference.d.ts +0 -17
  153. package/src/_internal/extension/vscode.proposed.chatReferenceDiagnostic.d.ts +0 -23
  154. package/src/_internal/extension/vscode.proposed.chatSessionsProvider.d.ts +0 -218
  155. package/src/_internal/extension/vscode.proposed.chatStatusItem.d.ts +0 -61
  156. package/src/_internal/extension/vscode.proposed.codeActionAI.d.ts +0 -16
  157. package/src/_internal/extension/vscode.proposed.commentReveal.d.ts +0 -32
  158. package/src/_internal/extension/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts +0 -8
  159. package/src/_internal/extension/vscode.proposed.contribCommentsViewThreadMenus.d.ts +0 -6
  160. package/src/_internal/extension/vscode.proposed.contribSourceControlInputBoxMenu.d.ts +0 -7
  161. package/src/_internal/extension/vscode.proposed.dataChannels.d.ts +0 -19
  162. package/src/_internal/extension/vscode.proposed.defaultChatParticipant.d.ts +0 -52
  163. package/src/_internal/extension/vscode.proposed.documentFiltersExclusive.d.ts +0 -13
  164. package/src/_internal/extension/vscode.proposed.embeddings.d.ts +0 -33
  165. package/src/_internal/extension/vscode.proposed.extensionsAny.d.ts +0 -40
  166. package/src/_internal/extension/vscode.proposed.findFiles2.d.ts +0 -125
  167. package/src/_internal/extension/vscode.proposed.findTextInFiles.d.ts +0 -104
  168. package/src/_internal/extension/vscode.proposed.findTextInFiles2.d.ts +0 -144
  169. package/src/_internal/extension/vscode.proposed.inlineCompletionsAdditions.d.ts +0 -202
  170. package/src/_internal/extension/vscode.proposed.interactive.d.ts +0 -11
  171. package/src/_internal/extension/vscode.proposed.languageModelCapabilities.d.ts +0 -25
  172. package/src/_internal/extension/vscode.proposed.languageModelDataPart.d.ts +0 -163
  173. package/src/_internal/extension/vscode.proposed.languageModelSystem.d.ts +0 -17
  174. package/src/_internal/extension/vscode.proposed.languageModelThinkingPart.d.ts +0 -49
  175. package/src/_internal/extension/vscode.proposed.languageModelToolResultAudience.d.ts +0 -36
  176. package/src/_internal/extension/vscode.proposed.mappedEditsProvider.d.ts +0 -110
  177. package/src/_internal/extension/vscode.proposed.newSymbolNamesProvider.d.ts +0 -47
  178. package/src/_internal/extension/vscode.proposed.readonlyMessage.d.ts +0 -14
  179. package/src/_internal/extension/vscode.proposed.resolvers.d.ts +0 -475
  180. package/src/_internal/extension/vscode.proposed.scmInputBoxValueProvider.d.ts +0 -25
  181. package/src/_internal/extension/vscode.proposed.taskProblemMatcherStatus.d.ts +0 -42
  182. package/src/_internal/extension/vscode.proposed.terminalDataWriteEvent.d.ts +0 -32
  183. package/src/_internal/extension/vscode.proposed.terminalExecuteCommandEvent.d.ts +0 -48
  184. package/src/_internal/extension/vscode.proposed.terminalQuickFixProvider.d.ts +0 -87
  185. package/src/_internal/extension/vscode.proposed.terminalSelection.d.ts +0 -16
  186. package/src/_internal/extension/vscode.proposed.testObserver.d.ts +0 -199
  187. package/src/_internal/extension/vscode.proposed.textDocumentChangeReason.d.ts +0 -30
  188. package/src/_internal/extension/vscode.proposed.textSearchProvider.d.ts +0 -281
  189. package/src/_internal/extension/vscode.proposed.textSearchProvider2.d.ts +0 -297
  190. package/src/_internal/extension/xtab/common/promptCrafting.ts +0 -670
  191. package/src/_internal/extension/xtab/node/xtabEndpoint.ts +0 -102
  192. package/src/_internal/extension/xtab/node/xtabProvider.ts +0 -976
  193. package/src/_internal/extension/xtab/node/xtabUtils.ts +0 -62
  194. package/src/_internal/platform/authentication/common/authentication.ts +0 -309
  195. package/src/_internal/platform/authentication/common/copilotToken.ts +0 -300
  196. package/src/_internal/platform/authentication/common/copilotTokenManager.ts +0 -59
  197. package/src/_internal/platform/authentication/common/copilotTokenStore.ts +0 -40
  198. package/src/_internal/platform/authentication/common/staticGitHubAuthenticationService.ts +0 -96
  199. package/src/_internal/platform/authentication/node/copilotTokenManager.ts +0 -303
  200. package/src/_internal/platform/chat/common/chatMLFetcher.ts +0 -124
  201. package/src/_internal/platform/chat/common/chatQuotaService.ts +0 -63
  202. package/src/_internal/platform/chat/common/chatQuotaServiceImpl.ts +0 -96
  203. package/src/_internal/platform/chat/common/commonTypes.ts +0 -353
  204. package/src/_internal/platform/chat/common/conversationOptions.ts +0 -16
  205. package/src/_internal/platform/chat/common/globalStringUtils.ts +0 -54
  206. package/src/_internal/platform/chat/common/interactionService.ts +0 -35
  207. package/src/_internal/platform/configuration/common/configurationService.ts +0 -803
  208. package/src/_internal/platform/configuration/common/defaultsOnlyConfigurationService.ts +0 -39
  209. package/src/_internal/platform/configuration/common/jsonSchema.ts +0 -139
  210. package/src/_internal/platform/configuration/common/validator.ts +0 -242
  211. package/src/_internal/platform/diff/common/diffService.ts +0 -41
  212. package/src/_internal/platform/diff/common/diffWorker.ts +0 -83
  213. package/src/_internal/platform/diff/node/diffServiceImpl.ts +0 -85
  214. package/src/_internal/platform/editing/common/abstractText.ts +0 -177
  215. package/src/_internal/platform/editing/common/notebookDocumentSnapshot.ts +0 -122
  216. package/src/_internal/platform/editing/common/positionOffsetTransformer.ts +0 -202
  217. package/src/_internal/platform/editing/common/textDocumentSnapshot.ts +0 -274
  218. package/src/_internal/platform/endpoint/common/capiClient.ts +0 -37
  219. package/src/_internal/platform/endpoint/common/chatModelCapabilities.ts +0 -115
  220. package/src/_internal/platform/endpoint/common/domainService.ts +0 -27
  221. package/src/_internal/platform/endpoint/common/endpointProvider.ts +0 -104
  222. package/src/_internal/platform/endpoint/common/endpointTypes.ts +0 -12
  223. package/src/_internal/platform/endpoint/common/licenseAgreement.ts +0 -11
  224. package/src/_internal/platform/endpoint/common/statefulMarkerContainer.tsx +0 -85
  225. package/src/_internal/platform/endpoint/common/thinkingDataContainer.tsx +0 -44
  226. package/src/_internal/platform/endpoint/node/capiClientImpl.ts +0 -18
  227. package/src/_internal/platform/endpoint/node/chatEndpoint.ts +0 -435
  228. package/src/_internal/platform/endpoint/node/domainServiceImpl.ts +0 -80
  229. package/src/_internal/platform/endpoint/node/proxyXtabEndpoint.ts +0 -43
  230. package/src/_internal/platform/endpoint/node/responsesApi.ts +0 -326
  231. package/src/_internal/platform/env/common/envService.ts +0 -134
  232. package/src/_internal/platform/env/common/nullEnvService.ts +0 -68
  233. package/src/_internal/platform/env/common/packagejson.ts +0 -49
  234. package/src/_internal/platform/git/common/gitExtensionService.ts +0 -21
  235. package/src/_internal/platform/git/common/nullGitExtensionService.ts +0 -20
  236. package/src/_internal/platform/git/vscode/git.d.ts +0 -414
  237. package/src/_internal/platform/github/common/githubAPI.ts +0 -44
  238. package/src/_internal/platform/github/common/githubService.ts +0 -87
  239. package/src/_internal/platform/github/common/nullOctokitServiceImpl.ts +0 -21
  240. package/src/_internal/platform/ignore/common/ignoreService.ts +0 -72
  241. package/src/_internal/platform/inlineCompletions/common/api.ts +0 -198
  242. package/src/_internal/platform/inlineEdits/common/dataTypes/diagnosticData.ts +0 -32
  243. package/src/_internal/platform/inlineEdits/common/dataTypes/documentId.ts +0 -52
  244. package/src/_internal/platform/inlineEdits/common/dataTypes/edit.ts +0 -165
  245. package/src/_internal/platform/inlineEdits/common/dataTypes/editUtils.ts +0 -74
  246. package/src/_internal/platform/inlineEdits/common/dataTypes/fetchCancellationError.ts +0 -14
  247. package/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.ts +0 -107
  248. package/src/_internal/platform/inlineEdits/common/dataTypes/languageId.ts +0 -14
  249. package/src/_internal/platform/inlineEdits/common/dataTypes/permutation.ts +0 -69
  250. package/src/_internal/platform/inlineEdits/common/dataTypes/rootedLineEdit.ts +0 -49
  251. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLength.ts +0 -74
  252. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/combineTextEditInfos.ts +0 -132
  253. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/length.ts +0 -184
  254. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/textEditInfo.ts +0 -32
  255. package/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts +0 -89
  256. package/src/_internal/platform/inlineEdits/common/debugRecorderBookmark.ts +0 -10
  257. package/src/_internal/platform/inlineEdits/common/editReason.ts +0 -134
  258. package/src/_internal/platform/inlineEdits/common/inlineEditLogContext.ts +0 -490
  259. package/src/_internal/platform/inlineEdits/common/observableGit.ts +0 -49
  260. package/src/_internal/platform/inlineEdits/common/observableWorkspace.ts +0 -239
  261. package/src/_internal/platform/inlineEdits/common/responseProcessor.ts +0 -249
  262. package/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.ts +0 -468
  263. package/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.ts +0 -59
  264. package/src/_internal/platform/inlineEdits/common/utils/observable.ts +0 -54
  265. package/src/_internal/platform/inlineEdits/common/utils/stringifyChatMessages.ts +0 -29
  266. package/src/_internal/platform/inlineEdits/common/utils/utils.ts +0 -56
  267. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/historyContextProvider.ts +0 -60
  268. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesHistoryContextProvider.ts +0 -353
  269. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker.ts +0 -176
  270. package/src/_internal/platform/languageContextProvider/common/languageContextProviderService.ts +0 -25
  271. package/src/_internal/platform/languageContextProvider/common/nullLanguageContextProviderService.ts +0 -38
  272. package/src/_internal/platform/languageServer/common/languageContextService.ts +0 -186
  273. package/src/_internal/platform/languages/common/languageDiagnosticsService.ts +0 -67
  274. package/src/_internal/platform/languages/common/testLanguageDiagnosticsService.ts +0 -28
  275. package/src/_internal/platform/log/common/logService.ts +0 -232
  276. package/src/_internal/platform/nesFetch/common/completionsAPI.ts +0 -78
  277. package/src/_internal/platform/nesFetch/common/completionsFetchService.ts +0 -118
  278. package/src/_internal/platform/nesFetch/common/responseStream.ts +0 -151
  279. package/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.ts +0 -236
  280. package/src/_internal/platform/nesFetch/node/streamTransformer.ts +0 -95
  281. package/src/_internal/platform/networking/common/fetch.ts +0 -349
  282. package/src/_internal/platform/networking/common/fetcherService.ts +0 -84
  283. package/src/_internal/platform/networking/common/networking.ts +0 -442
  284. package/src/_internal/platform/networking/common/openai.ts +0 -273
  285. package/src/_internal/platform/networking/node/chatStream.ts +0 -137
  286. package/src/_internal/platform/networking/node/stream.ts +0 -749
  287. package/src/_internal/platform/notebook/common/alternativeContent.ts +0 -89
  288. package/src/_internal/platform/notebook/common/alternativeContentFormat.ts +0 -10
  289. package/src/_internal/platform/notebook/common/alternativeContentProvider.json.ts +0 -262
  290. package/src/_internal/platform/notebook/common/alternativeContentProvider.text.ts +0 -243
  291. package/src/_internal/platform/notebook/common/alternativeContentProvider.ts +0 -41
  292. package/src/_internal/platform/notebook/common/alternativeContentProvider.xml.ts +0 -205
  293. package/src/_internal/platform/notebook/common/alternativeNotebookDocument.ts +0 -155
  294. package/src/_internal/platform/notebook/common/helpers.ts +0 -212
  295. package/src/_internal/platform/notebook/common/notebookService.ts +0 -43
  296. package/src/_internal/platform/openai/node/fetch.ts +0 -596
  297. package/src/_internal/platform/parser/node/nodes.ts +0 -190
  298. package/src/_internal/platform/requestLogger/node/nullRequestLogger.ts +0 -26
  299. package/src/_internal/platform/requestLogger/node/requestLogger.ts +0 -383
  300. package/src/_internal/platform/simulationTestContext/common/simulationTestContext.ts +0 -29
  301. package/src/_internal/platform/snippy/common/snippyService.ts +0 -25
  302. package/src/_internal/platform/telemetry/common/nullExperimentationService.ts +0 -64
  303. package/src/_internal/platform/telemetry/common/nullTelemetryService.ts +0 -53
  304. package/src/_internal/platform/telemetry/common/telemetry.ts +0 -215
  305. package/src/_internal/platform/telemetry/common/telemetryData.ts +0 -205
  306. package/src/_internal/platform/thinking/common/thinking.ts +0 -61
  307. package/src/_internal/platform/thinking/common/thinkingUtils.ts +0 -57
  308. package/src/_internal/platform/tokenizer/node/parseTikTokens.ts +0 -23
  309. package/src/_internal/platform/tokenizer/node/tikTokenizerImpl.ts +0 -74
  310. package/src/_internal/platform/tokenizer/node/tikTokenizerWorker.ts +0 -24
  311. package/src/_internal/platform/tokenizer/node/tokenizer.ts +0 -357
  312. package/src/_internal/platform/workspace/common/workspaceService.ts +0 -226
  313. package/src/_internal/platform/workspaceRecorder/common/workspaceLog.ts +0 -118
  314. package/src/_internal/util/common/anomalyDetection.ts +0 -112
  315. package/src/_internal/util/common/arrays.ts +0 -81
  316. package/src/_internal/util/common/async.ts +0 -155
  317. package/src/_internal/util/common/cache.ts +0 -183
  318. package/src/_internal/util/common/crypto.ts +0 -41
  319. package/src/_internal/util/common/errors.ts +0 -22
  320. package/src/_internal/util/common/globals.d.ts +0 -12
  321. package/src/_internal/util/common/imageUtils.ts +0 -154
  322. package/src/_internal/util/common/languages.ts +0 -940
  323. package/src/_internal/util/common/notebooks.ts +0 -286
  324. package/src/_internal/util/common/result.ts +0 -71
  325. package/src/_internal/util/common/services.ts +0 -43
  326. package/src/_internal/util/common/test/shims/chatTypes.ts +0 -448
  327. package/src/_internal/util/common/test/shims/editing.ts +0 -233
  328. package/src/_internal/util/common/test/shims/enums.ts +0 -61
  329. package/src/_internal/util/common/test/shims/l10n.ts +0 -37
  330. package/src/_internal/util/common/test/shims/newSymbolName.ts +0 -23
  331. package/src/_internal/util/common/test/shims/terminal.ts +0 -33
  332. package/src/_internal/util/common/test/shims/vscodeTypesShim.ts +0 -115
  333. package/src/_internal/util/common/time.ts +0 -31
  334. package/src/_internal/util/common/tokenizer.ts +0 -30
  335. package/src/_internal/util/common/tracing.ts +0 -52
  336. package/src/_internal/util/common/types.ts +0 -33
  337. package/src/_internal/util/common/variableLengthQuantity.ts +0 -40
  338. package/src/_internal/util/node/worker.ts +0 -130
  339. package/src/_internal/util/vs/base/common/arrays.ts +0 -926
  340. package/src/_internal/util/vs/base/common/arraysFind.ts +0 -206
  341. package/src/_internal/util/vs/base/common/assert.ts +0 -89
  342. package/src/_internal/util/vs/base/common/async.ts +0 -2582
  343. package/src/_internal/util/vs/base/common/buffer.ts +0 -501
  344. package/src/_internal/util/vs/base/common/cache.ts +0 -122
  345. package/src/_internal/util/vs/base/common/cancellation.ts +0 -150
  346. package/src/_internal/util/vs/base/common/charCode.ts +0 -452
  347. package/src/_internal/util/vs/base/common/codicons.ts +0 -66
  348. package/src/_internal/util/vs/base/common/codiconsLibrary.ts +0 -618
  349. package/src/_internal/util/vs/base/common/codiconsUtil.ts +0 -30
  350. package/src/_internal/util/vs/base/common/collections.ts +0 -156
  351. package/src/_internal/util/vs/base/common/diff/diff.ts +0 -1317
  352. package/src/_internal/util/vs/base/common/diff/diffChange.ts +0 -62
  353. package/src/_internal/util/vs/base/common/equals.ts +0 -148
  354. package/src/_internal/util/vs/base/common/errors.ts +0 -342
  355. package/src/_internal/util/vs/base/common/event.ts +0 -1782
  356. package/src/_internal/util/vs/base/common/extpath.ts +0 -425
  357. package/src/_internal/util/vs/base/common/filters.ts +0 -928
  358. package/src/_internal/util/vs/base/common/functional.ts +0 -34
  359. package/src/_internal/util/vs/base/common/glob.ts +0 -839
  360. package/src/_internal/util/vs/base/common/hash.ts +0 -326
  361. package/src/_internal/util/vs/base/common/htmlContent.ts +0 -212
  362. package/src/_internal/util/vs/base/common/iconLabels.ts +0 -118
  363. package/src/_internal/util/vs/base/common/iterator.ts +0 -196
  364. package/src/_internal/util/vs/base/common/lazy.ts +0 -59
  365. package/src/_internal/util/vs/base/common/lifecycle.ts +0 -845
  366. package/src/_internal/util/vs/base/common/linkedList.ts +0 -144
  367. package/src/_internal/util/vs/base/common/map.ts +0 -954
  368. package/src/_internal/util/vs/base/common/marshallingIds.ts +0 -35
  369. package/src/_internal/util/vs/base/common/mime.ts +0 -136
  370. package/src/_internal/util/vs/base/common/naturalLanguage/korean.ts +0 -425
  371. package/src/_internal/util/vs/base/common/network.ts +0 -429
  372. package/src/_internal/util/vs/base/common/numbers.ts +0 -166
  373. package/src/_internal/util/vs/base/common/objects.ts +0 -242
  374. package/src/_internal/util/vs/base/common/observable.ts +0 -10
  375. package/src/_internal/util/vs/base/common/observableInternal/base.ts +0 -208
  376. package/src/_internal/util/vs/base/common/observableInternal/changeTracker.ts +0 -96
  377. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/cancellation.ts +0 -9
  378. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/deps.ts +0 -12
  379. package/src/_internal/util/vs/base/common/observableInternal/debugLocation.ts +0 -88
  380. package/src/_internal/util/vs/base/common/observableInternal/debugName.ts +0 -150
  381. package/src/_internal/util/vs/base/common/observableInternal/experimental/utils.ts +0 -62
  382. package/src/_internal/util/vs/base/common/observableInternal/index.ts +0 -61
  383. package/src/_internal/util/vs/base/common/observableInternal/logging/consoleObservableLogger.ts +0 -388
  384. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerApi.d.ts +0 -154
  385. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerRpc.ts +0 -80
  386. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/devToolsLogger.ts +0 -485
  387. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/rpc.ts +0 -103
  388. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/utils.ts +0 -69
  389. package/src/_internal/util/vs/base/common/observableInternal/logging/logging.ts +0 -133
  390. package/src/_internal/util/vs/base/common/observableInternal/map.ts +0 -81
  391. package/src/_internal/util/vs/base/common/observableInternal/observables/baseObservable.ts +0 -172
  392. package/src/_internal/util/vs/base/common/observableInternal/observables/constObservable.ts +0 -44
  393. package/src/_internal/util/vs/base/common/observableInternal/observables/derived.ts +0 -190
  394. package/src/_internal/util/vs/base/common/observableInternal/observables/derivedImpl.ts +0 -445
  395. package/src/_internal/util/vs/base/common/observableInternal/observables/lazyObservableValue.ts +0 -154
  396. package/src/_internal/util/vs/base/common/observableInternal/observables/observableFromEvent.ts +0 -174
  397. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignal.ts +0 -67
  398. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignalFromEvent.ts +0 -62
  399. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValue.ts +0 -131
  400. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValueOpts.ts +0 -37
  401. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorun.ts +0 -188
  402. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorunImpl.ts +0 -256
  403. package/src/_internal/util/vs/base/common/observableInternal/set.ts +0 -78
  404. package/src/_internal/util/vs/base/common/observableInternal/transaction.ts +0 -115
  405. package/src/_internal/util/vs/base/common/observableInternal/utils/promise.ts +0 -129
  406. package/src/_internal/util/vs/base/common/observableInternal/utils/runOnChange.ts +0 -65
  407. package/src/_internal/util/vs/base/common/observableInternal/utils/utils.ts +0 -281
  408. package/src/_internal/util/vs/base/common/observableInternal/utils/utilsCancellation.ts +0 -101
  409. package/src/_internal/util/vs/base/common/observableInternal/utils/valueWithChangeEvent.ts +0 -31
  410. package/src/_internal/util/vs/base/common/path.ts +0 -1591
  411. package/src/_internal/util/vs/base/common/platform.ts +0 -282
  412. package/src/_internal/util/vs/base/common/process.ts +0 -78
  413. package/src/_internal/util/vs/base/common/resources.ts +0 -446
  414. package/src/_internal/util/vs/base/common/sequence.ts +0 -36
  415. package/src/_internal/util/vs/base/common/sseParser.ts +0 -247
  416. package/src/_internal/util/vs/base/common/stopwatch.ts +0 -43
  417. package/src/_internal/util/vs/base/common/stream.ts +0 -792
  418. package/src/_internal/util/vs/base/common/strings.ts +0 -1364
  419. package/src/_internal/util/vs/base/common/symbols.ts +0 -11
  420. package/src/_internal/util/vs/base/common/themables.ts +0 -106
  421. package/src/_internal/util/vs/base/common/types.ts +0 -345
  422. package/src/_internal/util/vs/base/common/uint.ts +0 -61
  423. package/src/_internal/util/vs/base/common/uri.ts +0 -752
  424. package/src/_internal/util/vs/base/common/uuid.ts +0 -72
  425. package/src/_internal/util/vs/base-common.d.ts +0 -42
  426. package/src/_internal/util/vs/editor/common/core/editOperation.ts +0 -62
  427. package/src/_internal/util/vs/editor/common/core/edits/edit.ts +0 -399
  428. package/src/_internal/util/vs/editor/common/core/edits/lineEdit.ts +0 -414
  429. package/src/_internal/util/vs/editor/common/core/edits/stringEdit.ts +0 -568
  430. package/src/_internal/util/vs/editor/common/core/edits/textEdit.ts +0 -411
  431. package/src/_internal/util/vs/editor/common/core/position.ts +0 -186
  432. package/src/_internal/util/vs/editor/common/core/range.ts +0 -519
  433. package/src/_internal/util/vs/editor/common/core/ranges/lineRange.ts +0 -416
  434. package/src/_internal/util/vs/editor/common/core/ranges/offsetRange.ts +0 -275
  435. package/src/_internal/util/vs/editor/common/core/text/abstractText.ts +0 -127
  436. package/src/_internal/util/vs/editor/common/core/text/positionToOffset.ts +0 -26
  437. package/src/_internal/util/vs/editor/common/core/text/positionToOffsetImpl.ts +0 -144
  438. package/src/_internal/util/vs/editor/common/core/text/textLength.ts +0 -150
  439. package/src/_internal/util/vs/editor/common/core/wordHelper.ts +0 -177
  440. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/diffAlgorithm.ts +0 -210
  441. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing.ts +0 -109
  442. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm.ts +0 -178
  443. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts +0 -331
  444. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/defaultLinesDiffComputer.ts +0 -273
  445. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/heuristicSequenceOptimizations.ts +0 -475
  446. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/lineSequence.ts +0 -47
  447. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/linesSliceCharSequence.ts +0 -248
  448. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/utils.ts +0 -76
  449. package/src/_internal/util/vs/editor/common/diff/legacyLinesDiffComputer.ts +0 -693
  450. package/src/_internal/util/vs/editor/common/diff/linesDiffComputer.ts +0 -61
  451. package/src/_internal/util/vs/editor/common/diff/rangeMapping.ts +0 -418
  452. package/src/_internal/util/vs/editor/common/model/prefixSumComputer.ts +0 -304
  453. package/src/_internal/util/vs/nls.messages.ts +0 -21
  454. package/src/_internal/util/vs/nls.ts +0 -243
  455. package/src/_internal/util/vs/platform/instantiation/common/descriptors.ts +0 -23
  456. package/src/_internal/util/vs/platform/instantiation/common/graph.ts +0 -113
  457. package/src/_internal/util/vs/platform/instantiation/common/instantiation.ts +0 -127
  458. package/src/_internal/util/vs/platform/instantiation/common/instantiationService.ts +0 -483
  459. package/src/_internal/util/vs/platform/instantiation/common/serviceCollection.ts +0 -34
  460. package/src/_internal/util/vs/vscode-globals-nls.d.ts +0 -42
  461. package/src/_internal/util/vs/vscode-globals-product.d.ts +0 -35
  462. package/src/_internal/util/vs/workbench/api/common/extHostTypes/diagnostic.ts +0 -109
  463. package/src/_internal/util/vs/workbench/api/common/extHostTypes/es5ClassCompat.ts +0 -34
  464. package/src/_internal/util/vs/workbench/api/common/extHostTypes/location.ts +0 -51
  465. package/src/_internal/util/vs/workbench/api/common/extHostTypes/markdownString.ts +0 -83
  466. package/src/_internal/util/vs/workbench/api/common/extHostTypes/notebooks.ts +0 -296
  467. package/src/_internal/util/vs/workbench/api/common/extHostTypes/position.ts +0 -195
  468. package/src/_internal/util/vs/workbench/api/common/extHostTypes/range.ts +0 -167
  469. package/src/_internal/util/vs/workbench/api/common/extHostTypes/selection.ts +0 -94
  470. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetString.ts +0 -103
  471. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts +0 -44
  472. package/src/_internal/util/vs/workbench/api/common/extHostTypes/symbolInformation.ts +0 -89
  473. package/src/_internal/util/vs/workbench/api/common/extHostTypes/textEdit.ts +0 -99
  474. package/src/_internal/vscodeTypes.ts +0 -100
  475. package/src/main.ts +0 -207
  476. package/src/package.json +0 -4063
@@ -1,1317 +0,0 @@
1
- //!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'
2
-
3
- /*---------------------------------------------------------------------------------------------
4
- * Copyright (c) Microsoft Corporation. All rights reserved.
5
- * Licensed under the MIT License. See License.txt in the project root for license information.
6
- *--------------------------------------------------------------------------------------------*/
7
-
8
- import { DiffChange } from './diffChange';
9
- import { stringHash } from '../hash';
10
- import { Constants } from '../uint';
11
-
12
- export class StringDiffSequence implements ISequence {
13
-
14
- constructor(private source: string) { }
15
-
16
- getElements(): Int32Array | number[] | string[] {
17
- const source = this.source;
18
- const characters = new Int32Array(source.length);
19
- for (let i = 0, len = source.length; i < len; i++) {
20
- characters[i] = source.charCodeAt(i);
21
- }
22
- return characters;
23
- }
24
- }
25
-
26
- export function stringDiff(original: string, modified: string, pretty: boolean): IDiffChange[] {
27
- return new LcsDiff(new StringDiffSequence(original), new StringDiffSequence(modified)).ComputeDiff(pretty).changes;
28
- }
29
-
30
- export interface ISequence {
31
- getElements(): Int32Array | number[] | string[];
32
- getStrictElement?(index: number): string;
33
- }
34
-
35
- export interface IDiffChange {
36
- /**
37
- * The position of the first element in the original sequence which
38
- * this change affects.
39
- */
40
- originalStart: number;
41
-
42
- /**
43
- * The number of elements from the original sequence which were
44
- * affected.
45
- */
46
- originalLength: number;
47
-
48
- /**
49
- * The position of the first element in the modified sequence which
50
- * this change affects.
51
- */
52
- modifiedStart: number;
53
-
54
- /**
55
- * The number of elements from the modified sequence which were
56
- * affected (added).
57
- */
58
- modifiedLength: number;
59
- }
60
-
61
- export interface IContinueProcessingPredicate {
62
- (furthestOriginalIndex: number, matchLengthOfLongest: number): boolean;
63
- }
64
-
65
- export interface IDiffResult {
66
- quitEarly: boolean;
67
- changes: IDiffChange[];
68
- }
69
-
70
- //
71
- // The code below has been ported from a C# implementation in VS
72
- //
73
-
74
- class Debug {
75
-
76
- public static Assert(condition: boolean, message: string): void {
77
- if (!condition) {
78
- throw new Error(message);
79
- }
80
- }
81
- }
82
-
83
- class MyArray {
84
- /**
85
- * Copies a range of elements from an Array starting at the specified source index and pastes
86
- * them to another Array starting at the specified destination index. The length and the indexes
87
- * are specified as 64-bit integers.
88
- * sourceArray:
89
- * The Array that contains the data to copy.
90
- * sourceIndex:
91
- * A 64-bit integer that represents the index in the sourceArray at which copying begins.
92
- * destinationArray:
93
- * The Array that receives the data.
94
- * destinationIndex:
95
- * A 64-bit integer that represents the index in the destinationArray at which storing begins.
96
- * length:
97
- * A 64-bit integer that represents the number of elements to copy.
98
- */
99
- public static Copy(sourceArray: unknown[], sourceIndex: number, destinationArray: unknown[], destinationIndex: number, length: number) {
100
- for (let i = 0; i < length; i++) {
101
- destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
102
- }
103
- }
104
- public static Copy2(sourceArray: Int32Array, sourceIndex: number, destinationArray: Int32Array, destinationIndex: number, length: number) {
105
- for (let i = 0; i < length; i++) {
106
- destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
107
- }
108
- }
109
- }
110
-
111
- //*****************************************************************************
112
- // LcsDiff.cs
113
- //
114
- // An implementation of the difference algorithm described in
115
- // "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers
116
- //
117
- // Copyright (C) 2008 Microsoft Corporation @minifier_do_not_preserve
118
- //*****************************************************************************
119
-
120
- // Our total memory usage for storing history is (worst-case):
121
- // 2 * [(MaxDifferencesHistory + 1) * (MaxDifferencesHistory + 1) - 1] * sizeof(int)
122
- // 2 * [1448*1448 - 1] * 4 = 16773624 = 16MB
123
- const enum LocalConstants {
124
- MaxDifferencesHistory = 1447
125
- }
126
-
127
- /**
128
- * A utility class which helps to create the set of DiffChanges from
129
- * a difference operation. This class accepts original DiffElements and
130
- * modified DiffElements that are involved in a particular change. The
131
- * MarkNextChange() method can be called to mark the separation between
132
- * distinct changes. At the end, the Changes property can be called to retrieve
133
- * the constructed changes.
134
- */
135
- class DiffChangeHelper {
136
-
137
- private m_changes: DiffChange[];
138
- private m_originalStart: number;
139
- private m_modifiedStart: number;
140
- private m_originalCount: number;
141
- private m_modifiedCount: number;
142
-
143
- /**
144
- * Constructs a new DiffChangeHelper for the given DiffSequences.
145
- */
146
- constructor() {
147
- this.m_changes = [];
148
- this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
149
- this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
150
- this.m_originalCount = 0;
151
- this.m_modifiedCount = 0;
152
- }
153
-
154
- /**
155
- * Marks the beginning of the next change in the set of differences.
156
- */
157
- public MarkNextChange(): void {
158
- // Only add to the list if there is something to add
159
- if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
160
- // Add the new change to our list
161
- this.m_changes.push(new DiffChange(this.m_originalStart, this.m_originalCount,
162
- this.m_modifiedStart, this.m_modifiedCount));
163
- }
164
-
165
- // Reset for the next change
166
- this.m_originalCount = 0;
167
- this.m_modifiedCount = 0;
168
- this.m_originalStart = Constants.MAX_SAFE_SMALL_INTEGER;
169
- this.m_modifiedStart = Constants.MAX_SAFE_SMALL_INTEGER;
170
- }
171
-
172
- /**
173
- * Adds the original element at the given position to the elements
174
- * affected by the current change. The modified index gives context
175
- * to the change position with respect to the original sequence.
176
- * @param originalIndex The index of the original element to add.
177
- * @param modifiedIndex The index of the modified element that provides corresponding position in the modified sequence.
178
- */
179
- public AddOriginalElement(originalIndex: number, modifiedIndex: number) {
180
- // The 'true' start index is the smallest of the ones we've seen
181
- this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
182
- this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
183
-
184
- this.m_originalCount++;
185
- }
186
-
187
- /**
188
- * Adds the modified element at the given position to the elements
189
- * affected by the current change. The original index gives context
190
- * to the change position with respect to the modified sequence.
191
- * @param originalIndex The index of the original element that provides corresponding position in the original sequence.
192
- * @param modifiedIndex The index of the modified element to add.
193
- */
194
- public AddModifiedElement(originalIndex: number, modifiedIndex: number): void {
195
- // The 'true' start index is the smallest of the ones we've seen
196
- this.m_originalStart = Math.min(this.m_originalStart, originalIndex);
197
- this.m_modifiedStart = Math.min(this.m_modifiedStart, modifiedIndex);
198
-
199
- this.m_modifiedCount++;
200
- }
201
-
202
- /**
203
- * Retrieves all of the changes marked by the class.
204
- */
205
- public getChanges(): DiffChange[] {
206
- if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
207
- // Finish up on whatever is left
208
- this.MarkNextChange();
209
- }
210
-
211
- return this.m_changes;
212
- }
213
-
214
- /**
215
- * Retrieves all of the changes marked by the class in the reverse order
216
- */
217
- public getReverseChanges(): DiffChange[] {
218
- if (this.m_originalCount > 0 || this.m_modifiedCount > 0) {
219
- // Finish up on whatever is left
220
- this.MarkNextChange();
221
- }
222
-
223
- this.m_changes.reverse();
224
- return this.m_changes;
225
- }
226
-
227
- }
228
-
229
- /**
230
- * An implementation of the difference algorithm described in
231
- * "An O(ND) Difference Algorithm and its variations" by Eugene W. Myers
232
- */
233
- export class LcsDiff {
234
-
235
- private readonly ContinueProcessingPredicate: IContinueProcessingPredicate | null;
236
-
237
- private readonly _originalSequence: ISequence;
238
- private readonly _modifiedSequence: ISequence;
239
- private readonly _hasStrings: boolean;
240
- private readonly _originalStringElements: string[];
241
- private readonly _originalElementsOrHash: Int32Array;
242
- private readonly _modifiedStringElements: string[];
243
- private readonly _modifiedElementsOrHash: Int32Array;
244
-
245
- private m_forwardHistory: Int32Array[];
246
- private m_reverseHistory: Int32Array[];
247
-
248
- /**
249
- * Constructs the DiffFinder
250
- */
251
- constructor(originalSequence: ISequence, modifiedSequence: ISequence, continueProcessingPredicate: IContinueProcessingPredicate | null = null) {
252
- this.ContinueProcessingPredicate = continueProcessingPredicate;
253
-
254
- this._originalSequence = originalSequence;
255
- this._modifiedSequence = modifiedSequence;
256
-
257
- const [originalStringElements, originalElementsOrHash, originalHasStrings] = LcsDiff._getElements(originalSequence);
258
- const [modifiedStringElements, modifiedElementsOrHash, modifiedHasStrings] = LcsDiff._getElements(modifiedSequence);
259
-
260
- this._hasStrings = (originalHasStrings && modifiedHasStrings);
261
- this._originalStringElements = originalStringElements;
262
- this._originalElementsOrHash = originalElementsOrHash;
263
- this._modifiedStringElements = modifiedStringElements;
264
- this._modifiedElementsOrHash = modifiedElementsOrHash;
265
-
266
- this.m_forwardHistory = [];
267
- this.m_reverseHistory = [];
268
- }
269
-
270
- private static _isStringArray(arr: Int32Array | number[] | string[]): arr is string[] {
271
- return (arr.length > 0 && typeof arr[0] === 'string');
272
- }
273
-
274
- private static _getElements(sequence: ISequence): [string[], Int32Array, boolean] {
275
- const elements = sequence.getElements();
276
-
277
- if (LcsDiff._isStringArray(elements)) {
278
- const hashes = new Int32Array(elements.length);
279
- for (let i = 0, len = elements.length; i < len; i++) {
280
- hashes[i] = stringHash(elements[i], 0);
281
- }
282
- return [elements, hashes, true];
283
- }
284
-
285
- if (elements instanceof Int32Array) {
286
- return [[], elements, false];
287
- }
288
-
289
- return [[], new Int32Array(elements), false];
290
- }
291
-
292
- private ElementsAreEqual(originalIndex: number, newIndex: number): boolean {
293
- if (this._originalElementsOrHash[originalIndex] !== this._modifiedElementsOrHash[newIndex]) {
294
- return false;
295
- }
296
- return (this._hasStrings ? this._originalStringElements[originalIndex] === this._modifiedStringElements[newIndex] : true);
297
- }
298
-
299
- private ElementsAreStrictEqual(originalIndex: number, newIndex: number): boolean {
300
- if (!this.ElementsAreEqual(originalIndex, newIndex)) {
301
- return false;
302
- }
303
- const originalElement = LcsDiff._getStrictElement(this._originalSequence, originalIndex);
304
- const modifiedElement = LcsDiff._getStrictElement(this._modifiedSequence, newIndex);
305
- return (originalElement === modifiedElement);
306
- }
307
-
308
- private static _getStrictElement(sequence: ISequence, index: number): string | null {
309
- if (typeof sequence.getStrictElement === 'function') {
310
- return sequence.getStrictElement(index);
311
- }
312
- return null;
313
- }
314
-
315
- private OriginalElementsAreEqual(index1: number, index2: number): boolean {
316
- if (this._originalElementsOrHash[index1] !== this._originalElementsOrHash[index2]) {
317
- return false;
318
- }
319
- return (this._hasStrings ? this._originalStringElements[index1] === this._originalStringElements[index2] : true);
320
- }
321
-
322
- private ModifiedElementsAreEqual(index1: number, index2: number): boolean {
323
- if (this._modifiedElementsOrHash[index1] !== this._modifiedElementsOrHash[index2]) {
324
- return false;
325
- }
326
- return (this._hasStrings ? this._modifiedStringElements[index1] === this._modifiedStringElements[index2] : true);
327
- }
328
-
329
- public ComputeDiff(pretty: boolean): IDiffResult {
330
- return this._ComputeDiff(0, this._originalElementsOrHash.length - 1, 0, this._modifiedElementsOrHash.length - 1, pretty);
331
- }
332
-
333
- /**
334
- * Computes the differences between the original and modified input
335
- * sequences on the bounded range.
336
- * @returns An array of the differences between the two input sequences.
337
- */
338
- private _ComputeDiff(originalStart: number, originalEnd: number, modifiedStart: number, modifiedEnd: number, pretty: boolean): IDiffResult {
339
- const quitEarlyArr = [false];
340
- let changes = this.ComputeDiffRecursive(originalStart, originalEnd, modifiedStart, modifiedEnd, quitEarlyArr);
341
-
342
- if (pretty) {
343
- // We have to clean up the computed diff to be more intuitive
344
- // but it turns out this cannot be done correctly until the entire set
345
- // of diffs have been computed
346
- changes = this.PrettifyChanges(changes);
347
- }
348
-
349
- return {
350
- quitEarly: quitEarlyArr[0],
351
- changes: changes
352
- };
353
- }
354
-
355
- /**
356
- * Private helper method which computes the differences on the bounded range
357
- * recursively.
358
- * @returns An array of the differences between the two input sequences.
359
- */
360
- private ComputeDiffRecursive(originalStart: number, originalEnd: number, modifiedStart: number, modifiedEnd: number, quitEarlyArr: boolean[]): DiffChange[] {
361
- quitEarlyArr[0] = false;
362
-
363
- // Find the start of the differences
364
- while (originalStart <= originalEnd && modifiedStart <= modifiedEnd && this.ElementsAreEqual(originalStart, modifiedStart)) {
365
- originalStart++;
366
- modifiedStart++;
367
- }
368
-
369
- // Find the end of the differences
370
- while (originalEnd >= originalStart && modifiedEnd >= modifiedStart && this.ElementsAreEqual(originalEnd, modifiedEnd)) {
371
- originalEnd--;
372
- modifiedEnd--;
373
- }
374
-
375
- // In the special case where we either have all insertions or all deletions or the sequences are identical
376
- if (originalStart > originalEnd || modifiedStart > modifiedEnd) {
377
- let changes: DiffChange[];
378
-
379
- if (modifiedStart <= modifiedEnd) {
380
- Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
381
-
382
- // All insertions
383
- changes = [
384
- new DiffChange(originalStart, 0, modifiedStart, modifiedEnd - modifiedStart + 1)
385
- ];
386
- } else if (originalStart <= originalEnd) {
387
- Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
388
-
389
- // All deletions
390
- changes = [
391
- new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, 0)
392
- ];
393
- } else {
394
- Debug.Assert(originalStart === originalEnd + 1, 'originalStart should only be one more than originalEnd');
395
- Debug.Assert(modifiedStart === modifiedEnd + 1, 'modifiedStart should only be one more than modifiedEnd');
396
-
397
- // Identical sequences - No differences
398
- changes = [];
399
- }
400
-
401
- return changes;
402
- }
403
-
404
- // This problem can be solved using the Divide-And-Conquer technique.
405
- const midOriginalArr = [0];
406
- const midModifiedArr = [0];
407
- const result = this.ComputeRecursionPoint(originalStart, originalEnd, modifiedStart, modifiedEnd, midOriginalArr, midModifiedArr, quitEarlyArr);
408
-
409
- const midOriginal = midOriginalArr[0];
410
- const midModified = midModifiedArr[0];
411
-
412
- if (result !== null) {
413
- // Result is not-null when there was enough memory to compute the changes while
414
- // searching for the recursion point
415
- return result;
416
- } else if (!quitEarlyArr[0]) {
417
- // We can break the problem down recursively by finding the changes in the
418
- // First Half: (originalStart, modifiedStart) to (midOriginal, midModified)
419
- // Second Half: (midOriginal + 1, minModified + 1) to (originalEnd, modifiedEnd)
420
- // NOTE: ComputeDiff() is inclusive, therefore the second range starts on the next point
421
-
422
- const leftChanges = this.ComputeDiffRecursive(originalStart, midOriginal, modifiedStart, midModified, quitEarlyArr);
423
- let rightChanges: DiffChange[] = [];
424
-
425
- if (!quitEarlyArr[0]) {
426
- rightChanges = this.ComputeDiffRecursive(midOriginal + 1, originalEnd, midModified + 1, modifiedEnd, quitEarlyArr);
427
- } else {
428
- // We didn't have time to finish the first half, so we don't have time to compute this half.
429
- // Consider the entire rest of the sequence different.
430
- rightChanges = [
431
- new DiffChange(midOriginal + 1, originalEnd - (midOriginal + 1) + 1, midModified + 1, modifiedEnd - (midModified + 1) + 1)
432
- ];
433
- }
434
-
435
- return this.ConcatenateChanges(leftChanges, rightChanges);
436
- }
437
-
438
- // If we hit here, we quit early, and so can't return anything meaningful
439
- return [
440
- new DiffChange(originalStart, originalEnd - originalStart + 1, modifiedStart, modifiedEnd - modifiedStart + 1)
441
- ];
442
- }
443
-
444
- private WALKTRACE(diagonalForwardBase: number, diagonalForwardStart: number, diagonalForwardEnd: number, diagonalForwardOffset: number,
445
- diagonalReverseBase: number, diagonalReverseStart: number, diagonalReverseEnd: number, diagonalReverseOffset: number,
446
- forwardPoints: Int32Array, reversePoints: Int32Array,
447
- originalIndex: number, originalEnd: number, midOriginalArr: number[],
448
- modifiedIndex: number, modifiedEnd: number, midModifiedArr: number[],
449
- deltaIsEven: boolean, quitEarlyArr: boolean[]
450
- ): DiffChange[] {
451
- let forwardChanges: DiffChange[] | null = null;
452
- let reverseChanges: DiffChange[] | null = null;
453
-
454
- // First, walk backward through the forward diagonals history
455
- let changeHelper = new DiffChangeHelper();
456
- let diagonalMin = diagonalForwardStart;
457
- let diagonalMax = diagonalForwardEnd;
458
- let diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalForwardOffset;
459
- let lastOriginalIndex = Constants.MIN_SAFE_SMALL_INTEGER;
460
- let historyIndex = this.m_forwardHistory.length - 1;
461
-
462
- do {
463
- // Get the diagonal index from the relative diagonal number
464
- const diagonal = diagonalRelative + diagonalForwardBase;
465
-
466
- // Figure out where we came from
467
- if (diagonal === diagonalMin || (diagonal < diagonalMax && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
468
- // Vertical line (the element is an insert)
469
- originalIndex = forwardPoints[diagonal + 1];
470
- modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
471
- if (originalIndex < lastOriginalIndex) {
472
- changeHelper.MarkNextChange();
473
- }
474
- lastOriginalIndex = originalIndex;
475
- changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex);
476
- diagonalRelative = (diagonal + 1) - diagonalForwardBase; //Setup for the next iteration
477
- } else {
478
- // Horizontal line (the element is a deletion)
479
- originalIndex = forwardPoints[diagonal - 1] + 1;
480
- modifiedIndex = originalIndex - diagonalRelative - diagonalForwardOffset;
481
- if (originalIndex < lastOriginalIndex) {
482
- changeHelper.MarkNextChange();
483
- }
484
- lastOriginalIndex = originalIndex - 1;
485
- changeHelper.AddOriginalElement(originalIndex, modifiedIndex + 1);
486
- diagonalRelative = (diagonal - 1) - diagonalForwardBase; //Setup for the next iteration
487
- }
488
-
489
- if (historyIndex >= 0) {
490
- forwardPoints = this.m_forwardHistory[historyIndex];
491
- diagonalForwardBase = forwardPoints[0]; //We stored this in the first spot
492
- diagonalMin = 1;
493
- diagonalMax = forwardPoints.length - 1;
494
- }
495
- } while (--historyIndex >= -1);
496
-
497
- // Ironically, we get the forward changes as the reverse of the
498
- // order we added them since we technically added them backwards
499
- forwardChanges = changeHelper.getReverseChanges();
500
-
501
- if (quitEarlyArr[0]) {
502
- // TODO: Calculate a partial from the reverse diagonals.
503
- // For now, just assume everything after the midOriginal/midModified point is a diff
504
-
505
- let originalStartPoint = midOriginalArr[0] + 1;
506
- let modifiedStartPoint = midModifiedArr[0] + 1;
507
-
508
- if (forwardChanges !== null && forwardChanges.length > 0) {
509
- const lastForwardChange = forwardChanges[forwardChanges.length - 1];
510
- originalStartPoint = Math.max(originalStartPoint, lastForwardChange.getOriginalEnd());
511
- modifiedStartPoint = Math.max(modifiedStartPoint, lastForwardChange.getModifiedEnd());
512
- }
513
-
514
- reverseChanges = [
515
- new DiffChange(originalStartPoint, originalEnd - originalStartPoint + 1,
516
- modifiedStartPoint, modifiedEnd - modifiedStartPoint + 1)
517
- ];
518
- } else {
519
- // Now walk backward through the reverse diagonals history
520
- changeHelper = new DiffChangeHelper();
521
- diagonalMin = diagonalReverseStart;
522
- diagonalMax = diagonalReverseEnd;
523
- diagonalRelative = (midOriginalArr[0] - midModifiedArr[0]) - diagonalReverseOffset;
524
- lastOriginalIndex = Constants.MAX_SAFE_SMALL_INTEGER;
525
- historyIndex = (deltaIsEven) ? this.m_reverseHistory.length - 1 : this.m_reverseHistory.length - 2;
526
-
527
- do {
528
- // Get the diagonal index from the relative diagonal number
529
- const diagonal = diagonalRelative + diagonalReverseBase;
530
-
531
- // Figure out where we came from
532
- if (diagonal === diagonalMin || (diagonal < diagonalMax && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
533
- // Horizontal line (the element is a deletion))
534
- originalIndex = reversePoints[diagonal + 1] - 1;
535
- modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
536
- if (originalIndex > lastOriginalIndex) {
537
- changeHelper.MarkNextChange();
538
- }
539
- lastOriginalIndex = originalIndex + 1;
540
- changeHelper.AddOriginalElement(originalIndex + 1, modifiedIndex + 1);
541
- diagonalRelative = (diagonal + 1) - diagonalReverseBase; //Setup for the next iteration
542
- } else {
543
- // Vertical line (the element is an insertion)
544
- originalIndex = reversePoints[diagonal - 1];
545
- modifiedIndex = originalIndex - diagonalRelative - diagonalReverseOffset;
546
- if (originalIndex > lastOriginalIndex) {
547
- changeHelper.MarkNextChange();
548
- }
549
- lastOriginalIndex = originalIndex;
550
- changeHelper.AddModifiedElement(originalIndex + 1, modifiedIndex + 1);
551
- diagonalRelative = (diagonal - 1) - diagonalReverseBase; //Setup for the next iteration
552
- }
553
-
554
- if (historyIndex >= 0) {
555
- reversePoints = this.m_reverseHistory[historyIndex];
556
- diagonalReverseBase = reversePoints[0]; //We stored this in the first spot
557
- diagonalMin = 1;
558
- diagonalMax = reversePoints.length - 1;
559
- }
560
- } while (--historyIndex >= -1);
561
-
562
- // There are cases where the reverse history will find diffs that
563
- // are correct, but not intuitive, so we need shift them.
564
- reverseChanges = changeHelper.getChanges();
565
- }
566
-
567
- return this.ConcatenateChanges(forwardChanges, reverseChanges);
568
- }
569
-
570
- /**
571
- * Given the range to compute the diff on, this method finds the point:
572
- * (midOriginal, midModified)
573
- * that exists in the middle of the LCS of the two sequences and
574
- * is the point at which the LCS problem may be broken down recursively.
575
- * This method will try to keep the LCS trace in memory. If the LCS recursion
576
- * point is calculated and the full trace is available in memory, then this method
577
- * will return the change list.
578
- * @param originalStart The start bound of the original sequence range
579
- * @param originalEnd The end bound of the original sequence range
580
- * @param modifiedStart The start bound of the modified sequence range
581
- * @param modifiedEnd The end bound of the modified sequence range
582
- * @param midOriginal The middle point of the original sequence range
583
- * @param midModified The middle point of the modified sequence range
584
- * @returns The diff changes, if available, otherwise null
585
- */
586
- private ComputeRecursionPoint(originalStart: number, originalEnd: number, modifiedStart: number, modifiedEnd: number, midOriginalArr: number[], midModifiedArr: number[], quitEarlyArr: boolean[]) {
587
- let originalIndex = 0, modifiedIndex = 0;
588
- let diagonalForwardStart = 0, diagonalForwardEnd = 0;
589
- let diagonalReverseStart = 0, diagonalReverseEnd = 0;
590
-
591
- // To traverse the edit graph and produce the proper LCS, our actual
592
- // start position is just outside the given boundary
593
- originalStart--;
594
- modifiedStart--;
595
-
596
- // We set these up to make the compiler happy, but they will
597
- // be replaced before we return with the actual recursion point
598
- midOriginalArr[0] = 0;
599
- midModifiedArr[0] = 0;
600
-
601
- // Clear out the history
602
- this.m_forwardHistory = [];
603
- this.m_reverseHistory = [];
604
-
605
- // Each cell in the two arrays corresponds to a diagonal in the edit graph.
606
- // The integer value in the cell represents the originalIndex of the furthest
607
- // reaching point found so far that ends in that diagonal.
608
- // The modifiedIndex can be computed mathematically from the originalIndex and the diagonal number.
609
- const maxDifferences = (originalEnd - originalStart) + (modifiedEnd - modifiedStart);
610
- const numDiagonals = maxDifferences + 1;
611
- const forwardPoints = new Int32Array(numDiagonals);
612
- const reversePoints = new Int32Array(numDiagonals);
613
- // diagonalForwardBase: Index into forwardPoints of the diagonal which passes through (originalStart, modifiedStart)
614
- // diagonalReverseBase: Index into reversePoints of the diagonal which passes through (originalEnd, modifiedEnd)
615
- const diagonalForwardBase = (modifiedEnd - modifiedStart);
616
- const diagonalReverseBase = (originalEnd - originalStart);
617
- // diagonalForwardOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
618
- // diagonal number (relative to diagonalForwardBase)
619
- // diagonalReverseOffset: Geometric offset which allows modifiedIndex to be computed from originalIndex and the
620
- // diagonal number (relative to diagonalReverseBase)
621
- const diagonalForwardOffset = (originalStart - modifiedStart);
622
- const diagonalReverseOffset = (originalEnd - modifiedEnd);
623
-
624
- // delta: The difference between the end diagonal and the start diagonal. This is used to relate diagonal numbers
625
- // relative to the start diagonal with diagonal numbers relative to the end diagonal.
626
- // The Even/Oddn-ness of this delta is important for determining when we should check for overlap
627
- const delta = diagonalReverseBase - diagonalForwardBase;
628
- const deltaIsEven = (delta % 2 === 0);
629
-
630
- // Here we set up the start and end points as the furthest points found so far
631
- // in both the forward and reverse directions, respectively
632
- forwardPoints[diagonalForwardBase] = originalStart;
633
- reversePoints[diagonalReverseBase] = originalEnd;
634
-
635
- // Remember if we quit early, and thus need to do a best-effort result instead of a real result.
636
- quitEarlyArr[0] = false;
637
-
638
-
639
-
640
- // A couple of points:
641
- // --With this method, we iterate on the number of differences between the two sequences.
642
- // The more differences there actually are, the longer this will take.
643
- // --Also, as the number of differences increases, we have to search on diagonals further
644
- // away from the reference diagonal (which is diagonalForwardBase for forward, diagonalReverseBase for reverse).
645
- // --We extend on even diagonals (relative to the reference diagonal) only when numDifferences
646
- // is even and odd diagonals only when numDifferences is odd.
647
- for (let numDifferences = 1; numDifferences <= (maxDifferences / 2) + 1; numDifferences++) {
648
- let furthestOriginalIndex = 0;
649
- let furthestModifiedIndex = 0;
650
-
651
- // Run the algorithm in the forward direction
652
- diagonalForwardStart = this.ClipDiagonalBound(diagonalForwardBase - numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
653
- diagonalForwardEnd = this.ClipDiagonalBound(diagonalForwardBase + numDifferences, numDifferences, diagonalForwardBase, numDiagonals);
654
- for (let diagonal = diagonalForwardStart; diagonal <= diagonalForwardEnd; diagonal += 2) {
655
- // STEP 1: We extend the furthest reaching point in the present diagonal
656
- // by looking at the diagonals above and below and picking the one whose point
657
- // is further away from the start point (originalStart, modifiedStart)
658
- if (diagonal === diagonalForwardStart || (diagonal < diagonalForwardEnd && forwardPoints[diagonal - 1] < forwardPoints[diagonal + 1])) {
659
- originalIndex = forwardPoints[diagonal + 1];
660
- } else {
661
- originalIndex = forwardPoints[diagonal - 1] + 1;
662
- }
663
- modifiedIndex = originalIndex - (diagonal - diagonalForwardBase) - diagonalForwardOffset;
664
-
665
- // Save the current originalIndex so we can test for false overlap in step 3
666
- const tempOriginalIndex = originalIndex;
667
-
668
- // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
669
- // so long as the elements are equal.
670
- while (originalIndex < originalEnd && modifiedIndex < modifiedEnd && this.ElementsAreEqual(originalIndex + 1, modifiedIndex + 1)) {
671
- originalIndex++;
672
- modifiedIndex++;
673
- }
674
- forwardPoints[diagonal] = originalIndex;
675
-
676
- if (originalIndex + modifiedIndex > furthestOriginalIndex + furthestModifiedIndex) {
677
- furthestOriginalIndex = originalIndex;
678
- furthestModifiedIndex = modifiedIndex;
679
- }
680
-
681
- // STEP 3: If delta is odd (overlap first happens on forward when delta is odd)
682
- // and diagonal is in the range of reverse diagonals computed for numDifferences-1
683
- // (the previous iteration; we haven't computed reverse diagonals for numDifferences yet)
684
- // then check for overlap.
685
- if (!deltaIsEven && Math.abs(diagonal - diagonalReverseBase) <= (numDifferences - 1)) {
686
- if (originalIndex >= reversePoints[diagonal]) {
687
- midOriginalArr[0] = originalIndex;
688
- midModifiedArr[0] = modifiedIndex;
689
-
690
- if (tempOriginalIndex <= reversePoints[diagonal] && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
691
- // BINGO! We overlapped, and we have the full trace in memory!
692
- return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset,
693
- diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset,
694
- forwardPoints, reversePoints,
695
- originalIndex, originalEnd, midOriginalArr,
696
- modifiedIndex, modifiedEnd, midModifiedArr,
697
- deltaIsEven, quitEarlyArr
698
- );
699
- } else {
700
- // Either false overlap, or we didn't have enough memory for the full trace
701
- // Just return the recursion point
702
- return null;
703
- }
704
- }
705
- }
706
- }
707
-
708
- // Check to see if we should be quitting early, before moving on to the next iteration.
709
- const matchLengthOfLongest = ((furthestOriginalIndex - originalStart) + (furthestModifiedIndex - modifiedStart) - numDifferences) / 2;
710
-
711
- if (this.ContinueProcessingPredicate !== null && !this.ContinueProcessingPredicate(furthestOriginalIndex, matchLengthOfLongest)) {
712
- // We can't finish, so skip ahead to generating a result from what we have.
713
- quitEarlyArr[0] = true;
714
-
715
- // Use the furthest distance we got in the forward direction.
716
- midOriginalArr[0] = furthestOriginalIndex;
717
- midModifiedArr[0] = furthestModifiedIndex;
718
-
719
- if (matchLengthOfLongest > 0 && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
720
- // Enough of the history is in memory to walk it backwards
721
- return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset,
722
- diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset,
723
- forwardPoints, reversePoints,
724
- originalIndex, originalEnd, midOriginalArr,
725
- modifiedIndex, modifiedEnd, midModifiedArr,
726
- deltaIsEven, quitEarlyArr
727
- );
728
- } else {
729
- // We didn't actually remember enough of the history.
730
-
731
- //Since we are quitting the diff early, we need to shift back the originalStart and modified start
732
- //back into the boundary limits since we decremented their value above beyond the boundary limit.
733
- originalStart++;
734
- modifiedStart++;
735
-
736
- return [
737
- new DiffChange(originalStart, originalEnd - originalStart + 1,
738
- modifiedStart, modifiedEnd - modifiedStart + 1)
739
- ];
740
- }
741
- }
742
-
743
- // Run the algorithm in the reverse direction
744
- diagonalReverseStart = this.ClipDiagonalBound(diagonalReverseBase - numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
745
- diagonalReverseEnd = this.ClipDiagonalBound(diagonalReverseBase + numDifferences, numDifferences, diagonalReverseBase, numDiagonals);
746
- for (let diagonal = diagonalReverseStart; diagonal <= diagonalReverseEnd; diagonal += 2) {
747
- // STEP 1: We extend the furthest reaching point in the present diagonal
748
- // by looking at the diagonals above and below and picking the one whose point
749
- // is further away from the start point (originalEnd, modifiedEnd)
750
- if (diagonal === diagonalReverseStart || (diagonal < diagonalReverseEnd && reversePoints[diagonal - 1] >= reversePoints[diagonal + 1])) {
751
- originalIndex = reversePoints[diagonal + 1] - 1;
752
- } else {
753
- originalIndex = reversePoints[diagonal - 1];
754
- }
755
- modifiedIndex = originalIndex - (diagonal - diagonalReverseBase) - diagonalReverseOffset;
756
-
757
- // Save the current originalIndex so we can test for false overlap
758
- const tempOriginalIndex = originalIndex;
759
-
760
- // STEP 2: We can continue to extend the furthest reaching point in the present diagonal
761
- // as long as the elements are equal.
762
- while (originalIndex > originalStart && modifiedIndex > modifiedStart && this.ElementsAreEqual(originalIndex, modifiedIndex)) {
763
- originalIndex--;
764
- modifiedIndex--;
765
- }
766
- reversePoints[diagonal] = originalIndex;
767
-
768
- // STEP 4: If delta is even (overlap first happens on reverse when delta is even)
769
- // and diagonal is in the range of forward diagonals computed for numDifferences
770
- // then check for overlap.
771
- if (deltaIsEven && Math.abs(diagonal - diagonalForwardBase) <= numDifferences) {
772
- if (originalIndex <= forwardPoints[diagonal]) {
773
- midOriginalArr[0] = originalIndex;
774
- midModifiedArr[0] = modifiedIndex;
775
-
776
- if (tempOriginalIndex >= forwardPoints[diagonal] && LocalConstants.MaxDifferencesHistory > 0 && numDifferences <= (LocalConstants.MaxDifferencesHistory + 1)) {
777
- // BINGO! We overlapped, and we have the full trace in memory!
778
- return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset,
779
- diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset,
780
- forwardPoints, reversePoints,
781
- originalIndex, originalEnd, midOriginalArr,
782
- modifiedIndex, modifiedEnd, midModifiedArr,
783
- deltaIsEven, quitEarlyArr
784
- );
785
- } else {
786
- // Either false overlap, or we didn't have enough memory for the full trace
787
- // Just return the recursion point
788
- return null;
789
- }
790
- }
791
- }
792
- }
793
-
794
- // Save current vectors to history before the next iteration
795
- if (numDifferences <= LocalConstants.MaxDifferencesHistory) {
796
- // We are allocating space for one extra int, which we fill with
797
- // the index of the diagonal base index
798
- let temp = new Int32Array(diagonalForwardEnd - diagonalForwardStart + 2);
799
- temp[0] = diagonalForwardBase - diagonalForwardStart + 1;
800
- MyArray.Copy2(forwardPoints, diagonalForwardStart, temp, 1, diagonalForwardEnd - diagonalForwardStart + 1);
801
- this.m_forwardHistory.push(temp);
802
-
803
- temp = new Int32Array(diagonalReverseEnd - diagonalReverseStart + 2);
804
- temp[0] = diagonalReverseBase - diagonalReverseStart + 1;
805
- MyArray.Copy2(reversePoints, diagonalReverseStart, temp, 1, diagonalReverseEnd - diagonalReverseStart + 1);
806
- this.m_reverseHistory.push(temp);
807
- }
808
-
809
- }
810
-
811
- // If we got here, then we have the full trace in history. We just have to convert it to a change list
812
- // NOTE: This part is a bit messy
813
- return this.WALKTRACE(diagonalForwardBase, diagonalForwardStart, diagonalForwardEnd, diagonalForwardOffset,
814
- diagonalReverseBase, diagonalReverseStart, diagonalReverseEnd, diagonalReverseOffset,
815
- forwardPoints, reversePoints,
816
- originalIndex, originalEnd, midOriginalArr,
817
- modifiedIndex, modifiedEnd, midModifiedArr,
818
- deltaIsEven, quitEarlyArr
819
- );
820
- }
821
-
822
- /**
823
- * Shifts the given changes to provide a more intuitive diff.
824
- * While the first element in a diff matches the first element after the diff,
825
- * we shift the diff down.
826
- *
827
- * @param changes The list of changes to shift
828
- * @returns The shifted changes
829
- */
830
- private PrettifyChanges(changes: DiffChange[]): DiffChange[] {
831
-
832
- // Shift all the changes down first
833
- for (let i = 0; i < changes.length; i++) {
834
- const change = changes[i];
835
- const originalStop = (i < changes.length - 1) ? changes[i + 1].originalStart : this._originalElementsOrHash.length;
836
- const modifiedStop = (i < changes.length - 1) ? changes[i + 1].modifiedStart : this._modifiedElementsOrHash.length;
837
- const checkOriginal = change.originalLength > 0;
838
- const checkModified = change.modifiedLength > 0;
839
-
840
- while (
841
- change.originalStart + change.originalLength < originalStop
842
- && change.modifiedStart + change.modifiedLength < modifiedStop
843
- && (!checkOriginal || this.OriginalElementsAreEqual(change.originalStart, change.originalStart + change.originalLength))
844
- && (!checkModified || this.ModifiedElementsAreEqual(change.modifiedStart, change.modifiedStart + change.modifiedLength))
845
- ) {
846
- const startStrictEqual = this.ElementsAreStrictEqual(change.originalStart, change.modifiedStart);
847
- const endStrictEqual = this.ElementsAreStrictEqual(change.originalStart + change.originalLength, change.modifiedStart + change.modifiedLength);
848
- if (endStrictEqual && !startStrictEqual) {
849
- // moving the change down would create an equal change, but the elements are not strict equal
850
- break;
851
- }
852
- change.originalStart++;
853
- change.modifiedStart++;
854
- }
855
-
856
- const mergedChangeArr: Array<DiffChange | null> = [null];
857
- if (i < changes.length - 1 && this.ChangesOverlap(changes[i], changes[i + 1], mergedChangeArr)) {
858
- changes[i] = mergedChangeArr[0]!;
859
- changes.splice(i + 1, 1);
860
- i--;
861
- continue;
862
- }
863
- }
864
-
865
- // Shift changes back up until we hit empty or whitespace-only lines
866
- for (let i = changes.length - 1; i >= 0; i--) {
867
- const change = changes[i];
868
-
869
- let originalStop = 0;
870
- let modifiedStop = 0;
871
- if (i > 0) {
872
- const prevChange = changes[i - 1];
873
- originalStop = prevChange.originalStart + prevChange.originalLength;
874
- modifiedStop = prevChange.modifiedStart + prevChange.modifiedLength;
875
- }
876
-
877
- const checkOriginal = change.originalLength > 0;
878
- const checkModified = change.modifiedLength > 0;
879
-
880
- let bestDelta = 0;
881
- let bestScore = this._boundaryScore(change.originalStart, change.originalLength, change.modifiedStart, change.modifiedLength);
882
-
883
- for (let delta = 1; ; delta++) {
884
- const originalStart = change.originalStart - delta;
885
- const modifiedStart = change.modifiedStart - delta;
886
-
887
- if (originalStart < originalStop || modifiedStart < modifiedStop) {
888
- break;
889
- }
890
-
891
- if (checkOriginal && !this.OriginalElementsAreEqual(originalStart, originalStart + change.originalLength)) {
892
- break;
893
- }
894
-
895
- if (checkModified && !this.ModifiedElementsAreEqual(modifiedStart, modifiedStart + change.modifiedLength)) {
896
- break;
897
- }
898
-
899
- const touchingPreviousChange = (originalStart === originalStop && modifiedStart === modifiedStop);
900
- const score = (
901
- (touchingPreviousChange ? 5 : 0)
902
- + this._boundaryScore(originalStart, change.originalLength, modifiedStart, change.modifiedLength)
903
- );
904
-
905
- if (score > bestScore) {
906
- bestScore = score;
907
- bestDelta = delta;
908
- }
909
- }
910
-
911
- change.originalStart -= bestDelta;
912
- change.modifiedStart -= bestDelta;
913
-
914
- const mergedChangeArr: Array<DiffChange | null> = [null];
915
- if (i > 0 && this.ChangesOverlap(changes[i - 1], changes[i], mergedChangeArr)) {
916
- changes[i - 1] = mergedChangeArr[0]!;
917
- changes.splice(i, 1);
918
- i++;
919
- continue;
920
- }
921
- }
922
-
923
- // There could be multiple longest common substrings.
924
- // Give preference to the ones containing longer lines
925
- if (this._hasStrings) {
926
- for (let i = 1, len = changes.length; i < len; i++) {
927
- const aChange = changes[i - 1];
928
- const bChange = changes[i];
929
- const matchedLength = bChange.originalStart - aChange.originalStart - aChange.originalLength;
930
- const aOriginalStart = aChange.originalStart;
931
- const bOriginalEnd = bChange.originalStart + bChange.originalLength;
932
- const abOriginalLength = bOriginalEnd - aOriginalStart;
933
- const aModifiedStart = aChange.modifiedStart;
934
- const bModifiedEnd = bChange.modifiedStart + bChange.modifiedLength;
935
- const abModifiedLength = bModifiedEnd - aModifiedStart;
936
- // Avoid wasting a lot of time with these searches
937
- if (matchedLength < 5 && abOriginalLength < 20 && abModifiedLength < 20) {
938
- const t = this._findBetterContiguousSequence(
939
- aOriginalStart, abOriginalLength,
940
- aModifiedStart, abModifiedLength,
941
- matchedLength
942
- );
943
- if (t) {
944
- const [originalMatchStart, modifiedMatchStart] = t;
945
- if (originalMatchStart !== aChange.originalStart + aChange.originalLength || modifiedMatchStart !== aChange.modifiedStart + aChange.modifiedLength) {
946
- // switch to another sequence that has a better score
947
- aChange.originalLength = originalMatchStart - aChange.originalStart;
948
- aChange.modifiedLength = modifiedMatchStart - aChange.modifiedStart;
949
- bChange.originalStart = originalMatchStart + matchedLength;
950
- bChange.modifiedStart = modifiedMatchStart + matchedLength;
951
- bChange.originalLength = bOriginalEnd - bChange.originalStart;
952
- bChange.modifiedLength = bModifiedEnd - bChange.modifiedStart;
953
- }
954
- }
955
- }
956
- }
957
- }
958
-
959
- return changes;
960
- }
961
-
962
- private _findBetterContiguousSequence(originalStart: number, originalLength: number, modifiedStart: number, modifiedLength: number, desiredLength: number): [number, number] | null {
963
- if (originalLength < desiredLength || modifiedLength < desiredLength) {
964
- return null;
965
- }
966
- const originalMax = originalStart + originalLength - desiredLength + 1;
967
- const modifiedMax = modifiedStart + modifiedLength - desiredLength + 1;
968
- let bestScore = 0;
969
- let bestOriginalStart = 0;
970
- let bestModifiedStart = 0;
971
- for (let i = originalStart; i < originalMax; i++) {
972
- for (let j = modifiedStart; j < modifiedMax; j++) {
973
- const score = this._contiguousSequenceScore(i, j, desiredLength);
974
- if (score > 0 && score > bestScore) {
975
- bestScore = score;
976
- bestOriginalStart = i;
977
- bestModifiedStart = j;
978
- }
979
- }
980
- }
981
- if (bestScore > 0) {
982
- return [bestOriginalStart, bestModifiedStart];
983
- }
984
- return null;
985
- }
986
-
987
- private _contiguousSequenceScore(originalStart: number, modifiedStart: number, length: number): number {
988
- let score = 0;
989
- for (let l = 0; l < length; l++) {
990
- if (!this.ElementsAreEqual(originalStart + l, modifiedStart + l)) {
991
- return 0;
992
- }
993
- score += this._originalStringElements[originalStart + l].length;
994
- }
995
- return score;
996
- }
997
-
998
- private _OriginalIsBoundary(index: number): boolean {
999
- if (index <= 0 || index >= this._originalElementsOrHash.length - 1) {
1000
- return true;
1001
- }
1002
- return (this._hasStrings && /^\s*$/.test(this._originalStringElements[index]));
1003
- }
1004
-
1005
- private _OriginalRegionIsBoundary(originalStart: number, originalLength: number): boolean {
1006
- if (this._OriginalIsBoundary(originalStart) || this._OriginalIsBoundary(originalStart - 1)) {
1007
- return true;
1008
- }
1009
- if (originalLength > 0) {
1010
- const originalEnd = originalStart + originalLength;
1011
- if (this._OriginalIsBoundary(originalEnd - 1) || this._OriginalIsBoundary(originalEnd)) {
1012
- return true;
1013
- }
1014
- }
1015
- return false;
1016
- }
1017
-
1018
- private _ModifiedIsBoundary(index: number): boolean {
1019
- if (index <= 0 || index >= this._modifiedElementsOrHash.length - 1) {
1020
- return true;
1021
- }
1022
- return (this._hasStrings && /^\s*$/.test(this._modifiedStringElements[index]));
1023
- }
1024
-
1025
- private _ModifiedRegionIsBoundary(modifiedStart: number, modifiedLength: number): boolean {
1026
- if (this._ModifiedIsBoundary(modifiedStart) || this._ModifiedIsBoundary(modifiedStart - 1)) {
1027
- return true;
1028
- }
1029
- if (modifiedLength > 0) {
1030
- const modifiedEnd = modifiedStart + modifiedLength;
1031
- if (this._ModifiedIsBoundary(modifiedEnd - 1) || this._ModifiedIsBoundary(modifiedEnd)) {
1032
- return true;
1033
- }
1034
- }
1035
- return false;
1036
- }
1037
-
1038
- private _boundaryScore(originalStart: number, originalLength: number, modifiedStart: number, modifiedLength: number): number {
1039
- const originalScore = (this._OriginalRegionIsBoundary(originalStart, originalLength) ? 1 : 0);
1040
- const modifiedScore = (this._ModifiedRegionIsBoundary(modifiedStart, modifiedLength) ? 1 : 0);
1041
- return (originalScore + modifiedScore);
1042
- }
1043
-
1044
- /**
1045
- * Concatenates the two input DiffChange lists and returns the resulting
1046
- * list.
1047
- * @param The left changes
1048
- * @param The right changes
1049
- * @returns The concatenated list
1050
- */
1051
- private ConcatenateChanges(left: DiffChange[], right: DiffChange[]): DiffChange[] {
1052
- const mergedChangeArr: DiffChange[] = [];
1053
-
1054
- if (left.length === 0 || right.length === 0) {
1055
- return (right.length > 0) ? right : left;
1056
- } else if (this.ChangesOverlap(left[left.length - 1], right[0], mergedChangeArr)) {
1057
- // Since we break the problem down recursively, it is possible that we
1058
- // might recurse in the middle of a change thereby splitting it into
1059
- // two changes. Here in the combining stage, we detect and fuse those
1060
- // changes back together
1061
- const result = new Array<DiffChange>(left.length + right.length - 1);
1062
- MyArray.Copy(left, 0, result, 0, left.length - 1);
1063
- result[left.length - 1] = mergedChangeArr[0];
1064
- MyArray.Copy(right, 1, result, left.length, right.length - 1);
1065
-
1066
- return result;
1067
- } else {
1068
- const result = new Array<DiffChange>(left.length + right.length);
1069
- MyArray.Copy(left, 0, result, 0, left.length);
1070
- MyArray.Copy(right, 0, result, left.length, right.length);
1071
-
1072
- return result;
1073
- }
1074
- }
1075
-
1076
- /**
1077
- * Returns true if the two changes overlap and can be merged into a single
1078
- * change
1079
- * @param left The left change
1080
- * @param right The right change
1081
- * @param mergedChange The merged change if the two overlap, null otherwise
1082
- * @returns True if the two changes overlap
1083
- */
1084
- private ChangesOverlap(left: DiffChange, right: DiffChange, mergedChangeArr: Array<DiffChange | null>): boolean {
1085
- Debug.Assert(left.originalStart <= right.originalStart, 'Left change is not less than or equal to right change');
1086
- Debug.Assert(left.modifiedStart <= right.modifiedStart, 'Left change is not less than or equal to right change');
1087
-
1088
- if (left.originalStart + left.originalLength >= right.originalStart || left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
1089
- const originalStart = left.originalStart;
1090
- let originalLength = left.originalLength;
1091
- const modifiedStart = left.modifiedStart;
1092
- let modifiedLength = left.modifiedLength;
1093
-
1094
- if (left.originalStart + left.originalLength >= right.originalStart) {
1095
- originalLength = right.originalStart + right.originalLength - left.originalStart;
1096
- }
1097
- if (left.modifiedStart + left.modifiedLength >= right.modifiedStart) {
1098
- modifiedLength = right.modifiedStart + right.modifiedLength - left.modifiedStart;
1099
- }
1100
-
1101
- mergedChangeArr[0] = new DiffChange(originalStart, originalLength, modifiedStart, modifiedLength);
1102
- return true;
1103
- } else {
1104
- mergedChangeArr[0] = null;
1105
- return false;
1106
- }
1107
- }
1108
-
1109
- /**
1110
- * Helper method used to clip a diagonal index to the range of valid
1111
- * diagonals. This also decides whether or not the diagonal index,
1112
- * if it exceeds the boundary, should be clipped to the boundary or clipped
1113
- * one inside the boundary depending on the Even/Odd status of the boundary
1114
- * and numDifferences.
1115
- * @param diagonal The index of the diagonal to clip.
1116
- * @param numDifferences The current number of differences being iterated upon.
1117
- * @param diagonalBaseIndex The base reference diagonal.
1118
- * @param numDiagonals The total number of diagonals.
1119
- * @returns The clipped diagonal index.
1120
- */
1121
- private ClipDiagonalBound(diagonal: number, numDifferences: number, diagonalBaseIndex: number, numDiagonals: number): number {
1122
- if (diagonal >= 0 && diagonal < numDiagonals) {
1123
- // Nothing to clip, its in range
1124
- return diagonal;
1125
- }
1126
-
1127
- // diagonalsBelow: The number of diagonals below the reference diagonal
1128
- // diagonalsAbove: The number of diagonals above the reference diagonal
1129
- const diagonalsBelow = diagonalBaseIndex;
1130
- const diagonalsAbove = numDiagonals - diagonalBaseIndex - 1;
1131
- const diffEven = (numDifferences % 2 === 0);
1132
-
1133
- if (diagonal < 0) {
1134
- const lowerBoundEven = (diagonalsBelow % 2 === 0);
1135
- return (diffEven === lowerBoundEven) ? 0 : 1;
1136
- } else {
1137
- const upperBoundEven = (diagonalsAbove % 2 === 0);
1138
- return (diffEven === upperBoundEven) ? numDiagonals - 1 : numDiagonals - 2;
1139
- }
1140
- }
1141
- }
1142
-
1143
-
1144
- /**
1145
- * Precomputed equality array for character codes.
1146
- */
1147
- const precomputedEqualityArray = new Uint32Array(0x10000);
1148
-
1149
- /**
1150
- * Computes the Levenshtein distance for strings of length <= 32.
1151
- * @param firstString - The first string.
1152
- * @param secondString - The second string.
1153
- * @returns The Levenshtein distance.
1154
- */
1155
- const computeLevenshteinDistanceForShortStrings = (firstString: string, secondString: string): number => {
1156
- const firstStringLength = firstString.length;
1157
- const secondStringLength = secondString.length;
1158
- const lastBitMask = 1 << (firstStringLength - 1);
1159
- let positiveVector = -1;
1160
- let negativeVector = 0;
1161
- let distance = firstStringLength;
1162
- let index = firstStringLength;
1163
-
1164
- // Initialize precomputedEqualityArray for firstString
1165
- while (index--) {
1166
- precomputedEqualityArray[firstString.charCodeAt(index)] |= 1 << index;
1167
- }
1168
-
1169
- // Process each character of secondString
1170
- for (index = 0; index < secondStringLength; index++) {
1171
- let equalityMask = precomputedEqualityArray[secondString.charCodeAt(index)];
1172
- const combinedVector = equalityMask | negativeVector;
1173
- equalityMask |= ((equalityMask & positiveVector) + positiveVector) ^ positiveVector;
1174
- negativeVector |= ~(equalityMask | positiveVector);
1175
- positiveVector &= equalityMask;
1176
- if (negativeVector & lastBitMask) {
1177
- distance++;
1178
- }
1179
- if (positiveVector & lastBitMask) {
1180
- distance--;
1181
- }
1182
- negativeVector = (negativeVector << 1) | 1;
1183
- positiveVector = (positiveVector << 1) | ~(combinedVector | negativeVector);
1184
- negativeVector &= combinedVector;
1185
- }
1186
-
1187
- // Reset precomputedEqualityArray
1188
- index = firstStringLength;
1189
- while (index--) {
1190
- precomputedEqualityArray[firstString.charCodeAt(index)] = 0;
1191
- }
1192
-
1193
- return distance;
1194
- };
1195
-
1196
- /**
1197
- * Computes the Levenshtein distance for strings of length > 32.
1198
- * @param firstString - The first string.
1199
- * @param secondString - The second string.
1200
- * @returns The Levenshtein distance.
1201
- */
1202
- function computeLevenshteinDistanceForLongStrings(firstString: string, secondString: string): number {
1203
- const firstStringLength = firstString.length;
1204
- const secondStringLength = secondString.length;
1205
- const horizontalBitArray = [];
1206
- const verticalBitArray = [];
1207
- const horizontalSize = Math.ceil(firstStringLength / 32);
1208
- const verticalSize = Math.ceil(secondStringLength / 32);
1209
-
1210
- // Initialize horizontal and vertical bit arrays
1211
- for (let i = 0; i < horizontalSize; i++) {
1212
- horizontalBitArray[i] = -1;
1213
- verticalBitArray[i] = 0;
1214
- }
1215
-
1216
- let verticalIndex = 0;
1217
- for (; verticalIndex < verticalSize - 1; verticalIndex++) {
1218
- let negativeVector = 0;
1219
- let positiveVector = -1;
1220
- const start = verticalIndex * 32;
1221
- const verticalLength = Math.min(32, secondStringLength) + start;
1222
-
1223
- // Initialize precomputedEqualityArray for secondString
1224
- for (let k = start; k < verticalLength; k++) {
1225
- precomputedEqualityArray[secondString.charCodeAt(k)] |= 1 << k;
1226
- }
1227
-
1228
- // Process each character of firstString
1229
- for (let i = 0; i < firstStringLength; i++) {
1230
- const equalityMask = precomputedEqualityArray[firstString.charCodeAt(i)];
1231
- const previousBit = (horizontalBitArray[(i / 32) | 0] >>> i) & 1;
1232
- const matchBit = (verticalBitArray[(i / 32) | 0] >>> i) & 1;
1233
- const combinedVector = equalityMask | negativeVector;
1234
- const combinedHorizontalVector = ((((equalityMask | matchBit) & positiveVector) + positiveVector) ^ positiveVector) | equalityMask | matchBit;
1235
- let positiveHorizontalVector = negativeVector | ~(combinedHorizontalVector | positiveVector);
1236
- let negativeHorizontalVector = positiveVector & combinedHorizontalVector;
1237
- if ((positiveHorizontalVector >>> 31) ^ previousBit) {
1238
- horizontalBitArray[(i / 32) | 0] ^= 1 << i;
1239
- }
1240
- if ((negativeHorizontalVector >>> 31) ^ matchBit) {
1241
- verticalBitArray[(i / 32) | 0] ^= 1 << i;
1242
- }
1243
- positiveHorizontalVector = (positiveHorizontalVector << 1) | previousBit;
1244
- negativeHorizontalVector = (negativeHorizontalVector << 1) | matchBit;
1245
- positiveVector = negativeHorizontalVector | ~(combinedVector | positiveHorizontalVector);
1246
- negativeVector = positiveHorizontalVector & combinedVector;
1247
- }
1248
-
1249
- // Reset precomputedEqualityArray
1250
- for (let k = start; k < verticalLength; k++) {
1251
- precomputedEqualityArray[secondString.charCodeAt(k)] = 0;
1252
- }
1253
- }
1254
-
1255
- let negativeVector = 0;
1256
- let positiveVector = -1;
1257
- const start = verticalIndex * 32;
1258
- const verticalLength = Math.min(32, secondStringLength - start) + start;
1259
-
1260
- // Initialize precomputedEqualityArray for secondString
1261
- for (let k = start; k < verticalLength; k++) {
1262
- precomputedEqualityArray[secondString.charCodeAt(k)] |= 1 << k;
1263
- }
1264
-
1265
- let distance = secondStringLength;
1266
-
1267
- // Process each character of firstString
1268
- for (let i = 0; i < firstStringLength; i++) {
1269
- const equalityMask = precomputedEqualityArray[firstString.charCodeAt(i)];
1270
- const previousBit = (horizontalBitArray[(i / 32) | 0] >>> i) & 1;
1271
- const matchBit = (verticalBitArray[(i / 32) | 0] >>> i) & 1;
1272
- const combinedVector = equalityMask | negativeVector;
1273
- const combinedHorizontalVector = ((((equalityMask | matchBit) & positiveVector) + positiveVector) ^ positiveVector) | equalityMask | matchBit;
1274
- let positiveHorizontalVector = negativeVector | ~(combinedHorizontalVector | positiveVector);
1275
- let negativeHorizontalVector = positiveVector & combinedHorizontalVector;
1276
- distance += (positiveHorizontalVector >>> (secondStringLength - 1)) & 1;
1277
- distance -= (negativeHorizontalVector >>> (secondStringLength - 1)) & 1;
1278
- if ((positiveHorizontalVector >>> 31) ^ previousBit) {
1279
- horizontalBitArray[(i / 32) | 0] ^= 1 << i;
1280
- }
1281
- if ((negativeHorizontalVector >>> 31) ^ matchBit) {
1282
- verticalBitArray[(i / 32) | 0] ^= 1 << i;
1283
- }
1284
- positiveHorizontalVector = (positiveHorizontalVector << 1) | previousBit;
1285
- negativeHorizontalVector = (negativeHorizontalVector << 1) | matchBit;
1286
- positiveVector = negativeHorizontalVector | ~(combinedVector | positiveHorizontalVector);
1287
- negativeVector = positiveHorizontalVector & combinedVector;
1288
- }
1289
-
1290
- // Reset precomputedEqualityArray
1291
- for (let k = start; k < verticalLength; k++) {
1292
- precomputedEqualityArray[secondString.charCodeAt(k)] = 0;
1293
- }
1294
-
1295
- return distance;
1296
- }
1297
-
1298
- /**
1299
- * Computes the Levenshtein distance between two strings.
1300
- * @param firstString - The first string.
1301
- * @param secondString - The second string.
1302
- * @returns The Levenshtein distance.
1303
- */
1304
- export function computeLevenshteinDistance(firstString: string, secondString: string): number {
1305
- if (firstString.length < secondString.length) {
1306
- const temp = secondString;
1307
- secondString = firstString;
1308
- firstString = temp;
1309
- }
1310
- if (secondString.length === 0) {
1311
- return firstString.length;
1312
- }
1313
- if (firstString.length <= 32) {
1314
- return computeLevenshteinDistanceForShortStrings(firstString, secondString);
1315
- }
1316
- return computeLevenshteinDistanceForLongStrings(firstString, secondString);
1317
- }