• 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

60.87
/src/BrightScriptSignatureHelpProvider.ts
1
import type {
2
    CancellationToken,
3
    SignatureHelpProvider,
4
    TextDocument
5
} from 'vscode';
6
import {
1✔
7
    ParameterInformation,
8
    Position,
9
    Range,
10
    SignatureHelp,
11
    SignatureInformation
12
} from 'vscode';
13

14
import type { DefinitionRepository } from './DefinitionRepository';
15

16
export default class BrightScriptSignatureHelpProvider implements SignatureHelpProvider {
1✔
17

18
    public constructor(provider: DefinitionRepository) {
19
        this.definitionRepo = provider;
7✔
20
    }
21

22
    public definitionRepo: DefinitionRepository;
23

24
    public provideSignatureHelp(document: TextDocument, position: Position, token: CancellationToken): SignatureHelp {
25
        //TODO - use AST/Parse tree to get the position of a symbol to our left
26
        //1. get first bracket to our left, - then get the symbol before that..
27
        //really crude crappy parser..
28
        //TODO this is whack - it's not even LTR ugh..
29
        let bracketCounts = { normal: 0, square: 0, curly: 0 };
3✔
30
        let commaCount = 0;
3✔
31
        let index = position.character;
3✔
32
        let line = document.getText(new Range(position.line, 0, position.line, position.character));
3✔
33
        let isArgStartFound = false;
3✔
34
        while (index >= 0) {
3✔
35
            if (isArgStartFound) {
33!
36
                if (line.charAt(index) !== ' ') {
×
37
                    break;
×
38
                }
39
            } else {
40
                if (line.charAt(index) === ')') {
33!
41
                    bracketCounts.normal++;
×
42
                }
43
                if (line.charAt(index) === ']') {
33!
44
                    bracketCounts.square++;
×
45
                }
46
                if (line.charAt(index) === '}') {
33!
47
                    bracketCounts.curly++;
×
48
                }
49
                if (line.charAt(index) === ',' && bracketCounts.normal <= 0 && bracketCounts.curly <= 0 && bracketCounts.square <= 0) {
33!
50
                    commaCount++;
×
51
                }
52

53
                if (line.charAt(index) === '(') {
33!
54
                    if (bracketCounts.normal === 0) {
×
55
                        isArgStartFound = true;
×
56
                    } else {
57
                        bracketCounts.normal--;
×
58
                    }
59
                }
60
                if (line.charAt(index) === '[') {
33!
61
                    bracketCounts.square--;
×
62
                }
63
                if (line.charAt(index) === '{') {
33!
64
                    bracketCounts.curly--;
×
65
                }
66
            }
67
            index--;
33✔
68
        }
69
        if (index === 0) {
3!
70
            return undefined;
×
71
        }
72

73
        //count number of commas from defintion start, to current pos
74
        const adjustedPosition = new Position(position.line, index - 1);
3✔
75
        let definition = this.definitionRepo.findDefinition(document, adjustedPosition).next();
3✔
76
        if (definition) {
3✔
77
            let signatureHelp = new SignatureHelp();
1✔
78

79
            let params: ParameterInformation[] = [];
1✔
80
            let paramNames: string[] = [];
1✔
81
            for (const param of definition.value.params) {
1✔
82
                let paramName: string = param.trim();
1✔
83
                let infoText = '';
1✔
84
                let infoIndex = param.indexOf('=');
1✔
85
                let hasDefault = infoIndex !== -1;
1✔
86
                if (infoIndex === -1) {
1!
87
                    infoIndex = param.indexOf(' as');
1✔
88
                }
89
                if (infoIndex !== -1) {
1!
90
                    paramName = param.substring(0, infoIndex).trim();
×
91
                    infoText = param.substring(infoIndex).trim();
×
92
                    if (hasDefault) {
×
93
                        infoText = infoText.replace('=', 'default:');
×
94
                    }
95
                }
96
                paramNames.push(paramName);
1✔
97
                params.push(new ParameterInformation(paramName, infoText));
1✔
98
            }
99
            let signatureInfo = new SignatureInformation(definition.value.name + '(' + paramNames.join(', ') + ')');
1✔
100
            signatureInfo.parameters = params;
1✔
101

102
            signatureHelp.signatures.push(signatureInfo);
1✔
103
            signatureHelp.activeParameter = commaCount;
1✔
104
            signatureHelp.activeSignature = 0;
1✔
105
            return signatureHelp;
1✔
106
        }
107
        return undefined;
2✔
108
    }
109
}
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