• 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

24.41
/src/SceneGraphDebugCommands.ts
1
import * as vscode from 'vscode';
1✔
2
import type { SceneGraphCommandResponse } from 'roku-debug';
3
import { SceneGraphDebugCommandController } from 'roku-debug';
1✔
4

5
export class SceneGraphDebugCommands {
1✔
6
    private outputChannel: vscode.OutputChannel;
7
    private context: vscode.ExtensionContext;
8
    private host: string;
9

10
    public registerCommands(context: vscode.ExtensionContext, outputChannel: vscode.OutputChannel) {
11
        this.context = context;
7✔
12
        this.outputChannel = outputChannel;
7✔
13

14
        let subscriptions = context.subscriptions;
7✔
15

16
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.bsprofPause', async () => {
7✔
17
            await this.logCommandOutput(async (commandController) => commandController.bsprof('pause'));
×
18
        }));
19

20
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.bsprofResume', async () => {
7✔
21
            await this.logCommandOutput(async (commandController) => commandController.bsprof('resume'));
×
22
        }));
23

24
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.bsprofStatus', async () => {
7✔
25
            await this.logCommandOutput(async (commandController) => commandController.bsprof('status'));
×
26
        }));
27

28
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.chanperf', async () => {
7✔
29
            await this.logCommandOutput(async (commandController) => commandController.chanperf());
×
30
        }));
31

32
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.chanperfChangeInterval', async () => {
7✔
33
            let interval = parseInt(await vscode.window.showInputBox({ placeHolder: 'seconds' }));
×
34
            if (!isNaN(interval)) {
×
35
                await this.logCommandOutput(async (commandController) => commandController.chanperf({ interval: interval }));
×
36
            }
37
        }));
38

39
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.clearLaunchCaches', async () => {
7✔
40
            await this.logCommandOutput(async (commandController) => commandController.clearLaunchCaches());
×
41
        }));
42

43
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.fpsDisplay', async () => {
7✔
44
            let option = await vscode.window.showQuickPick(['toggle', 'on', 'off'], { placeHolder: 'Please select an option' });
×
45
            if (option) {
×
46
                await this.logCommandOutput(async (commandController) => commandController.fpsDisplay(option as 'toggle' | 'on' | 'off'));
×
47
            }
48
        }));
49

50
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.free', async () => {
7✔
51
            await this.logCommandOutput(async (commandController) => commandController.free());
×
52
        }));
53

54
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.genkey', async () => {
7✔
55
            await this.logCommandOutput(async (commandController) => commandController.genkey());
×
56
        }));
57

58
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.loadedTextures', async () => {
7✔
59
            await this.logCommandOutput(async (commandController) => commandController.loadedTextures());
×
60
        }));
61

62
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.logrendezvous', async () => {
7✔
63
            let option = await vscode.window.showQuickPick(['status', 'on', 'off'], { placeHolder: 'Please select an option' });
×
64
            if (option) {
×
65
                await this.logCommandOutput(async (commandController) => commandController.logrendezvous(option as 'status' | 'on' | 'off'));
×
66
            }
67
        }));
68

69
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.plugins', async () => {
7✔
70
            await this.logCommandOutput(async (commandController) => commandController.plugins());
×
71
        }));
72

73
        // TODO: press? likely needs to go in the old area.
74
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.press', async () => {
7✔
75
            let keys = (await vscode.window.showInputBox({ placeHolder: 'comma separated list of keys' })).split(',');
×
76
            if (keys.length > 1) {
×
77
                await this.logCommandOutput(async (commandController) => commandController.press(keys));
×
78
            }
79
        }));
80

81
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.r2d2bitmaps', async () => {
7✔
82
            await this.logCommandOutput(async (commandController) => commandController.r2d2Bitmaps());
×
83
        }));
84

85
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.removePlugin', async () => {
7✔
86
            let pluginId = await vscode.window.showInputBox({ placeHolder: 'plugin_id' });
×
87

88
            if (pluginId) {
×
89
                await this.logCommandOutput(async (commandController) => commandController.removePlugin(pluginId));
×
90
            }
91
        }));
92

93
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgnodesAll', async () => {
7✔
94
            await this.logCommandOutput(async (commandController) => commandController.sgnodes('all'));
×
95
        }));
96

97
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgnodesRoots', async () => {
7✔
98
            await this.logCommandOutput(async (commandController) => commandController.sgnodes('roots'));
×
99
        }));
100

101
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgnodesNodeId', async () => {
7✔
102
            let nodeId = await vscode.window.showInputBox({ placeHolder: 'node_id' });
×
103
            if (nodeId) {
×
104
                await this.logCommandOutput(async (commandController) => commandController.sgnodes(nodeId));
×
105
            }
106
        }));
107

108
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgperfStart', async () => {
7✔
109
            await this.logCommandOutput(async (commandController) => commandController.sgperf('start'));
×
110
        }));
111

112
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgperfStop', async () => {
7✔
113
            await this.logCommandOutput(async (commandController) => commandController.sgperf('stop'));
×
114
        }));
115

116
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgperfClear', async () => {
7✔
117
            await this.logCommandOutput(async (commandController) => commandController.sgperf('clear'));
×
118
        }));
119

120
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.sgperfReport', async () => {
7✔
121
            await this.logCommandOutput(async (commandController) => commandController.sgperf('report'));
×
122
        }));
123

124
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.showkey', async () => {
7✔
125
            await this.logCommandOutput(async (commandController) => commandController.showkey());
×
126
        }));
127

128
        subscriptions.push(vscode.commands.registerCommand('extension.brightscript.custom8080Command', async () => {
7✔
129
            let command = await vscode.window.showInputBox({ placeHolder: 'custom command' });
×
130
            if (command) {
×
131
                await this.logCommandOutput(async (commandController) => commandController.exec(command));
×
132
            }
133
        }));
134
    }
135

136
    private async logCommandOutput(callback: (controller: SceneGraphDebugCommandController) => Promise<SceneGraphCommandResponse>) {
137
        await this.getRemoteHost();
×
138
        let response = await callback(new SceneGraphDebugCommandController(this.host));
×
139

140
        this.outputChannel.show();
×
141

142
        // The output channel seems to have a limit to the amount of output that can be displayed in a single log.
143
        // For this reason we split the output into groups of 20 lines and send each group. If we don't do this a lot of
144
        // the middle of the string gets cut out.
145
        let lines = (response?.error?.message ?? response.result.rawResponse).split('\n');
×
146
        let lineGroups = this.chunkArray(lines);
×
147

148
        // Log the command statement
149
        this.outputChannel.append(`>${response.command}\n`);
×
150

151
        // Log each group of 20 lines
152
        for (let lineGroup of lineGroups) {
×
153
            this.outputChannel.append(lineGroup.join('\n') + '\n');
×
154
        }
155
    }
156

157
    private chunkArray(arr: Array<any>, chunkSize = 20) {
×
158
        if (chunkSize <= 0) {
×
159
            return arr;
×
160
        }
161

162
        let chunks = [];
×
163
        for (let i = 0, len = arr.length; i < len; i += 20) {
×
164
            chunks.push(arr.slice(i, i + chunkSize));
×
165

166
        }
167

168
        return chunks;
×
169
    }
170

171
    public async getRemoteHost() {
172
        this.host = await this.context.workspaceState.get('remoteHost');
×
173
        if (!this.host) {
×
174
            let config = vscode.workspace.getConfiguration('brightscript.remoteControl', null);
×
175
            this.host = config.get('host');
×
176
            if (this.host === '${promptForHost}') {
×
177
                this.host = await vscode.window.showInputBox({
×
178
                    placeHolder: 'The IP address of your Roku device',
179
                    value: ''
180
                });
181
            }
182
        }
183
        if (!this.host) {
×
184
            throw new Error('Can\'t send command: host is required.');
×
185
        } else {
186
            await this.context.workspaceState.update('remoteHost', this.host);
×
187
        }
188
    }
189

190
}
191

192
export const sceneGraphDebugCommands = new SceneGraphDebugCommands();
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

© 2025 Coveralls, Inc