@theia/markers 1.34.2 → 1.34.3

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 (86) 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 -12
  52. package/lib/common/marker.d.ts.map +1 -1
  53. package/lib/common/marker.js +31 -17
  54. package/lib/common/marker.js.map +1 -1
  55. package/lib/common/problem-marker.d.ts +9 -9
  56. package/lib/common/problem-marker.d.ts.map +1 -1
  57. package/lib/common/problem-marker.js +27 -26
  58. package/lib/common/problem-marker.js.map +1 -1
  59. package/package.json +6 -6
  60. package/src/browser/index.ts +18 -18
  61. package/src/browser/marker-manager.ts +205 -205
  62. package/src/browser/marker-tree-label-provider.spec.ts +245 -245
  63. package/src/browser/marker-tree-label-provider.ts +75 -75
  64. package/src/browser/marker-tree-model.ts +47 -47
  65. package/src/browser/marker-tree.ts +154 -154
  66. package/src/browser/problem/problem-composite-tree-node.spec.ts +255 -255
  67. package/src/browser/problem/problem-composite-tree-node.ts +68 -68
  68. package/src/browser/problem/problem-container.ts +47 -47
  69. package/src/browser/problem/problem-contribution.ts +247 -247
  70. package/src/browser/problem/problem-decorations-provider.ts +67 -67
  71. package/src/browser/problem/problem-decorator.ts +222 -222
  72. package/src/browser/problem/problem-frontend-module.ts +64 -64
  73. package/src/browser/problem/problem-layout-migrations.ts +32 -32
  74. package/src/browser/problem/problem-manager.spec.ts +216 -216
  75. package/src/browser/problem/problem-manager.ts +51 -51
  76. package/src/browser/problem/problem-preferences.ts +64 -64
  77. package/src/browser/problem/problem-selection.ts +45 -45
  78. package/src/browser/problem/problem-tabbar-decorator.ts +151 -151
  79. package/src/browser/problem/problem-tree-model.spec.ts +189 -189
  80. package/src/browser/problem/problem-tree-model.ts +113 -113
  81. package/src/browser/problem/problem-utils.ts +90 -90
  82. package/src/browser/problem/problem-widget-tab-bar-decorator.ts +55 -55
  83. package/src/browser/problem/problem-widget.tsx +241 -241
  84. package/src/browser/style/index.css +92 -92
  85. package/src/common/marker.ts +53 -39
  86. package/src/common/problem-marker.ts +30 -30
