@theia/plugin-ext 1.45.1 → 1.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/lib/common/plugin-api-rpc.d.ts +9 -4
  2. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  3. package/lib/common/plugin-api-rpc.js +3 -1
  4. package/lib/common/plugin-api-rpc.js.map +1 -1
  5. package/lib/common/plugin-ext-api-contribution.d.ts +35 -5
  6. package/lib/common/plugin-ext-api-contribution.d.ts.map +1 -1
  7. package/lib/common/plugin-ext-api-contribution.js.map +1 -1
  8. package/lib/common/plugin-protocol.d.ts +5 -2
  9. package/lib/common/plugin-protocol.d.ts.map +1 -1
  10. package/lib/common/plugin-protocol.js +1 -0
  11. package/lib/common/plugin-protocol.js.map +1 -1
  12. package/lib/common/proxy-handler.d.ts +7 -0
  13. package/lib/common/proxy-handler.d.ts.map +1 -1
  14. package/lib/common/proxy-handler.js +5 -1
  15. package/lib/common/proxy-handler.js.map +1 -1
  16. package/lib/common/rpc-protocol.d.ts +10 -0
  17. package/lib/common/rpc-protocol.d.ts.map +1 -1
  18. package/lib/common/rpc-protocol.js +32 -3
  19. package/lib/common/rpc-protocol.js.map +1 -1
  20. package/lib/hosted/browser/hosted-plugin.d.ts +16 -74
  21. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  22. package/lib/hosted/browser/hosted-plugin.js +41 -314
  23. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  24. package/lib/hosted/browser/worker/debug-stub.d.ts +2 -2
  25. package/lib/hosted/browser/worker/debug-stub.d.ts.map +1 -1
  26. package/lib/hosted/browser/worker/debug-stub.js +3 -3
  27. package/lib/hosted/browser/worker/debug-stub.js.map +1 -1
  28. package/lib/hosted/browser/worker/worker-env-ext.d.ts +1 -2
  29. package/lib/hosted/browser/worker/worker-env-ext.d.ts.map +1 -1
  30. package/lib/hosted/browser/worker/worker-env-ext.js +18 -4
  31. package/lib/hosted/browser/worker/worker-env-ext.js.map +1 -1
  32. package/lib/hosted/browser/worker/worker-main.js +20 -32
  33. package/lib/hosted/browser/worker/worker-main.js.map +1 -1
  34. package/lib/hosted/browser/worker/worker-plugin-module.d.ts +5 -0
  35. package/lib/hosted/browser/worker/worker-plugin-module.d.ts.map +1 -0
  36. package/lib/hosted/browser/worker/worker-plugin-module.js +71 -0
  37. package/lib/hosted/browser/worker/worker-plugin-module.js.map +1 -0
  38. package/lib/hosted/common/hosted-plugin.d.ts +97 -0
  39. package/lib/hosted/common/hosted-plugin.d.ts.map +1 -0
  40. package/lib/hosted/common/hosted-plugin.js +408 -0
  41. package/lib/hosted/common/hosted-plugin.js.map +1 -0
  42. package/lib/hosted/node/hosted-plugin-process.d.ts +1 -1
  43. package/lib/hosted/node/hosted-plugin-process.d.ts.map +1 -1
  44. package/lib/hosted/node/hosted-plugin-process.js +2 -2
  45. package/lib/hosted/node/hosted-plugin-process.js.map +1 -1
  46. package/lib/hosted/node/plugin-ext-hosted-backend-module.d.ts.map +1 -1
  47. package/lib/hosted/node/plugin-ext-hosted-backend-module.js +2 -0
  48. package/lib/hosted/node/plugin-ext-hosted-backend-module.js.map +1 -1
  49. package/lib/hosted/node/plugin-host-module.d.ts +5 -0
  50. package/lib/hosted/node/plugin-host-module.d.ts.map +1 -0
  51. package/lib/hosted/node/plugin-host-module.js +68 -0
  52. package/lib/hosted/node/plugin-host-module.js.map +1 -0
  53. package/lib/hosted/node/plugin-host-rpc.d.ts +93 -7
  54. package/lib/hosted/node/plugin-host-rpc.d.ts.map +1 -1
  55. package/lib/hosted/node/plugin-host-rpc.js +202 -53
  56. package/lib/hosted/node/plugin-host-rpc.js.map +1 -1
  57. package/lib/hosted/node/plugin-host.js +6 -5
  58. package/lib/hosted/node/plugin-host.js.map +1 -1
  59. package/lib/hosted/node/plugin-reader.d.ts.map +1 -1
  60. package/lib/hosted/node/plugin-reader.js +3 -0
  61. package/lib/hosted/node/plugin-reader.js.map +1 -1
  62. package/lib/hosted/node/plugin-service.d.ts +8 -0
  63. package/lib/hosted/node/plugin-service.d.ts.map +1 -1
  64. package/lib/hosted/node/plugin-service.js +14 -4
  65. package/lib/hosted/node/plugin-service.js.map +1 -1
  66. package/lib/hosted/node/scanners/file-plugin-uri-factory.js +1 -1
  67. package/lib/hosted/node/scanners/file-plugin-uri-factory.js.map +1 -1
  68. package/lib/hosted/node/scanners/scanner-theia.d.ts +17 -3
  69. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  70. package/lib/hosted/node/scanners/scanner-theia.js +48 -19
  71. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  72. package/lib/main/browser/authentication-main.d.ts.map +1 -1
  73. package/lib/main/browser/authentication-main.js +3 -1
  74. package/lib/main/browser/authentication-main.js.map +1 -1
  75. package/lib/main/browser/env-main.d.ts +1 -10
  76. package/lib/main/browser/env-main.d.ts.map +1 -1
  77. package/lib/main/browser/env-main.js +2 -21
  78. package/lib/main/browser/env-main.js.map +1 -1
  79. package/lib/main/browser/menus/menus-contribution-handler.d.ts.map +1 -1
  80. package/lib/main/browser/menus/menus-contribution-handler.js +6 -3
  81. package/lib/main/browser/menus/menus-contribution-handler.js.map +1 -1
  82. package/lib/main/browser/menus/plugin-menu-command-adapter.js +1 -1
  83. package/lib/main/browser/menus/plugin-menu-command-adapter.js.map +1 -1
  84. package/lib/main/browser/message-registry-main.d.ts +6 -4
  85. package/lib/main/browser/message-registry-main.d.ts.map +1 -1
  86. package/lib/main/browser/message-registry-main.js +7 -19
  87. package/lib/main/browser/message-registry-main.js.map +1 -1
  88. package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts +1 -0
  89. package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts.map +1 -1
  90. package/lib/main/browser/notebooks/renderers/cell-output-webview.js +23 -22
  91. package/lib/main/browser/notebooks/renderers/cell-output-webview.js.map +1 -1
  92. package/lib/main/browser/notebooks/renderers/output-webview-internal.d.ts.map +1 -1
  93. package/lib/main/browser/notebooks/renderers/output-webview-internal.js +22 -14
  94. package/lib/main/browser/notebooks/renderers/output-webview-internal.js.map +1 -1
  95. package/lib/main/browser/notebooks/renderers/webview-communication.d.ts +2 -1
  96. package/lib/main/browser/notebooks/renderers/webview-communication.d.ts.map +1 -1
  97. package/lib/main/browser/notification-main.d.ts +2 -14
  98. package/lib/main/browser/notification-main.d.ts.map +1 -1
  99. package/lib/main/browser/notification-main.js +3 -52
  100. package/lib/main/browser/notification-main.js.map +1 -1
  101. package/lib/main/browser/terminal-main.d.ts +1 -1
  102. package/lib/main/browser/terminal-main.d.ts.map +1 -1
  103. package/lib/main/browser/terminal-main.js +2 -2
  104. package/lib/main/browser/terminal-main.js.map +1 -1
  105. package/lib/main/browser/view/plugin-view-registry.d.ts.map +1 -1
  106. package/lib/main/browser/view/plugin-view-registry.js +5 -2
  107. package/lib/main/browser/view/plugin-view-registry.js.map +1 -1
  108. package/lib/main/browser/webview/webview-context-keys.d.ts +5 -1
  109. package/lib/main/browser/webview/webview-context-keys.d.ts.map +1 -1
  110. package/lib/main/browser/webview/webview-context-keys.js +13 -4
  111. package/lib/main/browser/webview/webview-context-keys.js.map +1 -1
  112. package/lib/main/browser/webview/webview-widget-factory.d.ts.map +1 -1
  113. package/lib/main/browser/webview/webview-widget-factory.js +2 -1
  114. package/lib/main/browser/webview/webview-widget-factory.js.map +1 -1
  115. package/lib/main/browser/webview/webview.d.ts +1 -0
  116. package/lib/main/browser/webview/webview.d.ts.map +1 -1
  117. package/lib/main/browser/webview/webview.js +1 -0
  118. package/lib/main/browser/webview/webview.js.map +1 -1
  119. package/lib/main/browser/webviews-main.d.ts.map +1 -1
  120. package/lib/main/browser/webviews-main.js +7 -2
  121. package/lib/main/browser/webviews-main.js.map +1 -1
  122. package/lib/main/common/basic-message-registry-main.d.ts +14 -0
  123. package/lib/main/common/basic-message-registry-main.d.ts.map +1 -0
  124. package/lib/main/common/basic-message-registry-main.js +50 -0
  125. package/lib/main/common/basic-message-registry-main.js.map +1 -0
  126. package/lib/main/common/basic-notification-main.d.ts +19 -0
  127. package/lib/main/common/basic-notification-main.d.ts.map +1 -0
  128. package/lib/main/common/basic-notification-main.js +75 -0
  129. package/lib/main/common/basic-notification-main.js.map +1 -0
  130. package/lib/main/common/env-main.d.ts +11 -0
  131. package/lib/main/common/env-main.d.ts.map +1 -0
  132. package/lib/main/common/env-main.js +40 -0
  133. package/lib/main/common/env-main.js.map +1 -0
  134. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts +8 -3
  135. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts.map +1 -1
  136. package/lib/main/node/handlers/plugin-theia-directory-handler.js +38 -20
  137. package/lib/main/node/handlers/plugin-theia-directory-handler.js.map +1 -1
  138. package/lib/main/node/handlers/plugin-theia-file-handler.js +1 -1
  139. package/lib/main/node/handlers/plugin-theia-file-handler.js.map +1 -1
  140. package/lib/main/node/plugin-deployer-impl.d.ts.map +1 -1
  141. package/lib/main/node/plugin-deployer-impl.js +5 -1
  142. package/lib/main/node/plugin-deployer-impl.js.map +1 -1
  143. package/lib/main/node/plugins-key-value-storage.js +1 -1
  144. package/lib/main/node/plugins-key-value-storage.js.map +1 -1
  145. package/lib/plugin/clipboard-ext.d.ts +3 -2
  146. package/lib/plugin/clipboard-ext.d.ts.map +1 -1
  147. package/lib/plugin/clipboard-ext.js +28 -4
  148. package/lib/plugin/clipboard-ext.js.map +1 -1
  149. package/lib/plugin/debug/debug-ext.d.ts +3 -1
  150. package/lib/plugin/debug/debug-ext.d.ts.map +1 -1
  151. package/lib/plugin/debug/debug-ext.js +31 -4
  152. package/lib/plugin/debug/debug-ext.js.map +1 -1
  153. package/lib/plugin/documents.js +2 -2
  154. package/lib/plugin/documents.js.map +1 -1
  155. package/lib/plugin/editors-and-documents.d.ts +1 -2
  156. package/lib/plugin/editors-and-documents.d.ts.map +1 -1
  157. package/lib/plugin/editors-and-documents.js +21 -4
  158. package/lib/plugin/editors-and-documents.js.map +1 -1
  159. package/lib/plugin/env.d.ts +6 -2
  160. package/lib/plugin/env.d.ts.map +1 -1
  161. package/lib/plugin/env.js +37 -4
  162. package/lib/plugin/env.js.map +1 -1
  163. package/lib/plugin/localization-ext.d.ts +3 -2
  164. package/lib/plugin/localization-ext.d.ts.map +1 -1
  165. package/lib/plugin/localization-ext.js +30 -4
  166. package/lib/plugin/localization-ext.js.map +1 -1
  167. package/lib/plugin/message-registry.d.ts +2 -1
  168. package/lib/plugin/message-registry.d.ts.map +1 -1
  169. package/lib/plugin/message-registry.js +28 -4
  170. package/lib/plugin/message-registry.js.map +1 -1
  171. package/lib/plugin/node/debug/debug.spec.js +21 -1
  172. package/lib/plugin/node/debug/debug.spec.js.map +1 -1
  173. package/lib/plugin/node/env-node-ext.d.ts +1 -6
  174. package/lib/plugin/node/env-node-ext.d.ts.map +1 -1
  175. package/lib/plugin/node/env-node-ext.js +18 -10
  176. package/lib/plugin/node/env-node-ext.js.map +1 -1
  177. package/lib/plugin/node/plugin-container-module.d.ts +75 -0
  178. package/lib/plugin/node/plugin-container-module.d.ts.map +1 -0
  179. package/lib/plugin/node/plugin-container-module.js +115 -0
  180. package/lib/plugin/node/plugin-container-module.js.map +1 -0
  181. package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -1
  182. package/lib/plugin/notebook/notebook-kernels.js +0 -1
  183. package/lib/plugin/notebook/notebook-kernels.js.map +1 -1
  184. package/lib/plugin/plugin-context.d.ts.map +1 -1
  185. package/lib/plugin/plugin-context.js +9 -1
  186. package/lib/plugin/plugin-context.js.map +1 -1
  187. package/lib/plugin/plugin-manager.d.ts +26 -17
  188. package/lib/plugin/plugin-manager.d.ts.map +1 -1
  189. package/lib/plugin/plugin-manager.js +107 -37
  190. package/lib/plugin/plugin-manager.js.map +1 -1
  191. package/lib/plugin/plugin-storage.d.ts +11 -3
  192. package/lib/plugin/plugin-storage.d.ts.map +1 -1
  193. package/lib/plugin/plugin-storage.js +25 -5
  194. package/lib/plugin/plugin-storage.js.map +1 -1
  195. package/lib/plugin/preference-registry.d.ts +3 -2
  196. package/lib/plugin/preference-registry.d.ts.map +1 -1
  197. package/lib/plugin/preference-registry.js +35 -5
  198. package/lib/plugin/preference-registry.js.map +1 -1
  199. package/lib/plugin/preference-registry.spec.js +8 -1
  200. package/lib/plugin/preference-registry.spec.js.map +1 -1
  201. package/lib/plugin/quick-open.js +3 -3
  202. package/lib/plugin/quick-open.js.map +1 -1
  203. package/lib/plugin/secrets-ext.d.ts +16 -7
  204. package/lib/plugin/secrets-ext.d.ts.map +1 -1
  205. package/lib/plugin/secrets-ext.js +23 -3
  206. package/lib/plugin/secrets-ext.js.map +1 -1
  207. package/lib/plugin/terminal-ext.d.ts +1 -1
  208. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  209. package/lib/plugin/terminal-ext.js +26 -6
  210. package/lib/plugin/terminal-ext.js.map +1 -1
  211. package/lib/plugin/types-impl.d.ts +22 -2
  212. package/lib/plugin/types-impl.d.ts.map +1 -1
  213. package/lib/plugin/types-impl.js +22 -6
  214. package/lib/plugin/types-impl.js.map +1 -1
  215. package/lib/plugin/webview-views.d.ts.map +1 -1
  216. package/lib/plugin/webview-views.js +2 -1
  217. package/lib/plugin/webview-views.js.map +1 -1
  218. package/lib/plugin/webviews.d.ts +7 -5
  219. package/lib/plugin/webviews.d.ts.map +1 -1
  220. package/lib/plugin/webviews.js +46 -12
  221. package/lib/plugin/webviews.js.map +1 -1
  222. package/lib/plugin/workspace.d.ts +4 -3
  223. package/lib/plugin/workspace.d.ts.map +1 -1
  224. package/lib/plugin/workspace.js +40 -6
  225. package/lib/plugin/workspace.js.map +1 -1
  226. package/package.json +29 -29
  227. package/src/common/plugin-api-rpc.ts +10 -6
  228. package/src/common/plugin-ext-api-contribution.ts +38 -5
  229. package/src/common/plugin-protocol.ts +7 -2
  230. package/src/common/proxy-handler.ts +14 -1
  231. package/src/common/rpc-protocol.ts +41 -3
  232. package/src/hosted/browser/hosted-plugin.ts +47 -337
  233. package/src/hosted/browser/worker/debug-stub.ts +4 -3
  234. package/src/hosted/browser/worker/worker-env-ext.ts +5 -4
  235. package/src/hosted/browser/worker/worker-main.ts +103 -115
  236. package/src/hosted/browser/worker/worker-plugin-module.ts +73 -0
  237. package/src/hosted/common/hosted-plugin.ts +456 -0
  238. package/src/hosted/node/hosted-plugin-process.ts +4 -4
  239. package/src/hosted/node/plugin-ext-hosted-backend-module.ts +3 -1
  240. package/src/hosted/node/plugin-host-module.ts +69 -0
  241. package/src/hosted/node/plugin-host-rpc.ts +232 -73
  242. package/src/hosted/node/plugin-host.ts +9 -7
  243. package/src/hosted/node/plugin-reader.ts +3 -0
  244. package/src/hosted/node/plugin-service.ts +21 -4
  245. package/src/hosted/node/scanners/file-plugin-uri-factory.ts +1 -1
  246. package/src/hosted/node/scanners/scanner-theia.ts +46 -12
  247. package/src/main/browser/authentication-main.ts +3 -1
  248. package/src/main/browser/env-main.ts +1 -28
  249. package/src/main/browser/menus/menus-contribution-handler.ts +8 -3
  250. package/src/main/browser/menus/plugin-menu-command-adapter.ts +1 -1
  251. package/src/main/browser/message-registry-main.ts +10 -23
  252. package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +26 -24
  253. package/src/main/browser/notebooks/renderers/output-webview-internal.ts +22 -13
  254. package/src/main/browser/notebooks/renderers/webview-communication.ts +2 -1
  255. package/src/main/browser/notification-main.ts +4 -64
  256. package/src/main/browser/terminal-main.ts +2 -2
  257. package/src/main/browser/view/plugin-view-registry.ts +6 -3
  258. package/src/main/browser/webview/webview-context-keys.ts +17 -4
  259. package/src/main/browser/webview/webview-widget-factory.ts +2 -1
  260. package/src/main/browser/webview/webview.ts +2 -0
  261. package/src/main/browser/webviews-main.ts +7 -2
  262. package/src/main/common/basic-message-registry-main.ts +53 -0
  263. package/src/main/common/basic-notification-main.ts +86 -0
  264. package/src/main/common/env-main.ts +44 -0
  265. package/src/main/node/handlers/plugin-theia-directory-handler.ts +38 -16
  266. package/src/main/node/handlers/plugin-theia-file-handler.ts +1 -1
  267. package/src/main/node/plugin-deployer-impl.ts +5 -1
  268. package/src/main/node/plugins-key-value-storage.ts +1 -1
  269. package/src/plugin/clipboard-ext.ts +9 -3
  270. package/src/plugin/debug/debug-ext.ts +11 -2
  271. package/src/plugin/documents.ts +2 -2
  272. package/src/plugin/editors-and-documents.ts +5 -3
  273. package/src/plugin/env.ts +19 -3
  274. package/src/plugin/localization-ext.ts +8 -3
  275. package/src/plugin/message-registry.ts +7 -2
  276. package/src/plugin/node/debug/debug.spec.ts +5 -1
  277. package/src/plugin/node/env-node-ext.ts +5 -10
  278. package/src/plugin/node/plugin-container-module.ts +165 -0
  279. package/src/plugin/notebook/notebook-kernels.ts +0 -1
  280. package/src/plugin/plugin-context.ts +11 -2
  281. package/src/plugin/plugin-manager.ts +99 -45
  282. package/src/plugin/plugin-storage.ts +22 -4
  283. package/src/plugin/preference-registry.spec.ts +6 -1
  284. package/src/plugin/preference-registry.ts +11 -5
  285. package/src/plugin/quick-open.ts +3 -3
  286. package/src/plugin/secrets-ext.ts +25 -5
  287. package/src/plugin/terminal-ext.ts +5 -3
  288. package/src/plugin/types-impl.ts +30 -2
  289. package/src/plugin/webview-views.ts +2 -1
  290. package/src/plugin/webviews.ts +22 -13
  291. package/src/plugin/workspace.ts +14 -4
