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

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 (381) hide show
  1. package/README.md +54 -54
  2. package/lib/common/plugin-api-rpc.d.ts +1 -4
  3. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  4. package/lib/common/plugin-api-rpc.js.map +1 -1
  5. package/lib/hosted/browser/hosted-plugin.js +9 -9
  6. package/lib/main/browser/editors-and-documents-main.d.ts.map +1 -1
  7. package/lib/main/browser/editors-and-documents-main.js +14 -2
  8. package/lib/main/browser/editors-and-documents-main.js.map +1 -1
  9. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.d.ts.map +1 -1
  10. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js +2 -0
  11. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js.map +1 -1
  12. package/lib/main/browser/notebooks/renderers/cell-output-webview.js +86 -86
  13. package/lib/main/browser/plugin-icon-theme-service.js +20 -20
  14. package/lib/main/browser/plugin-shared-style.js +14 -14
  15. package/lib/main/browser/tabs/tabs-main.d.ts +1 -1
  16. package/lib/main/browser/tabs/tabs-main.d.ts.map +1 -1
  17. package/lib/main/browser/tabs/tabs-main.js +1 -1
  18. package/lib/main/browser/tabs/tabs-main.js.map +1 -1
  19. package/lib/main/browser/text-editor-main.d.ts +6 -3
  20. package/lib/main/browser/text-editor-main.d.ts.map +1 -1
  21. package/lib/main/browser/text-editor-main.js +39 -5
  22. package/lib/main/browser/text-editor-main.js.map +1 -1
  23. package/lib/main/browser/view/plugin-view-registry.js +3 -3
  24. package/lib/main/browser/webview/webview-frontend-security-warnings.js +2 -2
  25. package/lib/main/browser/webview/webview-secondary-window-support.js +10 -10
  26. package/lib/main/browser/workspace-main.d.ts +0 -2
  27. package/lib/main/browser/workspace-main.d.ts.map +1 -1
  28. package/lib/main/node/plugin-service.d.ts +1 -1
  29. package/lib/main/node/webview-backend-security-warnings.js +6 -6
  30. package/lib/plugin/languages.d.ts +0 -1
  31. package/lib/plugin/languages.d.ts.map +1 -1
  32. package/lib/plugin/notebook/notebook-kernels.d.ts +0 -2
  33. package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -1
  34. package/lib/plugin/notebook/notebooks.d.ts +1 -0
  35. package/lib/plugin/notebook/notebooks.d.ts.map +1 -1
  36. package/lib/plugin/notebook/notebooks.js +22 -2
  37. package/lib/plugin/notebook/notebooks.js.map +1 -1
  38. package/lib/plugin/scm.d.ts +0 -1
  39. package/lib/plugin/scm.d.ts.map +1 -1
  40. package/lib/plugin/terminal-ext.d.ts +0 -1
  41. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  42. package/lib/plugin/text-editor.d.ts +1 -1
  43. package/lib/plugin/text-editor.d.ts.map +1 -1
  44. package/lib/plugin/text-editor.js.map +1 -1
  45. package/lib/plugin/type-converters.d.ts +0 -1
  46. package/lib/plugin/type-converters.d.ts.map +1 -1
  47. package/lib/plugin/types-impl.d.ts +2 -3
  48. package/lib/plugin/types-impl.d.ts.map +1 -1
  49. package/lib/plugin/workspace.d.ts +0 -4
  50. package/lib/plugin/workspace.d.ts.map +1 -1
  51. package/package.json +28 -28
  52. package/src/common/arrays.ts +70 -70
  53. package/src/common/assert.ts +23 -23
  54. package/src/common/cache.ts +51 -51
  55. package/src/common/character-classifier.ts +73 -73
  56. package/src/common/collections.ts +54 -54
  57. package/src/common/commands.ts +19 -19
  58. package/src/common/connection.ts +137 -137
  59. package/src/common/disposable-util.ts +39 -39
  60. package/src/common/editor-options.ts +74 -74
  61. package/src/common/env.ts +19 -19
  62. package/src/common/errors.ts +63 -63
  63. package/src/common/id-generator.ts +26 -26
  64. package/src/common/index.ts +24 -24
  65. package/src/common/language-pack-service.ts +34 -34
  66. package/src/common/link-computer.ts +354 -354
  67. package/src/common/object-identifier.ts +33 -33
  68. package/src/common/objects.ts +50 -50
  69. package/src/common/paths-util.ts +158 -158
  70. package/src/common/plugin-api-rpc-model.ts +907 -907
  71. package/src/common/plugin-api-rpc.ts +2753 -2752
  72. package/src/common/plugin-ext-api-contribution.ts +115 -115
  73. package/src/common/plugin-identifiers.ts +84 -84
  74. package/src/common/plugin-protocol.ts +1094 -1094
  75. package/src/common/reference-map.ts +38 -38
  76. package/src/common/rpc-protocol.ts +306 -306
  77. package/src/common/semantic-tokens-dto.ts +182 -182
  78. package/src/common/test-types.ts +154 -154
  79. package/src/common/types.ts +129 -129
  80. package/src/common/uint.ts +37 -37
  81. package/src/common/uri-components.ts +81 -81
  82. package/src/hosted/browser/hosted-plugin-watcher.ts +54 -54
  83. package/src/hosted/browser/hosted-plugin.ts +635 -635
  84. package/src/hosted/browser/plugin-worker.ts +52 -52
  85. package/src/hosted/browser/worker/debug-stub.ts +29 -29
  86. package/src/hosted/browser/worker/plugin-manifest-loader.ts +114 -114
  87. package/src/hosted/browser/worker/worker-env-ext.ts +40 -40
  88. package/src/hosted/browser/worker/worker-main.ts +212 -212
  89. package/src/hosted/browser/worker/worker-plugin-module.ts +80 -80
  90. package/src/hosted/common/hosted-plugin.ts +456 -456
  91. package/src/hosted/node/hosted-plugin-cli-contribution.ts +75 -75
  92. package/src/hosted/node/hosted-plugin-deployer-handler.ts +274 -274
  93. package/src/hosted/node/hosted-plugin-localization-service.ts +410 -410
  94. package/src/hosted/node/hosted-plugin-process.ts +248 -248
  95. package/src/hosted/node/hosted-plugin-protocol.ts +49 -49
  96. package/src/hosted/node/hosted-plugin.ts +116 -116
  97. package/src/hosted/node/metadata-scanner.ts +64 -64
  98. package/src/hosted/node/plugin-activation-events.ts +112 -112
  99. package/src/hosted/node/plugin-ext-hosted-backend-module.ts +94 -94
  100. package/src/hosted/node/plugin-host-module.ts +69 -69
  101. package/src/hosted/node/plugin-host-proxy.ts +82 -82
  102. package/src/hosted/node/plugin-host-rpc.ts +377 -377
  103. package/src/hosted/node/plugin-host.ts +110 -110
  104. package/src/hosted/node/plugin-language-pack-service.ts +43 -43
  105. package/src/hosted/node/plugin-manifest-loader.ts +32 -32
  106. package/src/hosted/node/plugin-reader.ts +136 -136
  107. package/src/hosted/node/plugin-service.ts +197 -197
  108. package/src/hosted/node/scanners/backend-init-theia.ts +71 -71
  109. package/src/hosted/node/scanners/file-plugin-uri-factory.ts +32 -32
  110. package/src/hosted/node/scanners/grammars-reader.ts +57 -57
  111. package/src/hosted/node/scanners/plugin-uri-factory.ts +33 -33
  112. package/src/hosted/node/scanners/scanner-theia.ts +963 -963
  113. package/src/hosted/node-electron/plugin-ext-hosted-electron-backend-module.ts +26 -26
  114. package/src/hosted/node-electron/scanner-theia-electron.ts +32 -32
  115. package/src/main/browser/authentication-main.ts +401 -401
  116. package/src/main/browser/clipboard-main.ts +38 -38
  117. package/src/main/browser/command-registry-main.ts +130 -130
  118. package/src/main/browser/commands.ts +104 -104
  119. package/src/main/browser/comments/comment-glyph-widget.ts +66 -66
  120. package/src/main/browser/comments/comment-thread-widget.tsx +696 -696
  121. package/src/main/browser/comments/comments-context-key-service.ts +68 -68
  122. package/src/main/browser/comments/comments-contribution.ts +268 -268
  123. package/src/main/browser/comments/comments-decorator.ts +110 -110
  124. package/src/main/browser/comments/comments-main.ts +482 -482
  125. package/src/main/browser/comments/comments-service.ts +205 -205
  126. package/src/main/browser/custom-editors/custom-editor-opener.tsx +205 -205
  127. package/src/main/browser/custom-editors/custom-editor-service.ts +108 -108
  128. package/src/main/browser/custom-editors/custom-editor-undo-redo-handler.ts +41 -41
  129. package/src/main/browser/custom-editors/custom-editor-widget-factory.ts +44 -44
  130. package/src/main/browser/custom-editors/custom-editor-widget.ts +127 -127
  131. package/src/main/browser/custom-editors/custom-editors-main.ts +526 -526
  132. package/src/main/browser/custom-editors/plugin-custom-editor-registry.ts +126 -126
  133. package/src/main/browser/data-transfer/data-transfer-type-converters.ts +68 -68
  134. package/src/main/browser/debug/debug-main.ts +397 -397
  135. package/src/main/browser/debug/plugin-debug-adapter-contribution.ts +48 -48
  136. package/src/main/browser/debug/plugin-debug-configuration-provider.ts +63 -63
  137. package/src/main/browser/debug/plugin-debug-service.ts +427 -427
  138. package/src/main/browser/debug/plugin-debug-session-contribution-registry.ts +76 -76
  139. package/src/main/browser/debug/plugin-debug-session-factory.ts +115 -115
  140. package/src/main/browser/decorations/decorations-main.ts +146 -146
  141. package/src/main/browser/dialogs/modal-notification.ts +112 -112
  142. package/src/main/browser/dialogs/style/modal-notification.css +123 -123
  143. package/src/main/browser/dialogs-main.ts +185 -185
  144. package/src/main/browser/documents-main.ts +275 -275
  145. package/src/main/browser/editors-and-documents-main.ts +448 -425
  146. package/src/main/browser/env-main.ts +60 -60
  147. package/src/main/browser/file-system-main-impl.ts +267 -267
  148. package/src/main/browser/hierarchy/hierarchy-types-converters.ts +189 -189
  149. package/src/main/browser/keybindings/keybindings-contribution-handler.ts +66 -66
  150. package/src/main/browser/label-service-main.ts +51 -51
  151. package/src/main/browser/languages-main.ts +1439 -1439
  152. package/src/main/browser/localization-main.ts +34 -34
  153. package/src/main/browser/main-context.ts +210 -210
  154. package/src/main/browser/main-file-system-event-service.ts +76 -76
  155. package/src/main/browser/menus/menus-contribution-handler.ts +172 -172
  156. package/src/main/browser/menus/plugin-menu-command-adapter.ts +358 -358
  157. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +118 -118
  158. package/src/main/browser/message-registry-main.ts +43 -43
  159. package/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +252 -249
  160. package/src/main/browser/notebooks/notebook-documents-main.ts +202 -202
  161. package/src/main/browser/notebooks/notebook-dto.ts +131 -131
  162. package/src/main/browser/notebooks/notebook-editors-main.ts +88 -88
  163. package/src/main/browser/notebooks/notebook-kernels-main.ts +339 -339
  164. package/src/main/browser/notebooks/notebook-renderers-main.ts +47 -47
  165. package/src/main/browser/notebooks/notebooks-main.ts +164 -164
  166. package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +452 -452
  167. package/src/main/browser/notebooks/renderers/output-webview-internal.ts +636 -636
  168. package/src/main/browser/notebooks/renderers/webview-communication.ts +107 -107
  169. package/src/main/browser/notification-main.ts +26 -26
  170. package/src/main/browser/output-channel-registry-main.ts +53 -53
  171. package/src/main/browser/plugin-authentication-service.ts +71 -71
  172. package/src/main/browser/plugin-contribution-handler.ts +698 -698
  173. package/src/main/browser/plugin-ext-frontend-module.ts +291 -291
  174. package/src/main/browser/plugin-ext-widget.tsx +132 -132
  175. package/src/main/browser/plugin-frontend-contribution.ts +70 -70
  176. package/src/main/browser/plugin-frontend-view-contribution.ts +38 -38
  177. package/src/main/browser/plugin-icon-service.ts +92 -92
  178. package/src/main/browser/plugin-icon-theme-service.ts +625 -625
  179. package/src/main/browser/plugin-shared-style.ts +154 -154
  180. package/src/main/browser/plugin-storage.ts +55 -55
  181. package/src/main/browser/plugin-terminal-registry.ts +27 -27
  182. package/src/main/browser/preference-registry-main.ts +123 -123
  183. package/src/main/browser/quick-open-main.ts +367 -367
  184. package/src/main/browser/scm-main.ts +472 -472
  185. package/src/main/browser/secrets-main.ts +82 -82
  186. package/src/main/browser/selection-provider-command.ts +45 -45
  187. package/src/main/browser/status-bar-message-registry-main.ts +90 -90
  188. package/src/main/browser/style/comments.css +345 -345
  189. package/src/main/browser/style/index.css +84 -84
  190. package/src/main/browser/style/plugin-sidebar.css +73 -73
  191. package/src/main/browser/style/tree.css +54 -54
  192. package/src/main/browser/style/webview.css +55 -55
  193. package/src/main/browser/tabs/tabs-main.ts +388 -384
  194. package/src/main/browser/tasks-main.ts +268 -268
  195. package/src/main/browser/terminal-main.ts +370 -370
  196. package/src/main/browser/test-main.ts +632 -632
  197. package/src/main/browser/text-editor-main.ts +519 -478
  198. package/src/main/browser/text-editor-model-service.ts +111 -111
  199. package/src/main/browser/text-editors-main.ts +234 -234
  200. package/src/main/browser/theme-icon-override.ts +246 -246
  201. package/src/main/browser/theming-main.ts +42 -42
  202. package/src/main/browser/timeline-main.ts +80 -80
  203. package/src/main/browser/uri-main.ts +72 -72
  204. package/src/main/browser/view/dnd-file-content-store.ts +42 -42
  205. package/src/main/browser/view/plugin-tree-view-node-label-provider.ts +81 -81
  206. package/src/main/browser/view/plugin-view-registry.ts +967 -967
  207. package/src/main/browser/view/plugin-view-widget.ts +221 -221
  208. package/src/main/browser/view/tree-view-decorator-service.ts +51 -51
  209. package/src/main/browser/view/tree-view-widget.tsx +931 -931
  210. package/src/main/browser/view/tree-views-main.ts +205 -205
  211. package/src/main/browser/view/view-context-key-service.ts +64 -64
  212. package/src/main/browser/webview/pre/fake.html +14 -14
  213. package/src/main/browser/webview/pre/host.js +130 -130
  214. package/src/main/browser/webview/pre/index.html +17 -17
  215. package/src/main/browser/webview/pre/main.js +682 -682
  216. package/src/main/browser/webview/pre/service-worker.js +296 -296
  217. package/src/main/browser/webview/webview-context-keys.ts +62 -62
  218. package/src/main/browser/webview/webview-environment.ts +87 -87
  219. package/src/main/browser/webview/webview-frontend-security-warnings.ts +59 -59
  220. package/src/main/browser/webview/webview-preferences.ts +72 -72
  221. package/src/main/browser/webview/webview-resource-cache.ts +88 -88
  222. package/src/main/browser/webview/webview-secondary-window-support.ts +47 -47
  223. package/src/main/browser/webview/webview-theme-data-provider.ts +124 -124
  224. package/src/main/browser/webview/webview.ts +718 -718
  225. package/src/main/browser/webview-views/webview-views-main.ts +154 -154
  226. package/src/main/browser/webview-views/webview-views.ts +43 -43
  227. package/src/main/browser/webviews-main.ts +287 -287
  228. package/src/main/browser/window-activity-tracker.ts +96 -96
  229. package/src/main/browser/window-state-main.ts +85 -85
  230. package/src/main/browser/workspace-main.ts +424 -424
  231. package/src/main/common/basic-message-registry-main.ts +53 -53
  232. package/src/main/common/basic-notification-main.ts +86 -86
  233. package/src/main/common/env-main.ts +44 -44
  234. package/src/main/common/plugin-paths-protocol.ts +26 -26
  235. package/src/main/common/plugin-theia-environment.ts +36 -36
  236. package/src/main/common/webview-protocol.ts +28 -28
  237. package/src/main/electron-browser/plugin-ext-frontend-electron-module.ts +25 -25
  238. package/src/main/electron-browser/webview/electron-webview-widget-factory.ts +59 -59
  239. package/src/main/node/errors.spec.ts +37 -37
  240. package/src/main/node/handlers/plugin-theia-directory-handler.ts +137 -137
  241. package/src/main/node/handlers/plugin-theia-file-handler.ts +66 -66
  242. package/src/main/node/paths/const.ts +21 -21
  243. package/src/main/node/paths/plugin-paths-service.ts +163 -163
  244. package/src/main/node/plugin-cli-contribution.ts +85 -85
  245. package/src/main/node/plugin-deployer-contribution.ts +35 -35
  246. package/src/main/node/plugin-deployer-directory-handler-context-impl.ts +45 -45
  247. package/src/main/node/plugin-deployer-entry-impl.ts +132 -132
  248. package/src/main/node/plugin-deployer-file-handler-context-impl.ts +33 -33
  249. package/src/main/node/plugin-deployer-impl.ts +375 -375
  250. package/src/main/node/plugin-deployer-proxy-entry-impl.ts +96 -96
  251. package/src/main/node/plugin-deployer-resolver-context-impl.ts +55 -55
  252. package/src/main/node/plugin-ext-backend-module.ts +106 -106
  253. package/src/main/node/plugin-github-resolver.ts +139 -139
  254. package/src/main/node/plugin-http-resolver.ts +92 -92
  255. package/src/main/node/plugin-localization-server.ts +42 -42
  256. package/src/main/node/plugin-mgmt-cli-contribution.ts +64 -64
  257. package/src/main/node/plugin-remote-cli-contribution.ts +36 -36
  258. package/src/main/node/plugin-remote-copy-contribution.ts +36 -36
  259. package/src/main/node/plugin-server-handler.ts +69 -69
  260. package/src/main/node/plugin-service.ts +97 -97
  261. package/src/main/node/plugin-theia-deployer-participant.ts +32 -32
  262. package/src/main/node/plugin-uninstallation-manager.ts +74 -74
  263. package/src/main/node/plugins-key-value-storage.spec.ts +110 -110
  264. package/src/main/node/plugins-key-value-storage.ts +161 -161
  265. package/src/main/node/resolvers/local-directory-plugin-deployer-resolver.ts +37 -37
  266. package/src/main/node/resolvers/local-plugin-deployer-resolver.ts +56 -56
  267. package/src/main/node/temp-dir-util.ts +36 -36
  268. package/src/main/node/webview-backend-security-warnings.ts +45 -45
  269. package/src/main/style/status-bar.css +35 -35
  270. package/src/plugin/authentication-ext.ts +140 -140
  271. package/src/plugin/clipboard-ext.ts +43 -43
  272. package/src/plugin/command-registry.ts +219 -219
  273. package/src/plugin/comments.ts +549 -549
  274. package/src/plugin/custom-editors.ts +334 -334
  275. package/src/plugin/debug/debug-ext.ts +549 -549
  276. package/src/plugin/debug/plugin-debug-adapter-creator.ts +50 -50
  277. package/src/plugin/debug/plugin-debug-adapter-session.ts +106 -106
  278. package/src/plugin/debug/plugin-debug-adapter-tracker.ts +85 -85
  279. package/src/plugin/decorations.ts +140 -140
  280. package/src/plugin/dialogs.ts +96 -96
  281. package/src/plugin/document-data.ts +366 -366
  282. package/src/plugin/documents.ts +283 -283
  283. package/src/plugin/editors-and-documents.ts +176 -176
  284. package/src/plugin/env.ts +134 -134
  285. package/src/plugin/file-system-event-service-ext-impl.ts +256 -256
  286. package/src/plugin/file-system-ext-impl.ts +415 -415
  287. package/src/plugin/known-commands.spec.ts +50 -50
  288. package/src/plugin/known-commands.ts +429 -429
  289. package/src/plugin/label-service.ts +36 -36
  290. package/src/plugin/languages/call-hierarchy.ts +124 -124
  291. package/src/plugin/languages/code-action.ts +162 -162
  292. package/src/plugin/languages/color.ts +75 -75
  293. package/src/plugin/languages/completion.ts +183 -183
  294. package/src/plugin/languages/declaration.ts +72 -72
  295. package/src/plugin/languages/definition.ts +73 -73
  296. package/src/plugin/languages/diagnostics.ts +325 -325
  297. package/src/plugin/languages/document-drop-edit.ts +44 -44
  298. package/src/plugin/languages/document-formatting.ts +47 -47
  299. package/src/plugin/languages/document-highlight.ts +61 -61
  300. package/src/plugin/languages/evaluatable-expression.ts +47 -47
  301. package/src/plugin/languages/folding.ts +46 -46
  302. package/src/plugin/languages/hover.ts +58 -58
  303. package/src/plugin/languages/implementation.ts +73 -73
  304. package/src/plugin/languages/inlay-hints.ts +149 -149
  305. package/src/plugin/languages/inline-completion.ts +126 -126
  306. package/src/plugin/languages/inline-values.ts +50 -50
  307. package/src/plugin/languages/lens.ts +102 -102
  308. package/src/plugin/languages/link-provider.ts +81 -81
  309. package/src/plugin/languages/linked-editing-range.ts +48 -48
  310. package/src/plugin/languages/on-type-formatting.ts +50 -50
  311. package/src/plugin/languages/outline.ts +126 -126
  312. package/src/plugin/languages/range-formatting.ts +48 -48
  313. package/src/plugin/languages/reference.ts +58 -58
  314. package/src/plugin/languages/rename.ts +130 -130
  315. package/src/plugin/languages/selection-range.ts +80 -80
  316. package/src/plugin/languages/semantic-highlighting.ts +211 -211
  317. package/src/plugin/languages/signature.ts +82 -82
  318. package/src/plugin/languages/type-definition.ts +73 -73
  319. package/src/plugin/languages/type-hierarchy.ts +117 -117
  320. package/src/plugin/languages/util.ts +26 -26
  321. package/src/plugin/languages/workspace-symbol.ts +66 -66
  322. package/src/plugin/languages-utils.ts +68 -68
  323. package/src/plugin/languages.ts +1022 -1022
  324. package/src/plugin/localization-ext.ts +89 -89
  325. package/src/plugin/markdown-string.ts +115 -115
  326. package/src/plugin/message-registry.ts +70 -70
  327. package/src/plugin/node/debug/debug.spec.ts +98 -98
  328. package/src/plugin/node/debug/plugin-node-debug-adapter-creator.ts +167 -167
  329. package/src/plugin/node/env-node-ext.ts +64 -64
  330. package/src/plugin/node/plugin-container-module.ts +165 -165
  331. package/src/plugin/notebook/notebook-document.ts +446 -446
  332. package/src/plugin/notebook/notebook-documents.ts +58 -58
  333. package/src/plugin/notebook/notebook-editor.ts +116 -116
  334. package/src/plugin/notebook/notebook-editors.ts +71 -71
  335. package/src/plugin/notebook/notebook-kernels.ts +631 -631
  336. package/src/plugin/notebook/notebook-renderers.ts +71 -71
  337. package/src/plugin/notebook/notebooks.ts +470 -449
  338. package/src/plugin/notification.ts +80 -80
  339. package/src/plugin/output-channel/log-output-channel.ts +108 -108
  340. package/src/plugin/output-channel/output-channel-item.ts +73 -73
  341. package/src/plugin/output-channel-registry.ts +52 -52
  342. package/src/plugin/path.spec.ts +40 -40
  343. package/src/plugin/path.ts +68 -68
  344. package/src/plugin/plugin-context.ts +1606 -1606
  345. package/src/plugin/plugin-icon-path.ts +53 -53
  346. package/src/plugin/plugin-manager.ts +508 -508
  347. package/src/plugin/plugin-storage.ts +138 -138
  348. package/src/plugin/preference-registry.spec.ts +288 -288
  349. package/src/plugin/preference-registry.ts +335 -335
  350. package/src/plugin/prefix-sum-computer.ts +218 -218
  351. package/src/plugin/quick-open.ts +735 -735
  352. package/src/plugin/scm.ts +919 -919
  353. package/src/plugin/secrets-ext.ts +104 -104
  354. package/src/plugin/status-bar/status-bar-item.ts +193 -193
  355. package/src/plugin/status-bar-message-registry.ts +103 -103
  356. package/src/plugin/tabs.ts +431 -431
  357. package/src/plugin/tasks/task-provider.ts +57 -57
  358. package/src/plugin/tasks/tasks.ts +252 -252
  359. package/src/plugin/telemetry-ext.ts +298 -298
  360. package/src/plugin/terminal-ext.ts +569 -569
  361. package/src/plugin/test-item.ts +174 -174
  362. package/src/plugin/tests.ts +545 -545
  363. package/src/plugin/text-editor.ts +581 -581
  364. package/src/plugin/text-editors.ts +157 -157
  365. package/src/plugin/theming.ts +73 -73
  366. package/src/plugin/timeline.ts +186 -186
  367. package/src/plugin/tree/tree-views.ts +682 -682
  368. package/src/plugin/type-converters.spec.ts +476 -476
  369. package/src/plugin/type-converters.ts +1768 -1768
  370. package/src/plugin/types-impl.spec.ts +85 -85
  371. package/src/plugin/types-impl.ts +4011 -4011
  372. package/src/plugin/uri-ext.ts +60 -60
  373. package/src/plugin/webview-views.ts +228 -228
  374. package/src/plugin/webviews.ts +468 -468
  375. package/src/plugin/window-state.ts +75 -75
  376. package/src/plugin/word-helper.ts +162 -162
  377. package/src/plugin/workspace.ts +505 -505
  378. package/src/plugin-ext-backend-electron-module.ts +24 -24
  379. package/src/plugin-ext-backend-module.ts +24 -24
  380. package/src/plugin-ext-frontend-electron-module.ts +19 -19
  381. package/src/plugin-ext-frontend-module.ts +19 -19
