@vscode/chat-lib 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts.map +1 -1
  2. package/dist/src/_internal/extension/xtab/common/promptCrafting.js +6 -5
  3. package/dist/src/_internal/extension/xtab/common/promptCrafting.js.map +1 -1
  4. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +1 -0
  5. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
  6. package/dist/src/_internal/platform/configuration/common/configurationService.js +1 -0
  7. package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
  8. package/dist/src/_internal/platform/env/common/envService.d.ts +5 -0
  9. package/dist/src/_internal/platform/env/common/envService.d.ts.map +1 -1
  10. package/dist/src/_internal/platform/env/common/envService.js +2 -1
  11. package/dist/src/_internal/platform/env/common/envService.js.map +1 -1
  12. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts +3 -0
  13. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts.map +1 -1
  14. package/dist/src/_internal/platform/env/common/nullEnvService.js +8 -1
  15. package/dist/src/_internal/platform/env/common/nullEnvService.js.map +1 -1
  16. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts +7 -0
  17. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts.map +1 -1
  18. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js +1 -0
  19. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js.map +1 -1
  20. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts +8 -0
  21. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts.map +1 -1
  22. package/dist/src/_internal/util/common/test/shims/chatTypes.js +19 -1
  23. package/dist/src/_internal/util/common/test/shims/chatTypes.js.map +1 -1
  24. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.d.ts.map +1 -1
  25. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js +8 -1
  26. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js.map +1 -1
  27. package/dist/src/_internal/vscodeTypes.d.ts +4 -0
  28. package/dist/src/_internal/vscodeTypes.d.ts.map +1 -1
  29. package/dist/src/_internal/vscodeTypes.js +5 -1
  30. package/dist/src/_internal/vscodeTypes.js.map +1 -1
  31. package/dist/src/main.d.ts +5 -0
  32. package/dist/src/main.d.ts.map +1 -1
  33. package/dist/src/main.js +12 -0
  34. package/dist/src/main.js.map +1 -1
  35. package/dist/src/package.json +46 -19
  36. package/package.json +3 -6
  37. package/src/_internal/extension/byok/node/openAIEndpoint.ts +0 -171
  38. package/src/_internal/extension/common/constants.ts +0 -90
  39. package/src/_internal/extension/inlineEdits/common/delayer.ts +0 -108
  40. package/src/_internal/extension/inlineEdits/common/editRebase.ts +0 -268
  41. package/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.tsx +0 -163
  42. package/src/_internal/extension/inlineEdits/common/nearbyCursorInlineEditProvider.ts +0 -225
  43. package/src/_internal/extension/inlineEdits/common/rejectionCollector.ts +0 -164
  44. package/src/_internal/extension/inlineEdits/node/debugRecorder.ts +0 -205
  45. package/src/_internal/extension/inlineEdits/node/importFiltering.ts +0 -25
  46. package/src/_internal/extension/inlineEdits/node/nesConfigs.ts +0 -12
  47. package/src/_internal/extension/inlineEdits/node/nextEditCache.ts +0 -278
  48. package/src/_internal/extension/inlineEdits/node/nextEditProvider.ts +0 -778
  49. package/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.ts +0 -983
  50. package/src/_internal/extension/inlineEdits/node/nextEditResult.ts +0 -40
  51. package/src/_internal/extension/prompt/common/importStatement.ts +0 -25
  52. package/src/_internal/extension/prompt/node/chatMLFetcher.ts +0 -706
  53. package/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.ts +0 -146
  54. package/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.ts +0 -527
  55. package/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.ts +0 -76
  56. package/src/_internal/extension/prompts/node/inline/visualization.ts +0 -65
  57. package/src/_internal/extension/vscode.proposed.activeComment.d.ts +0 -23
  58. package/src/_internal/extension/vscode.proposed.aiRelatedInformation.d.ts +0 -49
  59. package/src/_internal/extension/vscode.proposed.aiSettingsSearch.d.ts +0 -31
  60. package/src/_internal/extension/vscode.proposed.aiTextSearchProvider.d.ts +0 -41
  61. package/src/_internal/extension/vscode.proposed.authLearnMore.d.ts +0 -16
  62. package/src/_internal/extension/vscode.proposed.chatBinaryReferenceData.d.ts +0 -41
  63. package/src/_internal/extension/vscode.proposed.chatEditing.d.ts +0 -29
  64. package/src/_internal/extension/vscode.proposed.chatParticipantAdditions.d.ts +0 -636
  65. package/src/_internal/extension/vscode.proposed.chatParticipantPrivate.d.ts +0 -276
  66. package/src/_internal/extension/vscode.proposed.chatProvider.d.ts +0 -62
  67. package/src/_internal/extension/vscode.proposed.chatReadonlyPromptReference.d.ts +0 -17
  68. package/src/_internal/extension/vscode.proposed.chatReferenceDiagnostic.d.ts +0 -23
  69. package/src/_internal/extension/vscode.proposed.chatSessionsProvider.d.ts +0 -218
  70. package/src/_internal/extension/vscode.proposed.chatStatusItem.d.ts +0 -61
  71. package/src/_internal/extension/vscode.proposed.codeActionAI.d.ts +0 -16
  72. package/src/_internal/extension/vscode.proposed.commentReveal.d.ts +0 -32
  73. package/src/_internal/extension/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts +0 -8
  74. package/src/_internal/extension/vscode.proposed.contribCommentsViewThreadMenus.d.ts +0 -6
  75. package/src/_internal/extension/vscode.proposed.contribSourceControlInputBoxMenu.d.ts +0 -7
  76. package/src/_internal/extension/vscode.proposed.dataChannels.d.ts +0 -19
  77. package/src/_internal/extension/vscode.proposed.defaultChatParticipant.d.ts +0 -52
  78. package/src/_internal/extension/vscode.proposed.documentFiltersExclusive.d.ts +0 -13
  79. package/src/_internal/extension/vscode.proposed.embeddings.d.ts +0 -33
  80. package/src/_internal/extension/vscode.proposed.extensionsAny.d.ts +0 -40
  81. package/src/_internal/extension/vscode.proposed.findFiles2.d.ts +0 -125
  82. package/src/_internal/extension/vscode.proposed.findTextInFiles.d.ts +0 -104
  83. package/src/_internal/extension/vscode.proposed.findTextInFiles2.d.ts +0 -144
  84. package/src/_internal/extension/vscode.proposed.inlineCompletionsAdditions.d.ts +0 -202
  85. package/src/_internal/extension/vscode.proposed.interactive.d.ts +0 -11
  86. package/src/_internal/extension/vscode.proposed.languageModelCapabilities.d.ts +0 -25
  87. package/src/_internal/extension/vscode.proposed.languageModelDataPart.d.ts +0 -163
  88. package/src/_internal/extension/vscode.proposed.languageModelSystem.d.ts +0 -17
  89. package/src/_internal/extension/vscode.proposed.languageModelThinkingPart.d.ts +0 -49
  90. package/src/_internal/extension/vscode.proposed.languageModelToolResultAudience.d.ts +0 -36
  91. package/src/_internal/extension/vscode.proposed.mappedEditsProvider.d.ts +0 -110
  92. package/src/_internal/extension/vscode.proposed.newSymbolNamesProvider.d.ts +0 -47
  93. package/src/_internal/extension/vscode.proposed.readonlyMessage.d.ts +0 -14
  94. package/src/_internal/extension/vscode.proposed.resolvers.d.ts +0 -475
  95. package/src/_internal/extension/vscode.proposed.scmInputBoxValueProvider.d.ts +0 -25
  96. package/src/_internal/extension/vscode.proposed.taskProblemMatcherStatus.d.ts +0 -42
  97. package/src/_internal/extension/vscode.proposed.terminalDataWriteEvent.d.ts +0 -32
  98. package/src/_internal/extension/vscode.proposed.terminalExecuteCommandEvent.d.ts +0 -48
  99. package/src/_internal/extension/vscode.proposed.terminalQuickFixProvider.d.ts +0 -87
  100. package/src/_internal/extension/vscode.proposed.terminalSelection.d.ts +0 -16
  101. package/src/_internal/extension/vscode.proposed.testObserver.d.ts +0 -199
  102. package/src/_internal/extension/vscode.proposed.textDocumentChangeReason.d.ts +0 -30
  103. package/src/_internal/extension/vscode.proposed.textSearchProvider.d.ts +0 -281
  104. package/src/_internal/extension/vscode.proposed.textSearchProvider2.d.ts +0 -297
  105. package/src/_internal/extension/xtab/common/promptCrafting.ts +0 -670
  106. package/src/_internal/extension/xtab/node/xtabEndpoint.ts +0 -102
  107. package/src/_internal/extension/xtab/node/xtabProvider.ts +0 -976
  108. package/src/_internal/extension/xtab/node/xtabUtils.ts +0 -62
  109. package/src/_internal/platform/authentication/common/authentication.ts +0 -309
  110. package/src/_internal/platform/authentication/common/copilotToken.ts +0 -300
  111. package/src/_internal/platform/authentication/common/copilotTokenManager.ts +0 -59
  112. package/src/_internal/platform/authentication/common/copilotTokenStore.ts +0 -40
  113. package/src/_internal/platform/authentication/common/staticGitHubAuthenticationService.ts +0 -96
  114. package/src/_internal/platform/authentication/node/copilotTokenManager.ts +0 -303
  115. package/src/_internal/platform/chat/common/chatMLFetcher.ts +0 -124
  116. package/src/_internal/platform/chat/common/chatQuotaService.ts +0 -63
  117. package/src/_internal/platform/chat/common/chatQuotaServiceImpl.ts +0 -96
  118. package/src/_internal/platform/chat/common/commonTypes.ts +0 -353
  119. package/src/_internal/platform/chat/common/conversationOptions.ts +0 -16
  120. package/src/_internal/platform/chat/common/globalStringUtils.ts +0 -54
  121. package/src/_internal/platform/chat/common/interactionService.ts +0 -35
  122. package/src/_internal/platform/configuration/common/configurationService.ts +0 -803
  123. package/src/_internal/platform/configuration/common/defaultsOnlyConfigurationService.ts +0 -39
  124. package/src/_internal/platform/configuration/common/jsonSchema.ts +0 -139
  125. package/src/_internal/platform/configuration/common/validator.ts +0 -242
  126. package/src/_internal/platform/diff/common/diffService.ts +0 -41
  127. package/src/_internal/platform/diff/common/diffWorker.ts +0 -83
  128. package/src/_internal/platform/diff/node/diffServiceImpl.ts +0 -85
  129. package/src/_internal/platform/editing/common/abstractText.ts +0 -177
  130. package/src/_internal/platform/editing/common/notebookDocumentSnapshot.ts +0 -122
  131. package/src/_internal/platform/editing/common/positionOffsetTransformer.ts +0 -202
  132. package/src/_internal/platform/editing/common/textDocumentSnapshot.ts +0 -274
  133. package/src/_internal/platform/endpoint/common/capiClient.ts +0 -37
  134. package/src/_internal/platform/endpoint/common/chatModelCapabilities.ts +0 -115
  135. package/src/_internal/platform/endpoint/common/domainService.ts +0 -27
  136. package/src/_internal/platform/endpoint/common/endpointProvider.ts +0 -104
  137. package/src/_internal/platform/endpoint/common/endpointTypes.ts +0 -12
  138. package/src/_internal/platform/endpoint/common/licenseAgreement.ts +0 -11
  139. package/src/_internal/platform/endpoint/common/statefulMarkerContainer.tsx +0 -85
  140. package/src/_internal/platform/endpoint/common/thinkingDataContainer.tsx +0 -44
  141. package/src/_internal/platform/endpoint/node/capiClientImpl.ts +0 -18
  142. package/src/_internal/platform/endpoint/node/chatEndpoint.ts +0 -435
  143. package/src/_internal/platform/endpoint/node/domainServiceImpl.ts +0 -80
  144. package/src/_internal/platform/endpoint/node/proxyXtabEndpoint.ts +0 -43
  145. package/src/_internal/platform/endpoint/node/responsesApi.ts +0 -326
  146. package/src/_internal/platform/env/common/envService.ts +0 -134
  147. package/src/_internal/platform/env/common/nullEnvService.ts +0 -68
  148. package/src/_internal/platform/env/common/packagejson.ts +0 -49
  149. package/src/_internal/platform/git/common/gitExtensionService.ts +0 -21
  150. package/src/_internal/platform/git/common/nullGitExtensionService.ts +0 -20
  151. package/src/_internal/platform/git/vscode/git.d.ts +0 -414
  152. package/src/_internal/platform/github/common/githubAPI.ts +0 -44
  153. package/src/_internal/platform/github/common/githubService.ts +0 -87
  154. package/src/_internal/platform/github/common/nullOctokitServiceImpl.ts +0 -21
  155. package/src/_internal/platform/ignore/common/ignoreService.ts +0 -72
  156. package/src/_internal/platform/inlineCompletions/common/api.ts +0 -198
  157. package/src/_internal/platform/inlineEdits/common/dataTypes/diagnosticData.ts +0 -32
  158. package/src/_internal/platform/inlineEdits/common/dataTypes/documentId.ts +0 -52
  159. package/src/_internal/platform/inlineEdits/common/dataTypes/edit.ts +0 -165
  160. package/src/_internal/platform/inlineEdits/common/dataTypes/editUtils.ts +0 -74
  161. package/src/_internal/platform/inlineEdits/common/dataTypes/fetchCancellationError.ts +0 -14
  162. package/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.ts +0 -107
  163. package/src/_internal/platform/inlineEdits/common/dataTypes/languageId.ts +0 -14
  164. package/src/_internal/platform/inlineEdits/common/dataTypes/permutation.ts +0 -69
  165. package/src/_internal/platform/inlineEdits/common/dataTypes/rootedLineEdit.ts +0 -49
  166. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLength.ts +0 -74
  167. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/combineTextEditInfos.ts +0 -132
  168. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/length.ts +0 -184
  169. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/textEditInfo.ts +0 -32
  170. package/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts +0 -89
  171. package/src/_internal/platform/inlineEdits/common/debugRecorderBookmark.ts +0 -10
  172. package/src/_internal/platform/inlineEdits/common/editReason.ts +0 -134
  173. package/src/_internal/platform/inlineEdits/common/inlineEditLogContext.ts +0 -490
  174. package/src/_internal/platform/inlineEdits/common/observableGit.ts +0 -49
  175. package/src/_internal/platform/inlineEdits/common/observableWorkspace.ts +0 -239
  176. package/src/_internal/platform/inlineEdits/common/responseProcessor.ts +0 -249
  177. package/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.ts +0 -468
  178. package/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.ts +0 -59
  179. package/src/_internal/platform/inlineEdits/common/utils/observable.ts +0 -54
  180. package/src/_internal/platform/inlineEdits/common/utils/stringifyChatMessages.ts +0 -29
  181. package/src/_internal/platform/inlineEdits/common/utils/utils.ts +0 -56
  182. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/historyContextProvider.ts +0 -60
  183. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesHistoryContextProvider.ts +0 -353
  184. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker.ts +0 -176
  185. package/src/_internal/platform/languageContextProvider/common/languageContextProviderService.ts +0 -25
  186. package/src/_internal/platform/languageContextProvider/common/nullLanguageContextProviderService.ts +0 -38
  187. package/src/_internal/platform/languageServer/common/languageContextService.ts +0 -186
  188. package/src/_internal/platform/languages/common/languageDiagnosticsService.ts +0 -67
  189. package/src/_internal/platform/languages/common/testLanguageDiagnosticsService.ts +0 -28
  190. package/src/_internal/platform/log/common/logService.ts +0 -232
  191. package/src/_internal/platform/nesFetch/common/completionsAPI.ts +0 -78
  192. package/src/_internal/platform/nesFetch/common/completionsFetchService.ts +0 -118
  193. package/src/_internal/platform/nesFetch/common/responseStream.ts +0 -151
  194. package/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.ts +0 -236
  195. package/src/_internal/platform/nesFetch/node/streamTransformer.ts +0 -95
  196. package/src/_internal/platform/networking/common/fetch.ts +0 -349
  197. package/src/_internal/platform/networking/common/fetcherService.ts +0 -84
  198. package/src/_internal/platform/networking/common/networking.ts +0 -442
  199. package/src/_internal/platform/networking/common/openai.ts +0 -273
  200. package/src/_internal/platform/networking/node/chatStream.ts +0 -137
  201. package/src/_internal/platform/networking/node/stream.ts +0 -749
  202. package/src/_internal/platform/notebook/common/alternativeContent.ts +0 -89
  203. package/src/_internal/platform/notebook/common/alternativeContentFormat.ts +0 -10
  204. package/src/_internal/platform/notebook/common/alternativeContentProvider.json.ts +0 -262
  205. package/src/_internal/platform/notebook/common/alternativeContentProvider.text.ts +0 -243
  206. package/src/_internal/platform/notebook/common/alternativeContentProvider.ts +0 -41
  207. package/src/_internal/platform/notebook/common/alternativeContentProvider.xml.ts +0 -205
  208. package/src/_internal/platform/notebook/common/alternativeNotebookDocument.ts +0 -155
  209. package/src/_internal/platform/notebook/common/helpers.ts +0 -212
  210. package/src/_internal/platform/notebook/common/notebookService.ts +0 -43
  211. package/src/_internal/platform/openai/node/fetch.ts +0 -596
  212. package/src/_internal/platform/parser/node/nodes.ts +0 -190
  213. package/src/_internal/platform/requestLogger/node/nullRequestLogger.ts +0 -26
  214. package/src/_internal/platform/requestLogger/node/requestLogger.ts +0 -383
  215. package/src/_internal/platform/simulationTestContext/common/simulationTestContext.ts +0 -29
  216. package/src/_internal/platform/snippy/common/snippyService.ts +0 -25
  217. package/src/_internal/platform/telemetry/common/nullExperimentationService.ts +0 -64
  218. package/src/_internal/platform/telemetry/common/nullTelemetryService.ts +0 -53
  219. package/src/_internal/platform/telemetry/common/telemetry.ts +0 -215
  220. package/src/_internal/platform/telemetry/common/telemetryData.ts +0 -205
  221. package/src/_internal/platform/thinking/common/thinking.ts +0 -61
  222. package/src/_internal/platform/thinking/common/thinkingUtils.ts +0 -57
  223. package/src/_internal/platform/tokenizer/node/parseTikTokens.ts +0 -23
  224. package/src/_internal/platform/tokenizer/node/tikTokenizerImpl.ts +0 -74
  225. package/src/_internal/platform/tokenizer/node/tikTokenizerWorker.ts +0 -24
  226. package/src/_internal/platform/tokenizer/node/tokenizer.ts +0 -357
  227. package/src/_internal/platform/workspace/common/workspaceService.ts +0 -226
  228. package/src/_internal/platform/workspaceRecorder/common/workspaceLog.ts +0 -118
  229. package/src/_internal/util/common/anomalyDetection.ts +0 -112
  230. package/src/_internal/util/common/arrays.ts +0 -81
  231. package/src/_internal/util/common/async.ts +0 -155
  232. package/src/_internal/util/common/cache.ts +0 -183
  233. package/src/_internal/util/common/crypto.ts +0 -41
  234. package/src/_internal/util/common/errors.ts +0 -22
  235. package/src/_internal/util/common/globals.d.ts +0 -12
  236. package/src/_internal/util/common/imageUtils.ts +0 -154
  237. package/src/_internal/util/common/languages.ts +0 -940
  238. package/src/_internal/util/common/notebooks.ts +0 -286
  239. package/src/_internal/util/common/result.ts +0 -71
  240. package/src/_internal/util/common/services.ts +0 -43
  241. package/src/_internal/util/common/test/shims/chatTypes.ts +0 -448
  242. package/src/_internal/util/common/test/shims/editing.ts +0 -233
  243. package/src/_internal/util/common/test/shims/enums.ts +0 -61
  244. package/src/_internal/util/common/test/shims/l10n.ts +0 -37
  245. package/src/_internal/util/common/test/shims/newSymbolName.ts +0 -23
  246. package/src/_internal/util/common/test/shims/terminal.ts +0 -33
  247. package/src/_internal/util/common/test/shims/vscodeTypesShim.ts +0 -115
  248. package/src/_internal/util/common/time.ts +0 -31
  249. package/src/_internal/util/common/tokenizer.ts +0 -30
  250. package/src/_internal/util/common/tracing.ts +0 -52
  251. package/src/_internal/util/common/types.ts +0 -33
  252. package/src/_internal/util/common/variableLengthQuantity.ts +0 -40
  253. package/src/_internal/util/node/worker.ts +0 -130
  254. package/src/_internal/util/vs/base/common/arrays.ts +0 -926
  255. package/src/_internal/util/vs/base/common/arraysFind.ts +0 -206
  256. package/src/_internal/util/vs/base/common/assert.ts +0 -89
  257. package/src/_internal/util/vs/base/common/async.ts +0 -2582
  258. package/src/_internal/util/vs/base/common/buffer.ts +0 -501
  259. package/src/_internal/util/vs/base/common/cache.ts +0 -122
  260. package/src/_internal/util/vs/base/common/cancellation.ts +0 -150
  261. package/src/_internal/util/vs/base/common/charCode.ts +0 -452
  262. package/src/_internal/util/vs/base/common/codicons.ts +0 -66
  263. package/src/_internal/util/vs/base/common/codiconsLibrary.ts +0 -618
  264. package/src/_internal/util/vs/base/common/codiconsUtil.ts +0 -30
  265. package/src/_internal/util/vs/base/common/collections.ts +0 -156
  266. package/src/_internal/util/vs/base/common/diff/diff.ts +0 -1317
  267. package/src/_internal/util/vs/base/common/diff/diffChange.ts +0 -62
  268. package/src/_internal/util/vs/base/common/equals.ts +0 -148
  269. package/src/_internal/util/vs/base/common/errors.ts +0 -342
  270. package/src/_internal/util/vs/base/common/event.ts +0 -1782
  271. package/src/_internal/util/vs/base/common/extpath.ts +0 -425
  272. package/src/_internal/util/vs/base/common/filters.ts +0 -928
  273. package/src/_internal/util/vs/base/common/functional.ts +0 -34
  274. package/src/_internal/util/vs/base/common/glob.ts +0 -839
  275. package/src/_internal/util/vs/base/common/hash.ts +0 -326
  276. package/src/_internal/util/vs/base/common/htmlContent.ts +0 -212
  277. package/src/_internal/util/vs/base/common/iconLabels.ts +0 -118
  278. package/src/_internal/util/vs/base/common/iterator.ts +0 -196
  279. package/src/_internal/util/vs/base/common/lazy.ts +0 -59
  280. package/src/_internal/util/vs/base/common/lifecycle.ts +0 -845
  281. package/src/_internal/util/vs/base/common/linkedList.ts +0 -144
  282. package/src/_internal/util/vs/base/common/map.ts +0 -954
  283. package/src/_internal/util/vs/base/common/marshallingIds.ts +0 -35
  284. package/src/_internal/util/vs/base/common/mime.ts +0 -136
  285. package/src/_internal/util/vs/base/common/naturalLanguage/korean.ts +0 -425
  286. package/src/_internal/util/vs/base/common/network.ts +0 -429
  287. package/src/_internal/util/vs/base/common/numbers.ts +0 -166
  288. package/src/_internal/util/vs/base/common/objects.ts +0 -242
  289. package/src/_internal/util/vs/base/common/observable.ts +0 -10
  290. package/src/_internal/util/vs/base/common/observableInternal/base.ts +0 -208
  291. package/src/_internal/util/vs/base/common/observableInternal/changeTracker.ts +0 -96
  292. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/cancellation.ts +0 -9
  293. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/deps.ts +0 -12
  294. package/src/_internal/util/vs/base/common/observableInternal/debugLocation.ts +0 -88
  295. package/src/_internal/util/vs/base/common/observableInternal/debugName.ts +0 -150
  296. package/src/_internal/util/vs/base/common/observableInternal/experimental/utils.ts +0 -62
  297. package/src/_internal/util/vs/base/common/observableInternal/index.ts +0 -61
  298. package/src/_internal/util/vs/base/common/observableInternal/logging/consoleObservableLogger.ts +0 -388
  299. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerApi.d.ts +0 -154
  300. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerRpc.ts +0 -80
  301. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/devToolsLogger.ts +0 -485
  302. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/rpc.ts +0 -103
  303. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/utils.ts +0 -69
  304. package/src/_internal/util/vs/base/common/observableInternal/logging/logging.ts +0 -133
  305. package/src/_internal/util/vs/base/common/observableInternal/map.ts +0 -81
  306. package/src/_internal/util/vs/base/common/observableInternal/observables/baseObservable.ts +0 -172
  307. package/src/_internal/util/vs/base/common/observableInternal/observables/constObservable.ts +0 -44
  308. package/src/_internal/util/vs/base/common/observableInternal/observables/derived.ts +0 -190
  309. package/src/_internal/util/vs/base/common/observableInternal/observables/derivedImpl.ts +0 -445
  310. package/src/_internal/util/vs/base/common/observableInternal/observables/lazyObservableValue.ts +0 -154
  311. package/src/_internal/util/vs/base/common/observableInternal/observables/observableFromEvent.ts +0 -174
  312. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignal.ts +0 -67
  313. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignalFromEvent.ts +0 -62
  314. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValue.ts +0 -131
  315. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValueOpts.ts +0 -37
  316. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorun.ts +0 -188
  317. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorunImpl.ts +0 -256
  318. package/src/_internal/util/vs/base/common/observableInternal/set.ts +0 -78
  319. package/src/_internal/util/vs/base/common/observableInternal/transaction.ts +0 -115
  320. package/src/_internal/util/vs/base/common/observableInternal/utils/promise.ts +0 -129
  321. package/src/_internal/util/vs/base/common/observableInternal/utils/runOnChange.ts +0 -65
  322. package/src/_internal/util/vs/base/common/observableInternal/utils/utils.ts +0 -281
  323. package/src/_internal/util/vs/base/common/observableInternal/utils/utilsCancellation.ts +0 -101
  324. package/src/_internal/util/vs/base/common/observableInternal/utils/valueWithChangeEvent.ts +0 -31
  325. package/src/_internal/util/vs/base/common/path.ts +0 -1591
  326. package/src/_internal/util/vs/base/common/platform.ts +0 -282
  327. package/src/_internal/util/vs/base/common/process.ts +0 -78
  328. package/src/_internal/util/vs/base/common/resources.ts +0 -446
  329. package/src/_internal/util/vs/base/common/sequence.ts +0 -36
  330. package/src/_internal/util/vs/base/common/sseParser.ts +0 -247
  331. package/src/_internal/util/vs/base/common/stopwatch.ts +0 -43
  332. package/src/_internal/util/vs/base/common/stream.ts +0 -792
  333. package/src/_internal/util/vs/base/common/strings.ts +0 -1364
  334. package/src/_internal/util/vs/base/common/symbols.ts +0 -11
  335. package/src/_internal/util/vs/base/common/themables.ts +0 -106
  336. package/src/_internal/util/vs/base/common/types.ts +0 -345
  337. package/src/_internal/util/vs/base/common/uint.ts +0 -61
  338. package/src/_internal/util/vs/base/common/uri.ts +0 -752
  339. package/src/_internal/util/vs/base/common/uuid.ts +0 -72
  340. package/src/_internal/util/vs/base-common.d.ts +0 -42
  341. package/src/_internal/util/vs/editor/common/core/editOperation.ts +0 -62
  342. package/src/_internal/util/vs/editor/common/core/edits/edit.ts +0 -399
  343. package/src/_internal/util/vs/editor/common/core/edits/lineEdit.ts +0 -414
  344. package/src/_internal/util/vs/editor/common/core/edits/stringEdit.ts +0 -568
  345. package/src/_internal/util/vs/editor/common/core/edits/textEdit.ts +0 -411
  346. package/src/_internal/util/vs/editor/common/core/position.ts +0 -186
  347. package/src/_internal/util/vs/editor/common/core/range.ts +0 -519
  348. package/src/_internal/util/vs/editor/common/core/ranges/lineRange.ts +0 -416
  349. package/src/_internal/util/vs/editor/common/core/ranges/offsetRange.ts +0 -275
  350. package/src/_internal/util/vs/editor/common/core/text/abstractText.ts +0 -127
  351. package/src/_internal/util/vs/editor/common/core/text/positionToOffset.ts +0 -26
  352. package/src/_internal/util/vs/editor/common/core/text/positionToOffsetImpl.ts +0 -144
  353. package/src/_internal/util/vs/editor/common/core/text/textLength.ts +0 -150
  354. package/src/_internal/util/vs/editor/common/core/wordHelper.ts +0 -177
  355. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/diffAlgorithm.ts +0 -210
  356. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing.ts +0 -109
  357. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm.ts +0 -178
  358. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts +0 -331
  359. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/defaultLinesDiffComputer.ts +0 -273
  360. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/heuristicSequenceOptimizations.ts +0 -475
  361. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/lineSequence.ts +0 -47
  362. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/linesSliceCharSequence.ts +0 -248
  363. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/utils.ts +0 -76
  364. package/src/_internal/util/vs/editor/common/diff/legacyLinesDiffComputer.ts +0 -693
  365. package/src/_internal/util/vs/editor/common/diff/linesDiffComputer.ts +0 -61
  366. package/src/_internal/util/vs/editor/common/diff/rangeMapping.ts +0 -418
  367. package/src/_internal/util/vs/editor/common/model/prefixSumComputer.ts +0 -304
  368. package/src/_internal/util/vs/nls.messages.ts +0 -21
  369. package/src/_internal/util/vs/nls.ts +0 -243
  370. package/src/_internal/util/vs/platform/instantiation/common/descriptors.ts +0 -23
  371. package/src/_internal/util/vs/platform/instantiation/common/graph.ts +0 -113
  372. package/src/_internal/util/vs/platform/instantiation/common/instantiation.ts +0 -127
  373. package/src/_internal/util/vs/platform/instantiation/common/instantiationService.ts +0 -483
  374. package/src/_internal/util/vs/platform/instantiation/common/serviceCollection.ts +0 -34
  375. package/src/_internal/util/vs/vscode-globals-nls.d.ts +0 -42
  376. package/src/_internal/util/vs/vscode-globals-product.d.ts +0 -35
  377. package/src/_internal/util/vs/workbench/api/common/extHostTypes/diagnostic.ts +0 -109
  378. package/src/_internal/util/vs/workbench/api/common/extHostTypes/es5ClassCompat.ts +0 -34
  379. package/src/_internal/util/vs/workbench/api/common/extHostTypes/location.ts +0 -51
  380. package/src/_internal/util/vs/workbench/api/common/extHostTypes/markdownString.ts +0 -83
  381. package/src/_internal/util/vs/workbench/api/common/extHostTypes/notebooks.ts +0 -296
  382. package/src/_internal/util/vs/workbench/api/common/extHostTypes/position.ts +0 -195
  383. package/src/_internal/util/vs/workbench/api/common/extHostTypes/range.ts +0 -167
  384. package/src/_internal/util/vs/workbench/api/common/extHostTypes/selection.ts +0 -94
  385. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetString.ts +0 -103
  386. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts +0 -44
  387. package/src/_internal/util/vs/workbench/api/common/extHostTypes/symbolInformation.ts +0 -89
  388. package/src/_internal/util/vs/workbench/api/common/extHostTypes/textEdit.ts +0 -99
  389. package/src/_internal/vscodeTypes.ts +0 -100
  390. package/src/main.ts +0 -207
  391. package/src/package.json +0 -4063