@@ -14,35 +14,8 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { interfaces } from '@theia/core/shared/inversify';
18
- import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
19
- import { RPCProtocol } from '../../common/rpc-protocol';
20
- import { EnvMain } from '../../common/plugin-api-rpc';
21
17
  import { QueryParameters } from '../../common/env';
22
- import { isWindows, isOSX } from '@theia/core';
23
- import { OperatingSystem } from '../../plugin/types-impl';
24
-
25
- export class EnvMainImpl implements EnvMain {
26
- private envVariableServer: EnvVariablesServer;
27
-
28
- constructor(rpc: RPCProtocol, container: interfaces.Container) {
29
- this.envVariableServer = container.get(EnvVariablesServer);
30
- }
31
-
32
- $getEnvVariable(envVarName: string): Promise<string | undefined> {
33
- return this.envVariableServer.getValue(envVarName).then(result => result ? result.value : undefined);
34
- }
35
-
36
- async $getClientOperatingSystem(): Promise<OperatingSystem> {
37
- if (isWindows) {
38
- return OperatingSystem.Windows;
39
- }
40
- if (isOSX) {
41
- return OperatingSystem.OSX;
42
- }
43
- return OperatingSystem.Linux;
44
- }
45
- }
18
+ export { EnvMainImpl } from '../common/env-main';
46
19
 