@@ -1,967 +1,967 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Red Hat, Inc. 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
- import { injectable, inject, postConstruct, optional } from '@theia/core/shared/inversify';
18
- import {
19
- ApplicationShell, ViewContainer as ViewContainerWidget, WidgetManager, QuickViewService,
20
- ViewContainerIdentifier, ViewContainerTitleOptions, Widget, FrontendApplicationContribution,
21
- StatefulWidget, CommonMenus, TreeViewWelcomeWidget, ViewContainerPart, BaseWidget,
22
- } from '@theia/core/lib/browser';
23
- import { ViewContainer, View, ViewWelcome, PluginViewType } from '../../../common';
24
- import { PluginSharedStyle } from '../plugin-shared-style';
25
- import { DebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
26
- import { PluginViewWidget, PluginViewWidgetIdentifier } from './plugin-view-widget';
27
- import { SCM_VIEW_CONTAINER_ID, ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
28
- import { EXPLORER_VIEW_CONTAINER_ID, FileNavigatorWidget, FILE_NAVIGATOR_ID } from '@theia/navigator/lib/browser';
29
- import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
30
- import { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
31
- import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
32
- import { CommandRegistry } from '@theia/core/lib/common/command';
33
- import { MenuModelRegistry } from '@theia/core/lib/common/menu';
34
- import { Emitter, Event } from '@theia/core/lib/common/event';
35
- import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
36
- import { ViewContextKeyService } from './view-context-key-service';
37
- import { PROBLEMS_WIDGET_ID } from '@theia/markers/lib/browser/problem/problem-widget';
38
- import { OutputWidget } from '@theia/output/lib/browser/output-widget';
39
- import { DebugConsoleContribution } from '@theia/debug/lib/browser/console/debug-console-contribution';
40
- import { TreeViewWidget } from './tree-view-widget';
41
- import { SEARCH_VIEW_CONTAINER_ID } from '@theia/search-in-workspace/lib/browser/search-in-workspace-factory';
42
- import { TEST_VIEW_CONTAINER_ID } from '@theia/test/lib/browser/view/test-view-contribution';
43
- import { WebviewView, WebviewViewResolver } from '../webview-views/webview-views';
44
- import { WebviewWidget, WebviewWidgetIdentifier } from '../webview/webview';
45
- import { CancellationToken } from '@theia/core/lib/common/cancellation';
46
- import { generateUuid } from '@theia/core/lib/common/uuid';
47
- import { nls } from '@theia/core';
48
- import { TheiaDockPanel } from '@theia/core/lib/browser/shell/theia-dock-panel';
49
- import { Deferred } from '@theia/core/lib/common/promise-util';
50
- import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/base/common/themables';
51
-
52
- export const PLUGIN_VIEW_FACTORY_ID = 'plugin-view';
53
- export const PLUGIN_VIEW_CONTAINER_FACTORY_ID = 'plugin-view-container';
54
- export const PLUGIN_VIEW_DATA_FACTORY_ID = 'plugin-view-data';
55
-
56
- export type ViewDataProvider = (params: { state?: object, viewInfo: View }) => Promise<TreeViewWidget>;
57
-
58
- export interface ViewContainerInfo {
59
- id: string
60
- location: string
61
- options: ViewContainerTitleOptions
62
- onViewAdded: () => void
63
- }
64
-
65
- @injectable()
66
- export class PluginViewRegistry implements FrontendApplicationContribution {
67
-
68
- @inject(ApplicationShell)
69
- protected readonly shell: ApplicationShell;
70
-
71
- @inject(PluginSharedStyle)
72
- protected readonly style: PluginSharedStyle;
73
-
74
- @inject(WidgetManager)
75
- protected readonly widgetManager: WidgetManager;
76
-
77
- @inject(ScmContribution)
78
- protected readonly scm: ScmContribution;
79
-
80
- @inject(FileNavigatorContribution)
81
- protected readonly explorer: FileNavigatorContribution;
82
-
83
- @inject(DebugFrontendApplicationContribution)
84
- protected readonly debug: DebugFrontendApplicationContribution;
85
-
86
- @inject(CommandRegistry)
87
- protected readonly commands: CommandRegistry;
88
-
89
- @inject(MenuModelRegistry)
90
- protected readonly menus: MenuModelRegistry;
91
-
92
- @inject(QuickViewService) @optional()
93
- protected readonly quickView: QuickViewService;
94
-
95
- @inject(ContextKeyService)
96
- protected readonly contextKeyService: ContextKeyService;
97
-
98
- @inject(ViewContextKeyService)
99
- protected readonly viewContextKeys: ViewContextKeyService;
100
-
101
- protected readonly onDidExpandViewEmitter = new Emitter<string>();
102
- readonly onDidExpandView = this.onDidExpandViewEmitter.event;
103
-
104
- private readonly views = new Map<string, [string, View]>();
105
- private readonly viewsWelcome = new Map<string, ViewWelcome[]>();
106
- private readonly viewContainers = new Map<string, ViewContainerInfo>();
107
- private readonly containerViews = new Map<string, string[]>();
108
- private readonly viewClauseContexts = new Map<string, Set<string> | undefined>();
109
-
110
- private readonly viewDataProviders = new Map<string, ViewDataProvider>();
111
- private readonly viewDataState = new Map<string, object>();
112
-
113
- private readonly webviewViewResolvers = new Map<string, WebviewViewResolver>();
114
- protected readonly onNewResolverRegisteredEmitter = new Emitter<{ readonly viewType: string }>();
115
- readonly onNewResolverRegistered = this.onNewResolverRegisteredEmitter.event;
116
-
117
- private readonly webviewViewRevivals = new Map<string, { readonly webview: WebviewView; readonly revival: Deferred<void> }>();
118
-
119
- private nextViewContainerId = 0;
120
-
121
- private static readonly BUILTIN_VIEW_CONTAINERS = new Set<string>([
122
- 'explorer',
123
- 'scm',
124
- 'search',
125
- 'test',
126
- 'debug'
127
- ]);
128
-
129
- private static readonly ID_MAPPINGS: Map<string, string> = new Map([
130
- // VS Code Viewlets
131
- [EXPLORER_VIEW_CONTAINER_ID, 'workbench.view.explorer'],
132
- [SCM_VIEW_CONTAINER_ID, 'workbench.view.scm'],
133
- [SEARCH_VIEW_CONTAINER_ID, 'workbench.view.search'],
134
- [DebugWidget.ID, 'workbench.view.debug'],
135
- ['vsx-extensions-view-container', 'workbench.view.extensions'], // cannot use the id from 'vsx-registry' package because of circular dependency
136
- [PROBLEMS_WIDGET_ID, 'workbench.panel.markers'],
137
- [TEST_VIEW_CONTAINER_ID, 'workbench.view.testing'],
138
- [OutputWidget.ID, 'workbench.panel.output'],
139
- [DebugConsoleContribution.options.id, 'workbench.panel.repl'],
140
- // Theia does not have a single terminal widget, but instead each terminal gets its own widget. Therefore "the terminal widget is active" doesn't make sense in Theia
141
- // [TERMINAL_WIDGET_FACTORY_ID, 'workbench.panel.terminal'],
142
- // [?? , 'workbench.panel.comments'] not sure what this mean: we don't show comments in sidebars nor the bottom
143
- ]);
144
-
145
- @postConstruct()
146
- protected init(): void {
147
-
148
- // TODO workbench.panel.comments - Theia does not have a proper comments view yet
149
-
150
- this.updateFocusedView();
151
- this.shell.onDidChangeActiveWidget(() => this.updateFocusedView());
152
-
153
- this.widgetManager.onWillCreateWidget(({ factoryId, widget, waitUntil }) => {
154
- if (factoryId === EXPLORER_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
155
- waitUntil(this.prepareViewContainer('explorer', widget));
156
- }
157
- if (factoryId === SCM_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
158
- waitUntil(this.prepareViewContainer('scm', widget));
159
- }
160
- if (factoryId === SEARCH_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
161
- waitUntil(this.prepareViewContainer('search', widget));
162
- }
163
- if (factoryId === TEST_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
164
- waitUntil(this.prepareViewContainer('test', widget));
165
- }
166
- if (factoryId === DebugWidget.ID && widget instanceof DebugWidget) {
167
- const viewContainer = widget['sessionWidget']['viewContainer'];
168
- waitUntil(this.prepareViewContainer('debug', viewContainer));
169
- }
170
- if (factoryId === PLUGIN_VIEW_CONTAINER_FACTORY_ID && widget instanceof ViewContainerWidget) {
171
- waitUntil(this.prepareViewContainer(this.toViewContainerId(widget.options), widget));
172
- }
173
- if (factoryId === PLUGIN_VIEW_FACTORY_ID && widget instanceof PluginViewWidget) {
174
- waitUntil(this.prepareView(widget));
175
- }
176
- });
177
- this.widgetManager.onDidCreateWidget(event => {
178
- if (event.widget instanceof FileNavigatorWidget) {
179
- const disposable = new DisposableCollection();
180
- disposable.push(this.registerViewWelcome({
181
- view: 'explorer',
182
- content: nls.localizeByDefault(
183
- 'You have not yet opened a folder.\n{0}',
184
- `[${nls.localizeByDefault('Open Folder')}](command:workbench.action.files.openFolder)`
185
- ),
186
- order: 0
187
- }));
188
- disposable.push(event.widget.onDidDispose(() => disposable.dispose()));
189
- }
190
- });
191
- this.contextKeyService.onDidChange(e => {
192
- for (const [, view] of this.views.values()) {
193
- const clauseContext = this.viewClauseContexts.get(view.id);
194
- if (clauseContext && e.affects(clauseContext)) {
195
- this.updateViewVisibility(view.id);
196
- }
197
- }
198
- for (const [viewId, viewWelcomes] of this.viewsWelcome) {
199
- for (const [index] of viewWelcomes.entries()) {
200
- const viewWelcomeId = this.toViewWelcomeId(index, viewId);
201
- const clauseContext = this.viewClauseContexts.get(viewWelcomeId);
202
- if (clauseContext && e.affects(clauseContext)) {
203
- this.updateViewWelcomeVisibility(viewId);
204
- }
205
- }
206
- }
207
- });
208
-
209
- const hookDockPanelKey = (panel: TheiaDockPanel, key: ContextKey<string>) => {
210
- let toDisposeOnActivate = new DisposableCollection();
211
- panel.onDidChangeCurrent(title => {
212
- toDisposeOnActivate.dispose();
213
- toDisposeOnActivate = new DisposableCollection();
214
- if (title && title.owner instanceof BaseWidget) {
215
- const widget = title.owner;
216
- let value = PluginViewRegistry.ID_MAPPINGS.get(widget.id);
217
- if (!value) {
218
- if (widget.id.startsWith(PLUGIN_VIEW_CONTAINER_FACTORY_ID)) {
219
- value = this.toViewContainerId({ id: widget.id });
220
- }
221
- }
222
- const setKey = () => {
223
- if (widget.isVisible && value) {
224
- key.set(value);
225
- } else {
226
- key.reset();
227
- }
228
- };
229
- toDisposeOnActivate.push(widget.onDidChangeVisibility(() => {
230
- setKey();
231
- }));
232
- setKey();
233
-
234
- }
235
- });
236
- };
237
-
238
- hookDockPanelKey(this.shell.leftPanelHandler.dockPanel, this.viewContextKeys.activeViewlet);
239
- hookDockPanelKey(this.shell.rightPanelHandler.dockPanel, this.viewContextKeys.activeAuxiliary);
240
- hookDockPanelKey(this.shell.bottomPanel, this.viewContextKeys.activePanel);
241
- }
242
-
243
- protected async updateViewWelcomeVisibility(viewId: string): Promise<void> {
244
- const widget = await this.getTreeViewWelcomeWidget(viewId);
245
- if (widget) {
246
- widget.handleWelcomeContextChange();
247
- }
248
- }
249
-
250
- protected async updateViewVisibility(viewId: string): Promise<void> {
251
- const widget = await this.getView(viewId);
252
- if (!widget) {
253
- if (this.isViewVisible(viewId)) {
254
- await this.openView(viewId);
255
- }
256
- return;
257
- }
258
- const viewInfo = this.views.get(viewId);
259
- if (!viewInfo) {
260
- return;
261
- }
262
- const [viewContainerId] = viewInfo;
263
- const viewContainer = await this.getPluginViewContainer(viewContainerId);
264
- if (!viewContainer) {
265
- return;
266
- }
267
- const part = viewContainer.getPartFor(widget);
268
- if (!part) {
269
- return;
270
- }
271
- widget.updateViewVisibility(() =>
272
- part.setHidden(!this.isViewVisible(viewId))
273
- );
274
- }
275
-
276
- protected isViewVisible(viewId: string): boolean {
277
- const viewInfo = this.views.get(viewId);
278
- if (!viewInfo) {
279
- return false;
280
- }
281
- const [, view] = viewInfo;
282
- return view.when === undefined || view.when === 'true' || this.contextKeyService.match(view.when);
283
- }
284
-
285
- registerViewContainer(location: string, viewContainer: ViewContainer): Disposable {
286
- const containerId = `workbench.view.extension.${viewContainer.id}`;
287
- if (this.viewContainers.has(containerId)) {
288
- console.warn('view container such id already registered: ', JSON.stringify(viewContainer));
289
- return Disposable.NULL;
290
- }
291
- const toDispose = new DisposableCollection();
292
- const containerClass = 'theia-plugin-view-container';
293
- let themeIconClass = '';
294
- const iconClass = 'plugin-view-container-icon-' + this.nextViewContainerId++; // having dots in class would not work for css, so we need to generate an id.
295
-
296
- if (viewContainer.themeIcon) {
297
- const icon = ThemeIcon.fromString(viewContainer.themeIcon);
298
- if (icon) {
299
- themeIconClass = ThemeIcon.asClassName(icon) ?? '';
300
- }
301
- }
302
-
303
- if (!themeIconClass) {
304
- const iconUrl = PluginSharedStyle.toExternalIconUrl(viewContainer.iconUrl);
305
- toDispose.push(this.style.insertRule('.' + containerClass + '.' + iconClass, () => `
306
- mask: url('${iconUrl}') no-repeat 50% 50%;
307
- -webkit-mask: url('${iconUrl}') no-repeat 50% 50%;
308
- `));
309
- }
310
-
311
- toDispose.push(this.doRegisterViewContainer(containerId, location, {
312
- label: viewContainer.title,
313
- // The container class automatically sets a mask; if we're using a theme icon, we don't want one.
314
- iconClass: (themeIconClass || containerClass) + ' ' + iconClass,
315
- closeable: true
316
- }));
317
- return toDispose;
318
- }
319
-
320
- protected async toggleViewContainer(id: string): Promise<void> {
321
- let widget = await this.getPluginViewContainer(id);
322
- if (widget && widget.isAttached) {
323
- widget.dispose();
324
- } else {
325
- widget = await this.openViewContainer(id);
326
- if (widget) {
327
- this.shell.activateWidget(widget.id);
328
- }
329
- }
330
- }
331
-
332
- protected doRegisterViewContainer(id: string, location: string, options: ViewContainerTitleOptions): Disposable {
333
- const toDispose = new DisposableCollection();
334
- toDispose.push(Disposable.create(() => this.viewContainers.delete(id)));
335
- const toggleCommandId = `plugin.view-container.${id}.toggle`;
336
- // Some plugins may register empty view containers.
337
- // We should not register commands for them immediately, as that leads to bad UX.
338
- // Instead, we register commands the first time we add a view to them.
339
- let activate = () => {
340
- toDispose.push(this.commands.registerCommand({
341
- id: toggleCommandId,
342
- category: nls.localizeByDefault('View'),
343
- label: nls.localizeByDefault('Toggle {0}', options.label)
344
- }, {
345
- execute: () => this.toggleViewContainer(id)
346
- }));
347
- toDispose.push(this.menus.registerMenuAction(CommonMenus.VIEW_VIEWS, {
348
- commandId: toggleCommandId,
349
- label: options.label
350
- }));
351
- toDispose.push(this.quickView?.registerItem({
352
- label: options.label,
353
- open: async () => {
354
- const widget = await this.openViewContainer(id);
355
- if (widget) {
356
- this.shell.activateWidget(widget.id);
357
- }
358
- }
359
- }));
360
- toDispose.push(Disposable.create(async () => {
361
- const widget = await this.getPluginViewContainer(id);
362
- if (widget) {
363
- widget.dispose();
364
- }
365
- }));
366
- // Ignore every subsequent activation call
367
- activate = () => { };
368
- };
369
- this.viewContainers.set(id, {
370
- id,
371
- location,
372
- options,
373
- onViewAdded: () => activate()
374
- });
375
- return toDispose;
376
- }
377
-
378
- getContainerViews(viewContainerId: string): string[] {
379
- return this.containerViews.get(viewContainerId) || [];
380
- }
381
-
382
- registerView(viewContainerId: string, view: View): Disposable {
383
- if (!PluginViewRegistry.BUILTIN_VIEW_CONTAINERS.has(viewContainerId)) {
384
- // if it's not a built-in view container, it must be a contributed view container, see https://github.com/eclipse-theia/theia/issues/13249
385
- viewContainerId = `workbench.view.extension.${viewContainerId}`;
386
- }
387
- if (this.views.has(view.id)) {
388
- console.warn('view with such id already registered: ', JSON.stringify(view));
389
- return Disposable.NULL;
390
- }
391
- const toDispose = new DisposableCollection();
392
-
393
- view.when = view.when?.trim();
394
- this.views.set(view.id, [viewContainerId, view]);
395
- toDispose.push(Disposable.create(() => this.views.delete(view.id)));
396
-
397
- const containerInfo = this.viewContainers.get(viewContainerId);
398
- if (containerInfo) {
399
- containerInfo.onViewAdded();
400
- }
401
-
402
- const containerViews = this.getContainerViews(viewContainerId);
403
- containerViews.push(view.id);
404
- this.containerViews.set(viewContainerId, containerViews);
405
- toDispose.push(Disposable.create(() => {
406
- const index = containerViews.indexOf(view.id);
407
- if (index !== -1) {
408
- containerViews.splice(index, 1);
409
- }
410
- }));
411
-
412
- if (view.when && view.when !== 'false' && view.when !== 'true') {
413
- const keys = this.contextKeyService.parseKeys(view.when);
414
- if (keys) {
415
- this.viewClauseContexts.set(view.id, keys);
416
- toDispose.push(Disposable.create(() => this.viewClauseContexts.delete(view.id)));
417
- }
418
- }
419
- toDispose.push(this.quickView?.registerItem({
420
- label: view.name,
421
- when: view.when,
422
- open: () => this.openView(view.id, { activate: true })
423
- }));
424
- toDispose.push(this.commands.registerCommand({ id: `${view.id}.focus` }, {
425
- execute: async () => { await this.openView(view.id, { activate: true }); }
426
- }));
427
- return toDispose;
428
- }
429
-
430
- async resolveWebviewView(viewId: string, webview: WebviewView, cancellation: CancellationToken): Promise<void> {
431
- const resolver = this.webviewViewResolvers.get(viewId);
432
- if (resolver) {
433
- return resolver.resolve(webview, cancellation);
434
- }
435
- const pendingRevival = this.webviewViewRevivals.get(viewId);
436
- if (pendingRevival) {
437
- return pendingRevival.revival.promise;
438
- }
439
- const pending = new Deferred<void>();
440
- this.webviewViewRevivals.set(viewId, { webview, revival: pending });
441
- return pending.promise;
442
- }
443
-
444
- async registerWebviewView(viewId: string, resolver: WebviewViewResolver): Promise<Disposable> {
445
- if (this.webviewViewResolvers.has(viewId)) {
446
- throw new Error(`View resolver already registered for ${viewId}`);
447
- }
448
- this.webviewViewResolvers.set(viewId, resolver);
449
- this.onNewResolverRegisteredEmitter.fire({ viewType: viewId });
450
-
451
- const toDispose = new DisposableCollection(Disposable.create(() => this.webviewViewResolvers.delete(viewId)));
452
- this.initView(viewId, toDispose);
453
-
454
- const pendingRevival = this.webviewViewRevivals.get(viewId);
455
- if (pendingRevival) {
456
- resolver.resolve(pendingRevival.webview, CancellationToken.None).then(() => {
457
- this.webviewViewRevivals.delete(viewId);
458
- pendingRevival.revival.resolve();
459
- });
460
- }
461
-
462
- return toDispose;
463
- }
464
-
465
- protected async createNewWebviewView(viewId: string): Promise<WebviewView> {
466
- const webview = await this.widgetManager.getOrCreateWidget<WebviewWidget>(
467
- WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{
468
- id: generateUuid(),
469
- viewId,
470
- });
471
- webview.setContentOptions({ allowScripts: true });
472
-
473
- let _description: string | undefined;
474
- let _resolved = false;
475
- let _pendingResolution: Promise<void> | undefined;
476
-
477
- const webviewView: WebviewView = {
478
- webview,
479
-
480
- get onDidChangeVisibility(): Event<boolean> { return webview.onDidChangeVisibility; },
481
- get onDidDispose(): Event<void> { return webview.onDidDispose; },
482
-
483
- get title(): string | undefined { return webview.title.label; },
484
- set title(value: string | undefined) { webview.title.label = value || ''; },
485
-
486
- get description(): string | undefined { return _description; },
487
- set description(value: string | undefined) { _description = value; },
488
-
489
- get badge(): number | undefined { return webview.badge; },
490
- set badge(badge: number | undefined) { webview.badge = badge; },
491
-
492
- get badgeTooltip(): string | undefined { return webview.badgeTooltip; },
493
- set badgeTooltip(badgeTooltip: string | undefined) { webview.badgeTooltip = badgeTooltip; },
494
- onDidChangeBadge: webview.onDidChangeBadge,
495
- onDidChangeBadgeTooltip: webview.onDidChangeBadgeTooltip,
496
-
497
- dispose: () => {
498
- _resolved = false;
499
- webview.dispose();
500
- toDispose.dispose();
501
- },
502
- resolve: async () => {
503
- if (_resolved) {
504
- return;
505
- }
506
- if (_pendingResolution) {
507
- return _pendingResolution;
508
- }
509
- _pendingResolution = this.resolveWebviewView(viewId, webviewView, CancellationToken.None).then(() => {
510
- _resolved = true;
511
- _pendingResolution = undefined;
512
- });
513
- return _pendingResolution;
514
- },
515
- show: webview.show
516
- };
517
-
518
- const toDispose = this.onNewResolverRegistered(resolver => {
519
- if (resolver.viewType === viewId) {
520
- // Potentially re-activate if we have a new resolver
521
- webviewView.resolve();
522
- }
523
- });
524
-
525
- webviewView.resolve();
526
- return webviewView;
527
- }
528
-
529
- registerViewWelcome(viewWelcome: ViewWelcome): Disposable {
530
- const toDispose = new DisposableCollection();
531
-
532
- const viewsWelcome = this.viewsWelcome.get(viewWelcome.view) || [];
533
- if (viewsWelcome.some(e => e.content === viewWelcome.content)) {
534
- return toDispose;
535
- }
536
- viewsWelcome.push(viewWelcome);
537
- this.viewsWelcome.set(viewWelcome.view, viewsWelcome);
538
- this.handleViewWelcomeChange(viewWelcome.view);
539
- toDispose.push(Disposable.create(() => {
540
- const index = viewsWelcome.indexOf(viewWelcome);
541
- if (index !== -1) {
542
- viewsWelcome.splice(index, 1);
543
- }
544
- this.handleViewWelcomeChange(viewWelcome.view);
545
- }));
546
-
547
- if (viewWelcome.when) {
548
- const index = viewsWelcome.indexOf(viewWelcome);
549
- const viewWelcomeId = this.toViewWelcomeId(index, viewWelcome.view);
550
- this.viewClauseContexts.set(viewWelcomeId, this.contextKeyService.parseKeys(viewWelcome.when));
551
- toDispose.push(Disposable.create(() => this.viewClauseContexts.delete(viewWelcomeId)));
552
- }
553
- return toDispose;
554
- }
555
-
556
- async handleViewWelcomeChange(viewId: string): Promise<void> {
557
- const widget = await this.getTreeViewWelcomeWidget(viewId);
558
- if (widget) {
559
- widget.handleViewWelcomeContentChange(this.getViewWelcomes(viewId));
560
- }
561
- }
562
-
563
- protected async getTreeViewWelcomeWidget(viewId: string): Promise<TreeViewWelcomeWidget | undefined> {
564
- switch (viewId) {
565
- case 'explorer':
566
- return this.widgetManager.getWidget<TreeViewWelcomeWidget>(FILE_NAVIGATOR_ID);
567
- default:
568
- return this.widgetManager.getWidget<TreeViewWelcomeWidget>(PLUGIN_VIEW_DATA_FACTORY_ID, { id: viewId });
569
- }
570
- }
571
-
572
- getViewWelcomes(viewId: string): ViewWelcome[] {
573
- return this.viewsWelcome.get(viewId) || [];
574
- }
575
-
576
- async getView(viewId: string): Promise<PluginViewWidget | undefined> {
577
- if (!this.views.has(viewId)) {
578
- return undefined;
579
- }
580
- return this.widgetManager.getWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, this.toPluginViewWidgetIdentifier(viewId));
581
- }
582
-
583
- async openView(viewId: string, options?: { activate?: boolean, reveal?: boolean }): Promise<PluginViewWidget | undefined> {
584
- const view = await this.doOpenView(viewId);
585
- if (view && options) {
586
- if (options.activate === true) {
587
- await this.shell.activateWidget(view.id);
588
- } else if (options.reveal === true) {
589
- await this.shell.revealWidget(view.id);
590
- }
591
- }
592
- return view;
593
- }
594
- protected async doOpenView(viewId: string): Promise<PluginViewWidget | undefined> {
595
- const widget = await this.getView(viewId);
596
- if (widget) {
597
- return widget;
598
- }
599
- const data = this.views.get(viewId);
600
- if (!data) {
601
- return undefined;
602
- }
603
- const [containerId] = data;
604
- await this.openViewContainer(containerId);
605
- return this.getView(viewId);
606
- }
607
-
608
- protected async prepareView(widget: PluginViewWidget): Promise<void> {
609
- const data = this.views.get(widget.options.viewId);
610
- if (!data) {
611
- return;
612
- }
613
- const [, view] = data;
614
- if (!widget.title.label) {
615
- widget.title.label = view.name;
616
- }
617
- const currentDataWidget = widget.widgets[0];
618
- const webviewId = currentDataWidget instanceof WebviewWidget ? currentDataWidget.identifier?.id : undefined;
619
- const viewDataWidget = await this.createViewDataWidget(view.id, webviewId);
620
- if (widget.isDisposed) {
621
- viewDataWidget?.dispose();
622
- return;
623
- }
624
- if (currentDataWidget !== viewDataWidget) {
625
- if (currentDataWidget) {
626
- currentDataWidget.dispose();
627
- }
628
- if (viewDataWidget) {
629
- widget.addWidget(viewDataWidget);
630
- }
631
- }
632
- }
633
-
634
- protected getOrCreateViewContainerWidget(containerId: string): Promise<ViewContainerWidget> {
635
- const identifier = this.toViewContainerIdentifier(containerId);
636
- return this.widgetManager.getOrCreateWidget<ViewContainerWidget>(PLUGIN_VIEW_CONTAINER_FACTORY_ID, identifier);
637
- }
638
-
639
- async openViewContainer(containerId: string): Promise<ViewContainerWidget | undefined> {
640
- if (containerId === 'explorer') {
641
- const widget = await this.explorer.openView();
642
- if (widget.parent instanceof ViewContainerWidget) {
643
- return widget.parent;
644
- }
645
- return undefined;
646
- }
647
- if (containerId === 'scm') {
648
- const widget = await this.scm.openView();
649
- if (widget.parent instanceof ViewContainerWidget) {
650
- return widget.parent;
651
- }
652
- return undefined;
653
- }
654
- if (containerId === 'debug') {
655
- const widget = await this.debug.openView();
656
- return widget['sessionWidget']['viewContainer'];
657
- }
658
- const data = this.viewContainers.get(containerId);
659
- if (!data) {
660
- return undefined;
661
- }
662
- const { location } = data;
663
- const containerWidget = await this.getOrCreateViewContainerWidget(containerId);
664
- if (!containerWidget.isAttached) {
665
- await this.shell.addWidget(containerWidget, {
666
- area: ApplicationShell.isSideArea(location) ? location : 'left',
667
- rank: Number.MAX_SAFE_INTEGER
668
- });
669
- }
670
- return containerWidget;
671
- }
672
-
673
- protected async prepareViewContainer(viewContainerId: string, containerWidget: ViewContainerWidget): Promise<void> {
674
- const data = this.viewContainers.get(viewContainerId);
675
- if (data) {
676
- const { options } = data;
677
- containerWidget.setTitleOptions(options);
678
- }
679
- for (const viewId of this.getContainerViews(viewContainerId)) {
680
- const identifier = this.toPluginViewWidgetIdentifier(viewId);
681
- // Keep existing widget in its current container and reregister its part to the plugin view widget events.
682
- const existingWidget = this.widgetManager.tryGetWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, identifier);
683
- if (existingWidget && existingWidget.currentViewContainerId) {
684
- const currentContainer = await this.getPluginViewContainer(existingWidget.currentViewContainerId);
685
- if (currentContainer && this.registerWidgetPartEvents(existingWidget, currentContainer)) {
686
- continue;
687
- }
688
- }
689
- const widget = await this.widgetManager.getOrCreateWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, identifier);
690
- if (containerWidget.getTrackableWidgets().indexOf(widget) === -1) {
691
- containerWidget.addWidget(widget, {
692
- initiallyCollapsed: !!containerWidget.getParts().length,
693
- initiallyHidden: !this.isViewVisible(viewId)
694
- });
695
- }
696
- this.registerWidgetPartEvents(widget, containerWidget);
697
- }
698
- }
699
-
700
- protected registerWidgetPartEvents(widget: PluginViewWidget, containerWidget: ViewContainerWidget): ViewContainerPart | undefined {
701
- const part = containerWidget.getPartFor(widget);
702
- if (part) {
703
-
704
- widget.currentViewContainerId = this.getViewContainerId(containerWidget);
705
- part.onDidMove(event => { widget.currentViewContainerId = this.getViewContainerId(event); });
706
-
707
- // if a view is explicitly hidden then suppress updating visibility based on `when` closure
708
- part.onDidChangeVisibility(() => widget.suppressUpdateViewVisibility = part.isHidden);
709
-
710
- const tryFireOnDidExpandView = () => {
711
- if (widget.widgets.length === 0) {
712
- if (!part.collapsed && part.isVisible) {
713
- const viewId = this.toViewId(widget.options);
714
- this.onDidExpandViewEmitter.fire(viewId);
715
- }
716
- } else {
717
- toFire.dispose();
718
- }
719
- };
720
- const toFire = new DisposableCollection(
721
- part.onCollapsed(tryFireOnDidExpandView),
722
- part.onDidChangeVisibility(tryFireOnDidExpandView)
723
- );
724
-
725
- tryFireOnDidExpandView();
726
- return part;
727
- }
728
- };
729
-
730
- protected getViewContainerId(container: ViewContainerWidget): string | undefined {
731
- const description = this.widgetManager.getDescription(container);
732
- switch (description?.factoryId) {
733
- case EXPLORER_VIEW_CONTAINER_ID: return 'explorer';
734
- case SCM_VIEW_CONTAINER_ID: return 'scm';
735
- case SEARCH_VIEW_CONTAINER_ID: return 'search';
736
- case TEST_VIEW_CONTAINER_ID: return 'test';
737
- case undefined: return container.parent?.parent instanceof DebugWidget ? 'debug' : container.id;
738
- case PLUGIN_VIEW_CONTAINER_FACTORY_ID: return this.toViewContainerId(description.options);
739
- default: return container.id;
740
- }
741
- }
742
-
743
- protected async getPluginViewContainer(viewContainerId: string): Promise<ViewContainerWidget | undefined> {
744
- if (viewContainerId === 'explorer') {
745
- return this.widgetManager.getWidget<ViewContainerWidget>(EXPLORER_VIEW_CONTAINER_ID);
746
- }
747
- if (viewContainerId === 'scm') {
748
- return this.widgetManager.getWidget<ViewContainerWidget>(SCM_VIEW_CONTAINER_ID);
749
- }
750
- if (viewContainerId === 'search') {
751
- return this.widgetManager.getWidget<ViewContainerWidget>(SEARCH_VIEW_CONTAINER_ID);
752
- }
753
- if (viewContainerId === 'test') {
754
- return this.widgetManager.getWidget<ViewContainerWidget>(TEST_VIEW_CONTAINER_ID);
755
- }
756
- if (viewContainerId === 'debug') {
757
- const debug = await this.widgetManager.getWidget(DebugWidget.ID);
758
- if (debug instanceof DebugWidget) {
759
- return debug['sessionWidget']['viewContainer'];
760
- }
761
- }
762
- const identifier = this.toViewContainerIdentifier(viewContainerId);
763
- return this.widgetManager.getWidget<ViewContainerWidget>(PLUGIN_VIEW_CONTAINER_FACTORY_ID, identifier);
764
- }
765
-
766
- protected async initViewContainer(containerId: string): Promise<void> {
767
- let viewContainer = await this.getPluginViewContainer(containerId);
768
- if (!viewContainer) {
769
- viewContainer = await this.openViewContainer(containerId);
770
- if (viewContainer && !viewContainer.getParts().filter(part => !part.isHidden).length) {
771
- // close view containers without any visible view parts
772
- viewContainer.dispose();
773
- }
774
- } else {
775
- await this.prepareViewContainer(this.toViewContainerId(viewContainer.options), viewContainer);
776
- }
777
- }
778
-
779
- async initWidgets(): Promise<void> {
780
- const promises: Promise<void>[] = [];
781
- for (const id of this.viewContainers.keys()) {
782
- promises.push((async () => {
783
- await this.initViewContainer(id);
784
- })().catch(console.error));
785
- }
786
- promises.push((async () => {
787
- const explorer = await this.widgetManager.getWidget(EXPLORER_VIEW_CONTAINER_ID);
788
- if (explorer instanceof ViewContainerWidget) {
789
- await this.prepareViewContainer('explorer', explorer);
790
- }
791
- })().catch(console.error));
792
- promises.push((async () => {
793
- const scm = await this.widgetManager.getWidget(SCM_VIEW_CONTAINER_ID);
794
- if (scm instanceof ViewContainerWidget) {
795
- await this.prepareViewContainer('scm', scm);
796
- }
797
- })().catch(console.error));
798
- promises.push((async () => {
799
- const search = await this.widgetManager.getWidget(SEARCH_VIEW_CONTAINER_ID);
800
- if (search instanceof ViewContainerWidget) {
801
- await this.prepareViewContainer('search', search);
802
- }
803
- })().catch(console.error));
804
- promises.push((async () => {
805
- const test = await this.widgetManager.getWidget(TEST_VIEW_CONTAINER_ID);
806
- if (test instanceof ViewContainerWidget) {
807
- await this.prepareViewContainer('test', test);
808
- }
809
- })().catch(console.error));
810
- promises.push((async () => {
811
- const debug = await this.widgetManager.getWidget(DebugWidget.ID);
812
- if (debug instanceof DebugWidget) {
813
- const viewContainer = debug['sessionWidget']['viewContainer'];
814
- await this.prepareViewContainer('debug', viewContainer);
815
- }
816
- })().catch(console.error));
817
- await Promise.all(promises);
818
- }
819
-
820
- async removeStaleWidgets(): Promise<void> {
821
- const views = this.widgetManager.getWidgets(PLUGIN_VIEW_FACTORY_ID);
822
- for (const view of views) {
823
- if (view instanceof PluginViewWidget) {
824
- const id = this.toViewId(view.options);
825
- if (!this.views.has(id)) {
826
- view.dispose();
827
- }
828
- }
829
- }
830
- const viewContainers = this.widgetManager.getWidgets(PLUGIN_VIEW_CONTAINER_FACTORY_ID);
831
- for (const viewContainer of viewContainers) {
832
- if (viewContainer instanceof ViewContainerWidget) {
833
- const id = this.toViewContainerId(viewContainer.options);
834
- if (!this.viewContainers.has(id)) {
835
- viewContainer.dispose();
836
- }
837
- }
838
- }
839
- }
840
-
841
- protected toViewContainerIdentifier(viewContainerId: string): ViewContainerIdentifier {
842
- return { id: PLUGIN_VIEW_CONTAINER_FACTORY_ID + ':' + viewContainerId, progressLocationId: viewContainerId };
843
- }
844
- protected toViewContainerId(identifier: ViewContainerIdentifier): string {
845
- return identifier.id.substring(PLUGIN_VIEW_CONTAINER_FACTORY_ID.length + 1);
846
- }
847
-
848
- protected toPluginViewWidgetIdentifier(viewId: string): PluginViewWidgetIdentifier {
849
- return { id: PLUGIN_VIEW_FACTORY_ID + ':' + viewId, viewId };
850
- }
851
- protected toViewId(identifier: PluginViewWidgetIdentifier): string {
852
- return identifier.viewId;
853
- }
854
-
855
- protected toViewWelcomeId(index: number, viewId: string): string {
856
- return `view-welcome.${viewId}.${index}`;
857
- }
858
-
859
- /**
860
- * retrieve restored layout state from previous user session but close widgets
861
- * widgets should be opened only when view data providers are registered
862
- */
863
- onDidInitializeLayout(): void {
864
- const widgets = this.widgetManager.getWidgets(PLUGIN_VIEW_DATA_FACTORY_ID);
865
- for (const widget of widgets) {
866
- if (StatefulWidget.is(widget)) {
867
- const state = widget.storeState();
868
- if (state) {
869
- this.viewDataState.set(widget.id, state);
870
- }
871
- }
872
- widget.dispose();
873
- }
874
- }
875
-
876
- registerViewDataProvider(viewId: string, provider: ViewDataProvider): Disposable {
877
- if (this.viewDataProviders.has(viewId)) {
878
- console.error(`data provider for '${viewId}' view is already registered`);
879
- return Disposable.NULL;
880
- }
881
- this.viewDataProviders.set(viewId, provider);
882
- const toDispose = new DisposableCollection(Disposable.create(() => {
883
- this.viewDataProviders.delete(viewId);
884
- this.viewDataState.delete(viewId);
885
- }));
886
- this.initView(viewId, toDispose);
887
- return toDispose;
888
- }
889
-
890
- protected async initView(viewId: string, toDispose: DisposableCollection): Promise<void> {
891
- const view = await this.getView(viewId);
892
- if (toDispose.disposed) {
893
- return;
894
- }
895
- if (view) {
896
- if (view.isVisible) {
897
- await this.prepareView(view);
898
- } else {
899
- const toDisposeOnDidExpandView = new DisposableCollection(this.onDidExpandView(async id => {
900
- if (id === viewId) {
901
- unsubscribe();
902
- await this.prepareView(view);
903
- }
904
- }));
905
- const unsubscribe = () => toDisposeOnDidExpandView.dispose();
906
- view.disposed.connect(unsubscribe);
907
- toDisposeOnDidExpandView.push(Disposable.create(() => view.disposed.disconnect(unsubscribe)));
908
- toDispose.push(toDisposeOnDidExpandView);
909
- }
910
- }
911
- }
912
-
913
- protected async createViewDataWidget(viewId: string, webviewId?: string): Promise<Widget | undefined> {
914
- const view = this.views.get(viewId);
915
- if (view?.[1]?.type === PluginViewType.Webview) {
916
- return this.createWebviewWidget(viewId, webviewId);
917
- }
918
- const provider = this.viewDataProviders.get(viewId);
919
- if (!view || !provider) {
920
- return undefined;
921
- }
922
- const [, viewInfo] = view;
923
- const state = this.viewDataState.get(viewId);
924
- const widget = await provider({ state, viewInfo });
925
- widget.handleViewWelcomeContentChange(this.getViewWelcomes(viewId));
926
- if (StatefulWidget.is(widget)) {
927
- this.storeViewDataStateOnDispose(viewId, widget);
928
- } else {
929
- this.viewDataState.delete(viewId);
930
- }
931
- return widget;
932
- }
933
-
934
- protected async createWebviewWidget(viewId: string, webviewId?: string): Promise<Widget | undefined> {
935
- if (!webviewId) {
936
- const webviewView = await this.createNewWebviewView(viewId);
937
- webviewId = webviewView.webview.identifier.id;
938
- }
939
- const webviewWidget = this.widgetManager.getWidget(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: webviewId, viewId });
940
- return webviewWidget;
941
- }
942
-
943
- protected storeViewDataStateOnDispose(viewId: string, widget: Widget & StatefulWidget): void {
944
- const dispose = widget.dispose.bind(widget);
945
- widget.dispose = () => {
946
- const state = widget.storeState();
947
- if (state) {
948
- this.viewDataState.set(viewId, state);
949
- }
950
- dispose();
951
- };
952
- }
953
-
954
- protected isVisibleWidget(widget: Widget): boolean {
955
- return !widget.isDisposed && widget.isVisible;
956
- }
957
-
958
- protected updateFocusedView(): void {
959
- const widget = this.shell.activeWidget;
960
- if (widget instanceof PluginViewWidget) {
961
- this.viewContextKeys.focusedView.set(widget.options.viewId);
962
- } else {
963
- this.viewContextKeys.focusedView.reset();
964
- }
965
- }
966
- }
967
-
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Red Hat, Inc. 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
+ import { injectable, inject, postConstruct, optional } from '@theia/core/shared/inversify';
18
+ import {
19
+ ApplicationShell, ViewContainer as ViewContainerWidget, WidgetManager, QuickViewService,
20
+ ViewContainerIdentifier, ViewContainerTitleOptions, Widget, FrontendApplicationContribution,
21
+ StatefulWidget, CommonMenus, TreeViewWelcomeWidget, ViewContainerPart, BaseWidget,
22
+ } from '@theia/core/lib/browser';
23
+ import { ViewContainer, View, ViewWelcome, PluginViewType } from '../../../common';
24
+ import { PluginSharedStyle } from '../plugin-shared-style';
25
+ import { DebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
26
+ import { PluginViewWidget, PluginViewWidgetIdentifier } from './plugin-view-widget';
27
+ import { SCM_VIEW_CONTAINER_ID, ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
28
+ import { EXPLORER_VIEW_CONTAINER_ID, FileNavigatorWidget, FILE_NAVIGATOR_ID } from '@theia/navigator/lib/browser';
29
+ import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
30
+ import { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
31
+ import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
32
+ import { CommandRegistry } from '@theia/core/lib/common/command';
33
+ import { MenuModelRegistry } from '@theia/core/lib/common/menu';
34
+ import { Emitter, Event } from '@theia/core/lib/common/event';
35
+ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
36
+ import { ViewContextKeyService } from './view-context-key-service';
37
+ import { PROBLEMS_WIDGET_ID } from '@theia/markers/lib/browser/problem/problem-widget';
38
+ import { OutputWidget } from '@theia/output/lib/browser/output-widget';
39
+ import { DebugConsoleContribution } from '@theia/debug/lib/browser/console/debug-console-contribution';
40
+ import { TreeViewWidget } from './tree-view-widget';
41
+ import { SEARCH_VIEW_CONTAINER_ID } from '@theia/search-in-workspace/lib/browser/search-in-workspace-factory';
42
+ import { TEST_VIEW_CONTAINER_ID } from '@theia/test/lib/browser/view/test-view-contribution';
43
+ import { WebviewView, WebviewViewResolver } from '../webview-views/webview-views';
44
+ import { WebviewWidget, WebviewWidgetIdentifier } from '../webview/webview';
45
+ import { CancellationToken } from '@theia/core/lib/common/cancellation';
46
+ import { generateUuid } from '@theia/core/lib/common/uuid';
47
+ import { nls } from '@theia/core';
48
+ import { TheiaDockPanel } from '@theia/core/lib/browser/shell/theia-dock-panel';
49
+ import { Deferred } from '@theia/core/lib/common/promise-util';
50
+ import { ThemeIcon } from '@theia/monaco-editor-core/esm/vs/base/common/themables';
51
+
52
+ export const PLUGIN_VIEW_FACTORY_ID = 'plugin-view';
53
+ export const PLUGIN_VIEW_CONTAINER_FACTORY_ID = 'plugin-view-container';
54
+ export const PLUGIN_VIEW_DATA_FACTORY_ID = 'plugin-view-data';
55
+
56
+ export type ViewDataProvider = (params: { state?: object, viewInfo: View }) => Promise<TreeViewWidget>;
57
+
58
+ export interface ViewContainerInfo {
59
+ id: string
60
+ location: string
61
+ options: ViewContainerTitleOptions
62
+ onViewAdded: () => void
63
+ }
64
+
65
+ @injectable()
66
+ export class PluginViewRegistry implements FrontendApplicationContribution {
67
+
68
+ @inject(ApplicationShell)
69
+ protected readonly shell: ApplicationShell;
70
+
71
+ @inject(PluginSharedStyle)
72
+ protected readonly style: PluginSharedStyle;
73
+
74
+ @inject(WidgetManager)
75
+ protected readonly widgetManager: WidgetManager;
76
+
77
+ @inject(ScmContribution)
78
+ protected readonly scm: ScmContribution;
79
+
80
+ @inject(FileNavigatorContribution)
81
+ protected readonly explorer: FileNavigatorContribution;
82
+
83
+ @inject(DebugFrontendApplicationContribution)
84
+ protected readonly debug: DebugFrontendApplicationContribution;
85
+
86
+ @inject(CommandRegistry)
87
+ protected readonly commands: CommandRegistry;
88
+
89
+ @inject(MenuModelRegistry)
90
+ protected readonly menus: MenuModelRegistry;
91
+
92
+ @inject(QuickViewService) @optional()
93
+ protected readonly quickView: QuickViewService;
94
+
95
+ @inject(ContextKeyService)
96
+ protected readonly contextKeyService: ContextKeyService;
97
+
98
+ @inject(ViewContextKeyService)
99
+ protected readonly viewContextKeys: ViewContextKeyService;
100
+
101
+ protected readonly onDidExpandViewEmitter = new Emitter<string>();
102
+ readonly onDidExpandView = this.onDidExpandViewEmitter.event;
103
+
104
+ private readonly views = new Map<string, [string, View]>();
105
+ private readonly viewsWelcome = new Map<string, ViewWelcome[]>();
106
+ private readonly viewContainers = new Map<string, ViewContainerInfo>();
107
+ private readonly containerViews = new Map<string, string[]>();
108
+ private readonly viewClauseContexts = new Map<string, Set<string> | undefined>();
109
+
110
+ private readonly viewDataProviders = new Map<string, ViewDataProvider>();
111
+ private readonly viewDataState = new Map<string, object>();
112
+
113
+ private readonly webviewViewResolvers = new Map<string, WebviewViewResolver>();
114
+ protected readonly onNewResolverRegisteredEmitter = new Emitter<{ readonly viewType: string }>();
115
+ readonly onNewResolverRegistered = this.onNewResolverRegisteredEmitter.event;
116
+
117
+ private readonly webviewViewRevivals = new Map<string, { readonly webview: WebviewView; readonly revival: Deferred<void> }>();
118
+
119
+ private nextViewContainerId = 0;
120
+
121
+ private static readonly BUILTIN_VIEW_CONTAINERS = new Set<string>([
122
+ 'explorer',
123
+ 'scm',
124
+ 'search',
125
+ 'test',
126
+ 'debug'
127
+ ]);
128
+
129
+ private static readonly ID_MAPPINGS: Map<string, string> = new Map([
130
+ // VS Code Viewlets
131
+ [EXPLORER_VIEW_CONTAINER_ID, 'workbench.view.explorer'],
132
+ [SCM_VIEW_CONTAINER_ID, 'workbench.view.scm'],
133
+ [SEARCH_VIEW_CONTAINER_ID, 'workbench.view.search'],
134
+ [DebugWidget.ID, 'workbench.view.debug'],
135
+ ['vsx-extensions-view-container', 'workbench.view.extensions'], // cannot use the id from 'vsx-registry' package because of circular dependency
136
+ [PROBLEMS_WIDGET_ID, 'workbench.panel.markers'],
137
+ [TEST_VIEW_CONTAINER_ID, 'workbench.view.testing'],
138
+ [OutputWidget.ID, 'workbench.panel.output'],
139
+ [DebugConsoleContribution.options.id, 'workbench.panel.repl'],
140
+ // Theia does not have a single terminal widget, but instead each terminal gets its own widget. Therefore "the terminal widget is active" doesn't make sense in Theia
141
+ // [TERMINAL_WIDGET_FACTORY_ID, 'workbench.panel.terminal'],
142
+ // [?? , 'workbench.panel.comments'] not sure what this mean: we don't show comments in sidebars nor the bottom
143
+ ]);
144
+
145
+ @postConstruct()
146
+ protected init(): void {
147
+
148
+ // TODO workbench.panel.comments - Theia does not have a proper comments view yet
149
+
150
+ this.updateFocusedView();
151
+ this.shell.onDidChangeActiveWidget(() => this.updateFocusedView());
152
+
153
+ this.widgetManager.onWillCreateWidget(({ factoryId, widget, waitUntil }) => {
154
+ if (factoryId === EXPLORER_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
155
+ waitUntil(this.prepareViewContainer('explorer', widget));
156
+ }
157
+ if (factoryId === SCM_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
158
+ waitUntil(this.prepareViewContainer('scm', widget));
159
+ }
160
+ if (factoryId === SEARCH_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
161
+ waitUntil(this.prepareViewContainer('search', widget));
162
+ }
163
+ if (factoryId === TEST_VIEW_CONTAINER_ID && widget instanceof ViewContainerWidget) {
164
+ waitUntil(this.prepareViewContainer('test', widget));
165
+ }
166
+ if (factoryId === DebugWidget.ID && widget instanceof DebugWidget) {
167
+ const viewContainer = widget['sessionWidget']['viewContainer'];
168
+ waitUntil(this.prepareViewContainer('debug', viewContainer));
169
+ }
170
+ if (factoryId === PLUGIN_VIEW_CONTAINER_FACTORY_ID && widget instanceof ViewContainerWidget) {
171
+ waitUntil(this.prepareViewContainer(this.toViewContainerId(widget.options), widget));
172
+ }
173
+ if (factoryId === PLUGIN_VIEW_FACTORY_ID && widget instanceof PluginViewWidget) {
174
+ waitUntil(this.prepareView(widget));
175
+ }
176
+ });
177
+ this.widgetManager.onDidCreateWidget(event => {
178
+ if (event.widget instanceof FileNavigatorWidget) {
179
+ const disposable = new DisposableCollection();
180
+ disposable.push(this.registerViewWelcome({
181
+ view: 'explorer',
182
+ content: nls.localizeByDefault(
183
+ 'You have not yet opened a folder.\n{0}',
184
+ `[${nls.localizeByDefault('Open Folder')}](command:workbench.action.files.openFolder)`
185
+ ),
186
+ order: 0
187
+ }));
188
+ disposable.push(event.widget.onDidDispose(() => disposable.dispose()));
189
+ }
190
+ });
191
+ this.contextKeyService.onDidChange(e => {
192
+ for (const [, view] of this.views.values()) {
193
+ const clauseContext = this.viewClauseContexts.get(view.id);
194
+ if (clauseContext && e.affects(clauseContext)) {
195
+ this.updateViewVisibility(view.id);
196
+ }
197
+ }
198
+ for (const [viewId, viewWelcomes] of this.viewsWelcome) {
199
+ for (const [index] of viewWelcomes.entries()) {
200
+ const viewWelcomeId = this.toViewWelcomeId(index, viewId);
201
+ const clauseContext = this.viewClauseContexts.get(viewWelcomeId);
202
+ if (clauseContext && e.affects(clauseContext)) {
203
+ this.updateViewWelcomeVisibility(viewId);
204
+ }
205
+ }
206
+ }
207
+ });
208
+
209
+ const hookDockPanelKey = (panel: TheiaDockPanel, key: ContextKey<string>) => {
210
+ let toDisposeOnActivate = new DisposableCollection();
211
+ panel.onDidChangeCurrent(title => {
212
+ toDisposeOnActivate.dispose();
213
+ toDisposeOnActivate = new DisposableCollection();
214
+ if (title && title.owner instanceof BaseWidget) {
215
+ const widget = title.owner;
216
+ let value = PluginViewRegistry.ID_MAPPINGS.get(widget.id);
217
+ if (!value) {
218
+ if (widget.id.startsWith(PLUGIN_VIEW_CONTAINER_FACTORY_ID)) {
219
+ value = this.toViewContainerId({ id: widget.id });
220
+ }
221
+ }
222
+ const setKey = () => {
223
+ if (widget.isVisible && value) {
224
+ key.set(value);
225
+ } else {
226
+ key.reset();
227
+ }
228
+ };
229
+ toDisposeOnActivate.push(widget.onDidChangeVisibility(() => {
230
+ setKey();
231
+ }));
232
+ setKey();
233
+
234
+ }
235
+ });
236
+ };
237
+
238
+ hookDockPanelKey(this.shell.leftPanelHandler.dockPanel, this.viewContextKeys.activeViewlet);
239
+ hookDockPanelKey(this.shell.rightPanelHandler.dockPanel, this.viewContextKeys.activeAuxiliary);
240
+ hookDockPanelKey(this.shell.bottomPanel, this.viewContextKeys.activePanel);
241
+ }
242
+
243
+ protected async updateViewWelcomeVisibility(viewId: string): Promise<void> {
244
+ const widget = await this.getTreeViewWelcomeWidget(viewId);
245
+ if (widget) {
246
+ widget.handleWelcomeContextChange();
247
+ }
248
+ }
249
+
250
+ protected async updateViewVisibility(viewId: string): Promise<void> {
251
+ const widget = await this.getView(viewId);
252
+ if (!widget) {
253
+ if (this.isViewVisible(viewId)) {
254
+ await this.openView(viewId);
255
+ }
256
+ return;
257
+ }
258
+ const viewInfo = this.views.get(viewId);
259
+ if (!viewInfo) {
260
+ return;
261
+ }
262
+ const [viewContainerId] = viewInfo;
263
+ const viewContainer = await this.getPluginViewContainer(viewContainerId);
264
+ if (!viewContainer) {
265
+ return;
266
+ }
267
+ const part = viewContainer.getPartFor(widget);
268
+ if (!part) {
269
+ return;
270
+ }
271
+ widget.updateViewVisibility(() =>
272
+ part.setHidden(!this.isViewVisible(viewId))
273
+ );
274
+ }
275
+
276
+ protected isViewVisible(viewId: string): boolean {
277
+ const viewInfo = this.views.get(viewId);
278
+ if (!viewInfo) {
279
+ return false;
280
+ }
281
+ const [, view] = viewInfo;
282
+ return view.when === undefined || view.when === 'true' || this.contextKeyService.match(view.when);
283
+ }
284
+
285
+ registerViewContainer(location: string, viewContainer: ViewContainer): Disposable {
286
+ const containerId = `workbench.view.extension.${viewContainer.id}`;
287
+ if (this.viewContainers.has(containerId)) {
288
+ console.warn('view container such id already registered: ', JSON.stringify(viewContainer));
289
+ return Disposable.NULL;
290
+ }
291
+ const toDispose = new DisposableCollection();
292
+ const containerClass = 'theia-plugin-view-container';
293
+ let themeIconClass = '';
294
+ const iconClass = 'plugin-view-container-icon-' + this.nextViewContainerId++; // having dots in class would not work for css, so we need to generate an id.
295
+
296
+ if (viewContainer.themeIcon) {
297
+ const icon = ThemeIcon.fromString(viewContainer.themeIcon);
298
+ if (icon) {
299
+ themeIconClass = ThemeIcon.asClassName(icon) ?? '';
300
+ }
301
+ }
302
+
303
+ if (!themeIconClass) {
304
+ const iconUrl = PluginSharedStyle.toExternalIconUrl(viewContainer.iconUrl);
305
+ toDispose.push(this.style.insertRule('.' + containerClass + '.' + iconClass, () => `
306
+ mask: url('${iconUrl}') no-repeat 50% 50%;
307
+ -webkit-mask: url('${iconUrl}') no-repeat 50% 50%;
308
+ `));
309
+ }
310
+
311
+ toDispose.push(this.doRegisterViewContainer(containerId, location, {
312
+ label: viewContainer.title,
313
+ // The container class automatically sets a mask; if we're using a theme icon, we don't want one.
314
+ iconClass: (themeIconClass || containerClass) + ' ' + iconClass,
315
+ closeable: true
316
+ }));
317
+ return toDispose;
318
+ }
319
+
320
+ protected async toggleViewContainer(id: string): Promise<void> {
321
+ let widget = await this.getPluginViewContainer(id);
322
+ if (widget && widget.isAttached) {
323
+ widget.dispose();
324
+ } else {
325
+ widget = await this.openViewContainer(id);
326
+ if (widget) {
327
+ this.shell.activateWidget(widget.id);
328
+ }
329
+ }
330
+ }
331
+
332
+ protected doRegisterViewContainer(id: string, location: string, options: ViewContainerTitleOptions): Disposable {
333
+ const toDispose = new DisposableCollection();
334
+ toDispose.push(Disposable.create(() => this.viewContainers.delete(id)));
335
+ const toggleCommandId = `plugin.view-container.${id}.toggle`;
336
+ // Some plugins may register empty view containers.
337
+ // We should not register commands for them immediately, as that leads to bad UX.
338
+ // Instead, we register commands the first time we add a view to them.
339
+ let activate = () => {
340
+ toDispose.push(this.commands.registerCommand({
341
+ id: toggleCommandId,
342
+ category: nls.localizeByDefault('View'),
343
+ label: nls.localizeByDefault('Toggle {0}', options.label)
344
+ }, {
345
+ execute: () => this.toggleViewContainer(id)
346
+ }));
347
+ toDispose.push(this.menus.registerMenuAction(CommonMenus.VIEW_VIEWS, {
348
+ commandId: toggleCommandId,
349
+ label: options.label
350
+ }));
351
+ toDispose.push(this.quickView?.registerItem({
352
+ label: options.label,
353
+ open: async () => {
354
+ const widget = await this.openViewContainer(id);
355
+ if (widget) {
356
+ this.shell.activateWidget(widget.id);
357
+ }
358
+ }
359
+ }));
360
+ toDispose.push(Disposable.create(async () => {
361
+ const widget = await this.getPluginViewContainer(id);
362
+ if (widget) {
363
+ widget.dispose();
364
+ }
365
+ }));
366
+ // Ignore every subsequent activation call
367
+ activate = () => { };
368
+ };
369
+ this.viewContainers.set(id, {
370
+ id,
371
+ location,
372
+ options,
373
+ onViewAdded: () => activate()
374
+ });
375
+ return toDispose;
376
+ }
377
+
378
+ getContainerViews(viewContainerId: string): string[] {
379
+ return this.containerViews.get(viewContainerId) || [];
380
+ }
381
+
382
+ registerView(viewContainerId: string, view: View): Disposable {
383
+ if (!PluginViewRegistry.BUILTIN_VIEW_CONTAINERS.has(viewContainerId)) {
384
+ // if it's not a built-in view container, it must be a contributed view container, see https://github.com/eclipse-theia/theia/issues/13249
385
+ viewContainerId = `workbench.view.extension.${viewContainerId}`;
386
+ }
387
+ if (this.views.has(view.id)) {
388
+ console.warn('view with such id already registered: ', JSON.stringify(view));
389
+ return Disposable.NULL;
390
+ }
391
+ const toDispose = new DisposableCollection();
392
+
393
+ view.when = view.when?.trim();
394
+ this.views.set(view.id, [viewContainerId, view]);
395
+ toDispose.push(Disposable.create(() => this.views.delete(view.id)));
396
+
397
+ const containerInfo = this.viewContainers.get(viewContainerId);
398
+ if (containerInfo) {
399
+ containerInfo.onViewAdded();
400
+ }
401
+
402
+ const containerViews = this.getContainerViews(viewContainerId);
403
+ containerViews.push(view.id);
404
+ this.containerViews.set(viewContainerId, containerViews);
405
+ toDispose.push(Disposable.create(() => {
406
+ const index = containerViews.indexOf(view.id);
407
+ if (index !== -1) {
408
+ containerViews.splice(index, 1);
409
+ }
410
+ }));
411
+
412
+ if (view.when && view.when !== 'false' && view.when !== 'true') {
413
+ const keys = this.contextKeyService.parseKeys(view.when);
414
+ if (keys) {
415
+ this.viewClauseContexts.set(view.id, keys);
416
+ toDispose.push(Disposable.create(() => this.viewClauseContexts.delete(view.id)));
417
+ }
418
+ }
419
+ toDispose.push(this.quickView?.registerItem({
420
+ label: view.name,
421
+ when: view.when,
422
+ open: () => this.openView(view.id, { activate: true })
423
+ }));
424
+ toDispose.push(this.commands.registerCommand({ id: `${view.id}.focus` }, {
425
+ execute: async () => { await this.openView(view.id, { activate: true }); }
426
+ }));
427
+ return toDispose;
428
+ }
429
+
430
+ async resolveWebviewView(viewId: string, webview: WebviewView, cancellation: CancellationToken): Promise<void> {
431
+ const resolver = this.webviewViewResolvers.get(viewId);
432
+ if (resolver) {
433
+ return resolver.resolve(webview, cancellation);
434
+ }
435
+ const pendingRevival = this.webviewViewRevivals.get(viewId);
436
+ if (pendingRevival) {
437
+ return pendingRevival.revival.promise;
438
+ }
439
+ const pending = new Deferred<void>();
440
+ this.webviewViewRevivals.set(viewId, { webview, revival: pending });
441
+ return pending.promise;
442
+ }
443
+
444
+ async registerWebviewView(viewId: string, resolver: WebviewViewResolver): Promise<Disposable> {
445
+ if (this.webviewViewResolvers.has(viewId)) {
446
+ throw new Error(`View resolver already registered for ${viewId}`);
447
+ }
448
+ this.webviewViewResolvers.set(viewId, resolver);
449
+ this.onNewResolverRegisteredEmitter.fire({ viewType: viewId });
450
+
451
+ const toDispose = new DisposableCollection(Disposable.create(() => this.webviewViewResolvers.delete(viewId)));
452
+ this.initView(viewId, toDispose);
453
+
454
+ const pendingRevival = this.webviewViewRevivals.get(viewId);
455
+ if (pendingRevival) {
456
+ resolver.resolve(pendingRevival.webview, CancellationToken.None).then(() => {
457
+ this.webviewViewRevivals.delete(viewId);
458
+ pendingRevival.revival.resolve();
459
+ });
460
+ }
461
+
462
+ return toDispose;
463
+ }
464
+
465
+ protected async createNewWebviewView(viewId: string): Promise<WebviewView> {
466
+ const webview = await this.widgetManager.getOrCreateWidget<WebviewWidget>(
467
+ WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{
468
+ id: generateUuid(),
469
+ viewId,
470
+ });
471
+ webview.setContentOptions({ allowScripts: true });
472
+
473
+ let _description: string | undefined;
474
+ let _resolved = false;
475
+ let _pendingResolution: Promise<void> | undefined;
476
+
477
+ const webviewView: WebviewView = {
478
+ webview,
479
+
480
+ get onDidChangeVisibility(): Event<boolean> { return webview.onDidChangeVisibility; },
481
+ get onDidDispose(): Event<void> { return webview.onDidDispose; },
482
+
483
+ get title(): string | undefined { return webview.title.label; },
484
+ set title(value: string | undefined) { webview.title.label = value || ''; },
485
+
486
+ get description(): string | undefined { return _description; },
487
+ set description(value: string | undefined) { _description = value; },
488
+
489
+ get badge(): number | undefined { return webview.badge; },
490
+ set badge(badge: number | undefined) { webview.badge = badge; },
491
+
492
+ get badgeTooltip(): string | undefined { return webview.badgeTooltip; },
493
+ set badgeTooltip(badgeTooltip: string | undefined) { webview.badgeTooltip = badgeTooltip; },
494
+ onDidChangeBadge: webview.onDidChangeBadge,
495
+ onDidChangeBadgeTooltip: webview.onDidChangeBadgeTooltip,
496
+
497
+ dispose: () => {
498
+ _resolved = false;
499
+ webview.dispose();
500
+ toDispose.dispose();
501
+ },
502
+ resolve: async () => {
503
+ if (_resolved) {
504
+ return;
505
+ }
506
+ if (_pendingResolution) {
507
+ return _pendingResolution;
508
+ }
509
+ _pendingResolution = this.resolveWebviewView(viewId, webviewView, CancellationToken.None).then(() => {
510
+ _resolved = true;
511
+ _pendingResolution = undefined;
512
+ });
513
+ return _pendingResolution;
514
+ },
515
+ show: webview.show
516
+ };
517
+
518
+ const toDispose = this.onNewResolverRegistered(resolver => {
519
+ if (resolver.viewType === viewId) {
520
+ // Potentially re-activate if we have a new resolver
521
+ webviewView.resolve();
522
+ }
523
+ });
524
+
525
+ webviewView.resolve();
526
+ return webviewView;
527
+ }
528
+
529
+ registerViewWelcome(viewWelcome: ViewWelcome): Disposable {
530
+ const toDispose = new DisposableCollection();
531
+
532
+ const viewsWelcome = this.viewsWelcome.get(viewWelcome.view) || [];
533
+ if (viewsWelcome.some(e => e.content === viewWelcome.content)) {
534
+ return toDispose;
535
+ }
536
+ viewsWelcome.push(viewWelcome);
537
+ this.viewsWelcome.set(viewWelcome.view, viewsWelcome);
538
+ this.handleViewWelcomeChange(viewWelcome.view);
539
+ toDispose.push(Disposable.create(() => {
540
+ const index = viewsWelcome.indexOf(viewWelcome);
541
+ if (index !== -1) {
542
+ viewsWelcome.splice(index, 1);
543
+ }
544
+ this.handleViewWelcomeChange(viewWelcome.view);
545
+ }));
546
+
547
+ if (viewWelcome.when) {
548
+ const index = viewsWelcome.indexOf(viewWelcome);
549
+ const viewWelcomeId = this.toViewWelcomeId(index, viewWelcome.view);
550
+ this.viewClauseContexts.set(viewWelcomeId, this.contextKeyService.parseKeys(viewWelcome.when));
551
+ toDispose.push(Disposable.create(() => this.viewClauseContexts.delete(viewWelcomeId)));
552
+ }
553
+ return toDispose;
554
+ }
555
+
556
+ async handleViewWelcomeChange(viewId: string): Promise<void> {
557
+ const widget = await this.getTreeViewWelcomeWidget(viewId);
558
+ if (widget) {
559
+ widget.handleViewWelcomeContentChange(this.getViewWelcomes(viewId));
560
+ }
561
+ }
562
+
563
+ protected async getTreeViewWelcomeWidget(viewId: string): Promise<TreeViewWelcomeWidget | undefined> {
564
+ switch (viewId) {
565
+ case 'explorer':
566
+ return this.widgetManager.getWidget<TreeViewWelcomeWidget>(FILE_NAVIGATOR_ID);
567
+ default:
568
+ return this.widgetManager.getWidget<TreeViewWelcomeWidget>(PLUGIN_VIEW_DATA_FACTORY_ID, { id: viewId });
569
+ }
570
+ }
571
+
572
+ getViewWelcomes(viewId: string): ViewWelcome[] {
573
+ return this.viewsWelcome.get(viewId) || [];
574
+ }
575
+
576
+ async getView(viewId: string): Promise<PluginViewWidget | undefined> {
577
+ if (!this.views.has(viewId)) {
578
+ return undefined;
579
+ }
580
+ return this.widgetManager.getWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, this.toPluginViewWidgetIdentifier(viewId));
581
+ }
582
+
583
+ async openView(viewId: string, options?: { activate?: boolean, reveal?: boolean }): Promise<PluginViewWidget | undefined> {
584
+ const view = await this.doOpenView(viewId);
585
+ if (view && options) {
586
+ if (options.activate === true) {
587
+ await this.shell.activateWidget(view.id);
588
+ } else if (options.reveal === true) {
589
+ await this.shell.revealWidget(view.id);
590
+ }
591
+ }
592
+ return view;
593
+ }
594
+ protected async doOpenView(viewId: string): Promise<PluginViewWidget | undefined> {
595
+ const widget = await this.getView(viewId);
596
+ if (widget) {
597
+ return widget;
598
+ }
599
+ const data = this.views.get(viewId);
600
+ if (!data) {
601
+ return undefined;
602
+ }
603
+ const [containerId] = data;
604
+ await this.openViewContainer(containerId);
605
+ return this.getView(viewId);
606
+ }
607
+
608
+ protected async prepareView(widget: PluginViewWidget): Promise<void> {
609
+ const data = this.views.get(widget.options.viewId);
610
+ if (!data) {
611
+ return;
612
+ }
613
+ const [, view] = data;
614
+ if (!widget.title.label) {
615
+ widget.title.label = view.name;
616
+ }
617
+ const currentDataWidget = widget.widgets[0];
618
+ const webviewId = currentDataWidget instanceof WebviewWidget ? currentDataWidget.identifier?.id : undefined;
619
+ const viewDataWidget = await this.createViewDataWidget(view.id, webviewId);
620
+ if (widget.isDisposed) {
621
+ viewDataWidget?.dispose();
622
+ return;
623
+ }
624
+ if (currentDataWidget !== viewDataWidget) {
625
+ if (currentDataWidget) {
626
+ currentDataWidget.dispose();
627
+ }
628
+ if (viewDataWidget) {
629
+ widget.addWidget(viewDataWidget);
630
+ }
631
+ }
632
+ }
633
+
634
+ protected getOrCreateViewContainerWidget(containerId: string): Promise<ViewContainerWidget> {
635
+ const identifier = this.toViewContainerIdentifier(containerId);
636
+ return this.widgetManager.getOrCreateWidget<ViewContainerWidget>(PLUGIN_VIEW_CONTAINER_FACTORY_ID, identifier);
637
+ }
638
+
639
+ async openViewContainer(containerId: string): Promise<ViewContainerWidget | undefined> {
640
+ if (containerId === 'explorer') {
641
+ const widget = await this.explorer.openView();
642
+ if (widget.parent instanceof ViewContainerWidget) {
643
+ return widget.parent;
644
+ }
645
+ return undefined;
646
+ }
647
+ if (containerId === 'scm') {
648
+ const widget = await this.scm.openView();
649
+ if (widget.parent instanceof ViewContainerWidget) {
650
+ return widget.parent;
651
+ }
652
+ return undefined;
653
+ }
654
+ if (containerId === 'debug') {
655
+ const widget = await this.debug.openView();
656
+ return widget['sessionWidget']['viewContainer'];
657
+ }
658
+ const data = this.viewContainers.get(containerId);
659
+ if (!data) {
660
+ return undefined;
661
+ }
662
+ const { location } = data;
663
+ const containerWidget = await this.getOrCreateViewContainerWidget(containerId);
664
+ if (!containerWidget.isAttached) {
665
+ await this.shell.addWidget(containerWidget, {
666
+ area: ApplicationShell.isSideArea(location) ? location : 'left',
667
+ rank: Number.MAX_SAFE_INTEGER
668
+ });
669
+ }
670
+ return containerWidget;
671
+ }
672
+
673
+ protected async prepareViewContainer(viewContainerId: string, containerWidget: ViewContainerWidget): Promise<void> {
674
+ const data = this.viewContainers.get(viewContainerId);
675
+ if (data) {
676
+ const { options } = data;
677
+ containerWidget.setTitleOptions(options);
678
+ }
679
+ for (const viewId of this.getContainerViews(viewContainerId)) {
680
+ const identifier = this.toPluginViewWidgetIdentifier(viewId);
681
+ // Keep existing widget in its current container and reregister its part to the plugin view widget events.
682
+ const existingWidget = this.widgetManager.tryGetWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, identifier);
683
+ if (existingWidget && existingWidget.currentViewContainerId) {
684
+ const currentContainer = await this.getPluginViewContainer(existingWidget.currentViewContainerId);
685
+ if (currentContainer && this.registerWidgetPartEvents(existingWidget, currentContainer)) {
686
+ continue;
687
+ }
688
+ }
689
+ const widget = await this.widgetManager.getOrCreateWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, identifier);
690
+ if (containerWidget.getTrackableWidgets().indexOf(widget) === -1) {
691
+ containerWidget.addWidget(widget, {
692
+ initiallyCollapsed: !!containerWidget.getParts().length,
693
+ initiallyHidden: !this.isViewVisible(viewId)
694
+ });
695
+ }
696
+ this.registerWidgetPartEvents(widget, containerWidget);
697
+ }
698
+ }
699
+
700
+ protected registerWidgetPartEvents(widget: PluginViewWidget, containerWidget: ViewContainerWidget): ViewContainerPart | undefined {
701
+ const part = containerWidget.getPartFor(widget);
702
+ if (part) {
703
+
704
+ widget.currentViewContainerId = this.getViewContainerId(containerWidget);
705
+ part.onDidMove(event => { widget.currentViewContainerId = this.getViewContainerId(event); });
706
+
707
+ // if a view is explicitly hidden then suppress updating visibility based on `when` closure
708
+ part.onDidChangeVisibility(() => widget.suppressUpdateViewVisibility = part.isHidden);
709
+
710
+ const tryFireOnDidExpandView = () => {
711
+ if (widget.widgets.length === 0) {
712
+ if (!part.collapsed && part.isVisible) {
713
+ const viewId = this.toViewId(widget.options);
714
+ this.onDidExpandViewEmitter.fire(viewId);
715
+ }
716
+ } else {
717
+ toFire.dispose();
718
+ }
719
+ };
720
+ const toFire = new DisposableCollection(
721
+ part.onCollapsed(tryFireOnDidExpandView),
722
+ part.onDidChangeVisibility(tryFireOnDidExpandView)
723
+ );
724
+
725
+ tryFireOnDidExpandView();
726
+ return part;
727
+ }
728
+ };
729
+
730
+ protected getViewContainerId(container: ViewContainerWidget): string | undefined {
731
+ const description = this.widgetManager.getDescription(container);
732
+ switch (description?.factoryId) {
733
+ case EXPLORER_VIEW_CONTAINER_ID: return 'explorer';
734
+ case SCM_VIEW_CONTAINER_ID: return 'scm';
735
+ case SEARCH_VIEW_CONTAINER_ID: return 'search';
736
+ case TEST_VIEW_CONTAINER_ID: return 'test';
737
+ case undefined: return container.parent?.parent instanceof DebugWidget ? 'debug' : container.id;
738
+ case PLUGIN_VIEW_CONTAINER_FACTORY_ID: return this.toViewContainerId(description.options);
739
+ default: return container.id;
740
+ }
741
+ }
742
+
743
+ protected async getPluginViewContainer(viewContainerId: string): Promise<ViewContainerWidget | undefined> {
744
+ if (viewContainerId === 'explorer') {
745
+ return this.widgetManager.getWidget<ViewContainerWidget>(EXPLORER_VIEW_CONTAINER_ID);
746
+ }
747
+ if (viewContainerId === 'scm') {
748
+ return this.widgetManager.getWidget<ViewContainerWidget>(SCM_VIEW_CONTAINER_ID);
749
+ }
750
+ if (viewContainerId === 'search') {
751
+ return this.widgetManager.getWidget<ViewContainerWidget>(SEARCH_VIEW_CONTAINER_ID);
752
+ }
753
+ if (viewContainerId === 'test') {
754
+ return this.widgetManager.getWidget<ViewContainerWidget>(TEST_VIEW_CONTAINER_ID);
755
+ }
756
+ if (viewContainerId === 'debug') {
757
+ const debug = await this.widgetManager.getWidget(DebugWidget.ID);
758
+ if (debug instanceof DebugWidget) {
759
+ return debug['sessionWidget']['viewContainer'];
760
+ }
761
+ }
762
+ const identifier = this.toViewContainerIdentifier(viewContainerId);
763
+ return this.widgetManager.getWidget<ViewContainerWidget>(PLUGIN_VIEW_CONTAINER_FACTORY_ID, identifier);
764
+ }
765
+
766
+ protected async initViewContainer(containerId: string): Promise<void> {
767
+ let viewContainer = await this.getPluginViewContainer(containerId);
768
+ if (!viewContainer) {
769
+ viewContainer = await this.openViewContainer(containerId);
770
+ if (viewContainer && !viewContainer.getParts().filter(part => !part.isHidden).length) {
771
+ // close view containers without any visible view parts
772
+ viewContainer.dispose();
773
+ }
774
+ } else {
775
+ await this.prepareViewContainer(this.toViewContainerId(viewContainer.options), viewContainer);
776
+ }
777
+ }
778
+
779
+ async initWidgets(): Promise<void> {
780
+ const promises: Promise<void>[] = [];
781
+ for (const id of this.viewContainers.keys()) {
782
+ promises.push((async () => {
783
+ await this.initViewContainer(id);
784
+ })().catch(console.error));
785
+ }
786
+ promises.push((async () => {
787
+ const explorer = await this.widgetManager.getWidget(EXPLORER_VIEW_CONTAINER_ID);
788
+ if (explorer instanceof ViewContainerWidget) {
789
+ await this.prepareViewContainer('explorer', explorer);
790
+ }
791
+ })().catch(console.error));
792
+ promises.push((async () => {
793
+ const scm = await this.widgetManager.getWidget(SCM_VIEW_CONTAINER_ID);
794
+ if (scm instanceof ViewContainerWidget) {
795
+ await this.prepareViewContainer('scm', scm);
796
+ }
797
+ })().catch(console.error));
798
+ promises.push((async () => {
799
+ const search = await this.widgetManager.getWidget(SEARCH_VIEW_CONTAINER_ID);
800
+ if (search instanceof ViewContainerWidget) {
801
+ await this.prepareViewContainer('search', search);
802
+ }
803
+ })().catch(console.error));
804
+ promises.push((async () => {
805
+ const test = await this.widgetManager.getWidget(TEST_VIEW_CONTAINER_ID);
806
+ if (test instanceof ViewContainerWidget) {
807
+ await this.prepareViewContainer('test', test);
808
+ }
809
+ })().catch(console.error));
810
+ promises.push((async () => {
811
+ const debug = await this.widgetManager.getWidget(DebugWidget.ID);
812
+ if (debug instanceof DebugWidget) {
813
+ const viewContainer = debug['sessionWidget']['viewContainer'];
814
+ await this.prepareViewContainer('debug', viewContainer);
815
+ }
816
+ })().catch(console.error));
817
+ await Promise.all(promises);
818
+ }
819
+
820
+ async removeStaleWidgets(): Promise<void> {
821
+ const views = this.widgetManager.getWidgets(PLUGIN_VIEW_FACTORY_ID);
822
+ for (const view of views) {
823
+ if (view instanceof PluginViewWidget) {
824
+ const id = this.toViewId(view.options);
825
+ if (!this.views.has(id)) {
826
+ view.dispose();
827
+ }
828
+ }
829
+ }
830
+ const viewContainers = this.widgetManager.getWidgets(PLUGIN_VIEW_CONTAINER_FACTORY_ID);
831
+ for (const viewContainer of viewContainers) {
832
+ if (viewContainer instanceof ViewContainerWidget) {
833
+ const id = this.toViewContainerId(viewContainer.options);
834
+ if (!this.viewContainers.has(id)) {
835
+ viewContainer.dispose();
836
+ }
837
+ }
838
+ }
839
+ }
840
+
841
+ protected toViewContainerIdentifier(viewContainerId: string): ViewContainerIdentifier {
842
+ return { id: PLUGIN_VIEW_CONTAINER_FACTORY_ID + ':' + viewContainerId, progressLocationId: viewContainerId };
843
+ }
844
+ protected toViewContainerId(identifier: ViewContainerIdentifier): string {
845
+ return identifier.id.substring(PLUGIN_VIEW_CONTAINER_FACTORY_ID.length + 1);
846
+ }
847
+
848
+ protected toPluginViewWidgetIdentifier(viewId: string): PluginViewWidgetIdentifier {
849
+ return { id: PLUGIN_VIEW_FACTORY_ID + ':' + viewId, viewId };
850
+ }
851
+ protected toViewId(identifier: PluginViewWidgetIdentifier): string {
852
+ return identifier.viewId;
853
+ }
854
+
855
+ protected toViewWelcomeId(index: number, viewId: string): string {
856
+ return `view-welcome.${viewId}.${index}`;
857
+ }
858
+
859
+ /**
860
+ * retrieve restored layout state from previous user session but close widgets
861
+ * widgets should be opened only when view data providers are registered
862
+ */
863
+ onDidInitializeLayout(): void {
864
+ const widgets = this.widgetManager.getWidgets(PLUGIN_VIEW_DATA_FACTORY_ID);
865
+ for (const widget of widgets) {
866
+ if (StatefulWidget.is(widget)) {
867
+ const state = widget.storeState();
868
+ if (state) {
869
+ this.viewDataState.set(widget.id, state);
870
+ }
871
+ }
872
+ widget.dispose();
873
+ }
874
+ }
875
+
876
+ registerViewDataProvider(viewId: string, provider: ViewDataProvider): Disposable {
877
+ if (this.viewDataProviders.has(viewId)) {
878
+ console.error(`data provider for '${viewId}' view is already registered`);
879
+ return Disposable.NULL;
880
+ }
881
+ this.viewDataProviders.set(viewId, provider);
882
+ const toDispose = new DisposableCollection(Disposable.create(() => {
883
+ this.viewDataProviders.delete(viewId);
884
+ this.viewDataState.delete(viewId);
885
+ }));
886
+ this.initView(viewId, toDispose);
887
+ return toDispose;
888
+ }
889
+
890
+ protected async initView(viewId: string, toDispose: DisposableCollection): Promise<void> {
891
+ const view = await this.getView(viewId);
892
+ if (toDispose.disposed) {
893
+ return;
894
+ }
895
+ if (view) {
896
+ if (view.isVisible) {
897
+ await this.prepareView(view);
898
+ } else {
899
+ const toDisposeOnDidExpandView = new DisposableCollection(this.onDidExpandView(async id => {
900
+ if (id === viewId) {
901
+ unsubscribe();
902
+ await this.prepareView(view);
903
+ }
904
+ }));
905
+ const unsubscribe = () => toDisposeOnDidExpandView.dispose();
906
+ view.disposed.connect(unsubscribe);
907
+ toDisposeOnDidExpandView.push(Disposable.create(() => view.disposed.disconnect(unsubscribe)));
908
+ toDispose.push(toDisposeOnDidExpandView);
909
+ }
910
+ }
911
+ }
912
+
913
+ protected async createViewDataWidget(viewId: string, webviewId?: string): Promise<Widget | undefined> {
914
+ const view = this.views.get(viewId);
915
+ if (view?.[1]?.type === PluginViewType.Webview) {
916
+ return this.createWebviewWidget(viewId, webviewId);
917
+ }
918
+ const provider = this.viewDataProviders.get(viewId);
919
+ if (!view || !provider) {
920
+ return undefined;
921
+ }
922
+ const [, viewInfo] = view;
923
+ const state = this.viewDataState.get(viewId);
924
+ const widget = await provider({ state, viewInfo });
925
+ widget.handleViewWelcomeContentChange(this.getViewWelcomes(viewId));
926
+ if (StatefulWidget.is(widget)) {
927
+ this.storeViewDataStateOnDispose(viewId, widget);
928
+ } else {
929
+ this.viewDataState.delete(viewId);
930
+ }
931
+ return widget;
932
+ }
933
+
934
+ protected async createWebviewWidget(viewId: string, webviewId?: string): Promise<Widget | undefined> {
935
+ if (!webviewId) {
936
+ const webviewView = await this.createNewWebviewView(viewId);
937
+ webviewId = webviewView.webview.identifier.id;
938
+ }
939
+ const webviewWidget = this.widgetManager.getWidget(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: webviewId, viewId });
940
+ return webviewWidget;
941
+ }
942
+
943
+ protected storeViewDataStateOnDispose(viewId: string, widget: Widget & StatefulWidget): void {
944
+ const dispose = widget.dispose.bind(widget);
945
+ widget.dispose = () => {
946
+ const state = widget.storeState();
947
+ if (state) {
948
+ this.viewDataState.set(viewId, state);
949
+ }
950
+ dispose();
951
+ };
952
+ }
953
+
954
+ protected isVisibleWidget(widget: Widget): boolean {
955
+ return !widget.isDisposed && widget.isVisible;
956
+ }
957
+
958
+ protected updateFocusedView(): void {
959
+ const widget = this.shell.activeWidget;
960
+ if (widget instanceof PluginViewWidget) {
961
+ this.viewContextKeys.focusedView.set(widget.options.viewId);
962
+ } else {
963
+ this.viewContextKeys.focusedView.reset();
964
+ }
965
+ }
966
+ }
967
+