• 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

34.33
/src/BrightScriptXmlDefinitionProvider.ts
1
import * as vscode from 'vscode';
1✔
2

3
import type {
4
    CancellationToken,
5
    Definition,
6
    DefinitionProvider, Position, TextDocument
7
} from 'vscode';
8
import {
9
    Range
10
} from 'vscode';
11

12
import { BrightScriptDeclaration } from './BrightScriptDeclaration';
1✔
13
import BrightScriptFileUtils from './BrightScriptFileUtils';
1✔
14
import { getExcludeGlob } from './DeclarationProvider';
1✔
15
import type { DefinitionRepository } from './DefinitionRepository';
16
import { XmlUtils, XmlWordType } from './XmlUtils';
1✔
17

18
export default class BrightScriptXmlDefinitionProvider implements DefinitionProvider {
1✔
19

20
    constructor(repo: DefinitionRepository) {
21
        this.repo = repo;
11✔
22
        this.fileUtils = new BrightScriptFileUtils();
11✔
23
        this.xmlUtils = new XmlUtils();
11✔
24
    }
25

26
    private repo: DefinitionRepository;
27
    private xmlUtils: XmlUtils;
28
    private fileUtils: BrightScriptFileUtils;
29

30
    public async provideDefinition(document: TextDocument, position: Position, token: CancellationToken): Promise<Definition> {
31
        //1. if it's not an xml doc, return empty
32
        if (!document.fileName.toLowerCase().endsWith('.xml') || !document.getText()) {
4✔
33
            return [];
3✔
34
        }
35

36
        let definitions = [];
1✔
37
        //2. if it's an xml element, jump to matching doc
38
        let xmlWordType = this.xmlUtils.getXmlWordType(document, position, token);
1✔
39
        let word = this.xmlUtils.getWord(document, position, xmlWordType).toLowerCase();
1✔
40

41
        await this.repo.sync();
1✔
42

43
        switch (xmlWordType) {
1!
44
            case XmlWordType.Tag:
45
                definitions = await this.getXmlFileMatchingWord(word);
×
46
                break;
×
47
            case XmlWordType.AttributeValue:
48
                //TODO - ascertain if this value is from an import tag!
49
                if (word.endsWith('.brs')) {
×
50
                    //assume it's a document
51
                    definitions = await this.getSymbolForBrsFile(word);
×
52
                } else {
53
                    //assume it's a symbol in our codebehind file
54
                    definitions = await this.getBrsSymbolsMatchingWord(document, position, word);
×
55
                }
56
                break;
×
57
            default:
58
                break;
1✔
59
        }
60

61
        return definitions;
1✔
62
    }
63

64
    private async getXmlFileMatchingWord(word: string): Promise<Definition[]> {
65
        let definitions = [];
×
66

67
        const excludes = getExcludeGlob();
×
68

69
        for (const uri of await vscode.workspace.findFiles('**/*.xml', excludes)) {
×
70
            let path = uri.path.toLowerCase();
×
71
            if (path.includes(word) && path.endsWith('.xml')) {
×
72
                let definition = BrightScriptDeclaration.fromUri(uri);
×
73
                definitions.push(definition.getLocation());
×
74
                if (path.endsWith(word + '.xml')) {
×
75
                    definitions = [definition.getLocation()];
×
76
                    break;
×
77
                }
78
            }
79
        }
80
        return definitions;
×
81
    }
82

83
    private async getBrsSymbolsMatchingWord(document: TextDocument, position: Position, word: string): Promise<Definition[]> {
84
        let alternateFilename = this.fileUtils.getAlternateFileName(document.fileName);
×
85
        let definitions = [];
×
86

87
        if (alternateFilename) {
×
88
            let uri = vscode.Uri.file(alternateFilename);
×
89
            let doc = await vscode.workspace.openTextDocument(uri); // calls back into the provider
×
90
            if (doc) {
×
91
                for (const d of this.repo.findDefinitionInDocument(doc, word)) {
×
92
                    definitions.push(d.getLocation());
×
93
                }
94
            }
95
        }
96
        return definitions;
×
97
    }
98

99
    private async getSymbolForBrsFile(word: string): Promise<Definition[]> {
100
        let definitions = [];
×
101
        for (const def of await this.repo.findDefinitionForBrsDocument(word)) {
×
102
            definitions.push(def.getLocation());
×
103
        }
104
        return definitions;
×
105
    }
106
}
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