47
20
  /**
48
21
  * Returns query parameters from current page.
@@ -99,9 +99,12 @@ export class MenusContributionPointHandler {
99
99
  const targets = this.getMatchingMenu(contributionPoint as ContributionPoint) ?? [contributionPoint];
100
100
  const { group, order } = this.parseGroup(item.group);
101
101
  const { submenu, command } = item;
102
- if (submenu) {
103
- targets.forEach(target => toDispose.push(this.menuRegistry.linkSubmenu(target, submenu!, { order, when: item.when }, group)));
104
- } else if (command) {
102
+ if (submenu && command) {
103
+ console.warn(
104
+ `Menu item ${command} from plugin ${plugin.metadata.model.id} contributed both submenu and command. Only command will be registered.`
105
+ );
106
+ }
107
+ if (command) {
105
108
  toDispose.push(this.commandAdapter.addCommand(command));
106
109
  targets.forEach(target => {
107
110
  const node = new ActionMenuNode({
@@ -112,6 +115,8 @@ export class MenusContributionPointHandler {
112
115
  const parent = this.menuRegistry.getMenuNode(target, group);
113
116
  toDispose.push(parent.addNode(node));
114
117
  });
118
+ } else if (submenu) {
119
+ targets.forEach(target => toDispose.push(this.menuRegistry.linkSubmenu(target, submenu!, { order, when: item.when }, group)));
115
120
  }
116
121
  }
117
122
  } catch (error) {
@@ -108,7 +108,7 @@ export class PluginMenuCommandAdapter implements MenuCommandAdapter {
108
108
  ['timeline/item/context', (...args) => this.toTimelineArgs(...args)],
109
109
  ['view/item/context', (...args) => this.toTreeArgs(...args)],
110
110
  ['view/title', noArgs],
111
- ['webview/context', noArgs]
111
+ ['webview/context', firstArgOnly]
112
112
  ]).forEach(([contributionPoint, adapter]) => {
113
113
  if (adapter) {
114
114
  const paths = codeToTheiaMappings.get(contributionPoint);
@@ -15,26 +15,21 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { interfaces } from '@theia/core/shared/inversify';
18
- import { MessageService } from '@theia/core/lib/common/message-service';
19
- import { MessageRegistryMain, MainMessageType, MainMessageOptions, MainMessageItem } from '../../common/plugin-api-rpc';
18
+ import { MainMessageType, MainMessageOptions, MainMessageItem } from '../../common/plugin-api-rpc';
20
19
  import { ModalNotification, MessageType } from './dialogs/modal-notification';
20
+ import { BasicMessageRegistryMainImpl } from '../common/basic-message-registry-main';
21
21
 
22
- export class MessageRegistryMainImpl implements MessageRegistryMain {
23
- private readonly messageService: MessageService;
24
-
22
+ /**
23
+ * Message registry implementation that adds support for the model option via dialog in the browser.
24
+ */
25
+ export class MessageRegistryMainImpl extends BasicMessageRegistryMainImpl {
25
26
  constructor(container: interfaces.Container) {
26
- this.messageService = container.get(MessageService);
27
+ super(container);
27
28
  }
28
29
 
29
- async $showMessage(type: MainMessageType, message: string, options: MainMessageOptions, actions: MainMessageItem[]): Promise<number | undefined> {
30
- const action = await this.doShowMessage(type, message, options, actions);
31
- const handle = action
32
- ? actions.map(a => a.title).indexOf(action)
33
- : undefined;
34
- return handle === undefined && options.modal ? options.onCloseActionHandle : handle;
35
- }
30
+ protected override async doShowMessage(type: MainMessageType, message: string,
31
+ options: MainMessageOptions, actions: MainMessageItem[]): Promise<string | undefined> {
36
32
 
37
- protected async doShowMessage(type: MainMessageType, message: string, options: MainMessageOptions, actions: MainMessageItem[]): Promise<string | undefined> {
38
33
  if (options.modal) {
39
34
  const messageType = type === MainMessageType.Error ? MessageType.Error :
40
35
  type === MainMessageType.Warning ? MessageType.Warning :
@@ -42,15 +37,7 @@ export class MessageRegistryMainImpl implements MessageRegistryMain {
42
37
  const modalNotification = new ModalNotification();
43
38
  return modalNotification.showDialog(messageType, message, options, actions);
44
39
  }
45
- switch (type) {
46
- case MainMessageType.Info:
47
- return this.messageService.info(message, ...actions.map(a => a.title));
48
- case MainMessageType.Warning:
49
- return this.messageService.warn(message, ...actions.map(a => a.title));
50
- case MainMessageType.Error:
51
- return this.messageService.error(message, ...actions.map(a => a.title));
52
- }
53
- throw new Error(`Message type '${type}' is not supported yet!`);
40
+ return super.doShowMessage(type, message, options, actions);
54
41
  }
55
42
 
56
43
  }
@@ -72,12 +72,14 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
72
72
 
73
73
  protected webviewWidget: WebviewWidget;
74
74
 
75
+ protected toDispose = new DisposableCollection();
76
+
75
77
  @postConstruct()
76
78
  protected async init(): Promise<void> {
77
- this.cell.onDidChangeOutputs(outputChange => this.updateOutput(outputChange));
78
- this.cell.onDidChangeOutputItems(output => {
79
+ this.toDispose.push(this.cell.onDidChangeOutputs(outputChange => this.updateOutput(outputChange)));
80
+ this.toDispose.push(this.cell.onDidChangeOutputItems(output => {
79
81
  this.updateOutput({start: this.cell.outputs.findIndex(o => o.outputId === output.outputId), deleteCount: 1, newOutputs: [output]});
80
- });
82
+ }));
81
83
 
82
84
  this.webviewWidget = await this.widgetManager.getOrCreateWidget(WebviewWidget.FACTORY_ID, { id: this.id });
83
85
  this.webviewWidget.setContentOptions({ allowScripts: true });
@@ -106,29 +108,28 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
106
108
  }
107
109
 
108
110
  updateOutput(update: NotebookCellOutputsSplice): void {
109
- if (this.cell.outputs.length > 0) {
110
- if (this.webviewWidget.isHidden) {
111
- this.webviewWidget.show();
112
- }
113
-
114
- this.outputPresentationListeners.dispose();
115
- this.outputPresentationListeners = new DisposableCollection();
116
- for (const output of this.cell.outputs) {
117
- this.outputPresentationListeners.push(output.onRequestOutputPresentationChange(() => this.requestOutputPresentationUpdate(output)));
118
- }
111
+ if (this.webviewWidget.isHidden) {
112
+ this.webviewWidget.show();
113
+ }
119
114
 
120
- const updateOutputMessage: OutputChangedMessage = {
121
- type: 'outputChanged',
122
- newOutputs: update.newOutputs.map(output => ({
123
- id: output.outputId,
124
- items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })),
125
- metadata: output.metadata
126
- })),
127
- deletedOutputIds: this.cell.outputs.slice(update.start, update.start + update.deleteCount).map(output => output.outputId)
128
- };
129
-
130
- this.webviewWidget.sendMessage(updateOutputMessage);
115
+ this.outputPresentationListeners.dispose();
116
+ this.outputPresentationListeners = new DisposableCollection();
117
+ for (const output of this.cell.outputs) {
118
+ this.outputPresentationListeners.push(output.onRequestOutputPresentationChange(() => this.requestOutputPresentationUpdate(output)));
131
119
  }
120
+
121
+ const updateOutputMessage: OutputChangedMessage = {
122
+ type: 'outputChanged',
123
+ newOutputs: update.newOutputs.map(output => ({
124
+ id: output.outputId,
125
+ items: output.outputs.map(item => ({ mime: item.mime, data: item.data.buffer })),
126
+ metadata: output.metadata
127
+ })),
128
+ deleteStart: update.start,
129
+ deleteCount: update.deleteCount
130
+ };
131
+
132
+ this.webviewWidget.sendMessage(updateOutputMessage);
132
133
  }
