@theia/markers 1.34.3 → 1.34.4

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 (82) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +33 -33
  3. package/lib/browser/index.d.ts +2 -2
  4. package/lib/browser/index.js +29 -29
  5. package/lib/browser/marker-manager.d.ts +47 -47
  6. package/lib/browser/marker-manager.js +187 -187
  7. package/lib/browser/marker-tree-label-provider.d.ts +15 -15
  8. package/lib/browser/marker-tree-label-provider.js +84 -84
  9. package/lib/browser/marker-tree-label-provider.spec.d.ts +1 -1
  10. package/lib/browser/marker-tree-label-provider.spec.js +201 -201
  11. package/lib/browser/marker-tree-model.d.ts +12 -12
  12. package/lib/browser/marker-tree-model.js +60 -60
  13. package/lib/browser/marker-tree.d.ts +42 -42
  14. package/lib/browser/marker-tree.js +143 -143
  15. package/lib/browser/problem/problem-composite-tree-node.d.ts +8 -8
  16. package/lib/browser/problem/problem-composite-tree-node.js +68 -68
  17. package/lib/browser/problem/problem-composite-tree-node.spec.d.ts +1 -1
  18. package/lib/browser/problem/problem-composite-tree-node.spec.js +216 -216
  19. package/lib/browser/problem/problem-container.d.ts +8 -8
  20. package/lib/browser/problem/problem-container.js +42 -42
  21. package/lib/browser/problem/problem-contribution.d.ts +51 -51
  22. package/lib/browser/problem/problem-contribution.js +247 -247
  23. package/lib/browser/problem/problem-decorations-provider.d.ts +18 -18
  24. package/lib/browser/problem/problem-decorations-provider.js +92 -92
  25. package/lib/browser/problem/problem-decorator.d.ts +57 -57
  26. package/lib/browser/problem/problem-decorator.js +233 -233
  27. package/lib/browser/problem/problem-frontend-module.d.ts +4 -4
  28. package/lib/browser/problem/problem-frontend-module.js +55 -55
  29. package/lib/browser/problem/problem-layout-migrations.d.ts +5 -5
  30. package/lib/browser/problem/problem-layout-migrations.js +43 -43
  31. package/lib/browser/problem/problem-manager.d.ts +11 -11
  32. package/lib/browser/problem/problem-manager.js +53 -53
  33. package/lib/browser/problem/problem-manager.spec.d.ts +1 -1
  34. package/lib/browser/problem/problem-manager.spec.js +167 -167
  35. package/lib/browser/problem/problem-preferences.d.ts +13 -13
  36. package/lib/browser/problem/problem-preferences.js +56 -56
  37. package/lib/browser/problem/problem-selection.d.ts +12 -12
  38. package/lib/browser/problem/problem-selection.js +34 -34
  39. package/lib/browser/problem/problem-tabbar-decorator.d.ts +42 -42
  40. package/lib/browser/problem/problem-tabbar-decorator.js +160 -160
  41. package/lib/browser/problem/problem-tree-model.d.ts +26 -26
  42. package/lib/browser/problem/problem-tree-model.js +122 -122
  43. package/lib/browser/problem/problem-tree-model.spec.d.ts +1 -1
  44. package/lib/browser/problem/problem-tree-model.spec.js +172 -172
  45. package/lib/browser/problem/problem-utils.d.ts +44 -44
  46. package/lib/browser/problem/problem-utils.js +84 -84
  47. package/lib/browser/problem/problem-widget-tab-bar-decorator.d.ts +14 -14
  48. package/lib/browser/problem/problem-widget-tab-bar-decorator.js +69 -69
  49. package/lib/browser/problem/problem-widget.d.ts +45 -45
  50. package/lib/browser/problem/problem-widget.js +231 -231
  51. package/lib/common/marker.d.ts +16 -16
  52. package/lib/common/marker.js +31 -31
  53. package/lib/common/problem-marker.d.ts +9 -9
  54. package/lib/common/problem-marker.js +27 -27
  55. package/package.json +6 -6
  56. package/src/browser/index.ts +18 -18
  57. package/src/browser/marker-manager.ts +205 -205
  58. package/src/browser/marker-tree-label-provider.spec.ts +245 -245
  59. package/src/browser/marker-tree-label-provider.ts +75 -75
  60. package/src/browser/marker-tree-model.ts +47 -47
  61. package/src/browser/marker-tree.ts +154 -154
  62. package/src/browser/problem/problem-composite-tree-node.spec.ts +255 -255
  63. package/src/browser/problem/problem-composite-tree-node.ts +68 -68
  64. package/src/browser/problem/problem-container.ts +47 -47
  65. package/src/browser/problem/problem-contribution.ts +247 -247
  66. package/src/browser/problem/problem-decorations-provider.ts +67 -67
  67. package/src/browser/problem/problem-decorator.ts +222 -222
  68. package/src/browser/problem/problem-frontend-module.ts +64 -64
  69. package/src/browser/problem/problem-layout-migrations.ts +32 -32
  70. package/src/browser/problem/problem-manager.spec.ts +216 -216
  71. package/src/browser/problem/problem-manager.ts +51 -51
  72. package/src/browser/problem/problem-preferences.ts +64 -64
  73. package/src/browser/problem/problem-selection.ts +45 -45
  74. package/src/browser/problem/problem-tabbar-decorator.ts +151 -151
  75. package/src/browser/problem/problem-tree-model.spec.ts +189 -189
  76. package/src/browser/problem/problem-tree-model.ts +113 -113
  77. package/src/browser/problem/problem-utils.ts +90 -90
  78. package/src/browser/problem/problem-widget-tab-bar-decorator.ts +55 -55
  79. package/src/browser/problem/problem-widget.tsx +241 -241
  80. package/src/browser/style/index.css +92 -92
  81. package/src/common/marker.ts +53 -53
  82. package/src/common/problem-marker.ts +30 -30
