@theia/plugin-ext 1.33.0 → 1.34.0-next.31

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 (117) hide show
  1. package/lib/common/collections.d.ts +5 -0
  2. package/lib/common/collections.d.ts.map +1 -0
  3. package/lib/common/collections.js +40 -0
  4. package/lib/common/collections.js.map +1 -0
  5. package/lib/common/plugin-api-rpc-model.d.ts +2 -0
  6. package/lib/common/plugin-api-rpc-model.d.ts.map +1 -1
  7. package/lib/common/plugin-api-rpc-model.js.map +1 -1
  8. package/lib/common/plugin-api-rpc.d.ts +108 -3
  9. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  10. package/lib/common/plugin-api-rpc.js +12 -8
  11. package/lib/common/plugin-api-rpc.js.map +1 -1
  12. package/lib/common/rpc-protocol.d.ts.map +1 -1
  13. package/lib/common/rpc-protocol.js +3 -4
  14. package/lib/common/rpc-protocol.js.map +1 -1
  15. package/lib/common/types.d.ts +5 -1
  16. package/lib/common/types.d.ts.map +1 -1
  17. package/lib/common/types.js +13 -4
  18. package/lib/common/types.js.map +1 -1
  19. package/lib/hosted/node/hosted-plugin-localization-service.d.ts.map +1 -1
  20. package/lib/hosted/node/hosted-plugin-localization-service.js +2 -2
  21. package/lib/hosted/node/hosted-plugin-localization-service.js.map +1 -1
  22. package/lib/hosted/node/plugin-host.d.ts +1 -1
  23. package/lib/hosted/node/plugin-host.d.ts.map +1 -1
  24. package/lib/hosted/node/plugin-host.js +1 -2
  25. package/lib/hosted/node/plugin-host.js.map +1 -1
  26. package/lib/main/browser/commands.js +1 -1
  27. package/lib/main/browser/commands.js.map +1 -1
  28. package/lib/main/browser/comments/comment-thread-widget.d.ts +1 -0
  29. package/lib/main/browser/comments/comment-thread-widget.d.ts.map +1 -1
  30. package/lib/main/browser/comments/comment-thread-widget.js +11 -0
  31. package/lib/main/browser/comments/comment-thread-widget.js.map +1 -1
  32. package/lib/main/browser/dialogs-main.d.ts.map +1 -1
  33. package/lib/main/browser/dialogs-main.js +2 -1
  34. package/lib/main/browser/dialogs-main.js.map +1 -1
  35. package/lib/main/browser/scm-main.d.ts +1 -0
  36. package/lib/main/browser/scm-main.d.ts.map +1 -1
  37. package/lib/main/browser/scm-main.js +7 -0
  38. package/lib/main/browser/scm-main.js.map +1 -1
  39. package/lib/main/browser/tabs/tabs-main.d.ts +10 -0
  40. package/lib/main/browser/tabs/tabs-main.d.ts.map +1 -0
  41. package/lib/main/browser/tabs/tabs-main.js +33 -0
  42. package/lib/main/browser/tabs/tabs-main.js.map +1 -0
  43. package/lib/main/browser/terminal-main.d.ts +6 -3
  44. package/lib/main/browser/terminal-main.d.ts.map +1 -1
  45. package/lib/main/browser/terminal-main.js +24 -2
  46. package/lib/main/browser/terminal-main.js.map +1 -1
  47. package/lib/main/browser/view/tree-view-decorator-service.d.ts +2 -4
  48. package/lib/main/browser/view/tree-view-decorator-service.d.ts.map +1 -1
  49. package/lib/main/browser/view/tree-view-decorator-service.js +1 -2
  50. package/lib/main/browser/view/tree-view-decorator-service.js.map +1 -1
  51. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts +1 -1
  52. package/lib/main/node/handlers/plugin-theia-directory-handler.d.ts.map +1 -1
  53. package/lib/plugin/comments.js +2 -0
  54. package/lib/plugin/comments.js.map +1 -1
  55. package/lib/plugin/languages/code-action.d.ts.map +1 -1
  56. package/lib/plugin/languages/code-action.js +8 -8
  57. package/lib/plugin/languages/code-action.js.map +1 -1
  58. package/lib/plugin/plugin-context.d.ts.map +1 -1
  59. package/lib/plugin/plugin-context.js +16 -1
  60. package/lib/plugin/plugin-context.js.map +1 -1
  61. package/lib/plugin/preference-registry.d.ts.map +1 -1
  62. package/lib/plugin/preference-registry.js +4 -2
  63. package/lib/plugin/preference-registry.js.map +1 -1
  64. package/lib/plugin/quick-open.d.ts +3 -0
  65. package/lib/plugin/quick-open.d.ts.map +1 -1
  66. package/lib/plugin/quick-open.js +7 -0
  67. package/lib/plugin/quick-open.js.map +1 -1
  68. package/lib/plugin/scm.d.ts +3 -0
  69. package/lib/plugin/scm.d.ts.map +1 -1
  70. package/lib/plugin/scm.js +7 -0
  71. package/lib/plugin/scm.js.map +1 -1
  72. package/lib/plugin/tabs.d.ts +23 -0
  73. package/lib/plugin/tabs.d.ts.map +1 -0
  74. package/lib/plugin/tabs.js +362 -0
  75. package/lib/plugin/tabs.js.map +1 -0
  76. package/lib/plugin/terminal-ext.d.ts +4 -0
  77. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  78. package/lib/plugin/terminal-ext.js +30 -2
  79. package/lib/plugin/terminal-ext.js.map +1 -1
  80. package/lib/plugin/type-converters.d.ts +8 -0
  81. package/lib/plugin/type-converters.d.ts.map +1 -1
  82. package/lib/plugin/type-converters.js +68 -46
  83. package/lib/plugin/type-converters.js.map +1 -1
  84. package/lib/plugin/type-converters.spec.js +19 -0
  85. package/lib/plugin/type-converters.spec.js.map +1 -1
  86. package/lib/plugin/types-impl.d.ts +76 -6
  87. package/lib/plugin/types-impl.d.ts.map +1 -1
  88. package/lib/plugin/types-impl.js +121 -16
  89. package/lib/plugin/types-impl.js.map +1 -1
  90. package/package.json +25 -25
  91. package/src/common/collections.ts +37 -0
  92. package/src/common/plugin-api-rpc-model.ts +2 -0
  93. package/src/common/plugin-api-rpc.ts +137 -13
  94. package/src/common/rpc-protocol.ts +2 -3
  95. package/src/common/types.ts +15 -4
  96. package/src/hosted/node/hosted-plugin-localization-service.ts +3 -3
  97. package/src/hosted/node/plugin-host.ts +1 -2
  98. package/src/main/browser/commands.ts +1 -1
  99. package/src/main/browser/comments/comment-thread-widget.tsx +11 -0
  100. package/src/main/browser/dialogs-main.ts +2 -1
  101. package/src/main/browser/scm-main.ts +10 -0
  102. package/src/main/browser/style/comments.css +6 -0
  103. package/src/main/browser/tabs/tabs-main.ts +42 -0
  104. package/src/main/browser/terminal-main.ts +25 -4
  105. package/src/main/browser/view/tree-view-decorator-service.ts +4 -5
  106. package/src/main/browser/webview/pre/main.js +112 -111
  107. package/src/plugin/comments.ts +2 -0
  108. package/src/plugin/languages/code-action.ts +8 -8
  109. package/src/plugin/plugin-context.ts +30 -5
  110. package/src/plugin/preference-registry.ts +4 -2
  111. package/src/plugin/quick-open.ts +10 -0
  112. package/src/plugin/scm.ts +11 -0
  113. package/src/plugin/tabs.ts +430 -0
  114. package/src/plugin/terminal-ext.ts +34 -3
  115. package/src/plugin/type-converters.spec.ts +20 -0
  116. package/src/plugin/type-converters.ts +73 -50
  117. package/src/plugin/types-impl.ts +126 -21