133
134
 
134
135
  private async requestOutputPresentationUpdate(output: NotebookCellOutputModel): Promise<void> {
@@ -195,6 +196,7 @@ export class CellOutputWebviewImpl implements CellOutputWebview, Disposable {
195
196
  }
196
197
 
197
198
  dispose(): void {
199
+ this.toDispose.dispose();
198
200
  this.outputPresentationListeners.dispose();
199
201
  this.webviewWidget.dispose();
200
202
  }
@@ -114,7 +114,7 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
114
114
  this.element.style.paddingRight = '10px';
115
115
  this.element.id = output.id;
116
116
  document.body.appendChild(this.element);
117
-
117
+ this.outputId = output.id;
118
118
  this.allItems = items;
119
119
  }
120
120
 
@@ -134,7 +134,7 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
134
134
  }
135
135
  }
136
136
 
137
- const outputs = new Map</* outputId */string, Output>();
137
+ const outputs: Output[] = [];
138
138
 
139
139
  class Renderer {
140
140
 
@@ -314,10 +314,17 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
314
314
  // we need to check for all images are loaded. Otherwise we can't determine the correct height of the output
315
315
  const images = Array.from(document.images);
316
316
  if (images.length > 0) {
317
- Promise.all(images.filter(img => !img.complete).map(img => new Promise(resolve => { img.onload = img.onerror = resolve; }))).then(() =>
318
- theia.postMessage(<webviewCommunication.OnDidRenderOutput>{ type: 'didRenderOutput', contentHeight: document.body.clientHeight }));
317
+ Promise.all(images.filter(img => !img.complete).map(img => new Promise(resolve => { img.onload = img.onerror = resolve; }))).then(() => {
318
+ theia.postMessage(<webviewCommunication.OnDidRenderOutput>{ type: 'didRenderOutput', contentHeight: document.body.clientHeight });
319
+ new ResizeObserver(() =>
320
+ theia.postMessage(<webviewCommunication.OnDidRenderOutput>{ type: 'didRenderOutput', contentHeight: document.body.clientHeight }))
321
+ .observe(document.body);
322
+ });
319
323
  } else {
320
324
  theia.postMessage(<webviewCommunication.OnDidRenderOutput>{ type: 'didRenderOutput', contentHeight: document.body.clientHeight });
325
+ new ResizeObserver(() =>
326
+ theia.postMessage(<webviewCommunication.OnDidRenderOutput>{ type: 'didRenderOutput', contentHeight: document.body.clientHeight }))
327
+ .observe(document.body);
321
328
  }
322
329
 
323
330
  }
