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

rokucommunity / vscode-brightscript-language / #2719

24 Aug 2022 12:51PM UTC coverage: 41.691% (+0.02%) from 41.675%
#2719

push

TwitchBronBron
2.35.0

477 of 1427 branches covered (33.43%)

Branch coverage included in aggregate %.

1126 of 2418 relevant lines covered (46.57%)

7.32 hits per line

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

11.67
/src/BrightScriptReferenceProvider.ts
1
import * as fs from 'fs';
1✔
2
import * as iconv from 'iconv-lite';
1✔
3
import * as vscode from 'vscode';
1✔
4
import type {
5
    TextDocument,
6
    Uri
7
} from 'vscode';
8
import {
1✔
9
    Location,
10
    Position
11
} from 'vscode';
12

13
import { getExcludeGlob, iterlines, WorkspaceEncoding } from './DeclarationProvider';
1✔
14

15
export class BrightScriptReferenceProvider implements vscode.ReferenceProvider {
1✔
16
    private encoding: WorkspaceEncoding = new WorkspaceEncoding();
4✔
17

18
    public async provideReferences(
19
        document: vscode.TextDocument,
20
        position: vscode.Position,
21
        options: { includeDeclaration: boolean },
22
        token: vscode.CancellationToken
23
    ): Promise<vscode.Location[]> {
24
        return this.find(document, position);
×
25
    }
26

27
    private async find(document: TextDocument, position: Position): Promise<Location[]> {
28
        const excludes = getExcludeGlob();
×
29
        const word = this.getWord(document, position).toLowerCase();
×
30
        let locations = [];
×
31
        for (const uri of await vscode.workspace.findFiles('**/*.brs', excludes)) {
×
32
            const input = await new Promise<string>((resolve, reject) => {
×
33
                fs.readFile(uri.fsPath, (err, data) => {
×
34
                    if (err) {
×
35
                        if (typeof err === 'object' && err.code === 'ENOENT') {
×
36
                            resolve(undefined);
×
37
                        } else {
38
                            reject(err);
×
39
                        }
40
                    } else {
41
                        resolve(iconv.decode(data, this.encoding.find(uri.fsPath)));
×
42
                    }
43
                });
44
            });
45
            if (input !== undefined) {
×
46
                locations = locations.concat(this.findWordInFile(uri, input, word));
×
47
            }
48
        }
49
        return locations;
×
50
    }
51

52
    public findWordInFile(uri: Uri, input: string, word: string): Location[] {
53
        let locations = [];
×
54
        let searchTerm = word;
×
55
        let regex = new RegExp(searchTerm, 'ig');
×
56
        let wordLength = word.length;
×
57
        for (const [line, text] of iterlines(input)) {
×
58
            let result;
59
            while ((result = regex.exec(text))) {
×
60
                locations.push(new Location(uri, new Position(line, result.index)));
×
61
            }
62
        }
63
        return locations;
×
64
    }
65

66
    public getIndicesOf(searchStr, str, caseSensitive) {
67
        let searchStrLen = searchStr.length;
×
68
        if (searchStrLen === 0) {
×
69
            return [];
×
70
        }
71
        let startIndex = 0;
×
72
        let index = 0;
×
73
        let indices = [];
×
74

75
        if (!caseSensitive) {
×
76
            str = str.toLowerCase();
×
77
            searchStr = searchStr.toLowerCase();
×
78
        }
79
        while ((index = str.indexOf(searchStr, startIndex)) > -1) {
×
80
            indices.push(index);
×
81
            startIndex = index + searchStrLen;
×
82
        }
83
        return indices;
×
84
    }
85

86
    private getWord(document: TextDocument, position: Position): string {
87
        const range = document.getWordRangeAtPosition(position, /[^\s\x21-\x2f\x3a-\x40\x5b-\x5e\x7b-\x7e]+/);
×
88
        if (range !== undefined) {
×
89
            return document.getText(range);
×
90
        }
91
    }
92
}
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

© 2025 Coveralls, Inc