• 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

17.39
/src/commands/LanguageServerInfoCommand.ts
1
import * as vscode from 'vscode';
1✔
2
import { languageServerManager } from '../LanguageServerManager';
1✔
3
import * as path from 'path';
1✔
4

5
export class LanguageServerInfoCommand {
1✔
6
    public static commandName = 'extension.brightscript.languageServer.info';
1✔
7

8
    private context: vscode.ExtensionContext;
9
    public register(context: vscode.ExtensionContext) {
10
        this.context = context;
6✔
11

12
        context.subscriptions.push(vscode.commands.registerCommand(LanguageServerInfoCommand.commandName, async () => {
6✔
13
            const commands = [{
×
14
                label: `Change Selected BrighterScript Version`,
15
                description: `(current v${languageServerManager.selectedBscInfo.version})`,
16
                command: this.selectBrighterScriptVersion.bind(this)
17
            }, {
18
                label: `Restart BrighterScript Language Server`,
19
                description: ``,
20
                command: this.restartLanguageServer.bind(this)
21
            }];
22
            let selection = await vscode.window.showQuickPick(commands, { placeHolder: `BrighterScript Project Info` });
×
23
            await selection?.command();
×
24
        }));
25
    }
26

27
    private async restartLanguageServer() {
28
        await vscode.commands.executeCommand('extension.brightscript.languageServer.restart');
×
29
    }
30

31
    /**
32
     * If this changes the user/folder/workspace settings, that will trigger a reload of the language server so there's no need to
33
     * call the reload manually
34
     */
35
    public async selectBrighterScriptVersion() {
36
        const versions = [{
×
37
            label: `Use VS Code's version`,
38
            description: languageServerManager.embeddedBscInfo.version,
39
            detail: undefined as string //require.resolve('brighterscript')
40
        }];
41

42
        //look for brighterscript in all workspace folders
43
        for (const workspaceFolder of vscode.workspace.workspaceFolders) {
×
44
            const workspaceOrFolderPath = this.getWorkspaceOrFolderPath(workspaceFolder.uri.fsPath);
×
45
            try {
×
46
                let bscPath = require.resolve('brighterscript', {
×
47
                    paths: [workspaceFolder.uri.fsPath]
48
                });
49
                //require.resolve returns a bsc script path, so remove that to get the root of brighterscript folder
50
                if (bscPath) {
×
51
                    bscPath = bscPath.replace(/[\\\/]dist[\\\/]index.js/i, '');
×
52
                    // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
53
                    const version = require(`${bscPath}/package.json`).version;
×
54
                    //make the path relative to the workspace folder
55
                    bscPath = path.relative(workspaceOrFolderPath, bscPath);
×
56

57
                    versions.push({
×
58
                        label: 'Use Workspace Version',
59
                        description: version,
60
                        detail: bscPath
61
                    });
62
                }
63
            } finally { }
64
        }
65
        let selection = await vscode.window.showQuickPick(versions, { placeHolder: `Select the BrighterScript version used for BrightScript and BrighterScript language features` });
×
66
        if (selection) {
×
67
            const config = vscode.workspace.getConfiguration('brightscript');
×
68
            //if the user picked "use embedded version", then remove the setting
69
            if (versions.indexOf(selection) === 0) {
×
70
                //setting to undefined means "remove"
71
                await config.update('bsdk', 'embedded');
×
72
                return 'embedded';
×
73
            } else {
74
                //save this to workspace/folder settings (vscode automatically decides if it goes into the code-workspace settings or the folder settings
75
                await config.update('bsdk', selection.detail);
×
76
                return selection.detail;
×
77
            }
78
        }
79
    }
80

81
    private getWorkspaceOrFolderPath(workspaceFolder: string) {
82
        const workspaceFile = vscode.workspace.workspaceFile;
×
83
        if (workspaceFile) {
×
84
            return path.dirname(workspaceFile.fsPath);
×
85
        } else {
86
            return workspaceFolder;
×
87
        }
88
    }
89
}
90

91
export const languageServerInfoCommand = new LanguageServerInfoCommand();
1✔
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