@@ -1,1782 +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 { CancelablePromise } from './async';
9
- import { CancellationToken } from './cancellation';
10
- import { diffSets } from './collections';
11
- import { onUnexpectedError } from './errors';
12
- import { createSingleCallFunction } from './functional';
13
- import { combinedDisposable, Disposable, DisposableMap, DisposableStore, IDisposable, toDisposable } from './lifecycle';
14
- import { LinkedList } from './linkedList';
15
- import { IObservable, IObservableWithChange, IObserver } from './observable';
16
- import { StopWatch } from './stopwatch';
17
- import { MicrotaskDelay } from './symbols';
18
-
19
-
20
- // -----------------------------------------------------------------------------------------------------------------------
21
- // Uncomment the next line to print warnings whenever an emitter with listeners is disposed. That is a sign of code smell.
22
- // -----------------------------------------------------------------------------------------------------------------------
23
- const _enableDisposeWithListenerWarning = false
24
- // || Boolean("TRUE") // causes a linter warning so that it cannot be pushed
25
- ;
26
-
27
-
28
- // -----------------------------------------------------------------------------------------------------------------------
29
- // Uncomment the next line to print warnings whenever a snapshotted event is used repeatedly without cleanup.
30
- // See https://github.com/microsoft/vscode/issues/142851
31
- // -----------------------------------------------------------------------------------------------------------------------
32
- const _enableSnapshotPotentialLeakWarning = false
33
- // || Boolean("TRUE") // causes a linter warning so that it cannot be pushed
34
- ;
35
-
36
- /**
37
- * An event with zero or one parameters that can be subscribed to. The event is a function itself.
38
- */
39
- export interface Event<T> {
40
- (listener: (e: T) => unknown, thisArgs?: any, disposables?: IDisposable[] | DisposableStore): IDisposable;
41
- }
42
-
43
- export namespace Event {
44
- export const None: Event<any> = () => Disposable.None;
45
-
46
- function _addLeakageTraceLogic(options: EmitterOptions) {
47
- if (_enableSnapshotPotentialLeakWarning) {
48
- const { onDidAddListener: origListenerDidAdd } = options;
49
- const stack = Stacktrace.create();
50
- let count = 0;
51
- options.onDidAddListener = () => {
52
- if (++count === 2) {
53
- console.warn('snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here');
54
- stack.print();
55
- }
56
- origListenerDidAdd?.();
57
- };
58
- }
59
- }
60
-
61
- /**
62
- * Given an event, returns another event which debounces calls and defers the listeners to a later task via a shared
63
- * `setTimeout`. The event is converted into a signal (`Event<void>`) to avoid additional object creation as a
64
- * result of merging events and to try prevent race conditions that could arise when using related deferred and
65
- * non-deferred events.
66
- *
67
- * This is useful for deferring non-critical work (eg. general UI updates) to ensure it does not block critical work
68
- * (eg. latency of keypress to text rendered).
69
- *
70
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
71
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
72
- * returned event causes this utility to leak a listener on the original event.
73
- *
74
- * @param event The event source for the new event.
75
- * @param disposable A disposable store to add the new EventEmitter to.
76
- */
77
- export function defer(event: Event<unknown>, disposable?: DisposableStore): Event<void> {
78
- return debounce<unknown, void>(event, () => void 0, 0, undefined, true, undefined, disposable);
79
- }
80
-
81
- /**
82
- * Given an event, returns another event which only fires once.
83
- *
84
- * @param event The event source for the new event.
85
- */
86
- export function once<T>(event: Event<T>): Event<T> {
87
- return (listener, thisArgs = null, disposables?) => {
88
- // we need this, in case the event fires during the listener call
89
- let didFire = false;
90
- let result: IDisposable | undefined = undefined;
91
- result = event(e => {
92
- if (didFire) {
93
- return;
94
- } else if (result) {
95
- result.dispose();
96
- } else {
97
- didFire = true;
98
- }
99
-
100
- return listener.call(thisArgs, e);
101
- }, null, disposables);
102
-
103
- if (didFire) {
104
- result.dispose();
105
- }
106
-
107
- return result;
108
- };
109
- }
110
-
111
- /**
112
- * Given an event, returns another event which only fires once, and only when the condition is met.
113
- *
114
- * @param event The event source for the new event.
115
- */
116
- export function onceIf<T>(event: Event<T>, condition: (e: T) => boolean): Event<T> {
117
- return Event.once(Event.filter(event, condition));
118
- }
119
-
120
- /**
121
- * Maps an event of one type into an event of another type using a mapping function, similar to how
122
- * `Array.prototype.map` works.
123
- *
124
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
125
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
126
- * returned event causes this utility to leak a listener on the original event.
127
- *
128
- * @param event The event source for the new event.
129
- * @param map The mapping function.
130
- * @param disposable A disposable store to add the new EventEmitter to.
131
- */
132
- export function map<I, O>(event: Event<I>, map: (i: I) => O, disposable?: DisposableStore): Event<O> {
133
- return snapshot((listener, thisArgs = null, disposables?) => event(i => listener.call(thisArgs, map(i)), null, disposables), disposable);
134
- }
135
-
136
- /**
137
- * Wraps an event in another event that performs some function on the event object before firing.
138
- *
139
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
140
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
141
- * returned event causes this utility to leak a listener on the original event.
142
- *
143
- * @param event The event source for the new event.
144
- * @param each The function to perform on the event object.
145
- * @param disposable A disposable store to add the new EventEmitter to.
146
- */
147
- export function forEach<I>(event: Event<I>, each: (i: I) => void, disposable?: DisposableStore): Event<I> {
148
- return snapshot((listener, thisArgs = null, disposables?) => event(i => { each(i); listener.call(thisArgs, i); }, null, disposables), disposable);
149
- }
150
-
151
- /**
152
- * Wraps an event in another event that fires only when some condition is met.
153
- *
154
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
155
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
156
- * returned event causes this utility to leak a listener on the original event.
157
- *
158
- * @param event The event source for the new event.
159
- * @param filter The filter function that defines the condition. The event will fire for the object if this function
160
- * returns true.
161
- * @param disposable A disposable store to add the new EventEmitter to.
162
- */
163
- export function filter<T, U>(event: Event<T | U>, filter: (e: T | U) => e is T, disposable?: DisposableStore): Event<T>;
164
- export function filter<T>(event: Event<T>, filter: (e: T) => boolean, disposable?: DisposableStore): Event<T>;
165
- export function filter<T, R>(event: Event<T | R>, filter: (e: T | R) => e is R, disposable?: DisposableStore): Event<R>;
166
- export function filter<T>(event: Event<T>, filter: (e: T) => boolean, disposable?: DisposableStore): Event<T> {
167
- return snapshot((listener, thisArgs = null, disposables?) => event(e => filter(e) && listener.call(thisArgs, e), null, disposables), disposable);
168
- }
169
-
170
- /**
171
- * Given an event, returns the same event but typed as `Event<void>`.
172
- */
173
- export function signal<T>(event: Event<T>): Event<void> {
174
- return event as Event<any> as Event<void>;
175
- }
176
-
177
- /**
178
- * Given a collection of events, returns a single event which emits whenever any of the provided events emit.
179
- */
180
- export function any<T>(...events: Event<T>[]): Event<T>;
181
- export function any(...events: Event<any>[]): Event<void>;
182
- export function any<T>(...events: Event<T>[]): Event<T> {
183
- return (listener, thisArgs = null, disposables?) => {
184
- const disposable = combinedDisposable(...events.map(event => event(e => listener.call(thisArgs, e))));
185
- return addAndReturnDisposable(disposable, disposables);
186
- };
187
- }
188
-
189
- /**
190
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
191
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
192
- * returned event causes this utility to leak a listener on the original event.
193
- */
194
- export function reduce<I, O>(event: Event<I>, merge: (last: O | undefined, event: I) => O, initial?: O, disposable?: DisposableStore): Event<O> {
195
- let output: O | undefined = initial;
196
-
197
- return map<I, O>(event, e => {
198
- output = merge(output, e);
199
- return output;
200
- }, disposable);
201
- }
202
-
203
- function snapshot<T>(event: Event<T>, disposable: DisposableStore | undefined): Event<T> {
204
- let listener: IDisposable | undefined;
205
-
206
- const options: EmitterOptions | undefined = {
207
- onWillAddFirstListener() {
208
- listener = event(emitter.fire, emitter);
209
- },
210
- onDidRemoveLastListener() {
211
- listener?.dispose();
212
- }
213
- };
214
-
215
- if (!disposable) {
216
- _addLeakageTraceLogic(options);
217
- }
218
-
219
- const emitter = new Emitter<T>(options);
220
-
221
- disposable?.add(emitter);
222
-
223
- return emitter.event;
224
- }
225
-
226
- /**
227
- * Adds the IDisposable to the store if it's set, and returns it. Useful to
228
- * Event function implementation.
229
- */
230
- function addAndReturnDisposable<T extends IDisposable>(d: T, store: DisposableStore | IDisposable[] | undefined): T {
231
- if (store instanceof Array) {
232
- store.push(d);
233
- } else if (store) {
234
- store.add(d);
235
- }
236
- return d;
237
- }
238
-
239
- /**
240
- * Given an event, creates a new emitter that event that will debounce events based on {@link delay} and give an
241
- * array event object of all events that fired.
242
- *
243
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
244
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
245
- * returned event causes this utility to leak a listener on the original event.
246
- *
247
- * @param event The original event to debounce.
248
- * @param merge A function that reduces all events into a single event.
249
- * @param delay The number of milliseconds to debounce.
250
- * @param leading Whether to fire a leading event without debouncing.
251
- * @param flushOnListenerRemove Whether to fire all debounced events when a listener is removed. If this is not
252
- * specified, some events could go missing. Use this if it's important that all events are processed, even if the
253
- * listener gets disposed before the debounced event fires.
254
- * @param leakWarningThreshold See {@link EmitterOptions.leakWarningThreshold}.
255
- * @param disposable A disposable store to register the debounce emitter to.
256
- */
257
- export function debounce<T>(event: Event<T>, merge: (last: T | undefined, event: T) => T, delay?: number | typeof MicrotaskDelay, leading?: boolean, flushOnListenerRemove?: boolean, leakWarningThreshold?: number, disposable?: DisposableStore): Event<T>;
258
- export function debounce<I, O>(event: Event<I>, merge: (last: O | undefined, event: I) => O, delay?: number | typeof MicrotaskDelay, leading?: boolean, flushOnListenerRemove?: boolean, leakWarningThreshold?: number, disposable?: DisposableStore): Event<O>;
259
- export function debounce<I, O>(event: Event<I>, merge: (last: O | undefined, event: I) => O, delay: number | typeof MicrotaskDelay = 100, leading = false, flushOnListenerRemove = false, leakWarningThreshold?: number, disposable?: DisposableStore): Event<O> {
260
- let subscription: IDisposable;
261
- let output: O | undefined = undefined;
262
- let handle: Timeout | undefined | null = undefined;
263
- let numDebouncedCalls = 0;
264
- let doFire: (() => void) | undefined;
265
-
266
- const options: EmitterOptions | undefined = {
267
- leakWarningThreshold,
268
- onWillAddFirstListener() {
269
- subscription = event(cur => {
270
- numDebouncedCalls++;
271
- output = merge(output, cur);
272
-
273
- if (leading && !handle) {
274
- emitter.fire(output);
275
- output = undefined;
276
- }
277
-
278
- doFire = () => {
279
- const _output = output;
280
- output = undefined;
281
- handle = undefined;
282
- if (!leading || numDebouncedCalls > 1) {
283
- emitter.fire(_output!);
284
- }
285
- numDebouncedCalls = 0;
286
- };
287
-
288
- if (typeof delay === 'number') {
289
- if (handle) {
290
- clearTimeout(handle);
291
- }
292
- handle = setTimeout(doFire, delay);
293
- } else {
294
- if (handle === undefined) {
295
- handle = null;
296
- queueMicrotask(doFire);
297
- }
298
- }
299
- });
300
- },
301
- onWillRemoveListener() {
302
- if (flushOnListenerRemove && numDebouncedCalls > 0) {
303
- doFire?.();
304
- }
305
- },
306
- onDidRemoveLastListener() {
307
- doFire = undefined;
308
- subscription.dispose();
309
- }
310
- };
311
-
312
- if (!disposable) {
313
- _addLeakageTraceLogic(options);
314
- }
315
-
316
- const emitter = new Emitter<O>(options);
317
-
318
- disposable?.add(emitter);
319
-
320
- return emitter.event;
321
- }
322
-
323
- /**
324
- * Debounces an event, firing after some delay (default=0) with an array of all event original objects.
325
- *
326
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
327
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
328
- * returned event causes this utility to leak a listener on the original event.
329
- */
330
- export function accumulate<T>(event: Event<T>, delay: number | typeof MicrotaskDelay = 0, disposable?: DisposableStore): Event<T[]> {
331
- return Event.debounce<T, T[]>(event, (last, e) => {
332
- if (!last) {
333
- return [e];
334
- }
335
- last.push(e);
336
- return last;
337
- }, delay, undefined, true, undefined, disposable);
338
- }
339
-
340
- /**
341
- * Filters an event such that some condition is _not_ met more than once in a row, effectively ensuring duplicate
342
- * event objects from different sources do not fire the same event object.
343
- *
344
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
345
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
346
- * returned event causes this utility to leak a listener on the original event.
347
- *
348
- * @param event The event source for the new event.
349
- * @param equals The equality condition.
350
- * @param disposable A disposable store to add the new EventEmitter to.
351
- *
352
- * @example
353
- * ```
354
- * // Fire only one time when a single window is opened or focused
355
- * Event.latch(Event.any(onDidOpenWindow, onDidFocusWindow))
356
- * ```
357
- */
358
- export function latch<T>(event: Event<T>, equals: (a: T, b: T) => boolean = (a, b) => a === b, disposable?: DisposableStore): Event<T> {
359
- let firstCall = true;
360
- let cache: T;
361
-
362
- return filter(event, value => {
363
- const shouldEmit = firstCall || !equals(value, cache);
364
- firstCall = false;
365
- cache = value;
366
- return shouldEmit;
367
- }, disposable);
368
- }
369
-
370
- /**
371
- * Splits an event whose parameter is a union type into 2 separate events for each type in the union.
372
- *
373
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
374
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
375
- * returned event causes this utility to leak a listener on the original event.
376
- *
377
- * @example
378
- * ```
379
- * const event = new EventEmitter<number | undefined>().event;
380
- * const [numberEvent, undefinedEvent] = Event.split(event, isUndefined);
381
- * ```
382
- *
383
- * @param event The event source for the new event.
384
- * @param isT A function that determines what event is of the first type.
385
- * @param disposable A disposable store to add the new EventEmitter to.
386
- */
387
- export function split<T, U>(event: Event<T | U>, isT: (e: T | U) => e is T, disposable?: DisposableStore): [Event<T>, Event<U>] {
388
- return [
389
- Event.filter(event, isT, disposable),
390
- Event.filter(event, e => !isT(e), disposable) as Event<U>,
391
- ];
392
- }
393
-
394
- /**
395
- * Buffers an event until it has a listener attached.
396
- *
397
- * *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
398
- * event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
399
- * returned event causes this utility to leak a listener on the original event.
400
- *
401
- * @param event The event source for the new event.
402
- * @param flushAfterTimeout Determines whether to flush the buffer after a timeout immediately or after a
403
- * `setTimeout` when the first event listener is added.
404
- * @param _buffer Internal: A source event array used for tests.
405
- *
406
- * @example
407
- * ```
408
- * // Start accumulating events, when the first listener is attached, flush
409
- * // the event after a timeout such that multiple listeners attached before
410
- * // the timeout would receive the event
411
- * this.onInstallExtension = Event.buffer(service.onInstallExtension, true);
412
- * ```
413
- */
414
- export function buffer<T>(event: Event<T>, flushAfterTimeout = false, _buffer: T[] = [], disposable?: DisposableStore): Event<T> {
415
- let buffer: T[] | null = _buffer.slice();
416
-
417
- let listener: IDisposable | null = event(e => {
418
- if (buffer) {
419
- buffer.push(e);
420
- } else {
421
- emitter.fire(e);
422
- }
423
- });
424
-
425
- if (disposable) {
426
- disposable.add(listener);
427
- }
428
-
429
- const flush = () => {
430
- buffer?.forEach(e => emitter.fire(e));
431
- buffer = null;
432
- };
433
-
434
- const emitter = new Emitter<T>({
435
- onWillAddFirstListener() {
436
- if (!listener) {
437
- listener = event(e => emitter.fire(e));
438
- if (disposable) {
439
- disposable.add(listener);
440
- }
441
- }
442
- },
443
-
444
- onDidAddFirstListener() {
445
- if (buffer) {
446
- if (flushAfterTimeout) {
447
- setTimeout(flush);
448
- } else {
449
- flush();
450
- }
451
- }
452
- },
453
-
454
- onDidRemoveLastListener() {
455
- if (listener) {
456
- listener.dispose();
457
- }
458
- listener = null;
459
- }
460
- });
461
-
462
- if (disposable) {
463
- disposable.add(emitter);
464
- }
465
-
466
- return emitter.event;
467
- }
468
- /**
469
- * Wraps the event in an {@link IChainableEvent}, allowing a more functional programming style.
470
- *
471
- * @example
472
- * ```
473
- * // Normal
474
- * const onEnterPressNormal = Event.filter(
475
- * Event.map(onKeyPress.event, e => new StandardKeyboardEvent(e)),
476
- * e.keyCode === KeyCode.Enter
477
- * ).event;
478
- *
479
- * // Using chain
480
- * const onEnterPressChain = Event.chain(onKeyPress.event, $ => $
481
- * .map(e => new StandardKeyboardEvent(e))
482
- * .filter(e => e.keyCode === KeyCode.Enter)
483
- * );
484
- * ```
485
- */
486
- export function chain<T, R>(event: Event<T>, sythensize: ($: IChainableSythensis<T>) => IChainableSythensis<R>): Event<R> {
487
- const fn: Event<R> = (listener, thisArgs, disposables) => {
488
- const cs = sythensize(new ChainableSynthesis()) as ChainableSynthesis;
489
- return event(function (value) {
490
- const result = cs.evaluate(value);
491
- if (result !== HaltChainable) {
492
- listener.call(thisArgs, result);
493
- }
494
- }, undefined, disposables);
495
- };
496
-
497
- return fn;
498
- }
499
-
500
- const HaltChainable = Symbol('HaltChainable');
501
-
502
- class ChainableSynthesis implements IChainableSythensis<any> {
503
- private readonly steps: ((input: any) => unknown)[] = [];
504
-
505
- map<O>(fn: (i: any) => O): this {
506
- this.steps.push(fn);
507
- return this;
508
- }
509
-
510
- forEach(fn: (i: any) => void): this {
511
- this.steps.push(v => {
512
- fn(v);
513
- return v;
514
- });
515
- return this;
516
- }
517
-
518
- filter(fn: (e: any) => boolean): this {
519
- this.steps.push(v => fn(v) ? v : HaltChainable);
520
- return this;
521
- }
522
-
523
- reduce<R>(merge: (last: R | undefined, event: any) => R, initial?: R | undefined): this {
524
- let last = initial;
525
- this.steps.push(v => {
526
- last = merge(last, v);
527
- return last;
528
- });
529
- return this;
530
- }
531
-
532
- latch(equals: (a: any, b: any) => boolean = (a, b) => a === b): ChainableSynthesis {
533
- let firstCall = true;
534
- let cache: any;
535
- this.steps.push(value => {
536
- const shouldEmit = firstCall || !equals(value, cache);
537
- firstCall = false;
538
- cache = value;
539
- return shouldEmit ? value : HaltChainable;
540
- });
541
-
542
- return this;
543
- }
544
-
545
- public evaluate(value: any) {
546
- for (const step of this.steps) {
547
- value = step(value);
548
- if (value === HaltChainable) {
549
- break;
550
- }
551
- }
552
-
553
- return value;
554
- }
555
- }
556
-
557
- export interface IChainableSythensis<T> {
558
- map<O>(fn: (i: T) => O): IChainableSythensis<O>;
559
- forEach(fn: (i: T) => void): IChainableSythensis<T>;
560
- filter<R extends T>(fn: (e: T) => e is R): IChainableSythensis<R>;
561
- filter(fn: (e: T) => boolean): IChainableSythensis<T>;
562
- reduce<R>(merge: (last: R, event: T) => R, initial: R): IChainableSythensis<R>;
563
- reduce<R>(merge: (last: R | undefined, event: T) => R): IChainableSythensis<R>;
564
- latch(equals?: (a: T, b: T) => boolean): IChainableSythensis<T>;
565
- }
566
-
567
- export interface NodeEventEmitter {
568
- on(event: string | symbol, listener: Function): unknown;
569
- removeListener(event: string | symbol, listener: Function): unknown;
570
- }
571
-
572
- /**
573
- * Creates an {@link Event} from a node event emitter.
574
- */
575
- export function fromNodeEventEmitter<T>(emitter: NodeEventEmitter, eventName: string, map: (...args: any[]) => T = id => id): Event<T> {
576
- const fn = (...args: any[]) => result.fire(map(...args));
577
- const onFirstListenerAdd = () => emitter.on(eventName, fn);
578
- const onLastListenerRemove = () => emitter.removeListener(eventName, fn);
579
- const result = new Emitter<T>({ onWillAddFirstListener: onFirstListenerAdd, onDidRemoveLastListener: onLastListenerRemove });
580
-
581
- return result.event;
582
- }
583
-
584
- export interface DOMEventEmitter {
585
- addEventListener(event: string | symbol, listener: Function): void;
586
- removeEventListener(event: string | symbol, listener: Function): void;
587
- }
588
-
589
- /**
590
- * Creates an {@link Event} from a DOM event emitter.
591
- */
592
- export function fromDOMEventEmitter<T>(emitter: DOMEventEmitter, eventName: string, map: (...args: any[]) => T = id => id): Event<T> {
593
- const fn = (...args: any[]) => result.fire(map(...args));
594
- const onFirstListenerAdd = () => emitter.addEventListener(eventName, fn);
595
- const onLastListenerRemove = () => emitter.removeEventListener(eventName, fn);
596
- const result = new Emitter<T>({ onWillAddFirstListener: onFirstListenerAdd, onDidRemoveLastListener: onLastListenerRemove });
597
-
598
- return result.event;
599
- }
600
-
601
- /**
602
- * Creates a promise out of an event, using the {@link Event.once} helper.
603
- */
604
- export function toPromise<T>(event: Event<T>, disposables?: IDisposable[] | DisposableStore): CancelablePromise<T> {
605
- let cancelRef: () => void;
606
- const promise = new Promise((resolve, reject) => {
607
- const listener = once(event)(resolve, null, disposables);
608
- // not resolved, matching the behavior of a normal disposal
609
- cancelRef = () => listener.dispose();
610
- }) as CancelablePromise<T>;
611
- promise.cancel = cancelRef!;
612
-
613
- return promise;
614
- }
615
-
616
- /**
617
- * A convenience function for forwarding an event to another emitter which
618
- * improves readability.
619
- *
620
- * This is similar to {@link Relay} but allows instantiating and forwarding
621
- * on a single line and also allows for multiple source events.
622
- * @param from The event to forward.
623
- * @param to The emitter to forward the event to.
624
- * @example
625
- * Event.forward(event, emitter);
626
- * // equivalent to
627
- * event(e => emitter.fire(e));
628
- * // equivalent to
629
- * event(emitter.fire, emitter);
630
- */
631
- export function forward<T>(from: Event<T>, to: Emitter<T>): IDisposable {
632
- return from(e => to.fire(e));
633
- }
634
-
635
- /**
636
- * Adds a listener to an event and calls the listener immediately with undefined as the event object.
637
- *
638
- * @example
639
- * ```
640
- * // Initialize the UI and update it when dataChangeEvent fires
641
- * runAndSubscribe(dataChangeEvent, () => this._updateUI());
642
- * ```
643
- */
644
- export function runAndSubscribe<T>(event: Event<T>, handler: (e: T) => unknown, initial: T): IDisposable;
645
- export function runAndSubscribe<T>(event: Event<T>, handler: (e: T | undefined) => unknown): IDisposable;
646
- export function runAndSubscribe<T>(event: Event<T>, handler: (e: T | undefined) => unknown, initial?: T): IDisposable {
647
- handler(initial);
648
- return event(e => handler(e));
649
- }
650
-
651
- class EmitterObserver<T> implements IObserver {
652
-
653
- readonly emitter: Emitter<T>;
654
-
655
- private _counter = 0;
656
- private _hasChanged = false;
657
-
658
- constructor(readonly _observable: IObservable<T>, store: DisposableStore | undefined) {
659
- const options: EmitterOptions = {
660
- onWillAddFirstListener: () => {
661
- _observable.addObserver(this);
662
-
663
- // Communicate to the observable that we received its current value and would like to be notified about future changes.
664
- this._observable.reportChanges();
665
- },
666
- onDidRemoveLastListener: () => {
667
- _observable.removeObserver(this);
668
- }
669
- };
670
- if (!store) {
671
- _addLeakageTraceLogic(options);
672
- }
673
- this.emitter = new Emitter<T>(options);
674
- if (store) {
675
- store.add(this.emitter);
676
- }
677
- }
678
-
679
- beginUpdate<T>(_observable: IObservable<T>): void {
680
- // assert(_observable === this.obs);
681
- this._counter++;
682
- }
683
-
684
- handlePossibleChange<T>(_observable: IObservable<T>): void {
685
- // assert(_observable === this.obs);
686
- }
687
-
688
- handleChange<T, TChange>(_observable: IObservableWithChange<T, TChange>, _change: TChange): void {
689
- // assert(_observable === this.obs);
690
- this._hasChanged = true;
691
- }
692
-
693
- endUpdate<T>(_observable: IObservable<T>): void {
694
- // assert(_observable === this.obs);
695
- this._counter--;
696
- if (this._counter === 0) {
697
- this._observable.reportChanges();
698
- if (this._hasChanged) {
699
- this._hasChanged = false;
700
- this.emitter.fire(this._observable.get());
701
- }
702
- }
703
- }
704
- }
705
-
706
- /**
707
- * Creates an event emitter that is fired when the observable changes.
708
- * Each listeners subscribes to the emitter.
709
- */
710
- export function fromObservable<T>(obs: IObservable<T>, store?: DisposableStore): Event<T> {
711
- const observer = new EmitterObserver(obs, store);
712
- return observer.emitter.event;
713
- }
714
-
715
- /**
716
- * Each listener is attached to the observable directly.
717
- */
718
- export function fromObservableLight(observable: IObservable<unknown>): Event<void> {
719
- return (listener, thisArgs, disposables) => {
720
- let count = 0;
721
- let didChange = false;
722
- const observer: IObserver = {
723
- beginUpdate() {
724
- count++;
725
- },
726
- endUpdate() {
727
- count--;
728
- if (count === 0) {
729
- observable.reportChanges();
730
- if (didChange) {
731
- didChange = false;
732
- listener.call(thisArgs);
733
- }
734
- }
735
- },
736
- handlePossibleChange() {
737
- // noop
738
- },
739
- handleChange() {
740
- didChange = true;
741
- }
742
- };
743
- observable.addObserver(observer);
744
- observable.reportChanges();
745
- const disposable = {
746
- dispose() {
747
- observable.removeObserver(observer);
748
- }
749
- };
750
-
751
- if (disposables instanceof DisposableStore) {
752
- disposables.add(disposable);
753
- } else if (Array.isArray(disposables)) {
754
- disposables.push(disposable);
755
- }
756
-
757
- return disposable;
758
- };
759
- }
760
- }
761
-
762
- export interface EmitterOptions {
763
- /**
764
- * Optional function that's called *before* the very first listener is added
765
- */
766
- onWillAddFirstListener?: Function;
767
- /**
768
- * Optional function that's called *after* the very first listener is added
769
- */
770
- onDidAddFirstListener?: Function;
771
- /**
772
- * Optional function that's called after a listener is added
773
- */
774
- onDidAddListener?: Function;
775
- /**
776
- * Optional function that's called *after* remove the very last listener
777
- */
778
- onDidRemoveLastListener?: Function;
779
- /**
780
- * Optional function that's called *before* a listener is removed
781
- */
782
- onWillRemoveListener?: Function;
783
- /**
784
- * Optional function that's called when a listener throws an error. Defaults to
785
- * {@link onUnexpectedError}
786
- */
787
- onListenerError?: (e: any) => void;
788
- /**
789
- * Number of listeners that are allowed before assuming a leak. Default to
790
- * a globally configured value
791
- *
792
- * @see setGlobalLeakWarningThreshold
793
- */
794
- leakWarningThreshold?: number;
795
- /**
796
- * Pass in a delivery queue, which is useful for ensuring
797
- * in order event delivery across multiple emitters.
798
- */
799
- deliveryQueue?: EventDeliveryQueue;
800
-
801
- /** ONLY enable this during development */
802
- _profName?: string;
803
- }
804
-
805
-
806
- export class EventProfiling {
807
-
808
- static readonly all = new Set<EventProfiling>();
809
-
810
- private static _idPool = 0;
811
-
812
- readonly name: string;
813
- public listenerCount: number = 0;
814
- public invocationCount = 0;
815
- public elapsedOverall = 0;
816
- public durations: number[] = [];
817
-
818
- private _stopWatch?: StopWatch;
819
-
820
- constructor(name: string) {
821
- this.name = `${name}_${EventProfiling._idPool++}`;
822
- EventProfiling.all.add(this);
823
- }
824
-
825
- start(listenerCount: number): void {
826
- this._stopWatch = new StopWatch();
827
- this.listenerCount = listenerCount;
828
- }
829
-
830
- stop(): void {
831
- if (this._stopWatch) {
832
- const elapsed = this._stopWatch.elapsed();
833
- this.durations.push(elapsed);
834
- this.elapsedOverall += elapsed;
835
- this.invocationCount += 1;
836
- this._stopWatch = undefined;
837
- }
838
- }
839
- }
840
-
841
- let _globalLeakWarningThreshold = -1;
842
- export function setGlobalLeakWarningThreshold(n: number): IDisposable {
843
- const oldValue = _globalLeakWarningThreshold;
844
- _globalLeakWarningThreshold = n;
845
- return {
846
- dispose() {
847
- _globalLeakWarningThreshold = oldValue;
848
- }
849
- };
850
- }
851
-
852
- class LeakageMonitor {
853
-
854
- private static _idPool = 1;
855
-
856
- private _stacks: Map<string, number> | undefined;
857
- private _warnCountdown: number = 0;
858
-
859
- constructor(
860
- private readonly _errorHandler: (err: Error) => void,
861
- readonly threshold: number,
862
- readonly name: string = (LeakageMonitor._idPool++).toString(16).padStart(3, '0')
863
- ) { }
864
-
865
- dispose(): void {
866
- this._stacks?.clear();
867
- }
868
-
869
- check(stack: Stacktrace, listenerCount: number): undefined | (() => void) {
870
-
871
- const threshold = this.threshold;
872
- if (threshold <= 0 || listenerCount < threshold) {
873
- return undefined;
874
- }
875
-
876
- if (!this._stacks) {
877
- this._stacks = new Map();
878
- }
879
- const count = (this._stacks.get(stack.value) || 0);
880
- this._stacks.set(stack.value, count + 1);
881
- this._warnCountdown -= 1;
882
-
883
- if (this._warnCountdown <= 0) {
884
- // only warn on first exceed and then every time the limit
885
- // is exceeded by 50% again
886
- this._warnCountdown = threshold * 0.5;
887
-
888
- const [topStack, topCount] = this.getMostFrequentStack()!;
889
- const message = `[${this.name}] potential listener LEAK detected, having ${listenerCount} listeners already. MOST frequent listener (${topCount}):`;
890
- console.warn(message);
891
- console.warn(topStack!);
892
-
893
- const error = new ListenerLeakError(message, topStack);
894
- this._errorHandler(error);
895
- }
896
-
897
- return () => {
898
- const count = (this._stacks!.get(stack.value) || 0);
899
- this._stacks!.set(stack.value, count - 1);
900
- };
901
- }
902
-
903
- getMostFrequentStack(): [string, number] | undefined {
904
- if (!this._stacks) {
905
- return undefined;
906
- }
907
- let topStack: [string, number] | undefined;
908
- let topCount: number = 0;
909
- for (const [stack, count] of this._stacks) {
910
- if (!topStack || topCount < count) {
911
- topStack = [stack, count];
912
- topCount = count;
913
- }
914
- }
915
- return topStack;
916
- }
917
- }
918
-
919
- class Stacktrace {
920
-
921
- static create() {
922
- const err = new Error();
923
- return new Stacktrace(err.stack ?? '');
924
- }
925
-
926
- private constructor(readonly value: string) { }
927
-
928
- print() {
929
- console.warn(this.value.split('\n').slice(2).join('\n'));
930
- }
931
- }
932
-
933
- // error that is logged when going over the configured listener threshold
934
- export class ListenerLeakError extends Error {
935
- constructor(message: string, stack: string) {
936
- super(message);
937
- this.name = 'ListenerLeakError';
938
- this.stack = stack;
939
- }
940
- }
941
-
942
- // SEVERE error that is logged when having gone way over the configured listener
943
- // threshold so that the emitter refuses to accept more listeners
944
- export class ListenerRefusalError extends Error {
945
- constructor(message: string, stack: string) {
946
- super(message);
947
- this.name = 'ListenerRefusalError';
948
- this.stack = stack;
949
- }
950
- }
951
-
952
- let id = 0;
953
- class UniqueContainer<T> {
954
- stack?: Stacktrace;
955
- public id = id++;
956
- constructor(public readonly value: T) { }
957
- }
958
- const compactionThreshold = 2;
959
-
960
- type ListenerContainer<T> = UniqueContainer<(data: T) => void>;
961
- type ListenerOrListeners<T> = (ListenerContainer<T> | undefined)[] | ListenerContainer<T>;
962
-
963
- const forEachListener = <T>(listeners: ListenerOrListeners<T>, fn: (c: ListenerContainer<T>) => void) => {
964
- if (listeners instanceof UniqueContainer) {
965
- fn(listeners);
966
- } else {
967
- for (let i = 0; i < listeners.length; i++) {
968
- const l = listeners[i];
969
- if (l) {
970
- fn(l);
971
- }
972
- }
973
- }
974
- };
975
-
976
- /**
977
- * The Emitter can be used to expose an Event to the public
978
- * to fire it from the insides.
979
- * Sample:
980
- class Document {
981
-
982
- private readonly _onDidChange = new Emitter<(value:string)=>any>();
983
-
984
- public onDidChange = this._onDidChange.event;
985
-
986
- // getter-style
987
- // get onDidChange(): Event<(value:string)=>any> {
988
- // return this._onDidChange.event;
989
- // }
990
-
991
- private _doIt() {
992
- //...
993
- this._onDidChange.fire(value);
994
- }
995
- }
996
- */
997
- export class Emitter<T> {
998
-
999
- private readonly _options?: EmitterOptions;
1000
- private readonly _leakageMon?: LeakageMonitor;
1001
- private readonly _perfMon?: EventProfiling;
1002
- private _disposed?: true;
1003
- private _event?: Event<T>;
1004
-
1005
- /**
1006
- * A listener, or list of listeners. A single listener is the most common
1007
- * for event emitters (#185789), so we optimize that special case to avoid
1008
- * wrapping it in an array (just like Node.js itself.)
1009
- *
1010
- * A list of listeners never 'downgrades' back to a plain function if
1011
- * listeners are removed, for two reasons:
1012
- *
1013
- * 1. That's complicated (especially with the deliveryQueue)
1014
- * 2. A listener with >1 listener is likely to have >1 listener again at
1015
- * some point, and swapping between arrays and functions may[citation needed]
1016
- * introduce unnecessary work and garbage.
1017
- *
1018
- * The array listeners can be 'sparse', to avoid reallocating the array
1019
- * whenever any listener is added or removed. If more than `1 / compactionThreshold`
1020
- * of the array is empty, only then is it resized.
1021
- */
1022
- protected _listeners?: ListenerOrListeners<T>;
1023
-
1024
- /**
1025
- * Always to be defined if _listeners is an array. It's no longer a true
1026
- * queue, but holds the dispatching 'state'. If `fire()` is called on an
1027
- * emitter, any work left in the _deliveryQueue is finished first.
1028
- */
1029
- private _deliveryQueue?: EventDeliveryQueuePrivate;
1030
- protected _size = 0;
1031
-
1032
- constructor(options?: EmitterOptions) {
1033
- this._options = options;
1034
- this._leakageMon = (_globalLeakWarningThreshold > 0 || this._options?.leakWarningThreshold)
1035
- ? new LeakageMonitor(options?.onListenerError ?? onUnexpectedError, this._options?.leakWarningThreshold ?? _globalLeakWarningThreshold) :
1036
- undefined;
1037
- this._perfMon = this._options?._profName ? new EventProfiling(this._options._profName) : undefined;
1038
- this._deliveryQueue = this._options?.deliveryQueue as EventDeliveryQueuePrivate | undefined;
1039
- }
1040
-
1041
- dispose() {
1042
- if (!this._disposed) {
1043
- this._disposed = true;
1044
-
1045
- // It is bad to have listeners at the time of disposing an emitter, it is worst to have listeners keep the emitter
1046
- // alive via the reference that's embedded in their disposables. Therefore we loop over all remaining listeners and
1047
- // unset their subscriptions/disposables. Looping and blaming remaining listeners is done on next tick because the
1048
- // the following programming pattern is very popular:
1049
- //
1050
- // const someModel = this._disposables.add(new ModelObject()); // (1) create and register model
1051
- // this._disposables.add(someModel.onDidChange(() => { ... }); // (2) subscribe and register model-event listener
1052
- // ...later...
1053
- // this._disposables.dispose(); disposes (1) then (2): don't warn after (1) but after the "overall dispose" is done
1054
-
1055
- if (this._deliveryQueue?.current === this) {
1056
- this._deliveryQueue.reset();
1057
- }
1058
- if (this._listeners) {
1059
- if (_enableDisposeWithListenerWarning) {
1060
- const listeners = this._listeners;
1061
- queueMicrotask(() => {
1062
- forEachListener(listeners, l => l.stack?.print());
1063
- });
1064
- }
1065
-
1066
- this._listeners = undefined;
1067
- this._size = 0;
1068
- }
1069
- this._options?.onDidRemoveLastListener?.();
1070
- this._leakageMon?.dispose();
1071
- }
1072
- }
1073
-
1074
- /**
1075
- * For the public to allow to subscribe
1076
- * to events from this Emitter
1077
- */
1078
- get event(): Event<T> {
1079
- this._event ??= (callback: (e: T) => unknown, thisArgs?: any, disposables?: IDisposable[] | DisposableStore) => {
1080
- if (this._leakageMon && this._size > this._leakageMon.threshold ** 2) {
1081
- const message = `[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;
1082
- console.warn(message);
1083
-
1084
- const tuple = this._leakageMon.getMostFrequentStack() ?? ['UNKNOWN stack', -1];
1085
- const error = new ListenerRefusalError(`${message}. HINT: Stack shows most frequent listener (${tuple[1]}-times)`, tuple[0]);
1086
- const errorHandler = this._options?.onListenerError || onUnexpectedError;
1087
- errorHandler(error);
1088
-
1089
- return Disposable.None;
1090
- }
1091
-
1092
- if (this._disposed) {
1093
- // todo: should we warn if a listener is added to a disposed emitter? This happens often
1094
- return Disposable.None;
1095
- }
1096
-
1097
- if (thisArgs) {
1098
- callback = callback.bind(thisArgs);
1099
- }
1100
-
1101
- const contained = new UniqueContainer(callback);
1102
-
1103
- let removeMonitor: Function | undefined;
1104
- let stack: Stacktrace | undefined;
1105
- if (this._leakageMon && this._size >= Math.ceil(this._leakageMon.threshold * 0.2)) {
1106
- // check and record this emitter for potential leakage
1107
- contained.stack = Stacktrace.create();
1108
- removeMonitor = this._leakageMon.check(contained.stack, this._size + 1);
1109
- }
1110
-
1111
- if (_enableDisposeWithListenerWarning) {
1112
- contained.stack = stack ?? Stacktrace.create();
1113
- }
1114
-
1115
- if (!this._listeners) {
1116
- this._options?.onWillAddFirstListener?.(this);
1117
- this._listeners = contained;
1118
- this._options?.onDidAddFirstListener?.(this);
1119
- } else if (this._listeners instanceof UniqueContainer) {
1120
- this._deliveryQueue ??= new EventDeliveryQueuePrivate();
1121
- this._listeners = [this._listeners, contained];
1122
- } else {
1123
- this._listeners.push(contained);
1124
- }
1125
- this._options?.onDidAddListener?.(this);
1126
-
1127
- this._size++;
1128
-
1129
-
1130
- const result = toDisposable(() => {
1131
- removeMonitor?.();
1132
- this._removeListener(contained);
1133
- });
1134
- if (disposables instanceof DisposableStore) {
1135
- disposables.add(result);
1136
- } else if (Array.isArray(disposables)) {
1137
- disposables.push(result);
1138
- }
1139
-
1140
- return result;
1141
- };
1142
-
1143
- return this._event;
1144
- }
1145
-
1146
- private _removeListener(listener: ListenerContainer<T>) {
1147
- this._options?.onWillRemoveListener?.(this);
1148
-
1149
- if (!this._listeners) {
1150
- return; // expected if a listener gets disposed
1151
- }
1152
-
1153
- if (this._size === 1) {
1154
- this._listeners = undefined;
1155
- this._options?.onDidRemoveLastListener?.(this);
1156
- this._size = 0;
1157
- return;
1158
- }
1159
-
1160
- // size > 1 which requires that listeners be a list:
1161
- const listeners = this._listeners as (ListenerContainer<T> | undefined)[];
1162
-
1163
- const index = listeners.indexOf(listener);
1164
- if (index === -1) {
1165
- console.log('disposed?', this._disposed);
1166
- console.log('size?', this._size);
1167
- console.log('arr?', JSON.stringify(this._listeners));
1168
- throw new Error('Attempted to dispose unknown listener');
1169
- }
1170
-
1171
- this._size--;
1172
- listeners[index] = undefined;
1173
-
1174
- const adjustDeliveryQueue = this._deliveryQueue!.current === this;
1175
- if (this._size * compactionThreshold <= listeners.length) {
1176
- let n = 0;
1177
- for (let i = 0; i < listeners.length; i++) {
1178
- if (listeners[i]) {
1179
- listeners[n++] = listeners[i];
1180
- } else if (adjustDeliveryQueue && n < this._deliveryQueue!.end) {
1181
- this._deliveryQueue!.end--;
1182
- if (n < this._deliveryQueue!.i) {
1183
- this._deliveryQueue!.i--;
1184
- }
1185
- }
1186
- }
1187
- listeners.length = n;
1188
- }
1189
- }
1190
-
1191
- private _deliver(listener: undefined | UniqueContainer<(value: T) => void>, value: T) {
1192
- if (!listener) {
1193
- return;
1194
- }
1195
-
1196
- const errorHandler = this._options?.onListenerError || onUnexpectedError;
1197
- if (!errorHandler) {
1198
- listener.value(value);
1199
- return;
1200
- }
1201
-
1202
- try {
1203
- listener.value(value);
1204
- } catch (e) {
1205
- errorHandler(e);
1206
- }
1207
- }
1208
-
1209
- /** Delivers items in the queue. Assumes the queue is ready to go. */
1210
- private _deliverQueue(dq: EventDeliveryQueuePrivate) {
1211
- const listeners = dq.current!._listeners! as (ListenerContainer<T> | undefined)[];
1212
- while (dq.i < dq.end) {
1213
- // important: dq.i is incremented before calling deliver() because it might reenter deliverQueue()
1214
- this._deliver(listeners[dq.i++], dq.value as T);
1215
- }
1216
- dq.reset();
1217
- }
1218
-
1219
- /**
1220
- * To be kept private to fire an event to
1221
- * subscribers
1222
- */
1223
- fire(event: T): void {
1224
- if (this._deliveryQueue?.current) {
1225
- this._deliverQueue(this._deliveryQueue);
1226
- this._perfMon?.stop(); // last fire() will have starting perfmon, stop it before starting the next dispatch
1227
- }
1228
-
1229
- this._perfMon?.start(this._size);
1230
-
1231
- if (!this._listeners) {
1232
- // no-op
1233
- } else if (this._listeners instanceof UniqueContainer) {
1234
- this._deliver(this._listeners, event);
1235
- } else {
1236
- const dq = this._deliveryQueue!;
1237
- dq.enqueue(this, event, this._listeners.length);
1238
- this._deliverQueue(dq);
1239
- }
1240
-
1241
- this._perfMon?.stop();
1242
- }
1243
-
1244
- hasListeners(): boolean {
1245
- return this._size > 0;
1246
- }
1247
- }
1248
-
1249
- export interface EventDeliveryQueue {
1250
- _isEventDeliveryQueue: true;
1251
- }
1252
-
1253
- export const createEventDeliveryQueue = (): EventDeliveryQueue => new EventDeliveryQueuePrivate();
1254
-
1255
- class EventDeliveryQueuePrivate implements EventDeliveryQueue {
1256
- declare _isEventDeliveryQueue: true;
1257
-
1258
- /**
1259
- * Index in current's listener list.
1260
- */
1261
- public i = -1;
1262
-
1263
- /**
1264
- * The last index in the listener's list to deliver.
1265
- */
1266
- public end = 0;
1267
-
1268
- /**
1269
- * Emitter currently being dispatched on. Emitter._listeners is always an array.
1270
- */
1271
- public current?: Emitter<any>;
1272
- /**
1273
- * Currently emitting value. Defined whenever `current` is.
1274
- */
1275
- public value?: unknown;
1276
-
1277
- public enqueue<T>(emitter: Emitter<T>, value: T, end: number) {
1278
- this.i = 0;
1279
- this.end = end;
1280
- this.current = emitter;
1281
- this.value = value;
1282
- }
1283
-
1284
- public reset() {
1285
- this.i = this.end; // force any current emission loop to stop, mainly for during dispose
1286
- this.current = undefined;
1287
- this.value = undefined;
1288
- }
1289
- }
1290
-
1291
- export interface IWaitUntil {
1292
- token: CancellationToken;
1293
- waitUntil(thenable: Promise<unknown>): void;
1294
- }
1295
-
1296
- export type IWaitUntilData<T> = Omit<Omit<T, 'waitUntil'>, 'token'>;
1297
-
1298
- export class AsyncEmitter<T extends IWaitUntil> extends Emitter<T> {
1299
-
1300
- private _asyncDeliveryQueue?: LinkedList<[(ev: T) => void, IWaitUntilData<T>]>;
1301
-
1302
- async fireAsync(data: IWaitUntilData<T>, token: CancellationToken, promiseJoin?: (p: Promise<unknown>, listener: Function) => Promise<unknown>): Promise<void> {
1303
- if (!this._listeners) {
1304
- return;
1305
- }
1306
-
1307
- if (!this._asyncDeliveryQueue) {
1308
- this._asyncDeliveryQueue = new LinkedList();
1309
- }
1310
-
1311
- forEachListener(this._listeners, listener => this._asyncDeliveryQueue!.push([listener.value, data]));
1312
-
1313
- while (this._asyncDeliveryQueue.size > 0 && !token.isCancellationRequested) {
1314
-
1315
- const [listener, data] = this._asyncDeliveryQueue.shift()!;
1316
- const thenables: Promise<unknown>[] = [];
1317
-
1318
- // eslint-disable-next-line local/code-no-dangerous-type-assertions
1319
- const event = <T>{
1320
- ...data,
1321
- token,
1322
- waitUntil: (p: Promise<unknown>): void => {
1323
- if (Object.isFrozen(thenables)) {
1324
- throw new Error('waitUntil can NOT be called asynchronous');
1325
- }
1326
- if (promiseJoin) {
1327
- p = promiseJoin(p, listener);
1328
- }
1329
- thenables.push(p);
1330
- }
1331
- };
1332
-
1333
- try {
1334
- listener(event);
1335
- } catch (e) {
1336
- onUnexpectedError(e);
1337
- continue;
1338
- }
1339
-
1340
- // freeze thenables-collection to enforce sync-calls to
1341
- // wait until and then wait for all thenables to resolve
1342
- Object.freeze(thenables);
1343
-
1344
- await Promise.allSettled(thenables).then(values => {
1345
- for (const value of values) {
1346
- if (value.status === 'rejected') {
1347
- onUnexpectedError(value.reason);
1348
- }
1349
- }
1350
- });
1351
- }
1352
- }
1353
- }
1354
-
1355
-
1356
- export class PauseableEmitter<T> extends Emitter<T> {
1357
-
1358
- private _isPaused = 0;
1359
- protected _eventQueue = new LinkedList<T>();
1360
- private _mergeFn?: (input: T[]) => T;
1361
-
1362
- public get isPaused(): boolean {
1363
- return this._isPaused !== 0;
1364
- }
1365
-
1366
- constructor(options?: EmitterOptions & { merge?: (input: T[]) => T }) {
1367
- super(options);
1368
- this._mergeFn = options?.merge;
1369
- }
1370
-
1371
- pause(): void {
1372
- this._isPaused++;
1373
- }
1374
-
1375
- resume(): void {
1376
- if (this._isPaused !== 0 && --this._isPaused === 0) {
1377
- if (this._mergeFn) {
1378
- // use the merge function to create a single composite
1379
- // event. make a copy in case firing pauses this emitter
1380
- if (this._eventQueue.size > 0) {
1381
- const events = Array.from(this._eventQueue);
1382
- this._eventQueue.clear();
1383
- super.fire(this._mergeFn(events));
1384
- }
1385
-
1386
- } else {
1387
- // no merging, fire each event individually and test
1388
- // that this emitter isn't paused halfway through
1389
- while (!this._isPaused && this._eventQueue.size !== 0) {
1390
- super.fire(this._eventQueue.shift()!);
1391
- }
1392
- }
1393
- }
1394
- }
1395
-
1396
- override fire(event: T): void {
1397
- if (this._size) {
1398
- if (this._isPaused !== 0) {
1399
- this._eventQueue.push(event);
1400
- } else {
1401
- super.fire(event);
1402
- }
1403
- }
1404
- }
1405
- }
1406
-
1407
- export class DebounceEmitter<T> extends PauseableEmitter<T> {
1408
-
1409
- private readonly _delay: number;
1410
- private _handle: Timeout | undefined;
1411
-
1412
- constructor(options: EmitterOptions & { merge: (input: T[]) => T; delay?: number }) {
1413
- super(options);
1414
- this._delay = options.delay ?? 100;
1415
- }
1416
-
1417
- override fire(event: T): void {
1418
- if (!this._handle) {
1419
- this.pause();
1420
- this._handle = setTimeout(() => {
1421
- this._handle = undefined;
1422
- this.resume();
1423
- }, this._delay);
1424
- }
1425
- super.fire(event);
1426
- }
1427
- }
1428
-
1429
- /**
1430
- * An emitter which queue all events and then process them at the
1431
- * end of the event loop.
1432
- */
1433
- export class MicrotaskEmitter<T> extends Emitter<T> {
1434
- private _queuedEvents: T[] = [];
1435
- private _mergeFn?: (input: T[]) => T;
1436
-
1437
- constructor(options?: EmitterOptions & { merge?: (input: T[]) => T }) {
1438
- super(options);
1439
- this._mergeFn = options?.merge;
1440
- }
1441
- override fire(event: T): void {
1442
-
1443
- if (!this.hasListeners()) {
1444
- return;
1445
- }
1446
-
1447
- this._queuedEvents.push(event);
1448
- if (this._queuedEvents.length === 1) {
1449
- queueMicrotask(() => {
1450
- if (this._mergeFn) {
1451
- super.fire(this._mergeFn(this._queuedEvents));
1452
- } else {
1453
- this._queuedEvents.forEach(e => super.fire(e));
1454
- }
1455
- this._queuedEvents = [];
1456
- });
1457
- }
1458
- }
1459
- }
1460
-
1461
- /**
1462
- * An event emitter that multiplexes many events into a single event.
1463
- *
1464
- * @example Listen to the `onData` event of all `Thing`s, dynamically adding and removing `Thing`s
1465
- * to the multiplexer as needed.
1466
- *
1467
- * ```typescript
1468
- * const anythingDataMultiplexer = new EventMultiplexer<{ data: string }>();
1469
- *
1470
- * const thingListeners = DisposableMap<Thing, IDisposable>();
1471
- *
1472
- * thingService.onDidAddThing(thing => {
1473
- * thingListeners.set(thing, anythingDataMultiplexer.add(thing.onData);
1474
- * });
1475
- * thingService.onDidRemoveThing(thing => {
1476
- * thingListeners.deleteAndDispose(thing);
1477
- * });
1478
- *
1479
- * anythingDataMultiplexer.event(e => {
1480
- * console.log('Something fired data ' + e.data)
1481
- * });
1482
- * ```
1483
- */
1484
- export class EventMultiplexer<T> implements IDisposable {
1485
-
1486
- private readonly emitter: Emitter<T>;
1487
- private hasListeners = false;
1488
- private events: { event: Event<T>; listener: IDisposable | null }[] = [];
1489
-
1490
- constructor() {
1491
- this.emitter = new Emitter<T>({
1492
- onWillAddFirstListener: () => this.onFirstListenerAdd(),
1493
- onDidRemoveLastListener: () => this.onLastListenerRemove()
1494
- });
1495
- }
1496
-
1497
- get event(): Event<T> {
1498
- return this.emitter.event;
1499
- }
1500
-
1501
- add(event: Event<T>): IDisposable {
1502
- const e = { event: event, listener: null };
1503
- this.events.push(e);
1504
-
1505
- if (this.hasListeners) {
1506
- this.hook(e);
1507
- }
1508
-
1509
- const dispose = () => {
1510
- if (this.hasListeners) {
1511
- this.unhook(e);
1512
- }
1513
-
1514
- const idx = this.events.indexOf(e);
1515
- this.events.splice(idx, 1);
1516
- };
1517
-
1518
- return toDisposable(createSingleCallFunction(dispose));
1519
- }
1520
-
1521
- private onFirstListenerAdd(): void {
1522
- this.hasListeners = true;
1523
- this.events.forEach(e => this.hook(e));
1524
- }
1525
-
1526
- private onLastListenerRemove(): void {
1527
- this.hasListeners = false;
1528
- this.events.forEach(e => this.unhook(e));
1529
- }
1530
-
1531
- private hook(e: { event: Event<T>; listener: IDisposable | null }): void {
1532
- e.listener = e.event(r => this.emitter.fire(r));
1533
- }
1534
-
1535
- private unhook(e: { event: Event<T>; listener: IDisposable | null }): void {
1536
- e.listener?.dispose();
1537
- e.listener = null;
1538
- }
1539
-
1540
- dispose(): void {
1541
- this.emitter.dispose();
1542
-
1543
- for (const e of this.events) {
1544
- e.listener?.dispose();
1545
- }
1546
- this.events = [];
1547
- }
1548
- }
1549
-
1550
- export interface IDynamicListEventMultiplexer<TEventType> extends IDisposable {
1551
- readonly event: Event<TEventType>;
1552
- }
1553
- export class DynamicListEventMultiplexer<TItem, TEventType> implements IDynamicListEventMultiplexer<TEventType> {
1554
- private readonly _store = new DisposableStore();
1555
-
1556
- readonly event: Event<TEventType>;
1557
-
1558
- constructor(
1559
- items: TItem[],
1560
- onAddItem: Event<TItem>,
1561
- onRemoveItem: Event<TItem>,
1562
- getEvent: (item: TItem) => Event<TEventType>
1563
- ) {
1564
- const multiplexer = this._store.add(new EventMultiplexer<TEventType>());
1565
- const itemListeners = this._store.add(new DisposableMap<TItem, IDisposable>());
1566
-
1567
- function addItem(instance: TItem) {
1568
- itemListeners.set(instance, multiplexer.add(getEvent(instance)));
1569
- }
1570
-
1571
- // Existing items
1572
- for (const instance of items) {
1573
- addItem(instance);
1574
- }
1575
-
1576
- // Added items
1577
- this._store.add(onAddItem(instance => {
1578
- addItem(instance);
1579
- }));
1580
-
1581
- // Removed items
1582
- this._store.add(onRemoveItem(instance => {
1583
- itemListeners.deleteAndDispose(instance);
1584
- }));
1585
-
1586
- this.event = multiplexer.event;
1587
- }
1588
-
1589
- dispose() {
1590
- this._store.dispose();
1591
- }
1592
- }
1593
-
1594
- /**
1595
- * The EventBufferer is useful in situations in which you want
1596
- * to delay firing your events during some code.
1597
- * You can wrap that code and be sure that the event will not
1598
- * be fired during that wrap.
1599
- *
1600
- * ```
1601
- * const emitter: Emitter;
1602
- * const delayer = new EventDelayer();
1603
- * const delayedEvent = delayer.wrapEvent(emitter.event);
1604
- *
1605
- * delayedEvent(console.log);
1606
- *
1607
- * delayer.bufferEvents(() => {
1608
- * emitter.fire(); // event will not be fired yet
1609
- * });
1610
- *
1611
- * // event will only be fired at this point
1612
- * ```
1613
- */
1614
- export class EventBufferer {
1615
-
1616
- private data: { buffers: Function[] }[] = [];
1617
-
1618
- wrapEvent<T>(event: Event<T>): Event<T>;
1619
- wrapEvent<T>(event: Event<T>, reduce: (last: T | undefined, event: T) => T): Event<T>;
1620
- wrapEvent<T, O>(event: Event<T>, reduce: (last: O | undefined, event: T) => O, initial: O): Event<O>;
1621
- wrapEvent<T, O>(event: Event<T>, reduce?: (last: T | O | undefined, event: T) => T | O, initial?: O): Event<O | T> {
1622
- return (listener, thisArgs?, disposables?) => {
1623
- return event(i => {
1624
- const data = this.data[this.data.length - 1];
1625
-
1626
- // Non-reduce scenario
1627
- if (!reduce) {
1628
- // Buffering case
1629
- if (data) {
1630
- data.buffers.push(() => listener.call(thisArgs, i));
1631
- } else {
1632
- // Not buffering case
1633
- listener.call(thisArgs, i);
1634
- }
1635
- return;
1636
- }
1637
-
1638
- // Reduce scenario
1639
- const reduceData = data as typeof data & {
1640
- /**
1641
- * The accumulated items that will be reduced.
1642
- */
1643
- items?: T[];
1644
- /**
1645
- * The reduced result cached to be shared with other listeners.
1646
- */
1647
- reducedResult?: T | O;
1648
- };
1649
-
1650
- // Not buffering case
1651
- if (!reduceData) {
1652
- // TODO: Is there a way to cache this reduce call for all listeners?
1653
- listener.call(thisArgs, reduce(initial, i));
1654
- return;
1655
- }
1656
-
1657
- // Buffering case
1658
- reduceData.items ??= [];
1659
- reduceData.items.push(i);
1660
- if (reduceData.buffers.length === 0) {
1661
- // Include a single buffered function that will reduce all events when we're done buffering events
1662
- data.buffers.push(() => {
1663
- // cache the reduced result so that the value can be shared across all listeners
1664
- reduceData.reducedResult ??= initial
1665
- ? reduceData.items!.reduce(reduce as (last: O | undefined, event: T) => O, initial)
1666
- : reduceData.items!.reduce(reduce as (last: T | undefined, event: T) => T);
1667
- listener.call(thisArgs, reduceData.reducedResult);
1668
- });
1669
- }
1670
- }, undefined, disposables);
1671
- };
1672
- }
1673
-
1674
- bufferEvents<R = void>(fn: () => R): R {
1675
- const data = { buffers: new Array<Function>() };
1676
- this.data.push(data);
1677
- const r = fn();
1678
- this.data.pop();
1679
- data.buffers.forEach(flush => flush());
1680
- return r;
1681
- }
1682
- }
1683
-
1684
- /**
1685
- * A Relay is an event forwarder which functions as a replugabble event pipe.
1686
- * Once created, you can connect an input event to it and it will simply forward
1687
- * events from that input event through its own `event` property. The `input`
1688
- * can be changed at any point in time.
1689
- */
1690
- export class Relay<T> implements IDisposable {
1691
-
1692
- private listening = false;
1693
- private inputEvent: Event<T> = Event.None;
1694
- private inputEventListener: IDisposable = Disposable.None;
1695
-
1696
- private readonly emitter = new Emitter<T>({
1697
- onDidAddFirstListener: () => {
1698
- this.listening = true;
1699
- this.inputEventListener = this.inputEvent(this.emitter.fire, this.emitter);
1700
- },
1701
- onDidRemoveLastListener: () => {
1702
- this.listening = false;
1703
- this.inputEventListener.dispose();
1704
- }
1705
- });
1706
-
1707
- readonly event: Event<T> = this.emitter.event;
1708
-
1709
- set input(event: Event<T>) {
1710
- this.inputEvent = event;
1711
-
1712
- if (this.listening) {
1713
- this.inputEventListener.dispose();
1714
- this.inputEventListener = event(this.emitter.fire, this.emitter);
1715
- }
1716
- }
1717
-
1718
- dispose() {
1719
- this.inputEventListener.dispose();
1720
- this.emitter.dispose();
1721
- }
1722
- }
1723
-
1724
- export interface IValueWithChangeEvent<T> {
1725
- readonly onDidChange: Event<void>;
1726
- get value(): T;
1727
- }
1728
-
1729
- export class ValueWithChangeEvent<T> implements IValueWithChangeEvent<T> {
1730
- public static const<T>(value: T): IValueWithChangeEvent<T> {
1731
- return new ConstValueWithChangeEvent(value);
1732
- }
1733
-
1734
- private readonly _onDidChange = new Emitter<void>();
1735
- readonly onDidChange: Event<void> = this._onDidChange.event;
1736
-
1737
- constructor(private _value: T) { }
1738
-
1739
- get value(): T {
1740
- return this._value;
1741
- }
1742
-
1743
- set value(value: T) {
1744
- if (value !== this._value) {
1745
- this._value = value;
1746
- this._onDidChange.fire(undefined);
1747
- }
1748
- }
1749
- }
1750
-
1751
- class ConstValueWithChangeEvent<T> implements IValueWithChangeEvent<T> {
1752
- public readonly onDidChange: Event<void> = Event.None;
1753
-
1754
- constructor(readonly value: T) { }
1755
- }
1756
-
1757
- /**
1758
- * @param handleItem Is called for each item in the set (but only the first time the item is seen in the set).
1759
- * The returned disposable is disposed if the item is no longer in the set.
1760
- */
1761
- export function trackSetChanges<T>(getData: () => ReadonlySet<T>, onDidChangeData: Event<unknown>, handleItem: (d: T) => IDisposable): IDisposable {
1762
- const map = new DisposableMap<T, IDisposable>();
1763
- let oldData = new Set(getData());
1764
- for (const d of oldData) {
1765
- map.set(d, handleItem(d));
1766
- }
1767
-
1768
- const store = new DisposableStore();
1769
- store.add(onDidChangeData(() => {
1770
- const newData = getData();
1771
- const diff = diffSets(oldData, newData);
1772
- for (const r of diff.removed) {
1773
- map.deleteAndDispose(r);
1774
- }
1775
- for (const a of diff.added) {
1776
- map.set(a, handleItem(a));
1777
- }
1778
- oldData = new Set(newData);
1779
- }));
1780
- store.add(map);
1781
- return store;
1782
- }