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 <[email protected]>
  • Loading branch information
JonasHelming committed Mar 17, 2021
1 parent be686ee commit 8362c7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
18 changes: 14 additions & 4 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'
message: 'message',
};
return Object.freeze({
uri: name,
uri: '',
kind: 'marker',
owner: '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 8362c7c

Please sign in to comment.