@@ -0,0 +1,430 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 TypeFox 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 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as theia from '@theia/plugin';
18
+ import { Emitter } from '@theia/core';
19
+ import { RPCProtocol } from '../common/rpc-protocol';
20
+ import { PLUGIN_RPC_CONTEXT, TabDto, TabGroupDto, TabInputKind, TabModelOperationKind, TabOperation, TabsExt, TabsMain } from '../common/plugin-api-rpc';
21
+ import {
22
+ CustomEditorTabInput,
23
+ InteractiveWindowInput,
24
+ NotebookDiffEditorTabInput,
25
+ NotebookEditorTabInput,
26
+ TerminalEditorTabInput,
27
+ TextDiffTabInput,
28
+ TextMergeTabInput,
29
+ TextTabInput,
30
+ URI,
31
+ WebviewEditorTabInput
32
+ } from './types-impl';
33
+ import { assertIsDefined } from '../common/types';
34
+ import { diffSets } from '../common/collections';
35
+ import { ViewColumn } from './type-converters';
36
+
37
+ /*---------------------------------------------------------------------------------------------
38
+ * Copyright (c) Microsoft Corporation. All rights reserved.
39
+ * Licensed under the MIT License. See License.txt in the project root for license information.
40
+ *--------------------------------------------------------------------------------------------*/
41
+ // some code copied and modified from https://github.com/microsoft/vscode/blob/1.71.2/src/vs/workbench/api/common/extHostEditorTabs.ts
42
+
43
+ type AnyTabInput =
44
+ TextTabInput |
45
+ TextDiffTabInput |
46
+ CustomEditorTabInput |
47
+ NotebookEditorTabInput |
48
+ NotebookDiffEditorTabInput |
49
+ WebviewEditorTabInput |
50
+ TerminalEditorTabInput |
51
+ InteractiveWindowInput;
52
+
53
+ class TabExt {
54
+ private tabApiObject: theia.Tab | undefined;
55
+ private tabDto!: TabDto;
56
+ private input: AnyTabInput | undefined;
57
+ private parentGroup: TabGroupExt;
58
+ private readonly activeTabIdGetter: () => string;
59
+
60
+ constructor(dto: TabDto, parentGroup: TabGroupExt, activeTabIdGetter: () => string) {
61
+ this.activeTabIdGetter = activeTabIdGetter;
62
+ this.parentGroup = parentGroup;
63
+ this.acceptDtoUpdate(dto);
64
+ }
65
+
66
+ get apiObject(): theia.Tab {
67
+ if (!this.tabApiObject) {
68
+ // Don't want to lose reference to parent `this` in the getters
69
+ const that = this;
70
+ const obj: theia.Tab = {
71
+ get isActive(): boolean {
72
+ // We use a getter function here to always ensure at most 1 active tab per group and prevent iteration for being required
73
+ return that.tabDto.id === that.activeTabIdGetter();
74
+ },
75
+ get label(): string {
76
+ return that.tabDto.label;
77
+ },
78
+ get input(): AnyTabInput | undefined {
79
+ return that.input;
80
+ },
81
+ get isDirty(): boolean {
82
+ return that.tabDto.isDirty;
83
+ },
84
+ get isPinned(): boolean {
85
+ return that.tabDto.isPinned;
86
+ },
87
+ get isPreview(): boolean {
88
+ return that.tabDto.isPreview;
89
+ },
90
+ get group(): theia.TabGroup {
91
+ return that.parentGroup.apiObject;
92
+ }
93
+ };
94
+ this.tabApiObject = Object.freeze<theia.Tab>(obj);
95
+ }
96
+ return this.tabApiObject;
97
+ }
98
+
99
+ get tabId(): string {
100
+ return this.tabDto.id;
101
+ }
102
+
103
+ acceptDtoUpdate(tabDto: TabDto): void {
104
+ this.tabDto = tabDto;
105
+ this.input = this.initInput();
106
+ }
107
+
108
+ private initInput(): AnyTabInput | undefined {
109
+ switch (this.tabDto.input.kind) {
110
+ case TabInputKind.TextInput:
111
+ return new TextTabInput(URI.revive(this.tabDto.input.uri));
112
+ case TabInputKind.TextDiffInput:
113
+ return new TextDiffTabInput(URI.revive(this.tabDto.input.original), URI.revive(this.tabDto.input.modified));
114
+ case TabInputKind.TextMergeInput:
115
+ return new TextMergeTabInput(
116
+ URI.revive(this.tabDto.input.base),
117
+ URI.revive(this.tabDto.input.input1),
118
+ URI.revive(this.tabDto.input.input2),
119
+ URI.revive(this.tabDto.input.result));
120
+ case TabInputKind.CustomEditorInput:
121
+ return new CustomEditorTabInput(URI.revive(this.tabDto.input.uri), this.tabDto.input.viewType);
122
+ case TabInputKind.WebviewEditorInput:
123
+ return new WebviewEditorTabInput(this.tabDto.input.viewType);
124
+ case TabInputKind.NotebookInput:
125
+ return new NotebookEditorTabInput(URI.revive(this.tabDto.input.uri), this.tabDto.input.notebookType);
126
+ case TabInputKind.NotebookDiffInput:
127
+ return new NotebookDiffEditorTabInput(URI.revive(this.tabDto.input.original), URI.revive(this.tabDto.input.modified), this.tabDto.input.notebookType);
128
+ case TabInputKind.TerminalEditorInput:
129
+ return new TerminalEditorTabInput();
130
+ case TabInputKind.InteractiveEditorInput:
131
+ return new InteractiveWindowInput(URI.revive(this.tabDto.input.uri), URI.revive(this.tabDto.input.inputBoxUri));
132
+ default:
133
+ return undefined;
134
+ }
135
+ }
136
+ }
137
+
138
+ class TabGroupExt {
139
+
140
+ private tabGroupApiObject: theia.TabGroup | undefined;
141
+ private tabGroupDto: TabGroupDto;
142
+ private tabsArr: TabExt[] = [];
143
+ private activeTabId: string = '';
144
+ private activeGroupIdGetter: () => number | undefined;
145
+
146
+ constructor(dto: TabGroupDto, activeGroupIdGetter: () => number | undefined) {
147
+ this.tabGroupDto = dto;
148
+ this.activeGroupIdGetter = activeGroupIdGetter;
149
+ // Construct all tabs from the given dto
150
+ for (const tabDto of dto.tabs) {
151
+ if (tabDto.isActive) {
152
+ this.activeTabId = tabDto.id;
153
+ }
154
+ this.tabsArr.push(new TabExt(tabDto, this, () => this.getActiveTabId()));
155
+ }
156
+ }
157
+
158
+ get apiObject(): theia.TabGroup {
159
+ if (!this.tabGroupApiObject) {
160
+ // Don't want to lose reference to parent `this` in the getters
161
+ const that = this;
162
+ const obj: theia.TabGroup = {
163
+ get isActive(): boolean {
164
+ // We use a getter function here to always ensure at most 1 active group and prevent iteration for being required
165
+ return that.tabGroupDto.groupId === that.activeGroupIdGetter();
166
+ },
167
+ get viewColumn(): theia.ViewColumn {
168
+ return ViewColumn.to(that.tabGroupDto.viewColumn);
169
+ },
170
+ get activeTab(): theia.Tab | undefined {
171
+ return that.tabsArr.find(tab => tab.tabId === that.activeTabId)?.apiObject;
172
+ },
173
+ get tabs(): Readonly<theia.Tab[]> {
174
+ return Object.freeze(that.tabsArr.map(tab => tab.apiObject));
175
+ }
176
+ };
177
+ this.tabGroupApiObject = Object.freeze<theia.TabGroup>(obj);
178
+ }
179
+ return this.tabGroupApiObject;
180
+ }
181
+
182
+ get groupId(): number {
183
+ return this.tabGroupDto.groupId;
184
+ }
185
+
186
+ get tabs(): TabExt[] {
187
+ return this.tabsArr;
188
+ }
189
+
190
+ acceptGroupDtoUpdate(dto: TabGroupDto): void {
191
+ this.tabGroupDto = dto;
192
+ }
193
+
194
+ acceptTabOperation(operation: TabOperation): TabExt {
195
+ // In the open case we add the tab to the group
196
+ if (operation.kind === TabModelOperationKind.TAB_OPEN) {
197
+ const tab = new TabExt(operation.tabDto, this, () => this.getActiveTabId());
198
+ // Insert tab at editor index
199
+ this.tabsArr.splice(operation.index, 0, tab);
200
+ if (operation.tabDto.isActive) {
201
+ this.activeTabId = tab.tabId;
202
+ }
203
+ return tab;
204
+ } else if (operation.kind === TabModelOperationKind.TAB_CLOSE) {
205
+ const tab = this.tabsArr.splice(operation.index, 1)[0];
206
+ if (!tab) {
207
+ throw new Error(`Tab close updated received for index ${operation.index} which does not exist`);
208
+ }
209
+ if (tab.tabId === this.activeTabId) {
210
+ this.activeTabId = '';
211
+ }
212
+ return tab;
213
+ } else if (operation.kind === TabModelOperationKind.TAB_MOVE) {
214
+ if (operation.oldIndex === undefined) {
215
+ throw new Error('Invalid old index on move IPC');
216
+ }
217
+ // Splice to remove at old index and insert at new index === moving the tab
218
+ const tab = this.tabsArr.splice(operation.oldIndex, 1)[0];
219
+ if (!tab) {
220
+ throw new Error(`Tab move updated received for index ${operation.oldIndex} which does not exist`);
221
+ }
222
+ this.tabsArr.splice(operation.index, 0, tab);
223
+ return tab;
224
+ }
225
+ const _tab = this.tabsArr.find(extHostTab => extHostTab.tabId === operation.tabDto.id);
226
+ if (!_tab) {
227
+ throw new Error('INVALID tab');
228
+ }
229
+ if (operation.tabDto.isActive) {
230
+ this.activeTabId = operation.tabDto.id;
231
+ } else if (this.activeTabId === operation.tabDto.id && !operation.tabDto.isActive) {
232
+ // Events aren't guaranteed to be in order so if we receive a dto that matches the active tab id
233
+ // but isn't active we mark the active tab id as empty. This prevent onDidActiveTabChange from
234
+ // firing incorrectly
235
+ this.activeTabId = '';
236
+ }
237
+ _tab.acceptDtoUpdate(operation.tabDto);
238
+ return _tab;
239
+ }
240
+
241
+ // Not a getter since it must be a function to be used as a callback for the tabs
242
+ getActiveTabId(): string {
243
+ return this.activeTabId;
244
+ }
245
+ }
246
+
247
+ export class TabsExtImpl implements TabsExt {
248
+ declare readonly _serviceBrand: undefined;
249
+
250
+ private readonly proxy: TabsMain;
251
+ private readonly onDidChangeTabs = new Emitter<theia.TabChangeEvent>();
252
+ private readonly onDidChangeTabGroups = new Emitter<theia.TabGroupChangeEvent>();
253
+
254
+ // Have to use ! because this gets initialized via an RPC proxy
255
+ private activeGroupId!: number;
256
+
257
+ private tabGroupArr: TabGroupExt[] = [];
258
+
259
+ private apiObject: theia.TabGroups | undefined;
260
+
261
+ constructor(readonly rpc: RPCProtocol) {
262
+ this.proxy = rpc.getProxy(PLUGIN_RPC_CONTEXT.TABS_MAIN);
263
+ }
264
+
265
+ get tabGroups(): theia.TabGroups {
266
+ if (!this.apiObject) {
267
+ const that = this;
268
+ const obj: theia.TabGroups = {
269
+ // never changes -> simple value
270
+ onDidChangeTabGroups: that.onDidChangeTabGroups.event,
271
+ onDidChangeTabs: that.onDidChangeTabs.event,
272
+ // dynamic -> getters
273
+ get all(): Readonly<theia.TabGroup[]> {
274
+ return Object.freeze(that.tabGroupArr.map(group => group.apiObject));
275
+ },
276
+ get activeTabGroup(): theia.TabGroup {
277
+ const activeTabGroupId = that.activeGroupId;
278
+ const activeTabGroup = assertIsDefined(that.tabGroupArr.find(candidate => candidate.groupId === activeTabGroupId)?.apiObject);
279
+ return activeTabGroup;
280
+ },
281
+ close: async (tabOrTabGroup: theia.Tab | readonly theia.Tab[] | theia.TabGroup | readonly theia.TabGroup[], preserveFocus?: boolean) => {
282
+ const tabsOrTabGroups = Array.isArray(tabOrTabGroup) ? tabOrTabGroup : [tabOrTabGroup];
283
+ if (!tabsOrTabGroups.length) {
284
+ return true;
285
+ }
286
+ // Check which type was passed in and call the appropriate close
287
+ // Casting is needed as typescript doesn't seem to infer enough from this
288
+ if (isTabGroup(tabsOrTabGroups[0])) {
289
+ return this._closeGroups(tabsOrTabGroups as theia.TabGroup[], preserveFocus);
290
+ } else {
291
+ return this._closeTabs(tabsOrTabGroups as theia.Tab[], preserveFocus);
292
+ }
293
+ },
294
+ // move: async (tab: theia.Tab, viewColumn: ViewColumn, index: number, preserveFocus?: boolean) => {
295
+ // const extHostTab = this._findExtHostTabFromApi(tab);
296
+ // if (!extHostTab) {
297
+ // throw new Error('Invalid tab');
298
+ // }
299
+ // this._proxy.$moveTab(extHostTab.tabId, index, typeConverters.ViewColumn.from(viewColumn), preserveFocus);
300
+ // return;
301
+ // }
302
+ };
303
+ this.apiObject = Object.freeze(obj);
304
+ }
305
+ return this.apiObject;
306
+ }
307
+
308
+ $acceptEditorTabModel(tabGroups: TabGroupDto[]): void {
309
+
310
+ const groupIdsBefore = new Set(this.tabGroupArr.map(group => group.groupId));
311
+ const groupIdsAfter = new Set(tabGroups.map(dto => dto.groupId));
312
+ const diff = diffSets(groupIdsBefore, groupIdsAfter);
313
+
314
+ const closed: theia.TabGroup[] = this.tabGroupArr.filter(group => diff.removed.includes(group.groupId)).map(group => group.apiObject);
315
+ const opened: theia.TabGroup[] = [];
316
+ const changed: theia.TabGroup[] = [];
317
+
318
+ this.tabGroupArr = tabGroups.map(tabGroup => {
319
+ const group = new TabGroupExt(tabGroup, () => this.activeGroupId);
320
+ if (diff.added.includes(group.groupId)) {
321
+ opened.push(group.apiObject);
322
+ } else {
323
+ changed.push(group.apiObject);
324
+ }
325
+ return group;
326
+ });
327
+
328
+ // Set the active tab group id
329
+ const activeTabGroupId = assertIsDefined(tabGroups.find(group => group.isActive === true)?.groupId);
330
+ if (activeTabGroupId !== undefined && this.activeGroupId !== activeTabGroupId) {
331
+ this.activeGroupId = activeTabGroupId;
332
+ }
333
+ this.onDidChangeTabGroups.fire(Object.freeze({ opened, closed, changed }));
334
+ }
335
+
336
+ $acceptTabGroupUpdate(groupDto: TabGroupDto): void {
337
+ const group = this.tabGroupArr.find(tabGroup => tabGroup.groupId === groupDto.groupId);
338
+ if (!group) {
339
+ throw new Error('Update Group IPC call received before group creation.');
340
+ }
341
+ group.acceptGroupDtoUpdate(groupDto);
342
+ if (groupDto.isActive) {
343
+ this.activeGroupId = groupDto.groupId;
344
+ }
345
+ this.onDidChangeTabGroups.fire(Object.freeze({ changed: [group.apiObject], opened: [], closed: [] }));
346
+ }
347
+
348
+ $acceptTabOperation(operation: TabOperation): void {
349
+ const group = this.tabGroupArr.find(tabGroup => tabGroup.groupId === operation.groupId);
350
+ if (!group) {
351
+ throw new Error('Update Tabs IPC call received before group creation.');
352
+ }
353
+ const tab = group.acceptTabOperation(operation);
354
+
355
+ // Construct the tab change event based on the operation
356
+ switch (operation.kind) {
357
+ case TabModelOperationKind.TAB_OPEN:
358
+ this.onDidChangeTabs.fire(Object.freeze({
359
+ opened: [tab.apiObject],
360
+ closed: [],
361
+ changed: []
362
+ }));
363
+ return;
364
+ case TabModelOperationKind.TAB_CLOSE:
365
+ this.onDidChangeTabs.fire(Object.freeze({
366
+ opened: [],
367
+ closed: [tab.apiObject],
368
+ changed: []
369
+ }));
370
+ return;
371
+ case TabModelOperationKind.TAB_MOVE:
372
+ case TabModelOperationKind.TAB_UPDATE:
373
+ this.onDidChangeTabs.fire(Object.freeze({
374
+ opened: [],
375
+ closed: [],
376
+ changed: [tab.apiObject]
377
+ }));
378
+ return;
379
+ }
380
+ }
381
+
382
+ private _findExtHostTabFromApi(apiTab: theia.Tab): TabExt | undefined {
383
+ for (const group of this.tabGroupArr) {
384
+ for (const tab of group.tabs) {
385
+ if (tab.apiObject === apiTab) {
386
+ return tab;
387
+ }
388
+ }
389
+ }
390
+ return;
391
+ }
392
+
393
+ private _findExtHostTabGroupFromApi(apiTabGroup: theia.TabGroup): TabGroupExt | undefined {
394
+ return this.tabGroupArr.find(candidate => candidate.apiObject === apiTabGroup);
395
+ }
396
+
397
+ private async _closeTabs(tabs: theia.Tab[], preserveFocus?: boolean): Promise<boolean> {
398
+ const extHostTabIds: string[] = [];
399
+ for (const tab of tabs) {
400
+ const extHostTab = this._findExtHostTabFromApi(tab);
401
+ if (!extHostTab) {
402
+ throw new Error('Tab close: Invalid tab not found!');
403
+ }
404
+ extHostTabIds.push(extHostTab.tabId);
405
+ }
406
+ return this.proxy.$closeTab(extHostTabIds, preserveFocus);
407
+ }
408
+
409
+ private async _closeGroups(groups: theia.TabGroup[], preserveFocus?: boolean): Promise<boolean> {
410
+ const extHostGroupIds: number[] = [];
411
+ for (const group of groups) {
412
+ const extHostGroup = this._findExtHostTabGroupFromApi(group);
413
+ if (!extHostGroup) {
414
+ throw new Error('Group close: Invalid group not found!');
415
+ }
416
+ extHostGroupIds.push(extHostGroup.groupId);
417
+ }
418
+ return this.proxy.$closeGroup(extHostGroupIds, preserveFocus);
419
+ }
420
+ }
421
+
422
+ // #region Utils
423
+ function isTabGroup(obj: unknown): obj is theia.TabGroup {
424
+ const tabGroup = obj as theia.TabGroup;
425
+ if (tabGroup.tabs !== undefined) {
426
+ return true;
427
+ }
428
+ return false;
429
+ }
430
+ // #endregion
@@ -20,9 +20,25 @@ import { RPCProtocol } from '../common/rpc-protocol';
20
20
  import { Event, Emitter } from '@theia/core/lib/common/event';
