@theia/plugin-ext 1.53.0-next.4 → 1.53.0-next.55

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 (472) hide show
  1. package/README.md +54 -54
  2. package/lib/common/plugin-api-rpc.d.ts +19 -4
  3. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  4. package/lib/common/plugin-api-rpc.js +4 -2
  5. package/lib/common/plugin-api-rpc.js.map +1 -1
  6. package/lib/common/rpc-protocol.d.ts +14 -13
  7. package/lib/common/rpc-protocol.d.ts.map +1 -1
  8. package/lib/common/rpc-protocol.js +56 -53
  9. package/lib/common/rpc-protocol.js.map +1 -1
  10. package/lib/hosted/browser/hosted-plugin.d.ts +1 -0
  11. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  12. package/lib/hosted/browser/hosted-plugin.js +22 -12
  13. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  14. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  15. package/lib/hosted/node/scanners/scanner-theia.js +13 -1
  16. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  17. package/lib/main/browser/authentication-main.d.ts +6 -5
  18. package/lib/main/browser/authentication-main.d.ts.map +1 -1
  19. package/lib/main/browser/authentication-main.js +15 -9
  20. package/lib/main/browser/authentication-main.js.map +1 -1
  21. package/lib/main/browser/custom-editors/custom-editor-opener.d.ts +9 -3
  22. package/lib/main/browser/custom-editors/custom-editor-opener.d.ts.map +1 -1
  23. package/lib/main/browser/custom-editors/custom-editor-opener.js +120 -31
  24. package/lib/main/browser/custom-editors/custom-editor-opener.js.map +1 -1
  25. package/lib/main/browser/custom-editors/custom-editor-widget.d.ts +7 -4
  26. package/lib/main/browser/custom-editors/custom-editor-widget.d.ts.map +1 -1
  27. package/lib/main/browser/custom-editors/custom-editor-widget.js +21 -7
  28. package/lib/main/browser/custom-editors/custom-editor-widget.js.map +1 -1
  29. package/lib/main/browser/custom-editors/custom-editors-main.d.ts +3 -4
  30. package/lib/main/browser/custom-editors/custom-editors-main.d.ts.map +1 -1
  31. package/lib/main/browser/custom-editors/custom-editors-main.js +5 -55
  32. package/lib/main/browser/custom-editors/custom-editors-main.js.map +1 -1
  33. package/lib/main/browser/custom-editors/plugin-custom-editor-registry.d.ts +4 -3
  34. package/lib/main/browser/custom-editors/plugin-custom-editor-registry.d.ts.map +1 -1
  35. package/lib/main/browser/custom-editors/plugin-custom-editor-registry.js +24 -16
  36. package/lib/main/browser/custom-editors/plugin-custom-editor-registry.js.map +1 -1
  37. package/lib/main/browser/main-context.d.ts.map +1 -1
  38. package/lib/main/browser/main-context.js +3 -0
  39. package/lib/main/browser/main-context.js.map +1 -1
  40. package/lib/main/browser/menus/menus-contribution-handler.d.ts.map +1 -1
  41. package/lib/main/browser/menus/menus-contribution-handler.js +1 -1
  42. package/lib/main/browser/menus/menus-contribution-handler.js.map +1 -1
  43. package/lib/main/browser/menus/plugin-menu-command-adapter.d.ts +1 -0
  44. package/lib/main/browser/menus/plugin-menu-command-adapter.d.ts.map +1 -1
  45. package/lib/main/browser/menus/plugin-menu-command-adapter.js +22 -1
  46. package/lib/main/browser/menus/plugin-menu-command-adapter.js.map +1 -1
  47. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts +2 -2
  48. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts.map +1 -1
  49. package/lib/main/browser/menus/vscode-theia-menu-mappings.js +2 -0
  50. package/lib/main/browser/menus/vscode-theia-menu-mappings.js.map +1 -1
  51. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js +1 -1
  52. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js.map +1 -1
  53. package/lib/main/browser/notebooks/notebook-documents-main.d.ts.map +1 -1
  54. package/lib/main/browser/notebooks/notebook-documents-main.js +22 -3
  55. package/lib/main/browser/notebooks/notebook-documents-main.js.map +1 -1
  56. package/lib/main/browser/notebooks/notebook-editors-main.d.ts +1 -1
  57. package/lib/main/browser/notebooks/notebook-editors-main.d.ts.map +1 -1
  58. package/lib/main/browser/notebooks/notebook-editors-main.js +16 -2
  59. package/lib/main/browser/notebooks/notebook-editors-main.js.map +1 -1
  60. package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts +1 -1
  61. package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts.map +1 -1
  62. package/lib/main/browser/notebooks/renderers/cell-output-webview.js +152 -77
  63. package/lib/main/browser/notebooks/renderers/cell-output-webview.js.map +1 -1
  64. package/lib/main/browser/notebooks/renderers/output-webview-internal.d.ts.map +1 -1
  65. package/lib/main/browser/notebooks/renderers/output-webview-internal.js +38 -19
  66. package/lib/main/browser/notebooks/renderers/output-webview-internal.js.map +1 -1
  67. package/lib/main/browser/plugin-ext-frontend-module.d.ts.map +1 -1
  68. package/lib/main/browser/plugin-ext-frontend-module.js +18 -0
  69. package/lib/main/browser/plugin-ext-frontend-module.js.map +1 -1
  70. package/lib/main/browser/plugin-icon-theme-service.js +20 -20
  71. package/lib/main/browser/plugin-shared-style.js +14 -14
  72. package/lib/main/browser/uri-main.d.ts +16 -0
  73. package/lib/main/browser/uri-main.d.ts.map +1 -0
  74. package/lib/main/browser/uri-main.js +64 -0
  75. package/lib/main/browser/uri-main.js.map +1 -0
  76. package/lib/main/browser/view/plugin-view-registry.js +3 -3
  77. package/lib/main/browser/webview/webview-frontend-security-warnings.js +2 -2
  78. package/lib/main/browser/webview/webview-secondary-window-support.js +10 -10
  79. package/lib/main/browser/webview/webview.d.ts +1 -3
  80. package/lib/main/browser/webview/webview.d.ts.map +1 -1
  81. package/lib/main/browser/webview/webview.js +5 -4
  82. package/lib/main/browser/webview/webview.js.map +1 -1
  83. package/lib/main/browser/webviews-main.d.ts.map +1 -1
  84. package/lib/main/browser/webviews-main.js +6 -1
  85. package/lib/main/browser/webviews-main.js.map +1 -1
  86. package/lib/main/browser/workspace-main.d.ts +2 -0
  87. package/lib/main/browser/workspace-main.d.ts.map +1 -1
  88. package/lib/main/node/plugin-service.d.ts +1 -1
  89. package/lib/main/node/webview-backend-security-warnings.js +6 -6
  90. package/lib/plugin/authentication-ext.d.ts +3 -2
  91. package/lib/plugin/authentication-ext.d.ts.map +1 -1
  92. package/lib/plugin/authentication-ext.js +8 -5
  93. package/lib/plugin/authentication-ext.js.map +1 -1
  94. package/lib/plugin/custom-editors.d.ts +2 -4
  95. package/lib/plugin/custom-editors.d.ts.map +1 -1
  96. package/lib/plugin/custom-editors.js +5 -7
  97. package/lib/plugin/custom-editors.js.map +1 -1
  98. package/lib/plugin/env.d.ts +2 -0
  99. package/lib/plugin/env.d.ts.map +1 -1
  100. package/lib/plugin/env.js +4 -1
  101. package/lib/plugin/env.js.map +1 -1
  102. package/lib/plugin/known-commands.d.ts.map +1 -1
  103. package/lib/plugin/known-commands.js +1 -0
  104. package/lib/plugin/known-commands.js.map +1 -1
  105. package/lib/plugin/languages.d.ts +1 -0
  106. package/lib/plugin/languages.d.ts.map +1 -1
  107. package/lib/plugin/notebook/notebook-kernels.d.ts +2 -0
  108. package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -1
  109. package/lib/plugin/plugin-context.d.ts.map +1 -1
  110. package/lib/plugin/plugin-context.js +17 -6
  111. package/lib/plugin/plugin-context.js.map +1 -1
  112. package/lib/plugin/plugin-manager.d.ts.map +1 -1
  113. package/lib/plugin/plugin-manager.js +2 -1
  114. package/lib/plugin/plugin-manager.js.map +1 -1
  115. package/lib/plugin/scm.d.ts +1 -0
  116. package/lib/plugin/scm.d.ts.map +1 -1
  117. package/lib/plugin/terminal-ext.d.ts +3 -0
  118. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  119. package/lib/plugin/terminal-ext.js +2 -0
  120. package/lib/plugin/terminal-ext.js.map +1 -1
  121. package/lib/plugin/type-converters.d.ts +6 -0
  122. package/lib/plugin/type-converters.d.ts.map +1 -1
  123. package/lib/plugin/type-converters.js +24 -3
  124. package/lib/plugin/type-converters.js.map +1 -1
  125. package/lib/plugin/types-impl.d.ts +8 -2
  126. package/lib/plugin/types-impl.d.ts.map +1 -1
  127. package/lib/plugin/types-impl.js +9 -1
  128. package/lib/plugin/types-impl.js.map +1 -1
  129. package/lib/plugin/uri-ext.d.ts +37 -0
  130. package/lib/plugin/uri-ext.d.ts.map +1 -0
  131. package/lib/plugin/uri-ext.js +50 -0
  132. package/lib/plugin/uri-ext.js.map +1 -0
  133. package/lib/plugin/webviews.js +1 -1
  134. package/lib/plugin/webviews.js.map +1 -1
  135. package/lib/plugin/workspace.d.ts +4 -0
  136. package/lib/plugin/workspace.d.ts.map +1 -1
  137. package/package.json +29 -29
  138. package/src/common/arrays.ts +70 -70
  139. package/src/common/assert.ts +23 -23
  140. package/src/common/cache.ts +51 -51
  141. package/src/common/character-classifier.ts +73 -73
  142. package/src/common/collections.ts +54 -54
  143. package/src/common/commands.ts +19 -19
  144. package/src/common/connection.ts +137 -137
  145. package/src/common/disposable-util.ts +39 -39
  146. package/src/common/editor-options.ts +74 -74
  147. package/src/common/env.ts +19 -19
  148. package/src/common/errors.ts +63 -63
  149. package/src/common/id-generator.ts +26 -26
  150. package/src/common/index.ts +24 -24
  151. package/src/common/language-pack-service.ts +34 -34
  152. package/src/common/link-computer.ts +354 -354
  153. package/src/common/object-identifier.ts +33 -33
  154. package/src/common/objects.ts +50 -50
  155. package/src/common/paths-util.ts +158 -158
  156. package/src/common/plugin-api-rpc-model.ts +907 -907
  157. package/src/common/plugin-api-rpc.ts +2752 -2738
  158. package/src/common/plugin-ext-api-contribution.ts +115 -115
  159. package/src/common/plugin-identifiers.ts +84 -84
  160. package/src/common/plugin-protocol.ts +1094 -1094
  161. package/src/common/reference-map.ts +38 -38
  162. package/src/common/rpc-protocol.ts +306 -310
  163. package/src/common/semantic-tokens-dto.ts +182 -182
  164. package/src/common/test-types.ts +154 -154
  165. package/src/common/types.ts +129 -129
  166. package/src/common/uint.ts +37 -37
  167. package/src/common/uri-components.ts +81 -81
  168. package/src/hosted/browser/hosted-plugin-watcher.ts +54 -54
  169. package/src/hosted/browser/hosted-plugin.ts +635 -624
  170. package/src/hosted/browser/plugin-worker.ts +52 -52
  171. package/src/hosted/browser/worker/debug-stub.ts +29 -29
  172. package/src/hosted/browser/worker/plugin-manifest-loader.ts +114 -114
  173. package/src/hosted/browser/worker/worker-env-ext.ts +40 -40
  174. package/src/hosted/browser/worker/worker-main.ts +212 -212
  175. package/src/hosted/browser/worker/worker-plugin-module.ts +80 -80
  176. package/src/hosted/common/hosted-plugin.ts +456 -456
  177. package/src/hosted/node/hosted-plugin-cli-contribution.ts +75 -75
  178. package/src/hosted/node/hosted-plugin-deployer-handler.ts +274 -274
  179. package/src/hosted/node/hosted-plugin-localization-service.ts +410 -410
  180. package/src/hosted/node/hosted-plugin-process.ts +248 -248
  181. package/src/hosted/node/hosted-plugin-protocol.ts +49 -49
  182. package/src/hosted/node/hosted-plugin.ts +116 -116
  183. package/src/hosted/node/metadata-scanner.ts +64 -64
  184. package/src/hosted/node/plugin-activation-events.ts +112 -112
  185. package/src/hosted/node/plugin-ext-hosted-backend-module.ts +94 -94
  186. package/src/hosted/node/plugin-host-module.ts +69 -69
  187. package/src/hosted/node/plugin-host-proxy.ts +82 -82
  188. package/src/hosted/node/plugin-host-rpc.ts +377 -377
  189. package/src/hosted/node/plugin-host.ts +110 -110
  190. package/src/hosted/node/plugin-language-pack-service.ts +43 -43
  191. package/src/hosted/node/plugin-manifest-loader.ts +32 -32
  192. package/src/hosted/node/plugin-reader.ts +136 -136
  193. package/src/hosted/node/plugin-service.ts +197 -197
  194. package/src/hosted/node/scanners/backend-init-theia.ts +71 -71
  195. package/src/hosted/node/scanners/file-plugin-uri-factory.ts +32 -32
  196. package/src/hosted/node/scanners/grammars-reader.ts +57 -57
  197. package/src/hosted/node/scanners/plugin-uri-factory.ts +33 -33
  198. package/src/hosted/node/scanners/scanner-theia.ts +963 -952
  199. package/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts +26 -26
  200. package/src/hosted/node-electron/scanner-theia-electron.ts +32 -32
  201. package/src/main/browser/authentication-main.ts +401 -388
  202. package/src/main/browser/clipboard-main.ts +38 -38
  203. package/src/main/browser/command-registry-main.ts +130 -130
  204. package/src/main/browser/commands.ts +104 -104
  205. package/src/main/browser/comments/comment-glyph-widget.ts +66 -66
  206. package/src/main/browser/comments/comment-thread-widget.tsx +696 -696
  207. package/src/main/browser/comments/comments-context-key-service.ts +68 -68
  208. package/src/main/browser/comments/comments-contribution.ts +268 -268
  209. package/src/main/browser/comments/comments-decorator.ts +110 -110
  210. package/src/main/browser/comments/comments-main.ts +482 -482
  211. package/src/main/browser/comments/comments-service.ts +205 -205
  212. package/src/main/browser/custom-editors/custom-editor-opener.tsx +205 -105
  213. package/src/main/browser/custom-editors/custom-editor-service.ts +108 -108
  214. package/src/main/browser/custom-editors/custom-editor-undo-redo-handler.ts +41 -41
  215. package/src/main/browser/custom-editors/custom-editor-widget-factory.ts +44 -44
  216. package/src/main/browser/custom-editors/custom-editor-widget.ts +127 -118
  217. package/src/main/browser/custom-editors/custom-editors-main.ts +526 -585
  218. package/src/main/browser/custom-editors/plugin-custom-editor-registry.ts +126 -120
  219. package/src/main/browser/data-transfer/data-transfer-type-converters.ts +68 -68
  220. package/src/main/browser/debug/debug-main.ts +397 -397
  221. package/src/main/browser/debug/plugin-debug-adapter-contribution.ts +48 -48
  222. package/src/main/browser/debug/plugin-debug-configuration-provider.ts +63 -63
  223. package/src/main/browser/debug/plugin-debug-service.ts +427 -427
  224. package/src/main/browser/debug/plugin-debug-session-contribution-registry.ts +76 -76
  225. package/src/main/browser/debug/plugin-debug-session-factory.ts +115 -115
  226. package/src/main/browser/decorations/decorations-main.ts +146 -146
  227. package/src/main/browser/dialogs/modal-notification.ts +112 -112
  228. package/src/main/browser/dialogs/style/modal-notification.css +123 -123
  229. package/src/main/browser/dialogs-main.ts +185 -185
  230. package/src/main/browser/documents-main.ts +275 -275
  231. package/src/main/browser/editors-and-documents-main.ts +425 -425
  232. package/src/main/browser/env-main.ts +60 -60
  233. package/src/main/browser/file-system-main-impl.ts +267 -267
  234. package/src/main/browser/hierarchy/hierarchy-types-converters.ts +189 -189
  235. package/src/main/browser/keybindings/keybindings-contribution-handler.ts +66 -66
  236. package/src/main/browser/label-service-main.ts +51 -51
  237. package/src/main/browser/languages-main.ts +1439 -1439
  238. package/src/main/browser/localization-main.ts +34 -34
  239. package/src/main/browser/main-context.ts +210 -206
  240. package/src/main/browser/main-file-system-event-service.ts +76 -76
  241. package/src/main/browser/menus/menus-contribution-handler.ts +172 -171
  242. package/src/main/browser/menus/plugin-menu-command-adapter.ts +358 -337
  243. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +118 -116
  244. package/src/main/browser/message-registry-main.ts +43 -43
  245. package/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +249 -249
  246. package/src/main/browser/notebooks/notebook-documents-main.ts +202 -182
  247. package/src/main/browser/notebooks/notebook-dto.ts +131 -131
  248. package/src/main/browser/notebooks/notebook-editors-main.ts +88 -75
  249. package/src/main/browser/notebooks/notebook-kernels-main.ts +339 -339
  250. package/src/main/browser/notebooks/notebook-renderers-main.ts +47 -47
  251. package/src/main/browser/notebooks/notebooks-main.ts +164 -164
  252. package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +452 -375
  253. package/src/main/browser/notebooks/renderers/output-webview-internal.ts +636 -613
  254. package/src/main/browser/notebooks/renderers/webview-communication.ts +107 -107
  255. package/src/main/browser/notification-main.ts +26 -26
  256. package/src/main/browser/output-channel-registry-main.ts +53 -53
  257. package/src/main/browser/plugin-authentication-service.ts +71 -71
  258. package/src/main/browser/plugin-contribution-handler.ts +698 -698
  259. package/src/main/browser/plugin-ext-frontend-module.ts +291 -272
  260. package/src/main/browser/plugin-ext-widget.tsx +132 -132
  261. package/src/main/browser/plugin-frontend-contribution.ts +70 -70
  262. package/src/main/browser/plugin-frontend-view-contribution.ts +38 -38
  263. package/src/main/browser/plugin-icon-service.ts +92 -92
  264. package/src/main/browser/plugin-icon-theme-service.ts +625 -625
  265. package/src/main/browser/plugin-shared-style.ts +154 -154
  266. package/src/main/browser/plugin-storage.ts +55 -55
  267. package/src/main/browser/plugin-terminal-registry.ts +27 -27
  268. package/src/main/browser/preference-registry-main.ts +123 -123
  269. package/src/main/browser/quick-open-main.ts +367 -367
  270. package/src/main/browser/scm-main.ts +472 -472
  271. package/src/main/browser/secrets-main.ts +82 -82
  272. package/src/main/browser/selection-provider-command.ts +45 -45
  273. package/src/main/browser/status-bar-message-registry-main.ts +90 -90
  274. package/src/main/browser/style/comments.css +345 -345
  275. package/src/main/browser/style/index.css +84 -84
  276. package/src/main/browser/style/plugin-sidebar.css +73 -73
  277. package/src/main/browser/style/tree.css +54 -54
  278. package/src/main/browser/style/webview.css +55 -55
  279. package/src/main/browser/tabs/tabs-main.ts +384 -384
  280. package/src/main/browser/tasks-main.ts +268 -268
  281. package/src/main/browser/terminal-main.ts +370 -370
  282. package/src/main/browser/test-main.ts +632 -632
  283. package/src/main/browser/text-editor-main.ts +478 -478
  284. package/src/main/browser/text-editor-model-service.ts +111 -111
  285. package/src/main/browser/text-editors-main.ts +234 -234
  286. package/src/main/browser/theme-icon-override.ts +246 -246
  287. package/src/main/browser/theming-main.ts +42 -42
  288. package/src/main/browser/timeline-main.ts +80 -80
  289. package/src/main/browser/uri-main.ts +72 -0
  290. package/src/main/browser/view/dnd-file-content-store.ts +42 -42
  291. package/src/main/browser/view/plugin-tree-view-node-label-provider.ts +81 -81
  292. package/src/main/browser/view/plugin-view-registry.ts +967 -967
  293. package/src/main/browser/view/plugin-view-widget.ts +221 -221
  294. package/src/main/browser/view/tree-view-decorator-service.ts +51 -51
  295. package/src/main/browser/view/tree-view-widget.tsx +931 -931
  296. package/src/main/browser/view/tree-views-main.ts +205 -205
  297. package/src/main/browser/view/view-context-key-service.ts +64 -64
  298. package/src/main/browser/webview/pre/fake.html +14 -14
  299. package/src/main/browser/webview/pre/host.js +130 -130
  300. package/src/main/browser/webview/pre/index.html +17 -17
  301. package/src/main/browser/webview/pre/main.js +682 -682
  302. package/src/main/browser/webview/pre/service-worker.js +296 -295
  303. package/src/main/browser/webview/webview-context-keys.ts +62 -62
  304. package/src/main/browser/webview/webview-environment.ts +87 -87
  305. package/src/main/browser/webview/webview-frontend-security-warnings.ts +59 -59
  306. package/src/main/browser/webview/webview-preferences.ts +72 -72
  307. package/src/main/browser/webview/webview-resource-cache.ts +88 -88
  308. package/src/main/browser/webview/webview-secondary-window-support.ts +47 -47
  309. package/src/main/browser/webview/webview-theme-data-provider.ts +124 -124
  310. package/src/main/browser/webview/webview.ts +718 -719
  311. package/src/main/browser/webview-views/webview-views-main.ts +154 -154
  312. package/src/main/browser/webview-views/webview-views.ts +43 -43
  313. package/src/main/browser/webviews-main.ts +287 -282
  314. package/src/main/browser/window-activity-tracker.ts +96 -96
  315. package/src/main/browser/window-state-main.ts +85 -85
  316. package/src/main/browser/workspace-main.ts +424 -424
  317. package/src/main/common/basic-message-registry-main.ts +53 -53
  318. package/src/main/common/basic-notification-main.ts +86 -86
  319. package/src/main/common/env-main.ts +44 -44
  320. package/src/main/common/plugin-paths-protocol.ts +26 -26
  321. package/src/main/common/plugin-theia-environment.ts +36 -36
  322. package/src/main/common/webview-protocol.ts +28 -28
  323. package/src/main/electron-browser/plugin-ext-frontend-electron-module.ts +25 -25
  324. package/src/main/electron-browser/webview/electron-webview-widget-factory.ts +59 -59
  325. package/src/main/node/errors.spec.ts +37 -37
  326. package/src/main/node/handlers/plugin-theia-directory-handler.ts +137 -137
  327. package/src/main/node/handlers/plugin-theia-file-handler.ts +66 -66
  328. package/src/main/node/paths/const.ts +21 -21
  329. package/src/main/node/paths/plugin-paths-service.ts +163 -163
  330. package/src/main/node/plugin-cli-contribution.ts +85 -85
  331. package/src/main/node/plugin-deployer-contribution.ts +35 -35
  332. package/src/main/node/plugin-deployer-directory-handler-context-impl.ts +45 -45
  333. package/src/main/node/plugin-deployer-entry-impl.ts +132 -132
  334. package/src/main/node/plugin-deployer-file-handler-context-impl.ts +33 -33
  335. package/src/main/node/plugin-deployer-impl.ts +375 -375
  336. package/src/main/node/plugin-deployer-proxy-entry-impl.ts +96 -96
  337. package/src/main/node/plugin-deployer-resolver-context-impl.ts +55 -55
  338. package/src/main/node/plugin-ext-backend-module.ts +106 -106
  339. package/src/main/node/plugin-github-resolver.ts +139 -139
  340. package/src/main/node/plugin-http-resolver.ts +92 -92
  341. package/src/main/node/plugin-localization-server.ts +42 -42
  342. package/src/main/node/plugin-mgmt-cli-contribution.ts +64 -64
  343. package/src/main/node/plugin-remote-cli-contribution.ts +36 -36
  344. package/src/main/node/plugin-remote-copy-contribution.ts +36 -36
  345. package/src/main/node/plugin-server-handler.ts +69 -69
  346. package/src/main/node/plugin-service.ts +97 -97
  347. package/src/main/node/plugin-theia-deployer-participant.ts +32 -32
  348. package/src/main/node/plugin-uninstallation-manager.ts +74 -74
  349. package/src/main/node/plugins-key-value-storage.spec.ts +110 -110
  350. package/src/main/node/plugins-key-value-storage.ts +161 -161
  351. package/src/main/node/resolvers/local-directory-plugin-deployer-resolver.ts +37 -37
  352. package/src/main/node/resolvers/local-plugin-deployer-resolver.ts +56 -56
  353. package/src/main/node/temp-dir-util.ts +36 -36
  354. package/src/main/node/webview-backend-security-warnings.ts +45 -45
  355. package/src/main/style/status-bar.css +35 -35
  356. package/src/plugin/authentication-ext.ts +140 -136
  357. package/src/plugin/clipboard-ext.ts +43 -43
  358. package/src/plugin/command-registry.ts +219 -219
  359. package/src/plugin/comments.ts +549 -549
  360. package/src/plugin/custom-editors.ts +334 -336
  361. package/src/plugin/debug/debug-ext.ts +549 -549
  362. package/src/plugin/debug/plugin-debug-adapter-creator.ts +50 -50
  363. package/src/plugin/debug/plugin-debug-adapter-session.ts +106 -106
  364. package/src/plugin/debug/plugin-debug-adapter-tracker.ts +85 -85
  365. package/src/plugin/decorations.ts +140 -140
  366. package/src/plugin/dialogs.ts +96 -96
  367. package/src/plugin/document-data.ts +366 -366
  368. package/src/plugin/documents.ts +283 -283
  369. package/src/plugin/editors-and-documents.ts +176 -176
  370. package/src/plugin/env.ts +134 -129
  371. package/src/plugin/file-system-event-service-ext-impl.ts +256 -256
  372. package/src/plugin/file-system-ext-impl.ts +415 -415
  373. package/src/plugin/known-commands.spec.ts +50 -50
  374. package/src/plugin/known-commands.ts +429 -428
  375. package/src/plugin/label-service.ts +36 -36
  376. package/src/plugin/languages/call-hierarchy.ts +124 -124
  377. package/src/plugin/languages/code-action.ts +162 -162
  378. package/src/plugin/languages/color.ts +75 -75
  379. package/src/plugin/languages/completion.ts +183 -183
  380. package/src/plugin/languages/declaration.ts +72 -72
  381. package/src/plugin/languages/definition.ts +73 -73
  382. package/src/plugin/languages/diagnostics.ts +325 -325
  383. package/src/plugin/languages/document-drop-edit.ts +44 -44
  384. package/src/plugin/languages/document-formatting.ts +47 -47
  385. package/src/plugin/languages/document-highlight.ts +61 -61
  386. package/src/plugin/languages/evaluatable-expression.ts +47 -47
  387. package/src/plugin/languages/folding.ts +46 -46
  388. package/src/plugin/languages/hover.ts +58 -58
  389. package/src/plugin/languages/implementation.ts +73 -73
  390. package/src/plugin/languages/inlay-hints.ts +149 -149
  391. package/src/plugin/languages/inline-completion.ts +126 -126
  392. package/src/plugin/languages/inline-values.ts +50 -50
  393. package/src/plugin/languages/lens.ts +102 -102
  394. package/src/plugin/languages/link-provider.ts +81 -81
  395. package/src/plugin/languages/linked-editing-range.ts +48 -48
  396. package/src/plugin/languages/on-type-formatting.ts +50 -50
  397. package/src/plugin/languages/outline.ts +126 -126
  398. package/src/plugin/languages/range-formatting.ts +48 -48
  399. package/src/plugin/languages/reference.ts +58 -58
  400. package/src/plugin/languages/rename.ts +130 -130
  401. package/src/plugin/languages/selection-range.ts +80 -80
  402. package/src/plugin/languages/semantic-highlighting.ts +211 -211
  403. package/src/plugin/languages/signature.ts +82 -82
  404. package/src/plugin/languages/type-definition.ts +73 -73
  405. package/src/plugin/languages/type-hierarchy.ts +117 -117
  406. package/src/plugin/languages/util.ts +26 -26
  407. package/src/plugin/languages/workspace-symbol.ts +66 -66
  408. package/src/plugin/languages-utils.ts +68 -68
  409. package/src/plugin/languages.ts +1022 -1022
  410. package/src/plugin/localization-ext.ts +89 -89
  411. package/src/plugin/markdown-string.ts +115 -115
  412. package/src/plugin/message-registry.ts +70 -70
  413. package/src/plugin/node/debug/debug.spec.ts +98 -98
  414. package/src/plugin/node/debug/plugin-node-debug-adapter-creator.ts +167 -167
  415. package/src/plugin/node/env-node-ext.ts +64 -64
  416. package/src/plugin/node/plugin-container-module.ts +165 -165
  417. package/src/plugin/notebook/notebook-document.ts +446 -446
  418. package/src/plugin/notebook/notebook-documents.ts +58 -58
  419. package/src/plugin/notebook/notebook-editor.ts +116 -116
  420. package/src/plugin/notebook/notebook-editors.ts +71 -71
  421. package/src/plugin/notebook/notebook-kernels.ts +631 -631
  422. package/src/plugin/notebook/notebook-renderers.ts +71 -71
  423. package/src/plugin/notebook/notebooks.ts +449 -449
  424. package/src/plugin/notification.ts +80 -80
  425. package/src/plugin/output-channel/log-output-channel.ts +108 -108
  426. package/src/plugin/output-channel/output-channel-item.ts +73 -73
  427. package/src/plugin/output-channel-registry.ts +52 -52
  428. package/src/plugin/path.spec.ts +40 -40
  429. package/src/plugin/path.ts +68 -68
  430. package/src/plugin/plugin-context.ts +1606 -1595
  431. package/src/plugin/plugin-icon-path.ts +53 -53
  432. package/src/plugin/plugin-manager.ts +508 -507
  433. package/src/plugin/plugin-storage.ts +138 -138
  434. package/src/plugin/preference-registry.spec.ts +288 -288
  435. package/src/plugin/preference-registry.ts +335 -335
  436. package/src/plugin/prefix-sum-computer.ts +218 -218
  437. package/src/plugin/quick-open.ts +735 -735
  438. package/src/plugin/scm.ts +919 -919
  439. package/src/plugin/secrets-ext.ts +104 -104
  440. package/src/plugin/status-bar/status-bar-item.ts +193 -193
  441. package/src/plugin/status-bar-message-registry.ts +103 -103
  442. package/src/plugin/tabs.ts +431 -431
  443. package/src/plugin/tasks/task-provider.ts +57 -57
  444. package/src/plugin/tasks/tasks.ts +252 -252
  445. package/src/plugin/telemetry-ext.ts +298 -298
  446. package/src/plugin/terminal-ext.ts +569 -566
  447. package/src/plugin/test-item.ts +174 -174
  448. package/src/plugin/tests.ts +545 -545
  449. package/src/plugin/text-editor.ts +581 -581
  450. package/src/plugin/text-editors.ts +157 -157
  451. package/src/plugin/theming.ts +73 -73
  452. package/src/plugin/timeline.ts +186 -186
  453. package/src/plugin/tree/tree-views.ts +682 -682
  454. package/src/plugin/type-converters.spec.ts +476 -476
  455. package/src/plugin/type-converters.ts +1768 -1748
  456. package/src/plugin/types-impl.spec.ts +85 -85
  457. package/src/plugin/types-impl.ts +4011 -4001
  458. package/src/plugin/uri-ext.ts +60 -0
  459. package/src/plugin/webview-views.ts +228 -228
  460. package/src/plugin/webviews.ts +468 -468
  461. package/src/plugin/window-state.ts +75 -75
  462. package/src/plugin/word-helper.ts +162 -162
  463. package/src/plugin/workspace.ts +505 -505
  464. package/src/plugin-ext-backend-electron-module.ts +24 -24
  465. package/src/plugin-ext-backend-module.ts +24 -24
  466. package/src/plugin-ext-frontend-electron-module.ts +19 -19
  467. package/src/plugin-ext-frontend-module.ts +19 -19
  468. package/lib/common/proxy-handler.d.ts +0 -73
  469. package/lib/common/proxy-handler.d.ts.map +0 -1
  470. package/lib/common/proxy-handler.js +0 -106
  471. package/lib/common/proxy-handler.js.map +0 -1
  472. package/src/common/proxy-handler.ts +0 -143