@@ -1,67 +1,67 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
- import URI from '@theia/core/lib/common/uri';
19
- import { Decoration, DecorationsProvider, DecorationsService } from '@theia/core/lib/browser/decorations-service';
20
- import { ProblemManager } from './problem-manager';
21
- import { ProblemUtils } from './problem-utils';
22
- import { FrontendApplicationContribution } from '@theia/core/lib/browser';
23
- import { CancellationToken, Emitter, Event, nls } from '@theia/core';
24
-
25
- @injectable()
26
- export class ProblemDecorationsProvider implements DecorationsProvider {
27
- @inject(ProblemManager) protected readonly problemManager: ProblemManager;
28
-
29
- protected currentUris: URI[] = [];
30
-
31
- protected readonly onDidChangeEmitter = new Emitter<URI[]>();
32
- get onDidChange(): Event<URI[]> {
33
- return this.onDidChangeEmitter.event;
34
- }
35
-
36
- @postConstruct()
37
- protected init(): void {
38
- this.problemManager.onDidChangeMarkers(() => {
39
- const newUris = Array.from(this.problemManager.getUris(), stringified => new URI(stringified));
40
- this.onDidChangeEmitter.fire(newUris.concat(this.currentUris));
41
- this.currentUris = newUris;
42
- });
43
- }
44
-
45
- provideDecorations(uri: URI, token: CancellationToken): Decoration | Promise<Decoration | undefined> | undefined {
46
- const markers = this.problemManager.findMarkers({ uri }).filter(ProblemUtils.filterMarker).sort(ProblemUtils.severityCompareMarker);
47
- if (markers.length) {
48
- return {
49
- bubble: true,
50
- letter: markers.length.toString(),
51
- weight: ProblemUtils.getPriority(markers[0]),
52
- colorId: ProblemUtils.getColor(markers[0]),
53
- tooltip: markers.length === 1 ? nls.localizeByDefault('1 problem in this file') : nls.localizeByDefault('{0} problems in this file', markers.length),
54
- };
55
- }
56
- }
57
- }
58
-
59
- @injectable()
60
- export class ProblemDecorationContribution implements FrontendApplicationContribution {
61
- @inject(DecorationsService) protected readonly decorationsService: DecorationsService;
62
- @inject(ProblemDecorationsProvider) protected readonly problemDecorationProvider: ProblemDecorationsProvider;
63
-
64
- initialize(): void {
65
- this.decorationsService.registerDecorationsProvider(this.problemDecorationProvider);
66
- }
67
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import URI from '@theia/core/lib/common/uri';
19
+ import { Decoration, DecorationsProvider, DecorationsService } from '@theia/core/lib/browser/decorations-service';
20
+ import { ProblemManager } from './problem-manager';
21
+ import { ProblemUtils } from './problem-utils';
22
+ import { FrontendApplicationContribution } from '@theia/core/lib/browser';
23
+ import { CancellationToken, Emitter, Event, nls } from '@theia/core';
24
+
25
+ @injectable()
26
+ export class ProblemDecorationsProvider implements DecorationsProvider {
27
+ @inject(ProblemManager) protected readonly problemManager: ProblemManager;
28
+
29
+ protected currentUris: URI[] = [];
30
+
31
+ protected readonly onDidChangeEmitter = new Emitter<URI[]>();
32
+ get onDidChange(): Event<URI[]> {
33
+ return this.onDidChangeEmitter.event;
34
+ }
35
+
36
+ @postConstruct()
37
+ protected init(): void {
38
+ this.problemManager.onDidChangeMarkers(() => {
39
+ const newUris = Array.from(this.problemManager.getUris(), stringified => new URI(stringified));
40
+ this.onDidChangeEmitter.fire(newUris.concat(this.currentUris));
41
+ this.currentUris = newUris;
42
+ });
43
+ }
44
+
45
+ provideDecorations(uri: URI, token: CancellationToken): Decoration | Promise<Decoration | undefined> | undefined {
46
+ const markers = this.problemManager.findMarkers({ uri }).filter(ProblemUtils.filterMarker).sort(ProblemUtils.severityCompareMarker);
47
+ if (markers.length) {
48
+ return {
49
+ bubble: true,
50
+ letter: markers.length.toString(),
51
+ weight: ProblemUtils.getPriority(markers[0]),
52
+ colorId: ProblemUtils.getColor(markers[0]),
53
+ tooltip: markers.length === 1 ? nls.localizeByDefault('1 problem in this file') : nls.localizeByDefault('{0} problems in this file', markers.length),
54
+ };
55
+ }
56
+ }
57
+ }
58
+
59
+ @injectable()
60
+ export class ProblemDecorationContribution implements FrontendApplicationContribution {
61
+ @inject(DecorationsService) protected readonly decorationsService: DecorationsService;
62
+ @inject(ProblemDecorationsProvider) protected readonly problemDecorationProvider: ProblemDecorationsProvider;
63
+
64
+ initialize(): void {
65
+ this.decorationsService.registerDecorationsProvider(this.problemDecorationProvider);
66
+ }
67
+ }
@@ -1,222 +1,222 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
- import { Diagnostic, DiagnosticSeverity } from '@theia/core/shared/vscode-languageserver-protocol';
19
- import URI from '@theia/core/lib/common/uri';
20
- import { Event, Emitter } from '@theia/core/lib/common/event';
21
- import { Tree, TreeNode } from '@theia/core/lib/browser/tree/tree';
22
- import { DepthFirstTreeIterator } from '@theia/core/lib/browser/tree/tree-iterator';
23
- import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
24
- import { FileStatNode } from '@theia/filesystem/lib/browser';
25
- import { Marker } from '../../common/marker';
26
- import { ProblemManager } from './problem-manager';
27
- import { ProblemPreferences } from './problem-preferences';
28
- import { ProblemUtils } from './problem-utils';
29
- import { LabelProvider } from '@theia/core/lib/browser';
30
- import { WorkspaceService } from '@theia/workspace/lib/browser';
31
-
32
- /**
33
- * @deprecated since 1.25.0
34
- * URI-based decorators should implement `DecorationsProvider` and contribute decorations via the `DecorationsService`.
35
- */
36
- @injectable()
37
- export class ProblemDecorator implements TreeDecorator {
38
-
39
- @inject(ProblemPreferences)
40
- protected problemPreferences: ProblemPreferences;
41
- @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
42
- @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
43
-
44
- readonly id = 'theia-problem-decorator';
45
-
46
- protected readonly emitter: Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>;
47
-
48
- constructor(@inject(ProblemManager) protected readonly problemManager: ProblemManager) {
49
- this.emitter = new Emitter();
50
- this.problemManager.onDidChangeMarkers(() => this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree)));
51
- }
52
-
53
- @postConstruct()
54
- protected init(): void {
55
- this.problemPreferences.onPreferenceChanged(event => {
56
- if (event.preferenceName === 'problems.decorations.enabled') {
57
- this.fireDidChangeDecorations(tree => this.collectDecorators(tree));
58
- }
59
- });
60
- this.workspaceService.onWorkspaceChanged(() => {
61
- this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
62
- });
63
- this.workspaceService.onWorkspaceLocationChanged(() => {
64
- this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
65
- });
66
- }
67
-
68
- async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
69
- return this.collectDecorators(tree);
70
- }
71
-
72
- get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
73
- return this.emitter.event;
74
- }
75
-
76
- protected fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
77
- this.emitter.fire(event);
78
- }
79
-
80
- protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
81
- const decorations = new Map<string, TreeDecoration.Data>();
82
- // If the tree root is undefined or the preference for the decorations is disabled, return an empty result map.
83
- if (!tree.root || !this.problemPreferences['problems.decorations.enabled']) {
84
- return decorations;
85
- }
86
- const baseDecorations = this.collectMarkers(tree);
87
- for (const node of new DepthFirstTreeIterator(tree.root)) {
88
- const nodeUri = this.getUriFromNode(node);
89
- if (nodeUri) {
90
- const decorator = baseDecorations.get(nodeUri);
91
- if (decorator) {
92
- this.appendContainerMarkers(node, decorator, decorations);
93
- }
94
- if (decorator) {
95
- decorations.set(node.id, decorator);
96
- }
97
- }
98
- }
99
- return decorations;
100
- }
101
-
102
- protected generateCaptionSuffix(nodeURI: URI): string {
103
- const workspaceRoots = this.workspaceService.tryGetRoots();
104
- const parentWorkspace = this.workspaceService.getWorkspaceRootUri(nodeURI);
105
- let workspacePrefixString = '';
106
- let separator = '';
107
- let filePathString = '';
108
- const nodeURIDir = nodeURI.parent;
109
- if (parentWorkspace) {
110
- const relativeDirFromWorkspace = parentWorkspace.relative(nodeURIDir);
111
- workspacePrefixString = workspaceRoots.length > 1 ? this.labelProvider.getName(parentWorkspace) : '';
112
- filePathString = relativeDirFromWorkspace?.fsPath() ?? '';
113
- separator = filePathString && workspacePrefixString ? ' \u2022 ' : ''; // add a bullet point between workspace and path
114
- } else {
115
- workspacePrefixString = nodeURIDir.path.fsPath();
116
- }
117
- return `${workspacePrefixString}${separator}${filePathString}`;
118
- }
119
-
120
- /**
121
- * Traverses up the tree from the given node and attaches decorations to any parents.
122
- */
123
- protected appendContainerMarkers(node: TreeNode, decoration: TreeDecoration.Data, decorations: Map<string, TreeDecoration.Data>): void {
124
- let parent = node?.parent;
125
- while (parent) {
126
- const existing = decorations.get(parent.id);
127
- // Make sure the highest diagnostic severity (smaller number) will be propagated to the container directory.
128
- if (existing === undefined || this.compareDecorators(existing, decoration) < 0) {
129
- decorations.set(parent.id, decoration);
130
- parent = parent.parent;
131
- } else {
132
- break;
133
- }
134
- }
135
- }
136
-
137
- /**
138
- * @returns a map matching stringified URI's to a decoration whose features reflect the highest-severity problem found
139
- * and the number of problems found (based on {@link ProblemDecorator.toDecorator })
140
- */
141
- protected collectMarkers(tree: Tree): Map<string, TreeDecoration.Data> {
142
- const decorationsForUri = new Map();
143
- const compare = this.compare.bind(this);
144
- const filter = this.filterMarker.bind(this);
145
- for (const [, markers] of this.problemManager.getMarkersByUri()) {
146
- const relevant = markers.findMarkers({}).filter(filter).sort(compare);
147
- if (relevant.length) {
148
- decorationsForUri.set(relevant[0].uri, this.toDecorator(relevant));
149
- }
150
- }
151
- return decorationsForUri;
152
- }
153
-
154
- protected toDecorator(markers: Marker<Diagnostic>[]): TreeDecoration.Data {
155
- const color = this.getColor(markers[0]);
156
- const priority = this.getPriority(markers[0]);
157
- return {
158
- priority,
159
- fontData: {
160
- color,
161
- },
162
- tailDecorations: [{
163
- color,
164
- data: markers.length.toString(),
165
- }],
166
- };
167
- }
168
-
169
- protected getColor(marker: Marker<Diagnostic>): TreeDecoration.Color {
170
- const { severity } = marker.data;
171
- switch (severity) {
172
- case 1: return 'var(--theia-list-errorForeground)';
173
- case 2: return 'var(--theia-list-warningForeground)';
174
- default: return 'var(--theia-successBackground)';
175
- }
176
- }
177
-
178
- /**
179
- * Get the decoration for a given marker diagnostic.
180
- * Markers with higher severity have a higher priority and should be displayed.
181
- * @param marker the diagnostic marker.
182
- */
183
- protected getPriority(marker: Marker<Diagnostic>): number {
184
- const { severity } = marker.data;
185
- switch (severity) {
186
- case 1: return 30; // Errors.
187
- case 2: return 20; // Warnings.
188
- case 3: return 10; // Infos.
189
- default: return 0;
190
- }
191
- }
192
-
193
- /**
194
- * Returns `true` if the diagnostic (`data`) of the marker argument has `Error`, `Warning`, or `Information` severity.
195
- * Otherwise, returns `false`.
196
- */
197
- protected filterMarker(marker: Marker<Diagnostic>): boolean {
198
- const { severity } = marker.data;
199
- return severity === DiagnosticSeverity.Error
200
- || severity === DiagnosticSeverity.Warning
201
- || severity === DiagnosticSeverity.Information;
202
- }
203
-
204
- protected getUriFromNode(node: TreeNode): string | undefined {
205
- return FileStatNode.getUri(node);
206
- }
207
-
208
- protected compare(left: Marker<Diagnostic>, right: Marker<Diagnostic>): number {
209
- return ProblemDecorator.severityCompare(left, right);
210
- }
211
-
212
- protected compareDecorators(left: TreeDecoration.Data, right: TreeDecoration.Data): number {
213
- return TreeDecoration.Data.comparePriority(left, right);
214
- }
215
- }
216
-
217
- export namespace ProblemDecorator {
218
-
219
- // Highest severities (errors) come first, then the others. Undefined severities treated as the last ones.
220
- export const severityCompare = ProblemUtils.severityCompareMarker;
221
-
222
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import { Diagnostic, DiagnosticSeverity } from '@theia/core/shared/vscode-languageserver-protocol';
19
+ import URI from '@theia/core/lib/common/uri';
20
+ import { Event, Emitter } from '@theia/core/lib/common/event';
21
+ import { Tree, TreeNode } from '@theia/core/lib/browser/tree/tree';
22
+ import { DepthFirstTreeIterator } from '@theia/core/lib/browser/tree/tree-iterator';
23
+ import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
24
+ import { FileStatNode } from '@theia/filesystem/lib/browser';
25
+ import { Marker } from '../../common/marker';
26
+ import { ProblemManager } from './problem-manager';
27
+ import { ProblemPreferences } from './problem-preferences';
28
+ import { ProblemUtils } from './problem-utils';
29
+ import { LabelProvider } from '@theia/core/lib/browser';
30
+ import { WorkspaceService } from '@theia/workspace/lib/browser';
31
+
32
+ /**
33
+ * @deprecated since 1.25.0
34
+ * URI-based decorators should implement `DecorationsProvider` and contribute decorations via the `DecorationsService`.
35
+ */
36
+ @injectable()
37
+ export class ProblemDecorator implements TreeDecorator {
38
+
39
+ @inject(ProblemPreferences)
40
+ protected problemPreferences: ProblemPreferences;
41
+ @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
42
+ @inject(LabelProvider) protected readonly labelProvider: LabelProvider;
43
+
44
+ readonly id = 'theia-problem-decorator';
45
+
46
+ protected readonly emitter: Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>;
47
+
48
+ constructor(@inject(ProblemManager) protected readonly problemManager: ProblemManager) {
49
+ this.emitter = new Emitter();
50
+ this.problemManager.onDidChangeMarkers(() => this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree)));
51
+ }
52
+
53
+ @postConstruct()
54
+ protected init(): void {
55
+ this.problemPreferences.onPreferenceChanged(event => {
56
+ if (event.preferenceName === 'problems.decorations.enabled') {
57
+ this.fireDidChangeDecorations(tree => this.collectDecorators(tree));
58
+ }
59
+ });
60
+ this.workspaceService.onWorkspaceChanged(() => {
61
+ this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
62
+ });
63
+ this.workspaceService.onWorkspaceLocationChanged(() => {
64
+ this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
65
+ });
66
+ }
67
+
68
+ async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
69
+ return this.collectDecorators(tree);
70
+ }
71
+
72
+ get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
73
+ return this.emitter.event;
74
+ }
75
+
76
+ protected fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
77
+ this.emitter.fire(event);
78
+ }
79
+
80
+ protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
81
+ const decorations = new Map<string, TreeDecoration.Data>();
82
+ // If the tree root is undefined or the preference for the decorations is disabled, return an empty result map.
83
+ if (!tree.root || !this.problemPreferences['problems.decorations.enabled']) {
84
+ return decorations;
85
+ }
86
+ const baseDecorations = this.collectMarkers(tree);
87
+ for (const node of new DepthFirstTreeIterator(tree.root)) {
88
+ const nodeUri = this.getUriFromNode(node);
89
+ if (nodeUri) {
90
+ const decorator = baseDecorations.get(nodeUri);
91
+ if (decorator) {
92
+ this.appendContainerMarkers(node, decorator, decorations);
93
+ }
94
+ if (decorator) {
95
+ decorations.set(node.id, decorator);
96
+ }
97
+ }
98
+ }
99
+ return decorations;
100
+ }
101
+
102
+ protected generateCaptionSuffix(nodeURI: URI): string {
103
+ const workspaceRoots = this.workspaceService.tryGetRoots();
104
+ const parentWorkspace = this.workspaceService.getWorkspaceRootUri(nodeURI);
105
+ let workspacePrefixString = '';
106
+ let separator = '';
107
+ let filePathString = '';
108
+ const nodeURIDir = nodeURI.parent;
109
+ if (parentWorkspace) {
110
+ const relativeDirFromWorkspace = parentWorkspace.relative(nodeURIDir);
111
+ workspacePrefixString = workspaceRoots.length > 1 ? this.labelProvider.getName(parentWorkspace) : '';
112
+ filePathString = relativeDirFromWorkspace?.fsPath() ?? '';
113
+ separator = filePathString && workspacePrefixString ? ' \u2022 ' : ''; // add a bullet point between workspace and path
114
+ } else {
115
+ workspacePrefixString = nodeURIDir.path.fsPath();
116
+ }
117
+ return `${workspacePrefixString}${separator}${filePathString}`;
118
+ }
119
+
120
+ /**
121
+ * Traverses up the tree from the given node and attaches decorations to any parents.
122
+ */
123
+ protected appendContainerMarkers(node: TreeNode, decoration: TreeDecoration.Data, decorations: Map<string, TreeDecoration.Data>): void {
124
+ let parent = node?.parent;
125
+ while (parent) {
126
+ const existing = decorations.get(parent.id);
127
+ // Make sure the highest diagnostic severity (smaller number) will be propagated to the container directory.
128
+ if (existing === undefined || this.compareDecorators(existing, decoration) < 0) {
129
+ decorations.set(parent.id, decoration);
130
+ parent = parent.parent;
131
+ } else {
132
+ break;
133
+ }
134
+ }
135
+ }
136
+
137
+ /**
138
+ * @returns a map matching stringified URI's to a decoration whose features reflect the highest-severity problem found
139
+ * and the number of problems found (based on {@link ProblemDecorator.toDecorator })
140
+ */
141
+ protected collectMarkers(tree: Tree): Map<string, TreeDecoration.Data> {
142
+ const decorationsForUri = new Map();
143
+ const compare = this.compare.bind(this);
144
+ const filter = this.filterMarker.bind(this);
145
+ for (const [, markers] of this.problemManager.getMarkersByUri()) {
146
+ const relevant = markers.findMarkers({}).filter(filter).sort(compare);
147
+ if (relevant.length) {
148
+ decorationsForUri.set(relevant[0].uri, this.toDecorator(relevant));
149
+ }
150
+ }
151
+ return decorationsForUri;
152
+ }
153
+
154
+ protected toDecorator(markers: Marker<Diagnostic>[]): TreeDecoration.Data {
155
+ const color = this.getColor(markers[0]);
156
+ const priority = this.getPriority(markers[0]);
157
+ return {
158
+ priority,
159
+ fontData: {
160
+ color,
161
+ },
162
+ tailDecorations: [{
163
+ color,
164
+ data: markers.length.toString(),
165
+ }],
166
+ };
167
+ }
168
+
169
+ protected getColor(marker: Marker<Diagnostic>): TreeDecoration.Color {
170
+ const { severity } = marker.data;
171
+ switch (severity) {
172
+ case 1: return 'var(--theia-list-errorForeground)';
173
+ case 2: return 'var(--theia-list-warningForeground)';
174
+ default: return 'var(--theia-successBackground)';
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Get the decoration for a given marker diagnostic.
180
+ * Markers with higher severity have a higher priority and should be displayed.
181
+ * @param marker the diagnostic marker.
182
+ */
183
+ protected getPriority(marker: Marker<Diagnostic>): number {
184
+ const { severity } = marker.data;
185
+ switch (severity) {
186
+ case 1: return 30; // Errors.
187
+ case 2: return 20; // Warnings.
188
+ case 3: return 10; // Infos.
189
+ default: return 0;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Returns `true` if the diagnostic (`data`) of the marker argument has `Error`, `Warning`, or `Information` severity.
195
+ * Otherwise, returns `false`.
196
+ */
197
+ protected filterMarker(marker: Marker<Diagnostic>): boolean {
198
+ const { severity } = marker.data;
199
+ return severity === DiagnosticSeverity.Error
200
+ || severity === DiagnosticSeverity.Warning
201
+ || severity === DiagnosticSeverity.Information;
202
+ }
203
+
204
+ protected getUriFromNode(node: TreeNode): string | undefined {
205
+ return FileStatNode.getUri(node);
206
+ }
207
+
208
+ protected compare(left: Marker<Diagnostic>, right: Marker<Diagnostic>): number {
209
+ return ProblemDecorator.severityCompare(left, right);
210
+ }
211
+
212
+ protected compareDecorators(left: TreeDecoration.Data, right: TreeDecoration.Data): number {
213
+ return TreeDecoration.Data.comparePriority(left, right);
214
+ }
215
+ }
216
+
217
+ export namespace ProblemDecorator {
218
+
219
+ // Highest severities (errors) come first, then the others. Undefined severities treated as the last ones.
220
+ export const severityCompare = ProblemUtils.severityCompareMarker;
221
+
222
+ }