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

rokucommunity / vscode-brightscript-language / 30100866380

24 Jul 2026 02:24PM UTC coverage: 60.103% (+0.2%) from 59.908%
30100866380

Pull #802

github

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

2593 of 4745 branches covered (54.65%)

Branch coverage included in aggregate %.

64 of 102 new or added lines in 20 files covered. (62.75%)

4073 of 6346 relevant lines covered (64.18%)

43.71 hits per line

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

8.05
/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
import { createLogger } from './logging';
1✔
11

12
const logger = createLogger('DefinitionRepository');
1✔
13

14
export class DefinitionRepository {
1✔
15

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

31
    private declarationProvider: DeclarationProvider;
32
    private cache = new Map<string, BrightScriptDeclaration[]>();
44✔
33

34
    public sync(): Promise<void> {
35
        return this.provider.sync();
×
36
    }
37

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

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

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

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

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

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

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

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

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

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

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

170
    public async findDefinitionForBrsDocument(name: string): Promise<BrightScriptDeclaration[]> {
171
        let declarations = [];
×
172
        await this.sync();
×
173
        const excludes = getExcludeGlob();
×
174
        //get usable bit of name
175
        let fileName = name.replace(/^.*[\\\/]/, '').toLowerCase();
×
176
        for (const uri of await vscode.workspace.findFiles('**/*.{brs,bs}', excludes)) {
×
177
            if (uri.path.toLowerCase().includes(fileName)) {
×
178
                declarations.push(BrightScriptDeclaration.fromUri(uri));
×
179
            }
180
        }
181
        return declarations;
×
182
    }
183
}
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