@@ -378,15 +385,14 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
378
385
  }
379
386
  }();
380
387
 
381
- function clearOutput(outputId: string): void {
382
- outputs.get(outputId)?.clear();
383
- outputs.delete(outputId);
384
- document.getElementById(outputId)?.remove();
388
+ function clearOutput(output: Output): void {
389
+ output.clear();
390
+ output.element.remove();
385
391
  }
386
392
 
387
393
  function outputsChanged(changedEvent: webviewCommunication.OutputChangedMessage): void {
388
- for (const outputId of changedEvent.deletedOutputIds ?? []) {
389
- clearOutput(outputId);
394
+ for (const output of outputs.splice(changedEvent.deleteStart ?? 0, changedEvent.deleteCount ?? 0)) {
395
+ clearOutput(output);
390
396
  }
391
397
 
392
398
  for (const outputData of changedEvent.newOutputs ?? []) {
@@ -410,7 +416,7 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
410
416
  }));
411
417
 
412
418
  const output = new Output(outputData, apiItems);
413
- outputs.set(outputData.id, output);
419
+ outputs.push(output);
414
420
 
415
421
  renderers.render(output, undefined, undefined, new AbortController().signal);
416
422
  }
@@ -466,8 +472,11 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
466
472
  renderers.getRenderer(event.data.rendererId)?.receiveMessage(event.data.message);
