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

rokucommunity / vscode-brightscript-language / 30096694707

24 Jul 2026 01:23PM UTC coverage: 59.949% (+0.04%) from 59.908%
30096694707

Pull #802

github

web-flow
Merge 333fa7808 into e465804e3
Pull Request #802: Route extension logs through the BrightScript Extension output channel

2592 of 4745 branches covered (54.63%)

Branch coverage included in aggregate %.

19 of 23 new or added lines in 3 files covered. (82.61%)

732 existing lines in 18 files now uncovered.

4036 of 6311 relevant lines covered (63.95%)

43.79 hits per line

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

6.8
/src/DefinitionRepository.ts
1
import * as vscode from 'vscode';
1✔
2
import type {
3
    Location,
4
    Position,
5
    TextDocument
6
} from 'vscode';
7
import { BrightScriptDeclaration } from './BrightScriptDeclaration';
1✔
8
import type { DeclarationProvider } from './DeclarationProvider';
9
import { getExcludeGlob } from './DeclarationProvider';
1✔
10

11
export class DefinitionRepository {
1✔
12

13
    constructor(
14
        public provider: DeclarationProvider
44✔
15
    ) {
16
        this.declarationProvider = provider;
44✔
17
        provider.onDidChange((e) => {
44✔
UNCOV
18
            this.cache.set(e.uri.fsPath, e.decls.filter((d) => d.isGlobal));
×
19
        });
20
        provider.onDidDelete((e) => {
44✔
21
            this.cache.delete(e.uri.fsPath);
×
22
        });
23
        provider.onDidReset((e) => {
44✔
24
            this.cache.clear();
×
25
        });
26
    }
27

28
    private declarationProvider: DeclarationProvider;
29
    private cache = new Map<string, BrightScriptDeclaration[]>();
44✔
30

31
    public sync(): Promise<void> {
UNCOV
32
        return this.provider.sync();
×
33
    }
34

35
    public * find(document: TextDocument, position: Position): IterableIterator<Location> {
UNCOV
36
        const word = this.getWord(document, position).toLowerCase(); //brightscript is not case sensitive!
×
37

UNCOV
38
        void this.sync();
×
39
        if (word === undefined) {
×
UNCOV
40
            return;
×
41
        }
42
        yield* this.findInCurrentDocument(document, position, word);
×
43
        const ws = vscode.workspace.getWorkspaceFolder(document.uri);
×
UNCOV
44
        if (ws === undefined) {
×
45
            return;
×
46
        }
47
        const fresh = new Set<string>([document.uri.fsPath]);
×
48
        for (const doc of vscode.workspace.textDocuments) {
×
UNCOV
49
            if (!doc.isDirty) {
×
50
                continue;
×
51
            }
52
            if (doc === document) {
×
53
                continue;
×
54
            }
55
            if (!this.cache.has(doc.uri.fsPath)) {
×
56
                continue;
×
57
            }
58
            if (!doc.uri.fsPath.startsWith(ws.uri.fsPath)) {
×
59
                continue;
×
60
            }
61
            fresh.add(doc.uri.fsPath);
×
62
            yield* this.findInDocument(doc, word);
×
63
        }
64
        for (const [path, defs] of this.cache.entries()) {
×
65
            if (fresh.has(path)) {
×
UNCOV
66
                continue;
×
67
            }
68
            if (!path.startsWith(ws.uri.fsPath)) {
×
69
                continue;
×
70
            }
71
            yield* defs.filter((d) => d.name.toLowerCase() === word).map((d) => d.getLocation());
×
72
        }
73
    }
74

75
    private getWord(document: TextDocument, position: Position): string {
UNCOV
76
        const wordRange = document.getWordRangeAtPosition(position, /[^\s\x21-\x2f\x3a-\x40\x5b-\x5e\x7b-\x7e]+/);
×
77

UNCOV
78
        const phraseRange = document.getWordRangeAtPosition(position, /(\w|\.)+/);
×
79
        if (wordRange !== undefined) {
×
UNCOV
80
            const word = document.getText(wordRange);
×
81
            if (phraseRange !== undefined) {
×
82
                const phrase = document.getText(phraseRange);
×
83
                let parts = phrase.split('.');
×
84
                const index = parts.indexOf(word);
×
85
                if (index < parts.length - 1) {
×
86
                    parts.splice(index + 1, parts.length - 1 - index);
×
87
                    return parts.join('.');
×
88
                }
89
            }
90
            return word;
×
91
        }
92
    }
93

94
    private findInCurrentDocument(document: TextDocument, position: Position, word: string): Location[] {
UNCOV
95
        return this.declarationProvider.readDeclarations(document.uri, document.getText())
×
96
            .filter((d) => {
UNCOV
97
                return d.name.toLowerCase() === word && d.visible(position);
×
98
            })
99
            .map((d) => {
100
                return d.getLocation();
×
101
            });
102
    }
103

104
    private findInDocument(document: TextDocument, word: string): Location[] {
UNCOV
105
        return this.declarationProvider.readDeclarations(document.uri, document.getText())
×
UNCOV
106
            .filter((d) => d.name.toLowerCase() === word && d.isGlobal)
×
UNCOV
107
            .map((d) => d.getLocation());
×
108
    }
109

110
    public *findDefinition(document: TextDocument, position: Position): IterableIterator<BrightScriptDeclaration> {
UNCOV
111
        const word = this.getWord(document, position).toLowerCase(); //brightscript is not case sensitive!
×
UNCOV
112
        let result = yield* this.findDefinitionForWord(document, position, word);
×
UNCOV
113
        return result;
×
114
    }
115
    // duplicating some of thisactivate.olympicchanel.com to reduce the risk of introducing nasty performance issues/unwanted behaviour by extending Location
116
    public *findDefinitionForWord(document: TextDocument, position: Position, word: string): IterableIterator<BrightScriptDeclaration> {
117

UNCOV
118
        void this.sync();
×
UNCOV
119
        if (word === undefined) {
×
UNCOV
120
            return;
×
121
        }
122
        yield* this.findDefinitionInCurrentDocument(document, position, word);
×
123
        const ws = vscode.workspace.getWorkspaceFolder(document.uri);
×
UNCOV
124
        if (ws === undefined) {
×
125
            return;
×
126
        }
127
        const fresh = new Set<string>([document.uri.fsPath]);
×
128
        for (const doc of vscode.workspace.textDocuments) {
×
UNCOV
129
            console.log('>>>>>doc ' + doc.uri.path);
×
130

131
            if (!doc.isDirty) {
×
132
                continue;
×
133
            }
134
            if (doc === document) {
×
135
                continue;
×
136
            }
137
            if (!this.cache.has(doc.uri.fsPath)) {
×
138
                continue;
×
139
            }
140
            if (!doc.uri.fsPath.startsWith(ws.uri.fsPath)) {
×
141
                continue;
×
142
            }
143
            fresh.add(doc.uri.fsPath);
×
144
            yield* this.findDefinitionInDocument(doc, word);
×
145
        }
146
        for (const [path, defs] of this.cache.entries()) {
×
147
            if (fresh.has(path)) {
×
UNCOV
148
                continue;
×
149
            }
150
            if (!path.startsWith(ws.uri.fsPath)) {
×
151
                continue;
×
152
            }
153
            yield* defs.filter((d) => d.name.toLowerCase() === word);
×
154
        }
155
    }
156

157
    private findDefinitionInCurrentDocument(document: TextDocument, position: Position, word: string): BrightScriptDeclaration[] {
UNCOV
158
        return this.declarationProvider.readDeclarations(document.uri, document.getText())
×
UNCOV
159
            .filter((d) => d.name.toLowerCase() === word && d.visible(position));
×
160
    }
161

162
    public findDefinitionInDocument(document: TextDocument, word: string): BrightScriptDeclaration[] {
UNCOV
163
        return this.declarationProvider.readDeclarations(document.uri, document.getText())
×
UNCOV
164
            .filter((d) => d.name.toLowerCase() === word && d.isGlobal);
×
165
    }
166

167
    public async findDefinitionForBrsDocument(name: string): Promise<BrightScriptDeclaration[]> {
UNCOV
168
        let declarations = [];
×
UNCOV
169
        await this.sync();
×
UNCOV
170
        const excludes = getExcludeGlob();
×
171
        //get usable bit of name
172
        let fileName = name.replace(/^.*[\\\/]/, '').toLowerCase();
×
173
        for (const uri of await vscode.workspace.findFiles('**/*.{brs,bs}', excludes)) {
×
UNCOV
174
            if (uri.path.toLowerCase().includes(fileName)) {
×
175
                declarations.push(BrightScriptDeclaration.fromUri(uri));
×
176
            }
177
        }
178
        return declarations;
×
179
    }
180
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc