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

rokucommunity / brighterscript / #15048

01 Jan 2026 11:17PM UTC coverage: 87.048% (-0.9%) from 87.907%
#15048

push

web-flow
Merge 02ba2bb57 into 2ea4d2108

14498 of 17595 branches covered (82.4%)

Branch coverage included in aggregate %.

192 of 261 new or added lines in 12 files covered. (73.56%)

897 existing lines in 48 files now uncovered.

15248 of 16577 relevant lines covered (91.98%)

24112.76 hits per line

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

88.24
/src/SemanticTokenUtils.ts
1
import type {
2
    SemanticTokensLegend
3
} from 'vscode-languageserver-protocol/node';
4
import {
1✔
5
    SemanticTokenTypes,
6
    SemanticTokenModifiers
7
} from 'vscode-languageserver-protocol/node';
8
import { SemanticTokensBuilder } from 'vscode-languageserver/node';
1✔
9
import type {
10
    SemanticToken
11
} from './interfaces';
12
import util from './util';
1✔
13

14
export const semanticTokensLegend = {
1✔
15
    tokenTypes: [
16
        SemanticTokenTypes.namespace,
17
        SemanticTokenTypes.type,
18
        SemanticTokenTypes.class,
19
        SemanticTokenTypes.enum,
20
        SemanticTokenTypes.interface,
21
        SemanticTokenTypes.struct,
22
        SemanticTokenTypes.typeParameter,
23
        SemanticTokenTypes.parameter,
24
        SemanticTokenTypes.variable,
25
        SemanticTokenTypes.property,
26
        SemanticTokenTypes.enumMember,
27
        SemanticTokenTypes.event,
28
        SemanticTokenTypes.function,
29
        SemanticTokenTypes.method,
30
        SemanticTokenTypes.macro,
31
        SemanticTokenTypes.keyword,
32
        SemanticTokenTypes.modifier,
33
        SemanticTokenTypes.comment,
34
        SemanticTokenTypes.string,
35
        SemanticTokenTypes.number,
36
        SemanticTokenTypes.regexp,
37
        SemanticTokenTypes.operator
38
    ],
39
    tokenModifiers: [
40
        SemanticTokenModifiers.declaration,
41
        SemanticTokenModifiers.definition,
42
        SemanticTokenModifiers.readonly,
43
        SemanticTokenModifiers.static,
44
        SemanticTokenModifiers.deprecated,
45
        SemanticTokenModifiers.abstract,
46
        SemanticTokenModifiers.async,
47
        SemanticTokenModifiers.modification,
48
        SemanticTokenModifiers.documentation,
49
        SemanticTokenModifiers.defaultLibrary
50
    ]
51
} as SemanticTokensLegend;
52

53
/**
54
 * The LSP has a very specific format for semantic tokens, so this encodes our internal representation into the LSP format.
55
 * Currently all tokens must be single-line
56
 * See for more info: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
57
 */
58
export function encodeSemanticTokens(tokens: SemanticToken[]) {
1✔
59
    util.sortByRange(tokens);
4✔
60
    const builder = new SemanticTokensBuilder();
4✔
61
    for (const token of tokens ?? []) {
4!
62
        //skip tokens that have no range
63
        if (!token?.range) {
11!
64
            continue;
1✔
65
        }
66
        builder.push(
10✔
67
            token.range.start.line,
68
            token.range.start.character,
69
            token.range.end.character - token.range.start.character,
70
            //token type index
71
            semanticTokensLegend.tokenTypes.indexOf(token.tokenType),
72
            //modifier bit flags
73
            token.tokenModifiers ? getModifierBitFlags(token.tokenModifiers) : 0
10✔
74
        );
75
    }
76
    return builder.build().data;
4✔
77
}
78

79
/**
80
 * Convert an array of strings into a binary bitflag integer, where each non-zero bit indiciates the index of the modifier from `semanticTokensLegend.tokenModifiers`
81
 */
82
export function getModifierBitFlags(modifiers: SemanticTokenModifiers[]) {
1✔
83
    let result = 0;
18✔
84
    for (const modifier of modifiers) {
18✔
85
        const idx = semanticTokensLegend.tokenModifiers.indexOf(modifier);
16✔
86
        if (idx === -1) {
16!
UNCOV
87
            throw new Error(`Unknown semantic token modifier: '${modifier}'`);
×
88
        }
89

90
        //convert the index into a bit flag by bitshifting 1 the by the number of zeros for the idx.
91
        //example: idx=3. binary should be 0b1000, so we bitshift 1 << 3
92
        // eslint-disable-next-line no-bitwise
93
        result |= 1 << idx;
16✔
94
    }
95
    return result;
18✔
96
}
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

© 2026 Coveralls, Inc