467
473
  break;
468
474
  case 'changePreferredMimetype':
469
- clearOutput(event.data.outputId);
470
- renderers.render(outputs.get(event.data.outputId)!, event.data.mimeType, undefined, new AbortController().signal);
475
+ const outputId = event.data.outputId;
476
+ const index = outputs.findIndex(output => output.outputId === outputId);
477
+ outputs.splice(index, 1);
478
+ clearOutput(outputs.splice(index, 1)[0]);
479
+ renderers.render(outputs[index], event.data.mimeType, undefined, new AbortController().signal);
471
480
  break;
472
481
  }
473
482
  });
@@ -39,7 +39,8 @@ export interface UpdateRenderersMessage {
39
39
  export interface OutputChangedMessage {
40
40
  readonly type: 'outputChanged';
41
41
  readonly newOutputs?: Output[];
42
- readonly deletedOutputIds?: string[];
42
+ readonly deleteStart?: number;
43
+ readonly deleteCount?: number;
43
44
  }
44
45
 
45
46
  export interface ChangePreferredMimetypeMessage {
@@ -14,73 +14,13 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { NotificationExt, NotificationMain, MAIN_RPC_CONTEXT } from '../../common';
18
- import { ProgressService, Progress, ProgressMessage } from '@theia/core/lib/common';
17
+ import { MAIN_RPC_CONTEXT } from '../../common';
19
18
  import { interfaces } from '@theia/core/shared/inversify';
20
19
  import { RPCProtocol } from '../../common/rpc-protocol';
21
- import { Disposable, DisposableCollection } from '@theia/core/lib/common/disposable';
22
-
23
- export class NotificationMainImpl implements NotificationMain, Disposable {
24
- private readonly progressService: ProgressService;
25
- private readonly progressMap = new Map<string, Progress>();
26
- private readonly progress2Work = new Map<string, number>();
27
- private readonly proxy: NotificationExt;
28
-
29
- protected readonly toDispose = new DisposableCollection(
30
- Disposable.create(() => { /* mark as not disposed */ })
31
- );
20
+ import { BasicNotificationMainImpl } from '../common/basic-notification-main';
32
21
 
22
+ export class NotificationMainImpl extends BasicNotificationMainImpl {
33
23
  constructor(rpc: RPCProtocol, container: interfaces.Container) {
34
- this.progressService = container.get(ProgressService);
35
- this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.NOTIFICATION_EXT);
36
- }
37
-
38
- dispose(): void {
39
- this.toDispose.dispose();
40
- }
41
-
42
- async $startProgress(options: NotificationMain.StartProgressOptions): Promise<string> {
43
- const onDidCancel = () => {
44
- // If the map does not contain current id, it has already stopped and should not be cancelled
45
- if (this.progressMap.has(id)) {
46
- this.proxy.$acceptProgressCanceled(id);
47
- }
48
- };
49
-
50
- const progressMessage = this.mapOptions(options);
51
- const progress = await this.progressService.showProgress(progressMessage, onDidCancel);
52
- const id = progress.id;
53
- this.progressMap.set(id, progress);
54
- this.progress2Work.set(id, 0);
55
- if (this.toDispose.disposed) {
56
- this.$stopProgress(id);
57
- } else {
58
- this.toDispose.push(Disposable.create(() => this.$stopProgress(id)));
59
- }
60
- return id;
61
- }
62
- protected mapOptions(options: NotificationMain.StartProgressOptions): ProgressMessage {
63
- const { title, location, cancellable } = options;
64
- return { text: title, options: { location, cancelable: cancellable } };
65
- }
66
-
67
- $stopProgress(id: string): void {
68
- const progress = this.progressMap.get(id);
69
-
70
- if (progress) {
71
- this.progressMap.delete(id);
72
- this.progress2Work.delete(id);
73
- progress.cancel();
74
- }
75
- }
76
-
77
- $updateProgress(id: string, item: NotificationMain.ProgressReport): void {
78
- const progress = this.progressMap.get(id);
79
- if (!progress) {
80
- return;
81
- }
82
- const done = Math.min((this.progress2Work.get(id) || 0) + (item.increment || 0), 100);
83
- this.progress2Work.set(id, done);
84
- progress.report({ message: item.message, work: done ? { done, total: 100 } : undefined });
24
+ super(rpc, container, MAIN_RPC_CONTEXT.NOTIFICATION_EXT);
85
25
  }
86
26
  }
@@ -181,11 +181,11 @@ export class TerminalServiceMainImpl implements TerminalServiceMain, TerminalLin
181
181
  return undefined;
182
182
  }
183
183
 
184
- $sendText(id: string, text: string, addNewLine?: boolean): void {
184
+ $sendText(id: string, text: string, shouldExecute?: boolean): void {
185
185
  const terminal = this.terminals.getById(id);
186
186
  if (terminal) {
187
187
  text = text.replace(/\r?\n/g, '\r');
188
- if (addNewLine && text.charAt(text.length - 1) !== '\r') {
188
+ if (shouldExecute && text.charAt(text.length - 1) !== '\r') {
189
189
  text += '\r';
190
190
  }
191
191
  terminal.sendText(text);
@@ -18,7 +18,7 @@ import { injectable, inject, postConstruct, optional } from '@theia/core/shared/
18
18
  import {
19
19
  ApplicationShell, ViewContainer as ViewContainerWidget, WidgetManager, QuickViewService,
20
20
  ViewContainerIdentifier, ViewContainerTitleOptions, Widget, FrontendApplicationContribution,
21
- StatefulWidget, CommonMenus, TreeViewWelcomeWidget, ViewContainerPart, BaseWidget
21
+ StatefulWidget, CommonMenus, TreeViewWelcomeWidget, ViewContainerPart, BaseWidget,
22
22
  } from '@theia/core/lib/browser';
23
23
  import { ViewContainer, View, ViewWelcome, PluginViewType } from '../../../common';
24
24
  import { PluginSharedStyle } from '../plugin-shared-style';
@@ -424,7 +424,10 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
424
424
 
425
425
  protected async createNewWebviewView(viewId: string): Promise<WebviewView> {
426
426
  const webview = await this.widgetManager.getOrCreateWidget<WebviewWidget>(
427
- WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: v4() });
427
+ WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{
428
+ id: v4(),
429
+ viewId,
430
+ });
428
431
  webview.setContentOptions({ allowScripts: true });
429
432
 
430
433
  let _description: string | undefined;
@@ -893,7 +896,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
893
896
  const webviewView = await this.createNewWebviewView(viewId);
894
897
  webviewId = webviewView.webview.identifier.id;
895
898
  }
896
- const webviewWidget = this.widgetManager.getWidget(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: webviewId });
899
+ const webviewWidget = this.widgetManager.getWidget(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: webviewId, viewId });
897
900
  return webviewWidget;
898
901
  }
