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

rokucommunity / brighterscript / #12849

25 Jul 2024 12:51PM UTC coverage: 86.205%. Remained the same
#12849

push

web-flow
Merge 0c17734d3 into 5f3ffa3fa

10601 of 13088 branches covered (81.0%)

Branch coverage included in aggregate %.

82 of 88 new or added lines in 15 files covered. (93.18%)

288 existing lines in 16 files now uncovered.

12302 of 13480 relevant lines covered (91.26%)

26603.69 hits per line

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

75.76
/src/CodeActionUtil.ts
1
import type { Diagnostic, Position, Range, WorkspaceEdit } from 'vscode-languageserver';
2
import { CodeActionKind, CodeAction, TextEdit } from 'vscode-languageserver';
1✔
3
import { URI } from 'vscode-uri';
1✔
4
import type { BsDiagnostic } from './interfaces';
5

6
export class CodeActionUtil {
1✔
7

8
    public createCodeAction(obj: CodeActionShorthand) {
9
        const edit = {
12✔
10
            changes: {}
11
        } as WorkspaceEdit;
12
        for (const change of obj.changes) {
12✔
13
            const uri = URI.file(change.filePath).toString();
12✔
14

15
            //create the edit changes array for this uri
16
            if (!edit.changes![uri]) {
12!
17
                edit.changes![uri] = [];
12✔
18
            }
19
            if (change.type === 'insert') {
12!
20
                edit.changes![uri].push(
12✔
21
                    TextEdit.insert(change.position, change.newText)
22
                );
UNCOV
23
            } else if (change.type === 'replace') {
×
24
                edit.changes![uri].push(
×
25
                    TextEdit.replace(change.range, change.newText)
26
                );
27
            }
28
        }
29
        const action = CodeAction.create(obj.title, edit, obj.kind);
12✔
30
        action.isPreferred = obj.isPreferred;
12✔
31
        action.diagnostics = this.serializableDiagnostics(obj.diagnostics);
12✔
32
        return action;
12✔
33
    }
34

35
    public serializableDiagnostics(diagnostics: BsDiagnostic[] | undefined): Diagnostic[] {
36
        return diagnostics?.map(({ location, severity, code, source, message, relatedInformation }) => ({
12!
37
            range: location?.range,
36!
38
            severity: severity,
39
            source: source,
40
            code: code,
41
            message: message,
42
            relatedInformation: relatedInformation
43
        }));
44
    }
45
}
46

47
export { CodeActionKind };
1✔
48

49
export interface CodeActionShorthand {
50
    title: string;
51
    diagnostics?: BsDiagnostic[];
52
    kind?: CodeActionKind;
53
    isPreferred?: boolean;
54
    changes: Array<InsertChange | ReplaceChange>;
55
}
56

57
export interface InsertChange {
58
    filePath: string;
59
    newText: string;
60
    type: 'insert';
61
    position: Position;
62
}
63

64
export interface ReplaceChange {
65
    filePath: string;
66
    newText: string;
67
    type: 'replace';
68
    range: Range;
69
}
70

71
export const codeActionUtil = new CodeActionUtil();
1✔
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