@@ -1,245 +1,245 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 Ericsson 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 { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
18
-
19
- let disableJSDOM = enableJSDOM();
20
-
21
- import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
22
- FrontendApplicationConfigProvider.set({});
23
-
24
- import URI from '@theia/core/lib/common/uri';
25
- import { expect } from 'chai';
26
- import { Container } from '@theia/core/shared/inversify';
27
- import { ContributionProvider, Event } from '@theia/core/lib/common';
28
- import { LabelProvider, LabelProviderContribution, DefaultUriLabelProviderContribution, ApplicationShell, WidgetManager } from '@theia/core/lib/browser';
29
- import { MarkerInfoNode } from './marker-tree';
30
- import { MarkerTreeLabelProvider } from './marker-tree-label-provider';
31
- import { TreeLabelProvider } from '@theia/core/lib/browser/tree/tree-label-provider';
32
- import { WorkspaceService } from '@theia/workspace/lib/browser';
33
- import { WorkspaceUriLabelProviderContribution } from '@theia/workspace/lib/browser/workspace-uri-contribution';
34
- import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
35
- import { FileService } from '@theia/filesystem/lib/browser/file-service';
36
- import { FileStat } from '@theia/filesystem/lib/common/files';
37
- import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
38
- import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
39
- import { FileUri } from '@theia/core/lib/node';
40
- import { OS } from '@theia/core/lib/common/os';
41
- import * as temp from 'temp';
42
-
43
- disableJSDOM();
44
-
45
- let markerTreeLabelProvider: MarkerTreeLabelProvider;
46
- let workspaceService: WorkspaceService;
47
-
48
- before(() => {
49
- disableJSDOM = enableJSDOM();
50
- const testContainer = new Container();
51
-
52
- workspaceService = new WorkspaceService();
53
- testContainer.bind(WorkspaceService).toConstantValue(workspaceService);
54
- testContainer.bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
55
- testContainer.bind(ApplicationShell).toConstantValue({
56
- onDidChangeCurrentWidget: () => undefined,
57
- widgets: []
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- } as any);
60
- testContainer.bind(WidgetManager).toConstantValue({
61
- onDidCreateWidget: Event.None
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
- } as any);
64
- testContainer.bind(FileService).toConstantValue(<FileService>{});
65
-
66
- testContainer.bind(DefaultUriLabelProviderContribution).toSelf().inSingletonScope();
67
- testContainer.bind(WorkspaceUriLabelProviderContribution).toSelf().inSingletonScope();
68
- testContainer.bind(LabelProvider).toSelf().inSingletonScope();
69
- testContainer.bind(MarkerTreeLabelProvider).toSelf().inSingletonScope();
70
- testContainer.bind(TreeLabelProvider).toSelf().inSingletonScope();
71
- testContainer.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(FileUri.create(temp.track().mkdirSync())));
72
-
73
- testContainer.bind<ContributionProvider<LabelProviderContribution>>(ContributionProvider).toDynamicValue(ctx => ({
74
- getContributions(): LabelProviderContribution[] {
75
- return [
76
- ctx.container.get<MarkerTreeLabelProvider>(MarkerTreeLabelProvider),
77
- ctx.container.get<TreeLabelProvider>(TreeLabelProvider),
78
- ctx.container.get<WorkspaceUriLabelProviderContribution>(WorkspaceUriLabelProviderContribution),
79
- ctx.container.get<DefaultUriLabelProviderContribution>(DefaultUriLabelProviderContribution)
80
- ];
81
- }
82
- })).inSingletonScope();
83
-
84
- markerTreeLabelProvider = testContainer.get<MarkerTreeLabelProvider>(MarkerTreeLabelProvider);
85
- workspaceService = testContainer.get<WorkspaceService>(WorkspaceService);
86
- });
87
-
88
- after(() => {
89
- disableJSDOM();
90
- });
91
-
92
- describe('Marker Tree Label Provider', () => {
93
-
94
- describe('#getName', () => {
95
- it('should return the correct filename and extension', () => {
96
- const label = markerTreeLabelProvider.getName(
97
- createMarkerInfoNode('a/b/c/foo.ts')
98
- );
99
- expect(label).equals('foo.ts');
100
- });
101
- });
102
-
103
- describe('getLongName', () => {
104
- describe('single-root workspace', () => {
105
- beforeEach(() => {
106
- const root = FileStat.dir('file:///home/a');
107
- workspaceService['_workspace'] = root;
108
- workspaceService['_roots'] = [root];
109
- });
110
- it('should return the proper label for a directory', () => {
111
- const label = markerTreeLabelProvider.getLongName(
112
- createMarkerInfoNode('file:///home/a/b/c/foo.ts')
113
- );
114
- expect(label).equals('b/c');
115
- });
116
- it('should return the proper label for a directory starting with \'.\'', () => {
117
- const label = markerTreeLabelProvider.getLongName(
118
- createMarkerInfoNode('file:///home/a/b/.c/foo.ts')
119
- );
120
- expect(label).equals('b/.c');
121
- });
122
- it('should return the proper label when the resource is located at the workspace root', () => {
123
- const label = markerTreeLabelProvider.getLongName(
124
- createMarkerInfoNode('file:///home/a/foo.ts')
125
- );
126
- expect(label).equals('');
127
- });
128
- it('should return the full path when the resource does not exist in the workspace root', () => {
129
- const label = markerTreeLabelProvider.getLongName(
130
- createMarkerInfoNode('file:///home/b/foo.ts')
131
- );
132
- if (OS.backend.isWindows) {
133
- expect(label).eq('\\home\\b');
134
- } else {
135
- expect(label).eq('/home/b');
136
- }
137
- });
138
- });
139
- describe('multi-root workspace', () => {
140
- beforeEach(() => {
141
- const uri: string = 'file:///file';
142
- const file = FileStat.file(uri);
143
- const root1 = FileStat.dir('file:///root1');
144
- const root2 = FileStat.dir('file:///root2');
145
- workspaceService['_workspace'] = file;
146
- workspaceService['_roots'] = [root1, root2];
147
- });
148
- it('should return the proper root \'root1\' and directory', () => {
149
- const label = markerTreeLabelProvider.getLongName(
150
- createMarkerInfoNode('file:///root1/foo/foo.ts')
151
- );
152
- expect(label).equals('root1 ● foo');
153
- });
154
- it('should return the proper root \'root2\' and directory', () => {
155
- const label = markerTreeLabelProvider.getLongName(
156
- createMarkerInfoNode('file:///root2/foo/foo.ts')
157
- );
158
- expect(label).equals('root2 ● foo');
159
- });
160
- it('should only return the root when the resource is located at the workspace root', () => {
161
- const label = markerTreeLabelProvider.getLongName(
162
- createMarkerInfoNode('file:///root1/foo.ts')
163
- );
164
- expect(label).equals('root1');
165
- });
166
- it('should return the full path when the resource does not exist in any workspace root', () => {
167
- const label = markerTreeLabelProvider.getLongName(
168
- createMarkerInfoNode('file:///home/a/b/foo.ts')
169
- );
170
-
171
- if (OS.backend.isWindows) {
172
- expect(label).eq('\\home\\a\\b');
173
- } else {
174
- expect(label).eq('/home/a/b');
175
- }
176
- });
177
- });
178
- });
179
-
180
- describe('#getIcon', () => {
181
- it('should return a typescript icon for a typescript file', () => {
182
- const icon = markerTreeLabelProvider.getIcon(
183
- createMarkerInfoNode('a/b/c/foo.ts')
184
- );
185
- expect(icon).contain('ts-icon');
186
- });
187
- it('should return a json icon for a json file', () => {
188
- const icon = markerTreeLabelProvider.getIcon(
189
- createMarkerInfoNode('a/b/c/foo.json')
190
- );
191
- expect(icon).contain('database-icon');
192
- });
193
- it('should return a generic icon for a file with no extension', () => {
194
- const icon = markerTreeLabelProvider.getIcon(
195
- createMarkerInfoNode('a/b/c/foo.md')
196
- );
197
- expect(icon).contain('markdown-icon');
198
- });
199
- });
200
-
201
- describe('#getDescription', () => {
202
- beforeEach(() => {
203
- const root = FileStat.dir('file:///home/a');
204
- workspaceService['_workspace'] = root;
205
- workspaceService['_roots'] = [root];
206
- });
207
- it('should return the parent\' long name', () => {
208
- const label = markerTreeLabelProvider.getDescription(
209
- createMarkerInfoNode('file:///home/a/b/c/foo.ts')
210
- );
211
- expect(label).equals('b/c');
212
- });
213
- });
214
-
215
- describe('#canHandle', () => {
216
- it('should successfully handle \'MarkerInfoNodes\'', () => {
217
- const node = createMarkerInfoNode('a/b/c/foo.ts');
218
- expect(markerTreeLabelProvider.canHandle(node)).greaterThan(0);
219
- });
220
- });
221
-
222
- });
223
-
224
- /**
225
- * Create a marker info node for test purposes.
226
- * @param uri the marker uri.
227
- *
228
- * @returns a mock marker info node.
229
- */
230
- function createMarkerInfoNode(uri: string): MarkerInfoNode {
231
- return {
232
- id: 'id',
233
- parent: {
234
- id: 'parent-id',
235
- kind: '',
236
- parent: undefined,
237
- children: []
238
- },
239
- numberOfMarkers: 1,
240
- children: [],
241
- expanded: true,
242
- selected: true,
243
- uri: new URI(uri)
244
- };
245
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 Ericsson 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 { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
18
+
19
+ let disableJSDOM = enableJSDOM();
20
+
21
+ import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
22
+ FrontendApplicationConfigProvider.set({});
23
+
24
+ import URI from '@theia/core/lib/common/uri';
25
+ import { expect } from 'chai';
26
+ import { Container } from '@theia/core/shared/inversify';
27
+ import { ContributionProvider, Event } from '@theia/core/lib/common';
28
+ import { LabelProvider, LabelProviderContribution, DefaultUriLabelProviderContribution, ApplicationShell, WidgetManager } from '@theia/core/lib/browser';
29
+ import { MarkerInfoNode } from './marker-tree';
30
+ import { MarkerTreeLabelProvider } from './marker-tree-label-provider';
31
+ import { TreeLabelProvider } from '@theia/core/lib/browser/tree/tree-label-provider';
32
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
33
+ import { WorkspaceUriLabelProviderContribution } from '@theia/workspace/lib/browser/workspace-uri-contribution';
34
+ import { WorkspaceVariableContribution } from '@theia/workspace/lib/browser/workspace-variable-contribution';
35
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
36
+ import { FileStat } from '@theia/filesystem/lib/common/files';
37
+ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
38
+ import { MockEnvVariablesServerImpl } from '@theia/core/lib/browser/test/mock-env-variables-server';
39
+ import { FileUri } from '@theia/core/lib/node';
40
+ import { OS } from '@theia/core/lib/common/os';
41
+ import * as temp from 'temp';
42
+
43
+ disableJSDOM();
44
+
45
+ let markerTreeLabelProvider: MarkerTreeLabelProvider;
46
+ let workspaceService: WorkspaceService;
47
+
48
+ before(() => {
49
+ disableJSDOM = enableJSDOM();
50
+ const testContainer = new Container();
51
+
52
+ workspaceService = new WorkspaceService();
53
+ testContainer.bind(WorkspaceService).toConstantValue(workspaceService);
54
+ testContainer.bind(WorkspaceVariableContribution).toSelf().inSingletonScope();
55
+ testContainer.bind(ApplicationShell).toConstantValue({
56
+ onDidChangeCurrentWidget: () => undefined,
57
+ widgets: []
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ } as any);
60
+ testContainer.bind(WidgetManager).toConstantValue({
61
+ onDidCreateWidget: Event.None
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ } as any);
64
+ testContainer.bind(FileService).toConstantValue(<FileService>{});
65
+
66
+ testContainer.bind(DefaultUriLabelProviderContribution).toSelf().inSingletonScope();
67
+ testContainer.bind(WorkspaceUriLabelProviderContribution).toSelf().inSingletonScope();
68
+ testContainer.bind(LabelProvider).toSelf().inSingletonScope();
69
+ testContainer.bind(MarkerTreeLabelProvider).toSelf().inSingletonScope();
70
+ testContainer.bind(TreeLabelProvider).toSelf().inSingletonScope();
71
+ testContainer.bind(EnvVariablesServer).toConstantValue(new MockEnvVariablesServerImpl(FileUri.create(temp.track().mkdirSync())));
72
+
73
+ testContainer.bind<ContributionProvider<LabelProviderContribution>>(ContributionProvider).toDynamicValue(ctx => ({
74
+ getContributions(): LabelProviderContribution[] {
75
+ return [
76
+ ctx.container.get<MarkerTreeLabelProvider>(MarkerTreeLabelProvider),
77
+ ctx.container.get<TreeLabelProvider>(TreeLabelProvider),
78
+ ctx.container.get<WorkspaceUriLabelProviderContribution>(WorkspaceUriLabelProviderContribution),
79
+ ctx.container.get<DefaultUriLabelProviderContribution>(DefaultUriLabelProviderContribution)
80
+ ];
81
+ }
82
+ })).inSingletonScope();
83
+
84
+ markerTreeLabelProvider = testContainer.get<MarkerTreeLabelProvider>(MarkerTreeLabelProvider);
85
+ workspaceService = testContainer.get<WorkspaceService>(WorkspaceService);
86
+ });
87
+
88
+ after(() => {
89
+ disableJSDOM();
90
+ });
91
+
92
+ describe('Marker Tree Label Provider', () => {
93
+
94
+ describe('#getName', () => {
95
+ it('should return the correct filename and extension', () => {
96
+ const label = markerTreeLabelProvider.getName(
97
+ createMarkerInfoNode('a/b/c/foo.ts')
98
+ );
99
+ expect(label).equals('foo.ts');
100
+ });
101
+ });
102
+
103
+ describe('getLongName', () => {
104
+ describe('single-root workspace', () => {
105
+ beforeEach(() => {
106
+ const root = FileStat.dir('file:///home/a');
107
+ workspaceService['_workspace'] = root;
108
+ workspaceService['_roots'] = [root];
109
+ });
110
+ it('should return the proper label for a directory', () => {
111
+ const label = markerTreeLabelProvider.getLongName(
112
+ createMarkerInfoNode('file:///home/a/b/c/foo.ts')
113
+ );
114
+ expect(label).equals('b/c');
115
+ });
116
+ it('should return the proper label for a directory starting with \'.\'', () => {
117
+ const label = markerTreeLabelProvider.getLongName(
118
+ createMarkerInfoNode('file:///home/a/b/.c/foo.ts')
119
+ );
120
+ expect(label).equals('b/.c');
121
+ });
122
+ it('should return the proper label when the resource is located at the workspace root', () => {
123
+ const label = markerTreeLabelProvider.getLongName(
124
+ createMarkerInfoNode('file:///home/a/foo.ts')
125
+ );
126
+ expect(label).equals('');
127
+ });
128
+ it('should return the full path when the resource does not exist in the workspace root', () => {
129
+ const label = markerTreeLabelProvider.getLongName(
130
+ createMarkerInfoNode('file:///home/b/foo.ts')
131
+ );
132
+ if (OS.backend.isWindows) {
133
+ expect(label).eq('\\home\\b');
134
+ } else {
135
+ expect(label).eq('/home/b');
136
+ }
137
+ });
138
+ });
139
+ describe('multi-root workspace', () => {
140
+ beforeEach(() => {
141
+ const uri: string = 'file:///file';
142
+ const file = FileStat.file(uri);
143
+ const root1 = FileStat.dir('file:///root1');
144
+ const root2 = FileStat.dir('file:///root2');
145
+ workspaceService['_workspace'] = file;
146
+ workspaceService['_roots'] = [root1, root2];
147
+ });
148
+ it('should return the proper root \'root1\' and directory', () => {
149
+ const label = markerTreeLabelProvider.getLongName(
150
+ createMarkerInfoNode('file:///root1/foo/foo.ts')
151
+ );
152
+ expect(label).equals('root1 ● foo');
153
+ });
154
+ it('should return the proper root \'root2\' and directory', () => {
155
+ const label = markerTreeLabelProvider.getLongName(
156
+ createMarkerInfoNode('file:///root2/foo/foo.ts')
157
+ );
158
+ expect(label).equals('root2 ● foo');
159
+ });
160
+ it('should only return the root when the resource is located at the workspace root', () => {
161
+ const label = markerTreeLabelProvider.getLongName(
162
+ createMarkerInfoNode('file:///root1/foo.ts')
163
+ );
164
+ expect(label).equals('root1');
165
+ });
166
+ it('should return the full path when the resource does not exist in any workspace root', () => {
167
+ const label = markerTreeLabelProvider.getLongName(
168
+ createMarkerInfoNode('file:///home/a/b/foo.ts')
169
+ );
170
+
171
+ if (OS.backend.isWindows) {
172
+ expect(label).eq('\\home\\a\\b');
173
+ } else {
174
+ expect(label).eq('/home/a/b');
175
+ }
176
+ });
177
+ });
178
+ });
179
+
180
+ describe('#getIcon', () => {
181
+ it('should return a typescript icon for a typescript file', () => {
182
+ const icon = markerTreeLabelProvider.getIcon(
183
+ createMarkerInfoNode('a/b/c/foo.ts')
184
+ );
185
+ expect(icon).contain('ts-icon');
186
+ });
187
+ it('should return a json icon for a json file', () => {
188
+ const icon = markerTreeLabelProvider.getIcon(
189
+ createMarkerInfoNode('a/b/c/foo.json')
190
+ );
191
+ expect(icon).contain('database-icon');
192
+ });
193
+ it('should return a generic icon for a file with no extension', () => {
194
+ const icon = markerTreeLabelProvider.getIcon(
195
+ createMarkerInfoNode('a/b/c/foo.md')
196
+ );
197
+ expect(icon).contain('markdown-icon');
198
+ });
199
+ });
200
+
201
+ describe('#getDescription', () => {
202
+ beforeEach(() => {
203
+ const root = FileStat.dir('file:///home/a');
204
+ workspaceService['_workspace'] = root;
205
+ workspaceService['_roots'] = [root];
206
+ });
207
+ it('should return the parent\' long name', () => {
208
+ const label = markerTreeLabelProvider.getDescription(
209
+ createMarkerInfoNode('file:///home/a/b/c/foo.ts')
210
+ );
211
+ expect(label).equals('b/c');
212
+ });
213
+ });
214
+
215
+ describe('#canHandle', () => {
216
+ it('should successfully handle \'MarkerInfoNodes\'', () => {
217
+ const node = createMarkerInfoNode('a/b/c/foo.ts');
218
+ expect(markerTreeLabelProvider.canHandle(node)).greaterThan(0);
219
+ });
220
+ });
221
+
222
+ });
223
+
224
+ /**
225
+ * Create a marker info node for test purposes.
226
+ * @param uri the marker uri.
227
+ *
228
+ * @returns a mock marker info node.
229
+ */
230
+ function createMarkerInfoNode(uri: string): MarkerInfoNode {
231
+ return {
232
+ id: 'id',
233
+ parent: {
234
+ id: 'parent-id',
235
+ kind: '',
236
+ parent: undefined,
237
+ children: []
238
+ },
239
+ numberOfMarkers: 1,
240
+ children: [],
241
+ expanded: true,
242
+ selected: true,
243
+ uri: new URI(uri)
244
+ };
245
+ }
@@ -1,75 +1,75 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 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 { injectable, inject } from '@theia/core/shared/inversify';
18
- import { LabelProvider, LabelProviderContribution, DidChangeLabelEvent } from '@theia/core/lib/browser/label-provider';
19
- import { MarkerInfoNode } from './marker-tree';
20
- import { TreeLabelProvider } from '@theia/core/lib/browser/tree/tree-label-provider';
21
- import { WorkspaceService } from '@theia/workspace/lib/browser';
22
-
23
- @injectable()
24
- export class MarkerTreeLabelProvider implements LabelProviderContribution {
25
-
26
- @inject(LabelProvider)
27
- protected readonly labelProvider: LabelProvider;
28
-
29
- @inject(TreeLabelProvider)
30
- protected readonly treeLabelProvider: TreeLabelProvider;
31
-
32
- @inject(WorkspaceService)
33
- protected readonly workspaceService: WorkspaceService;
34
-
35
- canHandle(element: object): number {
36
- return MarkerInfoNode.is(element) ?
37
- this.treeLabelProvider.canHandle(element) + 1 :
38
- 0;
39
- }
40
-
41
- getIcon(node: MarkerInfoNode): string {
42
- return this.labelProvider.getIcon(node.uri);
43
- }
44
-
45
- getName(node: MarkerInfoNode): string {
46
- return this.labelProvider.getName(node.uri);
47
- }
48
-
49
- getLongName(node: MarkerInfoNode): string {
50
- const description: string[] = [];
51
- const rootUri = this.workspaceService.getWorkspaceRootUri(node.uri);
52
- // In a multiple-root workspace include the root name to the label before the parent directory.
53
- if (this.workspaceService.isMultiRootWorkspaceOpened && rootUri) {
54
- description.push(this.labelProvider.getName(rootUri));
55
- }
56
- // If the given resource is not at the workspace root, include the parent directory to the label.
57
- if (rootUri && rootUri.toString() !== node.uri.parent.toString()) {
58
- description.push(this.labelProvider.getLongName(node.uri.parent));
59
- }
60
- // Get the full path of a resource which does not exist in the given workspace.
61
- if (!rootUri) {
62
- description.push(this.labelProvider.getLongName(node.uri.parent.withScheme('markers')));
63
- }
64
- return description.join(' ● ');
65
- }
66
-
67
- getDescription(node: MarkerInfoNode): string {
68
- return this.labelProvider.getLongName(node.uri.parent);
69
- }
70
-
71
- affects(node: MarkerInfoNode, event: DidChangeLabelEvent): boolean {
72
- return event.affects(node.uri) || event.affects(node.uri.parent);
73
- }
74
-
75
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 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 { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { LabelProvider, LabelProviderContribution, DidChangeLabelEvent } from '@theia/core/lib/browser/label-provider';
19
+ import { MarkerInfoNode } from './marker-tree';
20
+ import { TreeLabelProvider } from '@theia/core/lib/browser/tree/tree-label-provider';
21
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
22
+
23
+ @injectable()
24
+ export class MarkerTreeLabelProvider implements LabelProviderContribution {
25
+
26
+ @inject(LabelProvider)
27
+ protected readonly labelProvider: LabelProvider;
28
+
29
+ @inject(TreeLabelProvider)
30
+ protected readonly treeLabelProvider: TreeLabelProvider;
31
+
32
+ @inject(WorkspaceService)
33
+ protected readonly workspaceService: WorkspaceService;
34
+
35
+ canHandle(element: object): number {
36
+ return MarkerInfoNode.is(element) ?
37
+ this.treeLabelProvider.canHandle(element) + 1 :
38
+ 0;
39
+ }
40
+
41
+ getIcon(node: MarkerInfoNode): string {
42
+ return this.labelProvider.getIcon(node.uri);
43
+ }
44
+
45
+ getName(node: MarkerInfoNode): string {
46
+ return this.labelProvider.getName(node.uri);
47
+ }
48
+
49
+ getLongName(node: MarkerInfoNode): string {
50
+ const description: string[] = [];
51
+ const rootUri = this.workspaceService.getWorkspaceRootUri(node.uri);
52
+ // In a multiple-root workspace include the root name to the label before the parent directory.
53
+ if (this.workspaceService.isMultiRootWorkspaceOpened && rootUri) {
54
+ description.push(this.labelProvider.getName(rootUri));
55
+ }
56
+ // If the given resource is not at the workspace root, include the parent directory to the label.
57
+ if (rootUri && rootUri.toString() !== node.uri.parent.toString()) {
58
+ description.push(this.labelProvider.getLongName(node.uri.parent));
59
+ }
60
+ // Get the full path of a resource which does not exist in the given workspace.
61
+ if (!rootUri) {
62
+ description.push(this.labelProvider.getLongName(node.uri.parent.withScheme('markers')));
63
+ }
64
+ return description.join(' ● ');
65
+ }
66
+
67
+ getDescription(node: MarkerInfoNode): string {
68
+ return this.labelProvider.getLongName(node.uri.parent);
69
+ }
70
+
71
+ affects(node: MarkerInfoNode, event: DidChangeLabelEvent): boolean {
72
+ return event.affects(node.uri) || event.affects(node.uri.parent);
73
+ }
74
+
75
+ }