Skip to content

Commit

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

Signed-off-by: Jonas Helming <jhelming@eclipsesource.com>
  • Loading branch information
JonasHelming committed Mar 16, 2021
1 parent be686ee commit 2f32b47
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
19 changes: 16 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,23 @@ function createMockMarkerNode(marker: Marker<Diagnostic>): MarkerNode {
* Create a mock diagnostic marker.
* @param range the diagnostic range.
* @param severity the diagnostic severity.
* @param owner the owner of the diagnostic (optional)
*
* @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'
message: 'message',
};
if (!owner) {
owner = 'owner';
}
return Object.freeze({
uri: name,
kind: 'marker',
owner: 'owner',
owner: owner,
data
});
}
5 changes: 5 additions & 0 deletions packages/markers/src/browser/problem/problem-tree-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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 2f32b47

Please sign in to comment.