@theia/plugin-ext 1.42.0 → 1.43.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 (189) hide show
  1. package/lib/common/arrays.d.ts +4 -0
  2. package/lib/common/arrays.d.ts.map +1 -1
  3. package/lib/common/arrays.js +15 -1
  4. package/lib/common/arrays.js.map +1 -1
  5. package/lib/common/commands.d.ts +4 -0
  6. package/lib/common/commands.d.ts.map +1 -0
  7. package/lib/common/commands.js +17 -0
  8. package/lib/common/commands.js.map +1 -0
  9. package/lib/common/plugin-api-rpc-model.d.ts +1 -0
  10. package/lib/common/plugin-api-rpc-model.d.ts.map +1 -1
  11. package/lib/common/plugin-api-rpc-model.js.map +1 -1
  12. package/lib/common/plugin-api-rpc.d.ts +48 -6
  13. package/lib/common/plugin-api-rpc.d.ts.map +1 -1
  14. package/lib/common/plugin-api-rpc.js +3 -2
  15. package/lib/common/plugin-api-rpc.js.map +1 -1
  16. package/lib/common/plugin-protocol.d.ts +27 -3
  17. package/lib/common/plugin-protocol.d.ts.map +1 -1
  18. package/lib/common/plugin-protocol.js +8 -1
  19. package/lib/common/plugin-protocol.js.map +1 -1
  20. package/lib/common/test-types.d.ts +83 -0
  21. package/lib/common/test-types.d.ts.map +1 -0
  22. package/lib/common/test-types.js +40 -0
  23. package/lib/common/test-types.js.map +1 -0
  24. package/lib/hosted/browser/hosted-plugin.d.ts +4 -1
  25. package/lib/hosted/browser/hosted-plugin.d.ts.map +1 -1
  26. package/lib/hosted/browser/hosted-plugin.js +11 -0
  27. package/lib/hosted/browser/hosted-plugin.js.map +1 -1
  28. package/lib/hosted/node/hosted-plugin-localization-service.d.ts.map +1 -1
  29. package/lib/hosted/node/hosted-plugin-localization-service.js +71 -33
  30. package/lib/hosted/node/hosted-plugin-localization-service.js.map +1 -1
  31. package/lib/hosted/node/plugin-reader.d.ts.map +1 -1
  32. package/lib/hosted/node/plugin-reader.js +4 -2
  33. package/lib/hosted/node/plugin-reader.js.map +1 -1
  34. package/lib/hosted/node/scanners/scanner-theia.d.ts +5 -4
  35. package/lib/hosted/node/scanners/scanner-theia.d.ts.map +1 -1
  36. package/lib/hosted/node/scanners/scanner-theia.js +79 -19
  37. package/lib/hosted/node/scanners/scanner-theia.js.map +1 -1
  38. package/lib/main/browser/command-registry-main.d.ts +3 -0
  39. package/lib/main/browser/command-registry-main.d.ts.map +1 -1
  40. package/lib/main/browser/command-registry-main.js +11 -1
  41. package/lib/main/browser/command-registry-main.js.map +1 -1
  42. package/lib/main/browser/languages-main.d.ts.map +1 -1
  43. package/lib/main/browser/languages-main.js +7 -5
  44. package/lib/main/browser/languages-main.js.map +1 -1
  45. package/lib/main/browser/main-context.d.ts.map +1 -1
  46. package/lib/main/browser/main-context.js +3 -0
  47. package/lib/main/browser/main-context.js.map +1 -1
  48. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts +2 -2
  49. package/lib/main/browser/menus/vscode-theia-menu-mappings.d.ts.map +1 -1
  50. package/lib/main/browser/menus/vscode-theia-menu-mappings.js +3 -0
  51. package/lib/main/browser/menus/vscode-theia-menu-mappings.js.map +1 -1
  52. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js +2 -2
  53. package/lib/main/browser/notebooks/notebook-documents-and-editors-main.js.map +1 -1
  54. package/lib/main/browser/notebooks/notebook-documents-main.js +1 -1
  55. package/lib/main/browser/notebooks/notebook-documents-main.js.map +1 -1
  56. package/lib/main/browser/notebooks/notebook-dto.js +2 -2
  57. package/lib/main/browser/notebooks/notebook-dto.js.map +1 -1
  58. package/lib/main/browser/notebooks/notebook-kernels-main.d.ts.map +1 -1
  59. package/lib/main/browser/notebooks/notebook-kernels-main.js +4 -10
  60. package/lib/main/browser/notebooks/notebook-kernels-main.js.map +1 -1
  61. package/lib/main/browser/notebooks/notebook-renderers-main.js +1 -1
  62. package/lib/main/browser/notebooks/notebook-renderers-main.js.map +1 -1
  63. package/lib/main/browser/notebooks/notebooks-main.d.ts +2 -2
  64. package/lib/main/browser/notebooks/notebooks-main.d.ts.map +1 -1
  65. package/lib/main/browser/notebooks/notebooks-main.js +5 -5
  66. package/lib/main/browser/notebooks/notebooks-main.js.map +1 -1
  67. package/lib/main/browser/notebooks/renderers/cell-output-webview.d.ts.map +1 -1
  68. package/lib/main/browser/notebooks/renderers/cell-output-webview.js +3 -0
  69. package/lib/main/browser/notebooks/renderers/cell-output-webview.js.map +1 -1
  70. package/lib/main/browser/notebooks/renderers/output-webview-internal.d.ts.map +1 -1
  71. package/lib/main/browser/notebooks/renderers/output-webview-internal.js +4 -2
  72. package/lib/main/browser/notebooks/renderers/output-webview-internal.js.map +1 -1
  73. package/lib/main/browser/plugin-contribution-handler.d.ts +2 -0
  74. package/lib/main/browser/plugin-contribution-handler.d.ts.map +1 -1
  75. package/lib/main/browser/plugin-contribution-handler.js +19 -1
  76. package/lib/main/browser/plugin-contribution-handler.js.map +1 -1
  77. package/lib/main/browser/plugin-ext-frontend-module.d.ts.map +1 -1
  78. package/lib/main/browser/plugin-ext-frontend-module.js +3 -0
  79. package/lib/main/browser/plugin-ext-frontend-module.js.map +1 -1
  80. package/lib/main/browser/plugin-icon-service.d.ts +20 -0
  81. package/lib/main/browser/plugin-icon-service.d.ts.map +1 -0
  82. package/lib/main/browser/plugin-icon-service.js +156 -0
  83. package/lib/main/browser/plugin-icon-service.js.map +1 -0
  84. package/lib/main/browser/terminal-main.d.ts +2 -2
  85. package/lib/main/browser/terminal-main.d.ts.map +1 -1
  86. package/lib/main/browser/terminal-main.js +5 -9
  87. package/lib/main/browser/terminal-main.js.map +1 -1
  88. package/lib/main/browser/test-main.d.ts +141 -0
  89. package/lib/main/browser/test-main.d.ts.map +1 -0
  90. package/lib/main/browser/test-main.js +560 -0
  91. package/lib/main/browser/test-main.js.map +1 -0
  92. package/lib/main/browser/view/plugin-view-registry.d.ts +14 -3
  93. package/lib/main/browser/view/plugin-view-registry.d.ts.map +1 -1
  94. package/lib/main/browser/view/plugin-view-registry.js +108 -56
  95. package/lib/main/browser/view/plugin-view-registry.js.map +1 -1
  96. package/lib/main/browser/webview-views/webview-views-main.d.ts.map +1 -1
  97. package/lib/main/browser/webview-views/webview-views-main.js +5 -2
  98. package/lib/main/browser/webview-views/webview-views-main.js.map +1 -1
  99. package/lib/main/browser/webview-views/webview-views.d.ts +1 -0
  100. package/lib/main/browser/webview-views/webview-views.d.ts.map +1 -1
  101. package/lib/main/node/plugin-service.d.ts +2 -0
  102. package/lib/main/node/plugin-service.d.ts.map +1 -1
  103. package/lib/main/node/plugin-service.js +14 -1
  104. package/lib/main/node/plugin-service.js.map +1 -1
  105. package/lib/plugin/command-registry.d.ts +1 -3
  106. package/lib/plugin/command-registry.d.ts.map +1 -1
  107. package/lib/plugin/command-registry.js.map +1 -1
  108. package/lib/plugin/notebook/notebook-kernels.d.ts.map +1 -1
  109. package/lib/plugin/notebook/notebook-kernels.js +1 -0
  110. package/lib/plugin/notebook/notebook-kernels.js.map +1 -1
  111. package/lib/plugin/notebook/notebooks.d.ts.map +1 -1
  112. package/lib/plugin/notebook/notebooks.js +2 -2
  113. package/lib/plugin/notebook/notebooks.js.map +1 -1
  114. package/lib/plugin/plugin-context.d.ts.map +1 -1
  115. package/lib/plugin/plugin-context.js +9 -18
  116. package/lib/plugin/plugin-context.js.map +1 -1
  117. package/lib/plugin/telemetry-ext.js +1 -1
  118. package/lib/plugin/telemetry-ext.js.map +1 -1
  119. package/lib/plugin/terminal-ext.d.ts +11 -9
  120. package/lib/plugin/terminal-ext.d.ts.map +1 -1
  121. package/lib/plugin/terminal-ext.js +37 -25
  122. package/lib/plugin/terminal-ext.js.map +1 -1
  123. package/lib/plugin/test-item.d.ts +47 -0
  124. package/lib/plugin/test-item.d.ts.map +1 -0
  125. package/lib/plugin/test-item.js +196 -0
  126. package/lib/plugin/test-item.js.map +1 -0
  127. package/lib/plugin/tests.d.ts +117 -0
  128. package/lib/plugin/tests.d.ts.map +1 -0
  129. package/lib/plugin/tests.js +402 -0
  130. package/lib/plugin/tests.js.map +1 -0
  131. package/lib/plugin/tree/tree-views.d.ts.map +1 -1
  132. package/lib/plugin/tree/tree-views.js +2 -1
  133. package/lib/plugin/tree/tree-views.js.map +1 -1
  134. package/lib/plugin/type-converters.d.ts +10 -1
  135. package/lib/plugin/type-converters.d.ts.map +1 -1
  136. package/lib/plugin/type-converters.js +74 -2
  137. package/lib/plugin/type-converters.js.map +1 -1
  138. package/lib/plugin/types-impl.d.ts +29 -4
  139. package/lib/plugin/types-impl.d.ts.map +1 -1
  140. package/lib/plugin/types-impl.js +30 -8
  141. package/lib/plugin/types-impl.js.map +1 -1
  142. package/package.json +30 -29
  143. package/src/common/arrays.ts +16 -0
  144. package/src/common/commands.ts +19 -0
  145. package/src/common/plugin-api-rpc-model.ts +1 -0
  146. package/src/common/plugin-api-rpc.ts +69 -7
  147. package/src/common/plugin-protocol.ts +31 -3
  148. package/src/common/test-types.ts +133 -0
  149. package/src/hosted/browser/hosted-plugin.ts +13 -1
  150. package/src/hosted/node/hosted-plugin-localization-service.ts +72 -37
  151. package/src/hosted/node/plugin-reader.ts +4 -2
  152. package/src/hosted/node/scanners/scanner-theia.ts +85 -20
  153. package/src/main/browser/command-registry-main.ts +14 -1
  154. package/src/main/browser/languages-main.ts +7 -5
  155. package/src/main/browser/main-context.ts +4 -0
  156. package/src/main/browser/menus/vscode-theia-menu-mappings.ts +3 -0
  157. package/src/main/browser/notebooks/notebook-documents-and-editors-main.ts +2 -2
  158. package/src/main/browser/notebooks/notebook-documents-main.ts +1 -1
  159. package/src/main/browser/notebooks/notebook-dto.ts +2 -2
  160. package/src/main/browser/notebooks/notebook-kernels-main.ts +6 -11
  161. package/src/main/browser/notebooks/notebook-renderers-main.ts +1 -1
  162. package/src/main/browser/notebooks/notebooks-main.ts +6 -6
  163. package/src/main/browser/notebooks/renderers/cell-output-webview.tsx +3 -0
  164. package/src/main/browser/notebooks/renderers/output-webview-internal.ts +3 -2
  165. package/src/main/browser/plugin-contribution-handler.ts +19 -2
  166. package/src/main/browser/plugin-ext-frontend-module.ts +4 -0
  167. package/src/main/browser/plugin-icon-service.ts +156 -0
  168. package/src/main/browser/terminal-main.ts +7 -11
  169. package/src/main/browser/test-main.ts +618 -0
  170. package/src/main/browser/view/plugin-view-registry.ts +114 -56
  171. package/src/main/browser/webview-views/webview-views-main.ts +5 -2
  172. package/src/main/browser/webview-views/webview-views.ts +1 -0
  173. package/src/main/node/plugin-service.ts +12 -1
  174. package/src/plugin/command-registry.ts +1 -5
  175. package/src/plugin/notebook/notebook-kernels.ts +3 -1
  176. package/src/plugin/notebook/notebooks.ts +1 -3
  177. package/src/plugin/plugin-context.ts +13 -32
  178. package/src/plugin/telemetry-ext.ts +1 -1
  179. package/src/plugin/terminal-ext.ts +40 -26
  180. package/src/plugin/test-item.ts +174 -0
  181. package/src/plugin/tests.ts +482 -0
  182. package/src/plugin/tree/tree-views.ts +2 -1
  183. package/src/plugin/type-converters.ts +87 -3
  184. package/src/plugin/types-impl.ts +36 -5
  185. package/lib/plugin/stubs/tests-api.d.ts +0 -25
  186. package/lib/plugin/stubs/tests-api.d.ts.map +0 -1
  187. package/lib/plugin/stubs/tests-api.js +0 -70
  188. package/lib/plugin/stubs/tests-api.js.map +0 -1
  189. package/src/plugin/stubs/tests-api.ts +0 -102