@@ -1,585 +1,526 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
- /*---------------------------------------------------------------------------------------------
17
- * Copyright (c) Microsoft Corporation. All rights reserved.
18
- * Licensed under the MIT License. See License.txt in the project root for license information.
19
- *--------------------------------------------------------------------------------------------*/
20
- // some code copied and modified from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/workbench/api/browser/mainThreadCustomEditors.ts
21
-
22
- import { interfaces } from '@theia/core/shared/inversify';
23
- import { MAIN_RPC_CONTEXT, CustomEditorsMain, CustomEditorsExt, CustomTextEditorCapabilities } from '../../../common/plugin-api-rpc';
24
- import { RPCProtocol } from '../../../common/rpc-protocol';
25
- import { HostedPluginSupport } from '../../../hosted/browser/hosted-plugin';
26
- import { PluginCustomEditorRegistry } from './plugin-custom-editor-registry';
27
- import { CustomEditorWidget } from './custom-editor-widget';
28
- import { Emitter } from '@theia/core';
29
- import { UriComponents } from '../../../common/uri-components';
30
- import { URI } from '@theia/core/shared/vscode-uri';
31
- import TheiaURI from '@theia/core/lib/common/uri';
32
- import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
33
- import { Reference } from '@theia/core/lib/common/reference';
34
- import { CancellationToken, CancellationTokenSource } from '@theia/core/lib/common/cancellation';
35
- import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
36
- import { EditorModelService } from '../text-editor-model-service';
37
- import { CustomEditorService } from './custom-editor-service';
38
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
39
- import { UndoRedoService } from '@theia/editor/lib/browser/undo-redo-service';
40
- import { WebviewsMainImpl } from '../webviews-main';
41
- import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
42
- import { ApplicationShell, DefaultUriLabelProviderContribution, Saveable, SaveOptions, WidgetOpenerOptions } from '@theia/core/lib/browser';
43
- import { WebviewOptions, WebviewPanelOptions, WebviewPanelShowOptions } from '@theia/plugin';
44
- import { WebviewWidgetIdentifier } from '../webview/webview';
45
- import { EditorPreferences } from '@theia/editor/lib/browser';
46
- import { ViewColumn, WebviewPanelTargetArea } from '../../../plugin/types-impl';
47
-
48
- const enum CustomEditorModelType {
49
- Custom,
50
- Text,
51
- }
52
-
53
- export class CustomEditorsMainImpl implements CustomEditorsMain, Disposable {
54
- protected readonly pluginService: HostedPluginSupport;
55
- protected readonly shell: ApplicationShell;
56
- protected readonly textModelService: EditorModelService;
57
- protected readonly fileService: FileService;
58
- protected readonly customEditorService: CustomEditorService;
59
- protected readonly undoRedoService: UndoRedoService;
60
- protected readonly customEditorRegistry: PluginCustomEditorRegistry;
61
- protected readonly labelProvider: DefaultUriLabelProviderContribution;
62
- protected readonly widgetManager: WidgetManager;
63
- protected readonly editorPreferences: EditorPreferences;
64
- private readonly proxy: CustomEditorsExt;
65
- private readonly editorProviders = new Map<string, Disposable>();
66
-
67
- constructor(rpc: RPCProtocol,
68
- container: interfaces.Container,
69
- readonly webviewsMain: WebviewsMainImpl,
70
- ) {
71
- this.pluginService = container.get(HostedPluginSupport);
72
- this.shell = container.get(ApplicationShell);
73
- this.textModelService = container.get(EditorModelService);
74
- this.fileService = container.get(FileService);
75
- this.customEditorService = container.get(CustomEditorService);
76
- this.undoRedoService = container.get(UndoRedoService);
77
- this.customEditorRegistry = container.get(PluginCustomEditorRegistry);
78
- this.labelProvider = container.get(DefaultUriLabelProviderContribution);
79
- this.editorPreferences = container.get(EditorPreferences);
80
- this.widgetManager = container.get(WidgetManager);
81
- this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.CUSTOM_EDITORS_EXT);
82
- }
83
-
84
- dispose(): void {
85
- for (const disposable of this.editorProviders.values()) {
86
- disposable.dispose();
87
- }
88
- this.editorProviders.clear();
89
- }
90
-
91
- $registerTextEditorProvider(
92
- viewType: string, options: WebviewPanelOptions, capabilities: CustomTextEditorCapabilities): void {
93
- this.registerEditorProvider(CustomEditorModelType.Text, viewType, options, capabilities, true);
94
- }
95
-
96
- $registerCustomEditorProvider(viewType: string, options: WebviewPanelOptions, supportsMultipleEditorsPerDocument: boolean): void {
97
- this.registerEditorProvider(CustomEditorModelType.Custom, viewType, options, {}, supportsMultipleEditorsPerDocument);
98
- }
99
-
100
- protected async registerEditorProvider(
101
- modelType: CustomEditorModelType,
102
- viewType: string,
103
- options: WebviewPanelOptions,
104
- capabilities: CustomTextEditorCapabilities,
105
- supportsMultipleEditorsPerDocument: boolean,
106
- ): Promise<void> {
107
- if (this.editorProviders.has(viewType)) {
108
- throw new Error(`Provider for ${viewType} already registered`);
109
- }
110
-
111
- const disposables = new DisposableCollection();
112
-
113
- disposables.push(
114
- this.customEditorRegistry.registerResolver(viewType, async (widget, widgetOpenerOptions) => {
115
- const { resource, identifier } = widget;
116
- widget.options = options;
117
-
118
- const cancellationSource = new CancellationTokenSource();
119
- let modelRef = await this.getOrCreateCustomEditorModel(modelType, resource, viewType, cancellationSource.token);
120
- widget.modelRef = modelRef;
121
-
122
- widget.onDidDispose(() => {
123
- // If the model is still dirty, make sure we have time to save it
124
- if (modelRef.object.dirty) {
125
- const sub = modelRef.object.onDirtyChanged(() => {
126
- if (!modelRef.object.dirty) {
127
- sub.dispose();
128
- modelRef.dispose();
129
- }
130
- });
131
- return;
132
- }
133
-
134
- modelRef.dispose();
135
- });
136
-
137
- if (capabilities.supportsMove) {
138
- const onMoveCancelTokenSource = new CancellationTokenSource();
139
- widget.onMove(async (newResource: TheiaURI) => {
140
- const oldModel = modelRef;
141
- modelRef = await this.getOrCreateCustomEditorModel(modelType, newResource, viewType, onMoveCancelTokenSource.token);
142
- this.proxy.$onMoveCustomEditor(identifier.id, newResource.toComponents(), viewType);
143
- oldModel.dispose();
144
- });
145
- }
146
-
147
- const _cancellationSource = new CancellationTokenSource();
148
- await this.proxy.$resolveWebviewEditor(
149
- resource.toComponents(),
150
- identifier.id,
151
- viewType,
152
- this.labelProvider.getName(resource)!,
153
- widgetOpenerOptions,
154
- options,
155
- _cancellationSource.token
156
- );
157
- })
158
- );
159
-
160
- this.editorProviders.set(viewType, disposables);
161
- }
162
-
163
- $unregisterEditorProvider(viewType: string): void {
164
- const provider = this.editorProviders.get(viewType);
165
- if (!provider) {
166
- throw new Error(`No provider for ${viewType} registered`);
167
- }
168
-
169
- provider.dispose();
170
- this.editorProviders.delete(viewType);
171
-
172
- this.customEditorService.models.disposeAllModelsForView(viewType);
173
- }
174
-
175
- protected async getOrCreateCustomEditorModel(
176
- modelType: CustomEditorModelType,
177
- resource: TheiaURI,
178
- viewType: string,
179
- cancellationToken: CancellationToken,
180
- ): Promise<Reference<CustomEditorModel>> {
181
- const existingModel = this.customEditorService.models.tryRetain(resource, viewType);
182
- if (existingModel) {
183
- return existingModel;
184
- }
185
-
186
- switch (modelType) {
187
- case CustomEditorModelType.Text: {
188
- const model = CustomTextEditorModel.create(viewType, resource, this.textModelService, this.fileService);
189
- return this.customEditorService.models.add(resource, viewType, model);
190
- }
191
- case CustomEditorModelType.Custom: {
192
- const model = MainCustomEditorModel.create(this.proxy, viewType, resource, this.undoRedoService, this.fileService, cancellationToken);
193
- return this.customEditorService.models.add(resource, viewType, model);
194
- }
195
- }
196
- }
197
-
198
- protected async getCustomEditorModel(resourceComponents: UriComponents, viewType: string): Promise<MainCustomEditorModel> {
199
- const resource = URI.revive(resourceComponents);
200
- const model = await this.customEditorService.models.get(new TheiaURI(resource), viewType);
201
- if (!model || !(model instanceof MainCustomEditorModel)) {
202
- throw new Error('Could not find model for custom editor');
203
- }
204
- return model;
205
- }
206
-
207
- async $onDidEdit(resourceComponents: UriComponents, viewType: string, editId: number, label: string | undefined): Promise<void> {
208
- const model = await this.getCustomEditorModel(resourceComponents, viewType);
209
- model.pushEdit(editId, label);
210
- }
211
-
212
- async $onContentChange(resourceComponents: UriComponents, viewType: string): Promise<void> {
213
- const model = await this.getCustomEditorModel(resourceComponents, viewType);
214
- model.changeContent();
215
- }
216
-
217
- async $createCustomEditorPanel(
218
- panelId: string,
219
- title: string,
220
- widgetOpenerOptions: WidgetOpenerOptions | undefined,
221
- options: WebviewPanelOptions & WebviewOptions
222
- ): Promise<void> {
223
- const view = await this.widgetManager.getOrCreateWidget<CustomEditorWidget>(CustomEditorWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: panelId });
224
- this.webviewsMain.hookWebview(view);
225
- view.title.label = title;
226
- const { enableFindWidget, retainContextWhenHidden, enableScripts, enableForms, localResourceRoots, ...contentOptions } = options;
227
- view.viewColumn = ViewColumn.One; // behaviour might be overridden later using widgetOpenerOptions (if available)
228
- view.options = { enableFindWidget, retainContextWhenHidden };
229
- view.setContentOptions({
230
- allowScripts: enableScripts,
231
- allowForms: enableForms,
232
- localResourceRoots: localResourceRoots && localResourceRoots.map(root => root.toString()),
233
- ...contentOptions,
234
- ...view.contentOptions
235
- });
236
- if (view.isAttached) {
237
- if (view.isVisible) {
238
- this.shell.revealWidget(view.id);
239
- }
240
- return;
241
- }
242
- const showOptions: WebviewPanelShowOptions = {
243
- preserveFocus: true
244
- };
245
-
246
- if (widgetOpenerOptions) {
247
- if (widgetOpenerOptions.mode === 'reveal') {
248
- showOptions.preserveFocus = false;
249
- }
250
-
251
- if (widgetOpenerOptions.widgetOptions) {
252
- let area: WebviewPanelTargetArea;
253
- switch (widgetOpenerOptions.widgetOptions.area) {
254
- case 'main':
255
- area = WebviewPanelTargetArea.Main;
256
- case 'left':
257
- area = WebviewPanelTargetArea.Left;
258
- case 'right':
259
- area = WebviewPanelTargetArea.Right;
260
- case 'bottom':
261
- area = WebviewPanelTargetArea.Bottom;
262
- default: // includes 'top' and 'secondaryWindow'
263
- area = WebviewPanelTargetArea.Main;
264
- }
265
- showOptions.area = area;
266
-
267
- if (widgetOpenerOptions.widgetOptions.mode === 'split-right' ||
268
- widgetOpenerOptions.widgetOptions.mode === 'open-to-right') {
269
- showOptions.viewColumn = ViewColumn.Beside;
270
- }
271
- }
272
- }
273
-
274
- this.webviewsMain.addOrReattachWidget(view, showOptions);
275
- }
276
- }
277
-
278
- export interface CustomEditorModel extends Saveable, Disposable {
279
- readonly viewType: string;
280
- readonly resource: URI;
281
- readonly readonly: boolean;
282
- readonly dirty: boolean;
283
-
284
- revert(options?: Saveable.RevertOptions): Promise<void>;
285
- saveCustomEditor(options?: SaveOptions): Promise<void>;
286
- saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void>;
287
-
288
- undo(): void;
289
- redo(): void;
290
- }
291
-
292
- export class MainCustomEditorModel implements CustomEditorModel {
293
- private currentEditIndex: number = -1;
294
- private savePoint: number = -1;
295
- private isDirtyFromContentChange = false;
296
- private ongoingSave?: CancellationTokenSource;
297
- private readonly edits: Array<number> = [];
298
- private readonly toDispose = new DisposableCollection();
299
-
300
- private readonly onDirtyChangedEmitter = new Emitter<void>();
301
- readonly onDirtyChanged = this.onDirtyChangedEmitter.event;
302
-
303
- private readonly onContentChangedEmitter = new Emitter<void>();
304
- readonly onContentChanged = this.onContentChangedEmitter.event;
305
-
306
- static async create(
307
- proxy: CustomEditorsExt,
308
- viewType: string,
309
- resource: TheiaURI,
310
- undoRedoService: UndoRedoService,
311
- fileService: FileService,
312
- cancellation: CancellationToken,
313
- ): Promise<MainCustomEditorModel> {
314
- const { editable } = await proxy.$createCustomDocument(resource.toComponents(), viewType, {}, cancellation);
315
- return new MainCustomEditorModel(proxy, viewType, resource, editable, undoRedoService, fileService);
316
- }
317
-
318
- constructor(
319
- private proxy: CustomEditorsExt,
320
- readonly viewType: string,
321
- private readonly editorResource: TheiaURI,
322
- private readonly editable: boolean,
323
- private readonly undoRedoService: UndoRedoService,
324
- private readonly fileService: FileService
325
- ) {
326
- this.toDispose.push(this.onDirtyChangedEmitter);
327
- }
328
-
329
- get resource(): URI {
330
- return URI.from(this.editorResource.toComponents());
331
- }
332
-
333
- get dirty(): boolean {
334
- if (this.isDirtyFromContentChange) {
335
- return true;
336
- }
337
- if (this.edits.length > 0) {
338
- return this.savePoint !== this.currentEditIndex;
339
- }
340
- return false;
341
- }
342
-
343
- get readonly(): boolean {
344
- return !this.editable;
345
- }
346
-
347
- setProxy(proxy: CustomEditorsExt): void {
348
- this.proxy = proxy;
349
- }
350
-
351
- dispose(): void {
352
- if (this.editable) {
353
- this.undoRedoService.removeElements(this.editorResource);
354
- }
355
- this.proxy.$disposeCustomDocument(this.resource, this.viewType);
356
- }
357
-
358
- changeContent(): void {
359
- this.change(() => {
360
- this.isDirtyFromContentChange = true;
361
- });
362
- }
363
-
364
- pushEdit(editId: number, label: string | undefined): void {
365
- if (!this.editable) {
366
- throw new Error('Document is not editable');
367
- }
368
-
369
- this.change(() => {
370
- this.spliceEdits(editId);
371
- this.currentEditIndex = this.edits.length - 1;
372
- });
373
-
374
- this.undoRedoService.pushElement(
375
- this.editorResource,
376
- () => this.undo(),
377
- () => this.redo(),
378
- );
379
- }
380
-
381
- async revert(options?: Saveable.RevertOptions): Promise<void> {
382
- if (!this.editable) {
383
- return;
384
- }
385
-
386
- if (this.currentEditIndex === this.savePoint && !this.isDirtyFromContentChange) {
387
- return;
388
- }
389
-
390
- const cancellationSource = new CancellationTokenSource();
391
- this.proxy.$revert(this.resource, this.viewType, cancellationSource.token);
392
- this.change(() => {
393
- this.isDirtyFromContentChange = false;
394
- this.currentEditIndex = this.savePoint;
395
- this.spliceEdits();
396
- });
397
- }
398
-
399
- async save(options?: SaveOptions): Promise<void> {
400
- await this.saveCustomEditor(options);
401
- }
402
-
403
- async saveCustomEditor(options?: SaveOptions): Promise<void> {
404
- if (!this.editable) {
405
- return;
406
- }
407
-
408
- const cancelable = new CancellationTokenSource();
409
- const savePromise = this.proxy.$onSave(this.resource, this.viewType, cancelable.token);
410
- this.ongoingSave?.cancel();
411
- this.ongoingSave = cancelable;
412
-
413
- try {
414
- await savePromise;
415
-
416
- if (this.ongoingSave === cancelable) { // Make sure we are still doing the same save
417
- this.change(() => {
418
- this.isDirtyFromContentChange = false;
419
- this.savePoint = this.currentEditIndex;
420
- });
421
- }
422
- } finally {
423
- if (this.ongoingSave === cancelable) { // Make sure we are still doing the same save
424
- this.ongoingSave = undefined;
425
- }
426
- }
427
- }
428
-
429
- async saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void> {
430
- if (this.editable) {
431
- const source = new CancellationTokenSource();
432
- await this.proxy.$onSaveAs(this.resource, this.viewType, targetResource.toComponents(), source.token);
433
- this.change(() => {
434
- this.savePoint = this.currentEditIndex;
435
- });
436
- } else {
437
- // Since the editor is readonly, just copy the file over
438
- await this.fileService.copy(resource, targetResource, { overwrite: false });
439
- }
440
- }
441
-
442
- async undo(): Promise<void> {
443
- if (!this.editable) {
444
- return;
445
- }
446
-
447
- if (this.currentEditIndex < 0) {
448
- // nothing to undo
449
- return;
450
- }
451
-
452
- const undoneEdit = this.edits[this.currentEditIndex];
453
- this.change(() => {
454
- --this.currentEditIndex;
455
- });
456
- await this.proxy.$undo(this.resource, this.viewType, undoneEdit, this.dirty);
457
- }
458
-
459
- async redo(): Promise<void> {
460
- if (!this.editable) {
461
- return;
462
- }
463
-
464
- if (this.currentEditIndex >= this.edits.length - 1) {
465
- // nothing to redo
466
- return;
467
- }
468
-
469
- const redoneEdit = this.edits[this.currentEditIndex + 1];
470
- this.change(() => {
471
- ++this.currentEditIndex;
472
- });
473
- await this.proxy.$redo(this.resource, this.viewType, redoneEdit, this.dirty);
474
- }
475
-
476
- private spliceEdits(editToInsert?: number): void {
477
- const start = this.currentEditIndex + 1;
478
- const toRemove = this.edits.length - this.currentEditIndex;
479
-
480
- const removedEdits = typeof editToInsert === 'number'
481
- ? this.edits.splice(start, toRemove, editToInsert)
482
- : this.edits.splice(start, toRemove);
483
-
484
- if (removedEdits.length) {
485
- this.proxy.$disposeEdits(this.resource, this.viewType, removedEdits);
486
- }
487
- }
488
-
489
- private change(makeEdit: () => void): void {
490
- const wasDirty = this.dirty;
491
- makeEdit();
492
-
493
- if (this.dirty !== wasDirty) {
494
- this.onDirtyChangedEmitter.fire();
495
- }
496
- this.onContentChangedEmitter.fire();
497
- }
498
-
499
- }
500
-
501
- // copied from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/workbench/contrib/customEditor/common/customTextEditorModel.ts
502
- export class CustomTextEditorModel implements CustomEditorModel {
503
- private readonly toDispose = new DisposableCollection();
504
- private readonly onDirtyChangedEmitter = new Emitter<void>();
505
- readonly onDirtyChanged = this.onDirtyChangedEmitter.event;
506
- private readonly onContentChangedEmitter = new Emitter<void>();
507
- readonly onContentChanged = this.onContentChangedEmitter.event;
508
-
509
- static async create(
510
- viewType: string,
511
- resource: TheiaURI,
512
- editorModelService: EditorModelService,
513
- fileService: FileService,
514
- ): Promise<CustomTextEditorModel> {
515
- const model = await editorModelService.createModelReference(resource);
516
- model.object.suppressOpenEditorWhenDirty = true;
517
- return new CustomTextEditorModel(viewType, resource, model, fileService);
518
- }
519
-
520
- constructor(
521
- readonly viewType: string,
522
- readonly editorResource: TheiaURI,
523
- private readonly model: Reference<MonacoEditorModel>,
524
- private readonly fileService: FileService,
525
- ) {
526
- this.toDispose.push(
527
- this.editorTextModel.onDirtyChanged(e => {
528
- this.onDirtyChangedEmitter.fire();
529
- })
530
- );
531
- this.toDispose.push(
532
- this.editorTextModel.onContentChanged(e => {
533
- this.onContentChangedEmitter.fire();
534
- })
535
- );
536
- this.toDispose.push(this.onDirtyChangedEmitter);
537
- this.toDispose.push(this.onContentChangedEmitter);
538
- }
539
-
540
- dispose(): void {
541
- this.toDispose.dispose();
542
- this.model.dispose();
543
- }
544
-
545
- get resource(): URI {
546
- return URI.from(this.editorResource.toComponents());
547
- }
548
-
549
- get dirty(): boolean {
550
- return this.editorTextModel.dirty;
551
- };
552
-
553
- get readonly(): boolean {
554
- return Boolean(this.editorTextModel.readOnly);
555
- }
556
-
557
- get editorTextModel(): MonacoEditorModel {
558
- return this.model.object;
559
- }
560
-
561
- revert(options?: Saveable.RevertOptions): Promise<void> {
562
- return this.editorTextModel.revert(options);
563
- }
564
-
565
- save(options?: SaveOptions): Promise<void> {
566
- return this.saveCustomEditor(options);
567
- }
568
-
569
- saveCustomEditor(options?: SaveOptions): Promise<void> {
570
- return this.editorTextModel.save(options);
571
- }
572
-
573
- async saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void> {
574
- await this.saveCustomEditor(options);
575
- await this.fileService.copy(resource, targetResource, { overwrite: false });
576
- }
577
-
578
- undo(): void {
579
- this.editorTextModel.undo();
580
- }
581
-
582
- redo(): void {
583
- this.editorTextModel.redo();
584
- }
585
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 SAP SE or an SAP affiliate company and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+ /*---------------------------------------------------------------------------------------------
17
+ * Copyright (c) Microsoft Corporation. All rights reserved.
18
+ * Licensed under the MIT License. See License.txt in the project root for license information.
19
+ *--------------------------------------------------------------------------------------------*/
20
+ // some code copied and modified from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/workbench/api/browser/mainThreadCustomEditors.ts
21
+
22
+ import { interfaces } from '@theia/core/shared/inversify';
23
+ import { MAIN_RPC_CONTEXT, CustomEditorsMain, CustomEditorsExt, CustomTextEditorCapabilities } from '../../../common/plugin-api-rpc';
24
+ import { RPCProtocol } from '../../../common/rpc-protocol';
25
+ import { HostedPluginSupport } from '../../../hosted/browser/hosted-plugin';
26
+ import { PluginCustomEditorRegistry } from './plugin-custom-editor-registry';
27
+ import { Emitter } from '@theia/core';
28
+ import { UriComponents } from '../../../common/uri-components';
29
+ import { URI } from '@theia/core/shared/vscode-uri';
30
+ import TheiaURI from '@theia/core/lib/common/uri';
31
+ import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
32
+ import { Reference } from '@theia/core/lib/common/reference';
33
+ import { CancellationToken, CancellationTokenSource } from '@theia/core/lib/common/cancellation';
34
+ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
35
+ import { EditorModelService } from '../text-editor-model-service';
36
+ import { CustomEditorService } from './custom-editor-service';
37
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
38
+ import { UndoRedoService } from '@theia/editor/lib/browser/undo-redo-service';
39
+ import { WebviewsMainImpl } from '../webviews-main';
40
+ import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
41
+ import { ApplicationShell, LabelProvider, Saveable, SaveOptions } from '@theia/core/lib/browser';
42
+ import { WebviewPanelOptions } from '@theia/plugin';
43
+ import { EditorPreferences } from '@theia/editor/lib/browser';
44
+
45
+ const enum CustomEditorModelType {
46
+ Custom,
47
+ Text,
48
+ }
49
+
50
+ export class CustomEditorsMainImpl implements CustomEditorsMain, Disposable {
51
+ protected readonly pluginService: HostedPluginSupport;
52
+ protected readonly shell: ApplicationShell;
53
+ protected readonly textModelService: EditorModelService;
54
+ protected readonly fileService: FileService;
55
+ protected readonly customEditorService: CustomEditorService;
56
+ protected readonly undoRedoService: UndoRedoService;
57
+ protected readonly customEditorRegistry: PluginCustomEditorRegistry;
58
+ protected readonly labelProvider: LabelProvider;
59
+ protected readonly widgetManager: WidgetManager;
60
+ protected readonly editorPreferences: EditorPreferences;
61
+ private readonly proxy: CustomEditorsExt;
62
+ private readonly editorProviders = new Map<string, Disposable>();
63
+
64
+ constructor(rpc: RPCProtocol,
65
+ container: interfaces.Container,
66
+ readonly webviewsMain: WebviewsMainImpl,
67
+ ) {
68
+ this.pluginService = container.get(HostedPluginSupport);
69
+ this.shell = container.get(ApplicationShell);
70
+ this.textModelService = container.get(EditorModelService);
71
+ this.fileService = container.get(FileService);
72
+ this.customEditorService = container.get(CustomEditorService);
73
+ this.undoRedoService = container.get(UndoRedoService);
74
+ this.customEditorRegistry = container.get(PluginCustomEditorRegistry);
75
+ this.labelProvider = container.get(LabelProvider);
76
+ this.editorPreferences = container.get(EditorPreferences);
77
+ this.widgetManager = container.get(WidgetManager);
78
+ this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.CUSTOM_EDITORS_EXT);
79
+ }
80
+
81
+ dispose(): void {
82
+ for (const disposable of this.editorProviders.values()) {
83
+ disposable.dispose();
84
+ }
85
+ this.editorProviders.clear();
86
+ }
87
+
88
+ $registerTextEditorProvider(
89
+ viewType: string, options: WebviewPanelOptions, capabilities: CustomTextEditorCapabilities): void {
90
+ this.registerEditorProvider(CustomEditorModelType.Text, viewType, options, capabilities, true);
91
+ }
92
+
93
+ $registerCustomEditorProvider(viewType: string, options: WebviewPanelOptions, supportsMultipleEditorsPerDocument: boolean): void {
94
+ this.registerEditorProvider(CustomEditorModelType.Custom, viewType, options, {}, supportsMultipleEditorsPerDocument);
95
+ }
96
+
97
+ protected async registerEditorProvider(
98
+ modelType: CustomEditorModelType,
99
+ viewType: string,
100
+ options: WebviewPanelOptions,
101
+ capabilities: CustomTextEditorCapabilities,
102
+ supportsMultipleEditorsPerDocument: boolean,
103
+ ): Promise<void> {
104
+ if (this.editorProviders.has(viewType)) {
105
+ throw new Error(`Provider for ${viewType} already registered`);
106
+ }
107
+
108
+ const disposables = new DisposableCollection();
109
+
110
+ disposables.push(
111
+ this.customEditorRegistry.registerResolver(viewType, async widget => {
112
+
113
+ const { resource, identifier } = widget;
114
+ widget.options = options;
115
+
116
+ const cancellationSource = new CancellationTokenSource();
117
+ let modelRef = await this.getOrCreateCustomEditorModel(modelType, resource, viewType, cancellationSource.token);
118
+ widget.modelRef = modelRef;
119
+
120
+ widget.onDidDispose(() => {
121
+ // If the model is still dirty, make sure we have time to save it
122
+ if (modelRef.object.dirty) {
123
+ const sub = modelRef.object.onDirtyChanged(() => {
124
+ if (!modelRef.object.dirty) {
125
+ sub.dispose();
126
+ modelRef.dispose();
127
+ }
128
+ });
129
+ return;
130
+ }
131
+
132
+ modelRef.dispose();
133
+ });
134
+
135
+ if (capabilities.supportsMove) {
136
+ const onMoveCancelTokenSource = new CancellationTokenSource();
137
+ widget.onMove(async (newResource: TheiaURI) => {
138
+ const oldModel = modelRef;
139
+ modelRef = await this.getOrCreateCustomEditorModel(modelType, newResource, viewType, onMoveCancelTokenSource.token);
140
+ this.proxy.$onMoveCustomEditor(identifier.id, newResource.toComponents(), viewType);
141
+ oldModel.dispose();
142
+ });
143
+ }
144
+
145
+ this.webviewsMain.hookWebview(widget);
146
+ widget.title.label = this.labelProvider.getName(resource);
147
+
148
+ const _cancellationSource = new CancellationTokenSource();
149
+ await this.proxy.$resolveWebviewEditor(
150
+ resource.toComponents(),
151
+ identifier.id,
152
+ viewType,
153
+ widget.title.label,
154
+ widget.viewState.position,
155
+ options,
156
+ _cancellationSource.token
157
+ );
158
+ })
159
+ );
160
+
161
+ this.editorProviders.set(viewType, disposables);
162
+ }
163
+
164
+ $unregisterEditorProvider(viewType: string): void {
165
+ const provider = this.editorProviders.get(viewType);
166
+ if (!provider) {
167
+ throw new Error(`No provider for ${viewType} registered`);
168
+ }
169
+
170
+ provider.dispose();
171
+ this.editorProviders.delete(viewType);
172
+
173
+ this.customEditorService.models.disposeAllModelsForView(viewType);
174
+ }
175
+
176
+ protected async getOrCreateCustomEditorModel(
177
+ modelType: CustomEditorModelType,
178
+ resource: TheiaURI,
179
+ viewType: string,
180
+ cancellationToken: CancellationToken,
181
+ ): Promise<Reference<CustomEditorModel>> {
182
+ const existingModel = this.customEditorService.models.tryRetain(resource, viewType);
183
+ if (existingModel) {
184
+ return existingModel;
185
+ }
186
+
187
+ switch (modelType) {
188
+ case CustomEditorModelType.Text: {
189
+ const model = CustomTextEditorModel.create(viewType, resource, this.textModelService, this.fileService);
190
+ return this.customEditorService.models.add(resource, viewType, model);
191
+ }
192
+ case CustomEditorModelType.Custom: {
193
+ const model = MainCustomEditorModel.create(this.proxy, viewType, resource, this.undoRedoService, this.fileService, cancellationToken);
194
+ return this.customEditorService.models.add(resource, viewType, model);
195
+ }
196
+ }
197
+ }
198
+
199
+ protected async getCustomEditorModel(resourceComponents: UriComponents, viewType: string): Promise<MainCustomEditorModel> {
200
+ const resource = URI.revive(resourceComponents);
201
+ const model = await this.customEditorService.models.get(new TheiaURI(resource), viewType);
202
+ if (!model || !(model instanceof MainCustomEditorModel)) {
203
+ throw new Error('Could not find model for custom editor');
204
+ }
205
+ return model;
206
+ }
207
+
208
+ async $onDidEdit(resourceComponents: UriComponents, viewType: string, editId: number, label: string | undefined): Promise<void> {
209
+ const model = await this.getCustomEditorModel(resourceComponents, viewType);
210
+ model.pushEdit(editId, label);
211
+ }
212
+
213
+ async $onContentChange(resourceComponents: UriComponents, viewType: string): Promise<void> {
214
+ const model = await this.getCustomEditorModel(resourceComponents, viewType);
215
+ model.changeContent();
216
+ }
217
+ }
218
+
219
+ export interface CustomEditorModel extends Saveable, Disposable {
220
+ readonly viewType: string;
221
+ readonly resource: URI;
222
+ readonly readonly: boolean;
223
+ readonly dirty: boolean;
224
+
225
+ revert(options?: Saveable.RevertOptions): Promise<void>;
226
+ saveCustomEditor(options?: SaveOptions): Promise<void>;
227
+ saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void>;
228
+
229
+ undo(): void;
230
+ redo(): void;
231
+ }
232
+
233
+ export class MainCustomEditorModel implements CustomEditorModel {
234
+ private currentEditIndex: number = -1;
235
+ private savePoint: number = -1;
236
+ private isDirtyFromContentChange = false;
237
+ private ongoingSave?: CancellationTokenSource;
238
+ private readonly edits: Array<number> = [];
239
+ private readonly toDispose = new DisposableCollection();
240
+
241
+ private readonly onDirtyChangedEmitter = new Emitter<void>();
242
+ readonly onDirtyChanged = this.onDirtyChangedEmitter.event;
243
+
244
+ private readonly onContentChangedEmitter = new Emitter<void>();
245
+ readonly onContentChanged = this.onContentChangedEmitter.event;
246
+
247
+ static async create(
248
+ proxy: CustomEditorsExt,
249
+ viewType: string,
250
+ resource: TheiaURI,
251
+ undoRedoService: UndoRedoService,
252
+ fileService: FileService,
253
+ cancellation: CancellationToken,
254
+ ): Promise<MainCustomEditorModel> {
255
+ const { editable } = await proxy.$createCustomDocument(resource.toComponents(), viewType, {}, cancellation);
256
+ return new MainCustomEditorModel(proxy, viewType, resource, editable, undoRedoService, fileService);
257
+ }
258
+
259
+ constructor(
260
+ private proxy: CustomEditorsExt,
261
+ readonly viewType: string,
262
+ private readonly editorResource: TheiaURI,
263
+ private readonly editable: boolean,
264
+ private readonly undoRedoService: UndoRedoService,
265
+ private readonly fileService: FileService
266
+ ) {
267
+ this.toDispose.push(this.onDirtyChangedEmitter);
268
+ }
269
+
270
+ get resource(): URI {
271
+ return URI.from(this.editorResource.toComponents());
272
+ }
273
+
274
+ get dirty(): boolean {
275
+ if (this.isDirtyFromContentChange) {
276
+ return true;
277
+ }
278
+ if (this.edits.length > 0) {
279
+ return this.savePoint !== this.currentEditIndex;
280
+ }
281
+ return false;
282
+ }
283
+
284
+ get readonly(): boolean {
285
+ return !this.editable;
286
+ }
287
+
288
+ setProxy(proxy: CustomEditorsExt): void {
289
+ this.proxy = proxy;
290
+ }
291
+
292
+ dispose(): void {
293
+ if (this.editable) {
294
+ this.undoRedoService.removeElements(this.editorResource);
295
+ }
296
+ this.proxy.$disposeCustomDocument(this.resource, this.viewType);
297
+ }
298
+
299
+ changeContent(): void {
300
+ this.change(() => {
301
+ this.isDirtyFromContentChange = true;
302
+ });
303
+ }
304
+
305
+ pushEdit(editId: number, label: string | undefined): void {
306
+ if (!this.editable) {
307
+ throw new Error('Document is not editable');
308
+ }
309
+
310
+ this.change(() => {
311
+ this.spliceEdits(editId);
312
+ this.currentEditIndex = this.edits.length - 1;
313
+ });
314
+
315
+ this.undoRedoService.pushElement(
316
+ this.editorResource,
317
+ () => this.undo(),
318
+ () => this.redo(),
319
+ );
320
+ }
321
+
322
+ async revert(options?: Saveable.RevertOptions): Promise<void> {
323
+ if (!this.editable) {
324
+ return;
325
+ }
326
+
327
+ if (this.currentEditIndex === this.savePoint && !this.isDirtyFromContentChange) {
328
+ return;
329
+ }
330
+
331
+ const cancellationSource = new CancellationTokenSource();
332
+ this.proxy.$revert(this.resource, this.viewType, cancellationSource.token);
333
+ this.change(() => {
334
+ this.isDirtyFromContentChange = false;
335
+ this.currentEditIndex = this.savePoint;
336
+ this.spliceEdits();
337
+ });
338
+ }
339
+
340
+ async save(options?: SaveOptions): Promise<void> {
341
+ await this.saveCustomEditor(options);
342
+ }
343
+
344
+ async saveCustomEditor(options?: SaveOptions): Promise<void> {
345
+ if (!this.editable) {
346
+ return;
347
+ }
348
+
349
+ const cancelable = new CancellationTokenSource();
350
+ const savePromise = this.proxy.$onSave(this.resource, this.viewType, cancelable.token);
351
+ this.ongoingSave?.cancel();
352
+ this.ongoingSave = cancelable;
353
+
354
+ try {
355
+ await savePromise;
356
+
357
+ if (this.ongoingSave === cancelable) { // Make sure we are still doing the same save
358
+ this.change(() => {
359
+ this.isDirtyFromContentChange = false;
360
+ this.savePoint = this.currentEditIndex;
361
+ });
362
+ }
363
+ } finally {
364
+ if (this.ongoingSave === cancelable) { // Make sure we are still doing the same save
365
+ this.ongoingSave = undefined;
366
+ }
367
+ }
368
+ }
369
+
370
+ async saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void> {
371
+ if (this.editable) {
372
+ const source = new CancellationTokenSource();
373
+ await this.proxy.$onSaveAs(this.resource, this.viewType, targetResource.toComponents(), source.token);
374
+ this.change(() => {
375
+ this.savePoint = this.currentEditIndex;
376
+ });
377
+ } else {
378
+ // Since the editor is readonly, just copy the file over
379
+ await this.fileService.copy(resource, targetResource, { overwrite: false });
380
+ }
381
+ }
382
+
383
+ async undo(): Promise<void> {
384
+ if (!this.editable) {
385
+ return;
386
+ }
387
+
388
+ if (this.currentEditIndex < 0) {
389
+ // nothing to undo
390
+ return;
391
+ }
392
+
393
+ const undoneEdit = this.edits[this.currentEditIndex];
394
+ this.change(() => {
395
+ --this.currentEditIndex;
396
+ });
397
+ await this.proxy.$undo(this.resource, this.viewType, undoneEdit, this.dirty);
398
+ }
399
+
400
+ async redo(): Promise<void> {
401
+ if (!this.editable) {
402
+ return;
403
+ }
404
+
405
+ if (this.currentEditIndex >= this.edits.length - 1) {
406
+ // nothing to redo
407
+ return;
408
+ }
409
+
410
+ const redoneEdit = this.edits[this.currentEditIndex + 1];
411
+ this.change(() => {
412
+ ++this.currentEditIndex;
413
+ });
414
+ await this.proxy.$redo(this.resource, this.viewType, redoneEdit, this.dirty);
415
+ }
416
+
417
+ private spliceEdits(editToInsert?: number): void {
418
+ const start = this.currentEditIndex + 1;
419
+ const toRemove = this.edits.length - this.currentEditIndex;
420
+
421
+ const removedEdits = typeof editToInsert === 'number'
422
+ ? this.edits.splice(start, toRemove, editToInsert)
423
+ : this.edits.splice(start, toRemove);
424
+
425
+ if (removedEdits.length) {
426
+ this.proxy.$disposeEdits(this.resource, this.viewType, removedEdits);
427
+ }
428
+ }
429
+
430
+ private change(makeEdit: () => void): void {
431
+ const wasDirty = this.dirty;
432
+ makeEdit();
433
+
434
+ if (this.dirty !== wasDirty) {
435
+ this.onDirtyChangedEmitter.fire();
436
+ }
437
+ this.onContentChangedEmitter.fire();
438
+ }
439
+
440
+ }
441
+
442
+ // copied from https://github.com/microsoft/vscode/blob/53eac52308c4611000a171cc7bf1214293473c78/src/vs/workbench/contrib/customEditor/common/customTextEditorModel.ts
443
+ export class CustomTextEditorModel implements CustomEditorModel {
444
+ private readonly toDispose = new DisposableCollection();
445
+ private readonly onDirtyChangedEmitter = new Emitter<void>();
446
+ readonly onDirtyChanged = this.onDirtyChangedEmitter.event;
447
+ private readonly onContentChangedEmitter = new Emitter<void>();
448
+ readonly onContentChanged = this.onContentChangedEmitter.event;
449
+
450
+ static async create(
451
+ viewType: string,
452
+ resource: TheiaURI,
453
+ editorModelService: EditorModelService,
454
+ fileService: FileService,
455
+ ): Promise<CustomTextEditorModel> {
456
+ const model = await editorModelService.createModelReference(resource);
457
+ model.object.suppressOpenEditorWhenDirty = true;
458
+ return new CustomTextEditorModel(viewType, resource, model, fileService);
459
+ }
460
+
461
+ constructor(
462
+ readonly viewType: string,
463
+ readonly editorResource: TheiaURI,
464
+ private readonly model: Reference<MonacoEditorModel>,
465
+ private readonly fileService: FileService,
466
+ ) {
467
+ this.toDispose.push(
468
+ this.editorTextModel.onDirtyChanged(e => {
469
+ this.onDirtyChangedEmitter.fire();
470
+ })
471
+ );
472
+ this.toDispose.push(
473
+ this.editorTextModel.onContentChanged(e => {
474
+ this.onContentChangedEmitter.fire();
475
+ })
476
+ );
477
+ this.toDispose.push(this.onDirtyChangedEmitter);
478
+ this.toDispose.push(this.onContentChangedEmitter);
479
+ }
480
+
481
+ dispose(): void {
482
+ this.toDispose.dispose();
483
+ this.model.dispose();
484
+ }
485
+
486
+ get resource(): URI {
487
+ return URI.from(this.editorResource.toComponents());
488
+ }
489
+
490
+ get dirty(): boolean {
491
+ return this.editorTextModel.dirty;
492
+ };
493
+
494
+ get readonly(): boolean {
495
+ return Boolean(this.editorTextModel.readOnly);
496
+ }
497
+
498
+ get editorTextModel(): MonacoEditorModel {
499
+ return this.model.object;
500
+ }
501
+
502
+ revert(options?: Saveable.RevertOptions): Promise<void> {
503
+ return this.editorTextModel.revert(options);
504
+ }
505
+
506
+ save(options?: SaveOptions): Promise<void> {
507
+ return this.saveCustomEditor(options);
508
+ }
509
+
510
+ saveCustomEditor(options?: SaveOptions): Promise<void> {
511
+ return this.editorTextModel.save(options);
512
+ }
513
+
514
+ async saveCustomEditorAs(resource: TheiaURI, targetResource: TheiaURI, options?: SaveOptions): Promise<void> {
515
+ await this.saveCustomEditor(options);
516
+ await this.fileService.copy(resource, targetResource, { overwrite: false });
517
+ }
518
+
519
+ undo(): void {
520
+ this.editorTextModel.undo();
521
+ }
522
+
523
+ redo(): void {
524
+ this.editorTextModel.redo();
525
+ }
526
+ }