diff --git a/src/vs/workbench/parts/markers/browser/markersFileDecorations.ts b/src/vs/workbench/parts/markers/browser/markersFileDecorations.ts index 9030dd7375eb78289932e25673fadfafa5cb5ec0..b5dad47b841cad34cecdeb0506d4e20f6c761b31 100644 --- a/src/vs/workbench/parts/markers/browser/markersFileDecorations.ts +++ b/src/vs/workbench/parts/markers/browser/markersFileDecorations.ts @@ -44,12 +44,14 @@ class MarkersFileDecorations implements IWorkbenchContribution { private _onDidChangeMarker(resources: URI[]): void { for (const resource of resources) { - const markers = this._markerService.read({ resource }); + const markers = this._markerService.read({ resource }) + .sort((a, b) => Severity.compare(a.severity, b.severity)); + if (!isFalsyOrEmpty(markers)) { - const data = markers.map(this._toFileDecorationData, this); - this._decorationsService.setFileDecorations(this._type, resource, data); + const data = this._toFileDecorationData(markers[0]); + this._decorationsService.setFileDecoration(this._type, resource, data); } else { - this._decorationsService.unsetFileDecorations(this._type, resource); + this._decorationsService.unsetFileDecoration(this._type, resource); } } } diff --git a/src/vs/workbench/parts/scm/electron-browser/scmFileDecorations.ts b/src/vs/workbench/parts/scm/electron-browser/scmFileDecorations.ts index 13f3ffb8f8eaa0da99c083f7334a6ec2c79726b9..59509fd3c01aed691a528cf4c40ac6c54a42d192 100644 --- a/src/vs/workbench/parts/scm/electron-browser/scmFileDecorations.ts +++ b/src/vs/workbench/parts/scm/electron-browser/scmFileDecorations.ts @@ -49,11 +49,11 @@ export class FileDecorations implements IWorkbenchContribution { for (const resource of group.resourceCollection.resources) { // TODO@Joh have a better color and icon which is based // on the resource decoration - this._decorationsService.setFileDecorations(type, resource.sourceUri, [{ + this._decorationsService.setFileDecoration(type, resource.sourceUri, { severity: Severity.Info, message: resource.decorations.tooltip, color - }]); + }); newDecorations.set(resource.sourceUri.toString(), resource.sourceUri); } @@ -61,7 +61,7 @@ export class FileDecorations implements IWorkbenchContribution { oldDecorations.forEach((value, key) => { if (!newDecorations.has(key)) { - this._decorationsService.unsetFileDecorations(type, value); + this._decorationsService.unsetFileDecoration(type, value); } }); diff --git a/src/vs/workbench/services/fileDecorations/browser/fileDecorations.ts b/src/vs/workbench/services/fileDecorations/browser/fileDecorations.ts index 3bb20dba2233f05f5969d8174beb419f90cbd331..15e1feb21d47c3c7b833e0157297089b88dc4ab7 100644 --- a/src/vs/workbench/services/fileDecorations/browser/fileDecorations.ts +++ b/src/vs/workbench/services/fileDecorations/browser/fileDecorations.ts @@ -43,9 +43,9 @@ export interface IFileDecorationsService { registerDecorationType(label: string): DecorationType; - setFileDecorations(type: DecorationType, target: URI, data: IFileDecorationData[]): void; + setFileDecoration(type: DecorationType, target: URI, data: IFileDecorationData): void; - unsetFileDecorations(type: DecorationType, target: URI): void; + unsetFileDecoration(type: DecorationType, target: URI): void; getDecorations(uri: URI, includeChildren: boolean): IFileDecoration[]; diff --git a/src/vs/workbench/services/fileDecorations/browser/fileDecorationsService.ts b/src/vs/workbench/services/fileDecorations/browser/fileDecorationsService.ts index a7c225ba106979057d255f2d427b9f24a0ec2956..e4f2932b524e8485c720c0392eb8da02320787f2 100644 --- a/src/vs/workbench/services/fileDecorations/browser/fileDecorationsService.ts +++ b/src/vs/workbench/services/fileDecorations/browser/fileDecorationsService.ts @@ -9,15 +9,13 @@ import Severity from 'vs/base/common/severity'; import Event, { Emitter, debounceEvent } from 'vs/base/common/event'; import { IFileDecorationsService, IFileDecoration, DecorationType, IFileDecorationData } from 'vs/workbench/services/fileDecorations/browser/fileDecorations'; import { TernarySearchTree } from 'vs/base/common/map'; -import { mergeSort, isFalsyOrEmpty } from 'vs/base/common/arrays'; - export class FileDecorationsService implements IFileDecorationsService { readonly _serviceBrand; private readonly _onDidChangeFileDecoration = new Emitter(); - private readonly _types = new Map>(); + private readonly _types = new Map>(); readonly onDidChangeFileDecoration: Event = debounceEvent( this._onDidChangeFileDecoration.event, @@ -44,17 +42,16 @@ export class FileDecorationsService implements IFileDecorationsService { } } }; - this._types.set(type, TernarySearchTree.forPaths()); + this._types.set(type, TernarySearchTree.forPaths()); return type; } - setFileDecorations(type: DecorationType, target: URI, data: IFileDecorationData[]): void { - let decorations = mergeSort(data.map(data => ({ type, ...data })), FileDecorationsService._compareFileDecorationsBySeverity); - this._types.get(type).set(target.toString(), decorations); + setFileDecoration(type: DecorationType, target: URI, data: IFileDecorationData): void { + this._types.get(type).set(target.toString(), { type, ...data }); this._onDidChangeFileDecoration.fire(target); } - unsetFileDecorations(type: DecorationType, target: URI): void { + unsetFileDecoration(type: DecorationType, target: URI): void { this._types.get(type).delete(target.toString()); this._onDidChangeFileDecoration.fire(target); } @@ -76,7 +73,7 @@ export class FileDecorationsService implements IFileDecorationsService { if (!top || FileDecorationsService._compareFileDecorationsBySeverity(top, decoration) > 0) { top = decoration; } - return top.severity === Severity.Error; + return top !== undefined && top.severity === Severity.Error; }); return top; } @@ -91,13 +88,11 @@ export class FileDecorationsService implements IFileDecorationsService { if (includeChildren) { let newTree = tree.findSuperstr(key); if (newTree) { - newTree.forEach(([, data]) => done = done || data.some(callback)); + newTree.forEach(([, deco]) => done = done || callback(deco)); } } else { - let list = tree.get(key); - if (!isFalsyOrEmpty(list)) { - done = list.some(callback); - } + let deco = tree.get(key); + done = done || deco && callback(deco); } }); }