@@ -0,0 +1,618 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 ST Microelectronics, 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 { SimpleObservableCollection, TreeCollection, observableProperty } from '@theia/test/lib/common/collections';
18
+ import {
19
+ TestController, TestItem, TestOutputItem, TestRun, TestRunProfile, TestService, TestState, TestStateChangedEvent
20
+ } from '@theia/test/lib/browser/test-service';
21
+ import { AccumulatingTreeDeltaEmitter, CollectionDelta, DeltaKind, TreeDelta, TreeDeltaBuilder } from '@theia/test/lib/common/tree-delta';
22
+ import { Emitter, Location, Range } from '@theia/core/shared/vscode-languageserver-protocol';
23
+ import { Range as PluginRange, Location as PluginLocation } from '../../common/plugin-api-rpc-model';
24
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
25
+ import { CancellationToken, Disposable, Event, URI } from '@theia/core';
26
+ import { MAIN_RPC_CONTEXT, TestControllerUpdate, TestingExt, TestingMain } from '../../common';
27
+ import { RPCProtocol } from '../../common/rpc-protocol';
28
+ import { interfaces } from '@theia/core/shared/inversify';
29
+ import { TestExecutionState, TestItemDTO, TestItemReference, TestOutputDTO, TestRunDTO, TestRunProfileDTO, TestStateChangeDTO } from '../../common/test-types';
30
+ import { TestRunProfileKind } from '../../plugin/types-impl';
31
+ import { CommandRegistryMainImpl } from './command-registry-main';
32
+
33
+ export class TestItemCollection extends TreeCollection<string, TestItemImpl, TestItemImpl | TestControllerImpl> {
34
+ override add(item: TestItemImpl): TestItemImpl | undefined {
35
+ item.realParent = this.owner;
36
+ return super.add(item);
37
+ }
38
+ }
39
+
40
+ export class TestItemImpl implements TestItem {
41
+ update(value: Partial<TestItemDTO>): void {
42
+ if ('label' in value) {
43
+ this.label = value.label!;
44
+ }
45
+
46
+ if ('range' in value) {
47
+ this.range = convertRange(value.range);
48
+ }
49
+
50
+ if ('sortKey' in value) {
51
+ this.sortKey = value.sortKey!;
52
+ }
53
+
54
+ if ('tags' in value) {
55
+ this.tags = value.tags!;
56
+ }
57
+ if ('busy' in value) {
58
+ this.busy = value.busy!;
59
+ }
60
+ if ('sortKey' in value) {
61
+ this.sortKey = value.sortKey;
62
+ }
63
+ if ('canResolveChildren' in value) {
64
+ this.canResolveChildren = value.canResolveChildren!;
65
+ }
66
+ if ('description' in value) {
67
+ this.description = value.description;
68
+ }
69
+
70
+ if ('error' in value) {
71
+ this.error = value.error;
72
+ }
73
+ }
74
+
75
+ constructor(readonly uri: URI, readonly id: string) {
76
+ this.items = new TestItemCollection(this, (v: TestItemImpl) => v.path, (v: TestItemImpl) => v.deltaBuilder);
77
+ }
78
+
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ protected notifyPropertyChange(property: keyof TestItemImpl, value: any): void {
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ const val: any = {};
83
+ val[property] = value;
84
+ if (this.path) {
85
+ this.deltaBuilder?.reportChanged(this.path, val);
86
+ }
87
+ }
88
+
89
+ _deltaBuilder: TreeDeltaBuilder<string, TestItemImpl> | undefined;
90
+ get deltaBuilder(): TreeDeltaBuilder<string, TestItemImpl> | undefined {
91
+ if (this._deltaBuilder) {
92
+ return this._deltaBuilder;
93
+ } else if (this.realParent) {
94
+ this._deltaBuilder = this.realParent.deltaBuilder;
95
+ return this._deltaBuilder;
96
+ } else {
97
+ return undefined;
98
+ }
99
+ }
100
+
101
+ _path: string[] | undefined;
102
+
103
+ get path(): string[] {
104
+ if (this._path) {
105
+ return this._path;
106
+ } else if (this.realParent instanceof TestItemImpl) {
107
+ this._path = [...this.realParent.path, this.id];
108
+ return this._path;
109
+ } else {
110
+ return [this.id];
111
+ }
112
+ };
113
+
114
+ get parent(): TestItem | undefined {
115
+ const realParent = this.realParent;
116
+ if (realParent instanceof TestItemImpl) {
117
+ return realParent;
118
+ }
119
+ return undefined;
120
+ }
121
+
122
+ private _parent?: TestItemImpl | TestControllerImpl;
123
+ get realParent(): TestItemImpl | TestControllerImpl | undefined {
124
+ return this._parent;
125
+ }
126
+
127
+ set realParent(v: TestItemImpl | TestControllerImpl | undefined) {
128
+ this.iterate(item => {
129
+ item._path = undefined;
130
+ return true;
131
+ });
132
+ this._parent = v;
133
+ }
134
+
135
+ get controller(): TestControllerImpl | undefined {
136
+ return this.realParent?.controller;
137
+ }
138
+
139
+ protected iterate(toDo: (v: TestItemImpl) => boolean): boolean {
140
+ if (toDo(this)) {
141
+ for (let i = 0; i < this.items.values.length; i++) {
142
+ if (!this.items.values[i].iterate(toDo)) {
143
+ return false;
144
+ }
145
+ }
146
+ return true;
147
+ } else {
148
+ return false;
149
+ }
150
+ }
151
+
152
+ @observableProperty('notifyPropertyChange')
153
+ label: string = '';
154
+
155
+ @observableProperty('notifyPropertyChange')
156
+ range?: Range;
157
+
158
+ @observableProperty('notifyPropertyChange')
159
+ sortKey?: string | undefined;
160
+
161
+ @observableProperty('notifyPropertyChange')
162
+ tags: string[] = [];
163
+
164
+ @observableProperty('notifyPropertyChange')
165
+ busy: boolean = false;
166
+
167
+ @observableProperty('notifyPropertyChange')
168
+ canResolveChildren: boolean = false;
169
+
170
+ @observableProperty('notifyPropertyChange')
171
+ description?: string | undefined;
172
+
173
+ @observableProperty('notifyPropertyChange')
174
+ error?: string | MarkdownString | undefined;
175
+
176
+ items: TestItemCollection;
177
+ get tests(): readonly TestItemImpl[] {
178
+ return this.items.values;
179
+ }
180
+
181
+ resolveChildren(): void {
182
+ if (this.canResolveChildren) {
183
+ this.controller?.resolveChildren(this);
184
+ }
185
+ }
186
+ }
187
+
188
+ function itemToPath(item: TestItem): string[] {
189
+ if (!(item instanceof TestItemImpl)) {
190
+ throw new Error(`Not a TestItemImpl: ${item.id}`);
191
+ }
192
+ return item.path;
193
+ }
194
+
195
+ class TestRunProfileImpl implements TestRunProfile {
196
+
197
+ label: string;
198
+ isDefault: boolean;
199
+ tag: string;
200
+ canConfigure: boolean;
201
+
202
+ update(update: Partial<TestRunProfileDTO>): void {
203
+ if ('label' in update) {
204
+ this.label = update.label!;
205
+ }
206
+
207
+ if ('isDefault' in update) {
208
+ this.isDefault = update.isDefault!;
209
+ }
210
+
211
+ if ('tag' in update) {
212
+ this.tag = update.tag!;
213
+ }
214
+
215
+ if ('canConfigure' in update) {
216
+ this.canConfigure = update.canConfigure!;
217
+ }
218
+
219
+ }
220
+
221
+ constructor(
222
+ private proxy: TestingExt,
223
+ private controllerId: string,
224
+ readonly id: string,
225
+ readonly kind: TestRunProfileKind,
226
+ label: string,
227
+ isDefault: boolean,
228
+ tag: string) {
229
+
230
+ this.label = label;
231
+ this.isDefault = isDefault;
232
+ this.tag = tag;
233
+ }
234
+
235
+ configure(): void {
236
+ this.proxy.$onConfigureRunProfile(this.controllerId, this.id);
237
+ }
238
+
239
+ run(name: string, included: TestItem[], excluded: TestItem[]): void {
240
+ this.proxy.$onRunControllerTests([{
241
+ controllerId: this.controllerId,
242
+ name,
243
+ profileId: this.id,
244
+ includedTests: included.map(item => itemToPath(item)),
245
+ excludedTests: excluded.map(item => itemToPath(item))
246
+ }]);
247
+ }
248
+ }
249
+
250
+ class TestRunImpl implements TestRun {
251
+ private testStates: Map<TestItem, TestState> = new Map();
252
+ private outputIndices: Map<TestItem, number[]> = new Map();
253
+ private outputs: TestOutputItem[] = [];
254
+ private onDidChangePropertyEmitter = new Emitter<{ name?: string; isRunning?: boolean; }>();
255
+ onDidChangeProperty: Event<{ name?: string; isRunning?: boolean; }> = this.onDidChangePropertyEmitter.event;
256
+
257
+ constructor(readonly controller: TestControllerImpl, readonly proxy: TestingExt, readonly id: string, name: string) {
258
+ this.name = name;
259
+ this.isRunning = false;
260
+ }
261
+
262
+ @observableProperty('notifyPropertyChange')
263
+ isRunning: boolean;
264
+
265
+ @observableProperty('notifyPropertyChange')
266
+ name: string;
267
+
268
+ ended(): void {
269
+ const stateEvents: TestStateChangedEvent[] = [];
270
+ this.testStates.forEach((state, item) => {
271
+ if (state.state <= TestExecutionState.Running) {
272
+ stateEvents.push({
273
+ oldState: state,
274
+ newState: undefined,
275
+ test: item
276
+ });
277
+ this.testStates.delete(item);
278
+ }
279
+ });
280
+ if (stateEvents.length > 0) {
281
+ this.onDidChangeTestStateEmitter.fire(stateEvents);
282
+ }
283
+ this.isRunning = false;
284
+ }
285
+
286
+ protected notifyPropertyChange(property: 'name' | 'isRunning', value: unknown): void {
287
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
288
+ const val: any = {};
289
+ val[property] = value;
290
+ this.onDidChangePropertyEmitter.fire(val);
291
+ }
292
+
293
+ cancel(): void {
294
+ this.proxy.$onCancelTestRun(this.controller.id, this.id);
295
+ }
296
+
297
+ getTestState(item: TestItem): TestState | undefined {
298
+ return this.testStates.get(item);
299
+ }
300
+
301
+ private onDidChangeTestStateEmitter: Emitter<TestStateChangedEvent[]> = new Emitter();
302
+ onDidChangeTestState: Event<TestStateChangedEvent[]> = this.onDidChangeTestStateEmitter.event;
303
+
304
+ getOutput(item?: TestItem | undefined): readonly TestOutputItem[] {
305
+ if (!item) {
306
+ return this.outputs;
307
+ } else {
308
+ const indices = this.outputIndices.get(item);
309
+ if (!indices) {
310
+ return [];
311
+ } else {
312
+ return indices.map(index => this.outputs[index]);
313
+ }
314
+ }
315
+ }
316
+ private onDidChangeTestOutputEmitter: Emitter<[TestItem | undefined, TestOutputItem][]> = new Emitter();
317
+ onDidChangeTestOutput: Event<[TestItem | undefined, TestOutputItem][]> = this.onDidChangeTestOutputEmitter.event;
318
+
319
+ applyChanges(stateChanges: TestStateChangeDTO[], outputChanges: TestOutputDTO[]): void {
320
+ const stateEvents: TestStateChangedEvent[] = [];
321
+ stateChanges.forEach(change => {
322
+ const item = this.controller.findItem(change.itemPath);
323
+ if (item) {
324
+ const oldState = this.testStates.get(item);
325
+ this.testStates.set(item, change);
326
+ stateEvents.push({ test: item, oldState: oldState, newState: change });
327
+ }
328
+ });
329
+ const outputEvents: [TestItem | undefined, TestOutputItem][] = [];
330
+ outputChanges.forEach(change => {
331
+ const output = {
332
+ output: change.output,
333
+ location: convertLocation(change.location)
334
+ };
335
+ this.outputs.push(output);
336
+ let item = undefined;
337
+ if (change.itemPath) {
338
+ item = this.controller.findItem(change.itemPath);
339
+ if (item) {
340
+ let indices = this.outputIndices.get(item);
341
+ if (!indices) {
342
+ indices = [];
343
+ this.outputIndices.set(item, indices);
344
+ }
345
+ indices.push(this.outputs.length - 1);
346
+ }
347
+ }
348
+ outputEvents.push([item, output]);
349
+ });
350
+
351
+ this.onDidChangeTestStateEmitter.fire(stateEvents);
352
+ this.onDidChangeTestOutputEmitter.fire(outputEvents);
353
+ }
354
+
355
+ get items(): readonly TestItem[] {
356
+ return [...this.testStates.keys()];
357
+ }
358
+ }
359
+
360
+ function convertLocation(location: PluginLocation | undefined): Location | undefined {
361
+ if (!location) {
362
+ return undefined;
363
+ }
364
+ return {
365
+ uri: location.uri.toString(),
366
+ range: convertRange(location.range)
367
+ };
368
+ }
369
+
370
+ interface TestCollectionHolder {
371
+ items: TestItemCollection;
372
+ }
373
+
374
+ function convertRange(range: PluginRange): Range;
375
+ function convertRange(range: PluginRange | undefined): Range | undefined;
376
+ function convertRange(range: PluginRange | undefined): Range | undefined {
377
+ if (range) {
378
+ return {
379
+ start: {
380
+ line: range.startLineNumber,
381
+ character: range.startColumn
382
+ }, end: {
383
+ line: range.endLineNumber,
384
+ character: range.endColumn
385
+
386
+ }
387
+ };
388
+ }
389
+ return undefined;
390
+
391
+ }
392
+
393
+ class TestControllerImpl implements TestController {
394
+
395
+ private _profiles = new SimpleObservableCollection<TestRunProfileImpl>();
396
+ private _runs = new SimpleObservableCollection<TestRunImpl>();
397
+ readonly deltaBuilder = new AccumulatingTreeDeltaEmitter<string, TestItemImpl>(300);
398
+ canRefresh: boolean;
399
+ private canResolveChildren: boolean = false;
400
+ readonly items = new TestItemCollection(this, item => item.path, () => this.deltaBuilder);
401
+
402
+ constructor(private readonly proxy: TestingExt, readonly id: string, public label: string) {
403
+ }
404
+ refreshTests(token: CancellationToken): Promise<void> {
405
+ return this.proxy.$refreshTests(this.id, token);
406
+ }
407
+
408
+ applyDelta(diff: TreeDelta<string, TestItemDTO>[]): void {
409
+ this.applyDeltasToCollection(this, diff);
410
+ }
411
+
412
+ withProfile(profileId: string): TestRunProfileImpl {
413
+ const profile = this._profiles.values.find(p => p.id === profileId);
414
+ if (!profile) {
415
+ throw new Error(`No test profile ${profileId} found in controller with id ${this.id} found`);
416
+ }
417
+ return profile;
418
+
419
+ }
420
+
421
+ withRun(runId: string): TestRunImpl {
422
+ const run = this._runs.values.find(p => p.id === runId);
423
+ if (!run) {
424
+ throw new Error(`No test profile ${runId} found in controller with id ${this.id} found`);
425
+ }
426
+ return run;
427
+ }
428
+
429
+ protected applyDeltasToCollection(root: TestCollectionHolder, deltas: TreeDelta<string, TestItemDTO>[]): void {
430
+ deltas.forEach(delta => this.applyDeltaToCollection(root, delta));
431
+ }
432
+
433
+ protected applyDeltaToCollection(root: TestCollectionHolder, delta: TreeDelta<string, TestItemDTO>): void {
434
+ if (delta.type === DeltaKind.ADDED || delta.type === DeltaKind.REMOVED) {
435
+ const node = this.findNodeInRoot(root, delta.path.slice(0, delta.path.length - 1), 0);
436
+ if (node) {
437
+ if (delta.type === DeltaKind.ADDED) {
438
+ node.items.add(this.createTestItem(delta.value! as TestItemDTO));
439
+ } else {
440
+ node.items.remove(delta.path[delta.path.length - 1]);
441
+ }
442
+ }
443
+ } else {
444
+ const node = this.findNodeInRoot(root, delta.path, 0);
445
+ if (node) {
446
+ if (delta.type === DeltaKind.CHANGED) {
447
+ (node as TestItemImpl).update(delta.value!);
448
+ }
449
+ if (delta.childDeltas) {
450
+ this.applyDeltasToCollection(node, delta.childDeltas);
451
+ }
452
+ }
453
+ }
454
+ }
455
+
456
+ findItem(path: string[]): TestItemImpl | undefined {
457
+ if (path.length === 0) {
458
+ console.warn('looking for item with zero-path');
459
+ return undefined;
460
+ }
461
+ return this.findNodeInRoot(this, path, 0) as TestItemImpl;
462
+ }
463
+
464
+ protected findNodeInRoot(root: TestCollectionHolder, path: string[], startIndex: number): TestCollectionHolder | undefined {
465
+ if (startIndex >= path.length) {
466
+ return root;
467
+ }
468
+ const child = root.items.get(path[startIndex]);
469
+ if (!child) {
470
+ return undefined;
471
+ }
472
+ return this.findNodeInRoot(child, path, startIndex + 1);
473
+ }
474
+
475
+ protected createTestItem(value: TestItemDTO): TestItemImpl {
476
+ const item = new TestItemImpl(URI.fromComponents(value.uri!), value?.id!);
477
+
478
+ item.update(value);
479
+
480
+ value.children?.forEach(child => item.items.add(this.createTestItem(child)));
481
+
482
+ return item;
483
+ }
484
+
485
+ get controller(): TestControllerImpl {
486
+ return this;
487
+ }
488
+
489
+ get testRunProfiles(): readonly TestRunProfile[] {
490
+ return this._profiles.values;
491
+ }
492
+
493
+ update(change: Partial<TestControllerUpdate>): void {
494
+ if ('canRefresh' in change) {
495
+ this.canRefresh = change.canRefresh!;
496
+ }
497
+ if ('canResolve' in change) {
498
+ this.canResolveChildren = change.canResolve!;
499
+ }
500
+ if ('label' in change) {
501
+ this.label = change.label!;
502
+ }
503
+ }
504
+
505
+ addProfile(profile: TestRunProfileImpl): void {
506
+ this._profiles.add(profile);
507
+ }
508
+
509
+ addRun(runId: string, runName: string, isRunning: boolean): TestRunImpl {
510
+ const run = new TestRunImpl(this, this.proxy, runId, runName);
511
+ run.isRunning = isRunning;
512
+ this._runs.add(run);
513
+ return run;
514
+ }
515
+
516
+ onProfilesChanged: Event<CollectionDelta<TestRunProfile, TestRunProfile>> = this._profiles.onChanged;
517
+
518
+ removeProfile(profileId: string): void {
519
+ this._profiles.remove(this.withProfile(profileId));
520
+ }
521
+
522
+ get testRuns(): readonly TestRun[] {
523
+ return this._runs.values;
524
+ }
525
+ onRunsChanged: Event<CollectionDelta<TestRun, TestRun>> = this._runs.onChanged;
526
+
527
+ get tests(): readonly TestItemImpl[] {
528
+ return this.items.values;
529
+ }
530
+ onItemsChanged: Event<TreeDelta<string, TestItemImpl>[]> = this.deltaBuilder.onDidFlush;
531
+
532
+ resolveChildren(item: TestItem): void {
533
+ if (this.canResolveChildren) {
534
+ this.proxy.$onResolveChildren(this.id, itemToPath(item));
535
+ }
536
+ }
537
+
538
+ clearRuns(): void {
539
+ this._runs.clear();
540
+ }
541
+ }
542
+
543
+ export class TestingMainImpl implements TestingMain {
544
+ private testService: TestService;
545
+ private controllerRegistrations = new Map<string, [TestControllerImpl, Disposable]>();
546
+ private proxy: TestingExt;
547
+ canRefresh: boolean;
548
+
549
+ constructor(rpc: RPCProtocol, container: interfaces.Container, commandRegistry: CommandRegistryMainImpl) {
550
+ this.testService = container.get(TestService);
551
+ this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.TESTING_EXT);
552
+ commandRegistry.registerArgumentProcessor({
553
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
554
+ processArgument(arg: any): any {
555
+ if (arg instanceof TestItemImpl) {
556
+ if (!arg.controller || !arg.path) {
557
+ throw new Error(`Passing unattached test item ${arg.id} as a command argument`);
558
+ }
559
+ return TestItemReference.create(arg.controller.id, arg.path);
560
+ }
561
+ return arg;
562
+ }
563
+ });
564
+ }
565
+
566
+ $registerTestController(controllerId: string, label: string): void {
567
+ const controller = new TestControllerImpl(this.proxy, controllerId, label);
568
+ this.controllerRegistrations.set(controllerId, [controller, this.testService.registerTestController(controller)]);
569
+ }
570
+ $updateController(controllerId: string, patch: Partial<TestControllerUpdate>): void {
571
+ this.withController(controllerId).update(patch);
572
+ }
573
+
574
+ $unregisterTestController(controllerId: string): void {
575
+ const registered = this.controllerRegistrations.get(controllerId);
576
+ if (registered) {
577
+ this.controllerRegistrations.delete(controllerId);
578
+ registered[1].dispose();
579
+ }
580
+ }
581
+
582
+ private withController(controllerId: string): TestControllerImpl {
583
+ const registration = this.controllerRegistrations.get(controllerId);
584
+ if (!registration) {
585
+ throw new Error(`No test controller with id ${controllerId} found`);
586
+ }
587
+ return registration[0];
588
+ }
589
+
590
+ $notifyDelta(controllerId: string, diff: TreeDelta<string, TestItemDTO>[]): void {
591
+ this.withController(controllerId).applyDelta(diff);
592
+ }
593
+
594
+ $notifyTestRunProfileCreated(controllerId: string, profile: TestRunProfileDTO): void {
595
+ const registration = this.controllerRegistrations.get(controllerId);
596
+ if (!registration) {
597
+ throw new Error(`No test controller with id ${controllerId} found`);
598
+ }
599
+ registration[0].addProfile(new TestRunProfileImpl(this.proxy, controllerId, profile.id, profile.kind, profile.label, profile.isDefault, profile.tag));
600
+ }
601
+
602
+ $updateTestRunProfile(controllerId: string, profileId: string, update: Partial<TestRunProfileDTO>): void {
603
+ this.withController(controllerId).withProfile(profileId).update(update);
604
+ }
605
+ $removeTestRunProfile(controllerId: string, profileId: string): void {
606
+ this.withController(controllerId).removeProfile(profileId);
607
+ }
608
+ $notifyTestRunCreated(controllerId: string, run: TestRunDTO): void {
609
+ this.withController(controllerId).addRun(run.id, run.name, run.isRunning);
610
+ }
611
+ $notifyTestStateChanged(controllerId: string, runId: string, stateChanges: TestStateChangeDTO[], outputChanges: TestOutputDTO[]): void {
612
+ this.withController(controllerId).withRun(runId).applyChanges(stateChanges, outputChanges);
613
+ }
614
+
615
+ $notifyTestRunEnded(controllerId: string, runId: string): void {
616
+ this.withController(controllerId).withRun(runId).ended();
617
+ }
618
+ }