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

rokucommunity / brighterscript / #13342

25 Nov 2024 08:44PM UTC coverage: 89.053% (+2.2%) from 86.874%
#13342

push

web-flow
Merge 961502182 into c5674f5d8

7359 of 8712 branches covered (84.47%)

Branch coverage included in aggregate %.

55 of 64 new or added lines in 9 files covered. (85.94%)

544 existing lines in 54 files now uncovered.

9724 of 10471 relevant lines covered (92.87%)

1825.46 hits per line

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

75.86
/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

5
export class CodeActionUtil {
1✔
6

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

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

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

46
export { CodeActionKind };
1✔
47

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

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

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

70
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