899
902
 
@@ -14,9 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
- import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
19
17
  import { ApplicationShell, FocusTracker, Widget } from '@theia/core/lib/browser';
18
+ import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
19
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
20
+ import { CustomEditorWidget } from '../custom-editors/custom-editor-widget';
20
21
  import { WebviewWidget } from './webview';
21
22
 
22
23
  @injectable()
@@ -27,6 +28,11 @@ export class WebviewContextKeys {
27
28
  */
28
29
  activeWebviewPanelId: ContextKey<string>;
29
30
 
31
+ /**
32
+ * Context key representing the `viewType` of the active `CustomEditorWidget`, if any.
33
+ */
34
+ activeCustomEditorId: ContextKey<string>;
35
+
30
36
  @inject(ApplicationShell)
31
37
  protected applicationShell: ApplicationShell;
32
38
 
@@ -36,12 +42,19 @@ export class WebviewContextKeys {
36
42
  @postConstruct()
37
43
  protected init(): void {
38
44
  this.activeWebviewPanelId = this.contextKeyService.createKey('activeWebviewPanelId', '');
45
+ this.activeCustomEditorId = this.contextKeyService.createKey('activeCustomEditorId', '');
39
46
  this.applicationShell.onDidChangeCurrentWidget(this.handleDidChangeCurrentWidget, this);
40
47
  }
41
48
 
42
49
  protected handleDidChangeCurrentWidget(change: FocusTracker.IChangedArgs<Widget>): void {
43
- if (change.newValue instanceof WebviewWidget) {
44
- this.activeWebviewPanelId.set(change.newValue.viewType);
50
+ const { newValue } = change;
51
+ if (newValue instanceof CustomEditorWidget) {
52
+ this.activeCustomEditorId.set(newValue.viewType);
53
+ } else {
54
+ this.activeCustomEditorId.set('');
55
+ }
56
+ if (newValue instanceof WebviewWidget) {
57
+ this.activeWebviewPanelId.set(newValue.viewType);
45
58
  } else {
46
59
  this.activeWebviewPanelId.set('');
47
60
  }
@@ -17,6 +17,7 @@
17
17
  import { interfaces } from '@theia/core/shared/inversify';
18
18
  import { WebviewWidget, WebviewWidgetIdentifier, WebviewWidgetExternalEndpoint } from './webview';
19
19
  import { WebviewEnvironment } from './webview-environment';
20
+ import { hashValue } from '@theia/core/lib/common/uuid';
20
21
 
21
22
  export class WebviewWidgetFactory {
22
23
 
@@ -30,7 +31,7 @@ export class WebviewWidgetFactory {
30
31
 
31
32
  async createWidget(identifier: WebviewWidgetIdentifier): Promise<WebviewWidget> {
32
33
  const externalEndpoint = await this.container.get(WebviewEnvironment).externalEndpoint();
33
- let endpoint = externalEndpoint.replace('{{uuid}}', identifier.id);
34
+ let endpoint = externalEndpoint.replace('{{uuid}}', identifier.viewId ? hashValue(identifier.viewId) : identifier.id);
34
35
  if (endpoint[endpoint.length - 1] === '/') {
35
36
  endpoint = endpoint.slice(0, endpoint.length - 1);
36
37
  }
@@ -97,6 +97,7 @@ export interface WebviewConsoleLog {
97
97
  @injectable()
98
98
  export class WebviewWidgetIdentifier {
99
99
  id: string;
100
+ viewId?: string;
100
101
  }
101
102
 
102
103
  export const WebviewWidgetExternalEndpoint = Symbol('WebviewWidgetExternalEndpoint');
@@ -404,6 +405,7 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
404
405
  () => {
405
406
  this.contextMenuRenderer.render({
406
407
  menuPath: WEBVIEW_CONTEXT_MENU,
408
+ args: [event.context],
407
409
  anchor: {
408
410
  x: domRect.x + event.clientX, y: domRect.y + event.clientY
409
411
  }
@@ -63,7 +63,7 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
63
63
  showOptions: WebviewPanelShowOptions,
64
64
  options: WebviewPanelOptions & WebviewOptions
65
65
  ): Promise<void> {
66
- const view = await this.widgetManager.getOrCreateWidget<WebviewWidget>(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: panelId });
66
+ const view = await this.widgetManager.getOrCreateWidget<WebviewWidget>(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id: panelId, viewId: viewType });
67
67
  this.hookWebview(view);
68
68
  view.viewType = viewType;
69
69
  view.title.label = title;
@@ -269,7 +269,12 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
269
269
  }
270
270
 
271
271
  private async tryGetWebview(id: string): Promise<WebviewWidget | undefined> {
272
- const webview = await this.widgetManager.getWidget<WebviewWidget>(WebviewWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id })
272
+ const webview = await this.widgetManager.findWidget<WebviewWidget>(WebviewWidget.FACTORY_ID, options => {
273
+ if (options) {
274
+ return options.id === id;
275
+ }
276
+ return false;
277
+ })
273
278
  || await this.widgetManager.getWidget<CustomEditorWidget>(CustomEditorWidget.FACTORY_ID, <WebviewWidgetIdentifier>{ id });
274
279
  return webview;
275
280
  }
@@ -0,0 +1,53 @@
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 { interfaces } from '@theia/core/shared/inversify';
18
+ import { MessageService } from '@theia/core/lib/common/message-service';
19
+ import { MessageRegistryMain, MainMessageType, MainMessageOptions, MainMessageItem } from '../../common/plugin-api-rpc';
20
+
21
+ /**
22
+ * A basic implementation of the message registry that does not support the modal option
23
+ * as that requires an UI.
24
+ */
25
+ export class BasicMessageRegistryMainImpl implements MessageRegistryMain {
26
+ protected readonly messageService: MessageService;
27
+
28
+ constructor(container: interfaces.Container) {
29
+ this.messageService = container.get(MessageService);
30
+ }
31
+
32
+ async $showMessage(type: MainMessageType, message: string, options: MainMessageOptions, actions: MainMessageItem[]): Promise<number | undefined> {
33
+ const action = await this.doShowMessage(type, message, options, actions);
34
+ const handle = action
35
+ ? actions.map(a => a.title).indexOf(action)
36
+ : undefined;
37
+ return handle === undefined && options.modal ? options.onCloseActionHandle : handle;
38
+ }
39
+
40
+ protected async doShowMessage(type: MainMessageType, message: string, options: MainMessageOptions, actions: MainMessageItem[]): Promise<string | undefined> {
41
+ // Modal notifications are not supported in this context
42
+ switch (type) {
43
+ case MainMessageType.Info:
44
+ return this.messageService.info(message, ...actions.map(a => a.title));
45
+ case MainMessageType.Warning:
46
+ return this.messageService.warn(message, ...actions.map(a => a.title));
47
+ case MainMessageType.Error:
48
+ return this.messageService.error(message, ...actions.map(a => a.title));
49
+ }
50
+ throw new Error(`Message type '${type}' is not supported yet!`);
51
+ }
52
+
53
+ }