• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #13125

01 Oct 2024 02:12PM UTC coverage: 86.842% (-1.4%) from 88.193%
#13125

push

web-flow
Merge d4a9e5fff into 3a2dc7282

11554 of 14068 branches covered (82.13%)

Branch coverage included in aggregate %.

7000 of 7592 new or added lines in 100 files covered. (92.2%)

83 existing lines in 18 files now uncovered.

12701 of 13862 relevant lines covered (91.62%)

29529.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.36
/src/DiagnosticCollection.ts
1
import type { BsDiagnostic } from './interfaces';
2
import type { Project } from './LanguageServer';
3
import { util } from './util';
1✔
4

5
export class DiagnosticCollection {
1✔
6
    private previousDiagnosticsByFile = {} as Record<string, KeyedDiagnostic[]>;
42✔
7

8
    public getPatch(projects: Project[]) {
9
        const diagnosticsByFile = this.getDiagnosticsByFileFromProjects(projects);
71✔
10

11
        const patch = {
71✔
12
            ...this.getRemovedPatch(diagnosticsByFile),
13
            ...this.getModifiedPatch(diagnosticsByFile),
14
            ...this.getAddedPatch(diagnosticsByFile)
15
        };
16

17
        //save the new list of diagnostics
18
        this.previousDiagnosticsByFile = diagnosticsByFile;
71✔
19
        return patch;
71✔
20
    }
21

22
    private getDiagnosticsByFileFromProjects(projects: Project[]) {
23
        const result = {} as Record<string, KeyedDiagnostic[]>;
71✔
24

25
        //get all diagnostics for all projects
26
        let diagnostics = Array.prototype.concat.apply([] as KeyedDiagnostic[],
71✔
27
            projects.map((x) => x.builder.getDiagnostics())
90✔
28
        ) as KeyedDiagnostic[];
29

30
        const keys = {};
71✔
31
        //build the full current set of diagnostics by file
32
        for (let diagnostic of diagnostics) {
71✔
33
            const fileUri = diagnostic?.location?.uri;
40!
34
            if (!fileUri) {
40!
NEW
35
                continue;
×
36
            }
37

38
            //ensure the file entry exists
39
            if (!result[fileUri]) {
40✔
40
                result[fileUri] = [];
23✔
41
            }
42
            const diagnosticMap = result[fileUri];
40✔
43

44
            //fall back to a default range if missing
45
            const range = diagnostic?.location?.range ?? util.createRange(0, 0, 0, 0);
40!
46

47
            diagnostic.key =
40✔
48
                fileUri.toLowerCase() + '-' +
49
                diagnostic.code + '-' +
50
                range.start.line + '-' +
51
                range.start.character + '-' +
52
                range.end.line + '-' +
53
                range.end.character +
54
                diagnostic.message;
55

56
            //don't include duplicates
57
            if (!keys[diagnostic.key]) {
40✔
58
                keys[diagnostic.key] = true;
37✔
59
                diagnosticMap.push(diagnostic);
37✔
60
            }
61
        }
62
        return result;
71✔
63
    }
64

65
    /**
66
     * Get a patch for all the files that have been removed since last time
67
     */
68
    private getRemovedPatch(currentDiagnosticsByFile: Record<string, KeyedDiagnostic[]>) {
69
        const result = {} as Record<string, KeyedDiagnostic[]>;
71✔
70
        for (const filePath in this.previousDiagnosticsByFile) {
71✔
71
            if (!currentDiagnosticsByFile[filePath]) {
10✔
72
                result[filePath] = [];
1✔
73
            }
74
        }
75
        return result;
71✔
76
    }
77

78
    /**
79
     * Get all files whose diagnostics have changed since last time
80
     */
81
    private getModifiedPatch(currentDiagnosticsByFile: Record<string, KeyedDiagnostic[]>) {
82
        const result = {} as Record<string, KeyedDiagnostic[]>;
71✔
83
        for (const filePath in currentDiagnosticsByFile) {
71✔
84
            //for this file, if there were diagnostics last time AND there are diagnostics this time, and the lists are different
85
            if (this.previousDiagnosticsByFile[filePath] && !this.diagnosticListsAreIdentical(this.previousDiagnosticsByFile[filePath], currentDiagnosticsByFile[filePath])) {
23✔
86
                result[filePath] = currentDiagnosticsByFile[filePath];
1✔
87
            }
88
        }
89
        return result;
71✔
90
    }
91

92
    /**
93
     * Determine if two diagnostic lists are identical
94
     */
95
    private diagnosticListsAreIdentical(list1: KeyedDiagnostic[], list2: KeyedDiagnostic[]) {
96
        //skip all checks if the lists are not the same size
97
        if (list1.length !== list2.length) {
9✔
98
            return false;
1✔
99
        }
100
        for (let i = 0; i < list1.length; i++) {
8✔
101
            if (list1[i].key !== list2[i].key) {
12!
102
                return false;
×
103
            }
104
        }
105

106
        //if we made it here, the lists are identical
107
        return true;
8✔
108
    }
109

110
    /**
111
     * Get diagnostics for all new files not seen since last time
112
     */
113
    private getAddedPatch(currentDiagnosticsByFile: Record<string, KeyedDiagnostic[]>) {
114
        const result = {} as Record<string, KeyedDiagnostic[]>;
71✔
115
        for (const filePath in currentDiagnosticsByFile) {
71✔
116
            if (!this.previousDiagnosticsByFile[filePath]) {
23✔
117
                result[filePath] = currentDiagnosticsByFile[filePath];
14✔
118
            }
119
        }
120
        return result;
71✔
121
    }
122
}
123

124
interface KeyedDiagnostic extends BsDiagnostic {
125
    key: string;
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc