Skip to content

Commit

Permalink
Added pmarker sorting by owner
Browse files Browse the repository at this point in the history
fixed #6572

Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
  • Loading branch information
JonasHelming committed Mar 17, 2021
1 parent be686ee commit 87f408e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
16 changes: 13 additions & 3 deletions packages/markers/src/browser/problem/problem-tree-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ describe('Problem Tree', () => {
expect(problemTree['sortMarkers'](nodeB, nodeA)).equals(10);
});

it('should sort markers based on owner if their severities, line numbers and columns are equal', () => {
const markerA = createMockMarker({ start: { line: 1, character: 10 }, end: { line: 1, character: 10 } }, DiagnosticSeverity.Error, 'A');
const markerB = createMockMarker({ start: { line: 1, character: 10 }, end: { line: 1, character: 10 } }, DiagnosticSeverity.Error, 'B');
const nodeA = createMockMarkerNode(markerA);
const nodeB = createMockMarkerNode(markerB);
expect(problemTree['sortMarkers'](nodeA, nodeB)).equals(-1);
expect(problemTree['sortMarkers'](nodeB, nodeA)).equals(1);
});

it('should not sort if markers are equal', () => {
const markerA = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
const markerB = createMockMarker({ start: { line: 0, character: 10 }, end: { line: 0, character: 10 } }, DiagnosticSeverity.Error);
Expand Down Expand Up @@ -158,19 +167,20 @@ function createMockMarkerNode(marker: Marker<Diagnostic>): MarkerNode {
* Create a mock diagnostic marker.
* @param range the diagnostic range.
* @param severity the diagnostic severity.
* @param owner the optional owner of the diagnostic
*
* @returns a mock diagnostic marker.
*/
function createMockMarker(range: Range, severity: DiagnosticSeverity): Readonly<Marker<Diagnostic>> {
function createMockMarker(range: Range, severity: DiagnosticSeverity, owner?: string): Readonly<Marker<Diagnostic>> {
const data: Diagnostic = {
range: range,
severity: severity,
message: 'message'
};
return Object.freeze({
uri: name,
uri: 'uri',
kind: 'marker',
owner: 'owner',
owner: owner ?? 'owner',
data
});
}
8 changes: 7 additions & 1 deletion packages/markers/src/browser/problem/problem-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class ProblemTree extends MarkerTree<Diagnostic> {
* Sort markers based on the following rules:
* - Markers are fist sorted by `severity`.
* - Markers are sorted by `line number` if applicable.
* - Markers are sorted by `column number` if
* - Markers are sorted by `column number` if applicable.
* - Markers are then finally sorted by `owner` if applicable.
* @param a the first marker for comparison.
* @param b the second marker for comparison.
*/
Expand All @@ -65,6 +66,11 @@ export class ProblemTree extends MarkerTree<Diagnostic> {
if (columnNumber !== 0) {
return columnNumber;
}
// Sort by owner in alphabetical order.
const owner = ProblemUtils.ownerCompare(markerA, markerB);
if (owner !== 0) {
return owner;
}
return 0;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/markers/src/browser/problem/problem-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ export namespace ProblemUtils {
*/
export const columnNumberCompare = (a: Marker<Diagnostic>, b: Marker<Diagnostic>): number => a.data.range.start.character - b.data.range.start.character;

/**
* Comparator for marker owner (source).
* - The order is alphabetical.
* @param a the first marker for comparison.
* @param b the second marker for comparison.
*/
export const ownerCompare = (a: Marker<Diagnostic>, b: Marker<Diagnostic>): number => a.owner.localeCompare(b.owner);

}

0 comments on commit 87f408e

Please sign in to comment.