aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/utils/vscode_diagnostics.ts
blob: 9d763c8d64a8bd7de699cf57ba1d31ae3d7fa9e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as vscode from 'vscode';

/** Compares two `vscode.Diagnostic`s for equality */
export function areDiagnosticsEqual(
    left: vscode.Diagnostic,
    right: vscode.Diagnostic
): boolean {
    return (
        left.source === right.source &&
        left.severity === right.severity &&
        left.range.isEqual(right.range) &&
        left.message === right.message
    );
}

/** Compares two `vscode.TextEdit`s for equality */
function areTextEditsEqual(
    left: vscode.TextEdit,
    right: vscode.TextEdit
): boolean {
    if (!left.range.isEqual(right.range)) {
        return false;
    }

    if (left.newText !== right.newText) {
        return false;
    }

    return true;
}

/** Compares two `vscode.CodeAction`s for equality */
export function areCodeActionsEqual(
    left: vscode.CodeAction,
    right: vscode.CodeAction
): boolean {
    if (
        left.kind !== right.kind ||
        left.title !== right.title ||
        !left.edit ||
        !right.edit
    ) {
        return false;
    }

    const leftEditEntries = left.edit.entries();
    const rightEditEntries = right.edit.entries();

    if (leftEditEntries.length !== rightEditEntries.length) {
        return false;
    }

    for (let i = 0; i < leftEditEntries.length; i++) {
        const [leftUri, leftEdits] = leftEditEntries[i];
        const [rightUri, rightEdits] = rightEditEntries[i];

        if (leftUri.toString() !== rightUri.toString()) {
            return false;
        }

        if (leftEdits.length !== rightEdits.length) {
            return false;
        }

        for (let j = 0; j < leftEdits.length; j++) {
            if (!areTextEditsEqual(leftEdits[j], rightEdits[j])) {
                return false;
            }
        }
    }

    return true;
}