21
21
  import { Deferred } from '@theia/core/lib/common/promise-util';
22
22
  import * as theia from '@theia/plugin';
23
- import { Disposable, EnvironmentVariableMutatorType } from './types-impl';
23
+ import { Disposable, EnvironmentVariableMutatorType, ThemeIcon } from './types-impl';
24
24
  import { SerializableEnvironmentVariableCollection } from '@theia/terminal/lib/common/base-terminal-protocol';
25
25
  import { ProvidedTerminalLink } from '../common/plugin-api-rpc-model';
26
+ import { ThemeIcon as MonacoThemeIcon } from '@theia/monaco-editor-core/esm/vs/platform/theme/common/themeService';
27
+
28
+ export function getIconUris(iconPath: theia.TerminalOptions['iconPath']): { id: string } | undefined {
29
+ if (ThemeIcon.is(iconPath)) {
30
+ return { id: iconPath.id };
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ export function getIconClass(options: theia.TerminalOptions | theia.ExtensionTerminalOptions): string | undefined {
36
+ const iconClass = getIconUris(options.iconPath);
37
+ if (iconClass) {
38
+ return MonacoThemeIcon.asClassName(iconClass);
39
+ }
40
+ return undefined;
41
+ }
26
42
 
27
43
  /**
28
44
  * Provides high level terminal plugin api to use in the Theia plugins.
@@ -65,7 +81,7 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
65
81
  nameOrOptions: TerminalOptions | PseudoTerminalOptions | ExtensionTerminalOptions | (string | undefined),
66
82
  shellPath?: string, shellArgs?: string[] | string
67
83
  ): Terminal {
68
- let options: TerminalOptions;
84
+ let options: TerminalOptions | ExtensionTerminalOptions;
69
85
  let pseudoTerminal: theia.Pseudoterminal | undefined = undefined;
70
86
  const id = `plugin-terminal-${UUID.uuid4()}`;
71
87
  if (typeof nameOrOptions === 'object') {
@@ -85,7 +101,22 @@ export class TerminalServiceExtImpl implements TerminalServiceExt {
85
101
  shellArgs: shellArgs
86
102
  };
87
103
  }
88
- this.proxy.$createTerminal(id, options, !!pseudoTerminal);
104
+
105
+ let parentId;
106
+
107
+ if (options.location && typeof options.location === 'object' && 'parentTerminal' in options.location) {
108
+ const parentTerminal = options.location.parentTerminal;
109
+ if (parentTerminal instanceof TerminalExtImpl) {
110
+ for (const [k, v] of this._terminals) {
111
+ if (v === parentTerminal) {
112
+ parentId = k;
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ this.proxy.$createTerminal(id, options, parentId, !!pseudoTerminal);
89
120
 
90
121
  let creationOptions: theia.TerminalOptions | theia.ExtensionTerminalOptions = options;
91
122
  // make sure to pass ExtensionTerminalOptions as creation options
@@ -453,4 +453,24 @@ describe('Type converters:', () => {
453
453
  assert.deepStrictEqual(result, showOptions);
454
454
  });
455
455
  });
456
+
457
+ describe('#convertCode', () => {
458
+ it('should convert a "code" of type "string"', () => {
459
+ assert.strictEqual(Converter.convertCode('string'), 'string');
460
+ });
461
+ it('should convert a "code" of type "number"', () => {
462
+ assert.strictEqual(Converter.convertCode(4), '4');
463
+ });
464
+ it('should convert an undefined "code"', () => {
465
+ assert.strictEqual(Converter.convertCode(undefined), undefined);
466
+ });
467
+ it('should convert a "code" of type "{ value: number, target: Uri }"', () => {
468
+ const uri = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose');
469
+ assert.strictEqual(Converter.convertCode({ value: 4, target: uri }), '4');
470
+ });
471
+ it('should convert a "code" of type "{ value: number, target: Uri }"', () => {
472
+ const uri = types.URI.parse('foo://example.com:8042/over/there?name=ferret#nose');
473
+ assert.strictEqual(Converter.convertCode({ value: 'string', target: uri }), 'string');
474
+ });
475
+ });
456
476
  });