Skip to content

Commit 2279319

Browse files
Add new launch variable substitution called activeHost (#657)
2 parents 18b5b84 + 0f8c963 commit 2279319

File tree

5 files changed

+101
-5
lines changed

5 files changed

+101
-5
lines changed

docs/variable-substitutions.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Variable Substitutions
2+
3+
BrightScript extension supports variable substitutions in launch.json configurations to make your debugging workflow more flexible and dynamic.
4+
5+
## Overview
6+
7+
Variable substitutions allow you to avoid hardcoding values in your launch configurations. Instead of specifying static IP addresses or passwords, you can use variables that are resolved at runtime.
8+
9+
## Available Variable Substitutions
10+
11+
| Variable | Description | Behavior |
12+
|----------|-------------|----------|
13+
| `${promptForHost}` | Prompts you to enter or select a host IP address | Shows input dialog or device picker when debugging starts |
14+
| `${promptForPassword}` | Prompts you to enter the device password | Shows password input dialog when debugging starts |
15+
| `${activeHost}` | Uses the currently active device | Automatically uses pre-configured device, or prompts if none set |
16+
| `${host}` | References the resolved host value | Can be used in other fields like `deepLinkUrl` |
17+
18+
## `${promptForHost}` - Interactive Host Selection
19+
20+
The most common variable substitution. When used, VS Code will:
21+
- Show a list of discovered Roku devices (if device discovery is enabled)
22+
- Allow manual IP entry
23+
- Remember the last used device
24+
25+
```json
26+
{
27+
"host": "${promptForHost}"
28+
}
29+
```
30+
31+
## `${promptForPassword}` - Interactive Password Entry
32+
33+
Prompts for the developer password when debugging starts:
34+
35+
```json
36+
{
37+
"password": "${promptForPassword}"
38+
}
39+
```
40+
41+
## `${activeHost}` - Smart Device Selection
42+
43+
**New!** Uses the currently active device without prompting, but gracefully falls back to prompting if no device is set. This provides the best of both worlds: convenience when you have a preferred device, flexibility when you don't.
44+
45+
### Basic Usage
46+
47+
```json
48+
{
49+
"version": "0.2.0",
50+
"configurations": [
51+
{
52+
"type": "brightscript",
53+
"name": "Launch with Current Device",
54+
"request": "launch",
55+
"host": "${activeHost}",
56+
"password": "${promptForPassword}",
57+
"rootDir": "${workspaceFolder}",
58+
"files": [
59+
"manifest",
60+
"source/**/*.*",
61+
"components/**/*.*",
62+
"images/**/*.*"
63+
]
64+
}
65+
]
66+
}
67+
```
68+
69+
### Requirements
70+
71+
To use `${activeHost}` optimally, you should set an active device using one of these methods:
72+
73+
1. **Via Command Palette:**
74+
- Open Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`)
75+
- Type "BrightScript: Set Active Device"
76+
- Enter the IP address of your Roku device
77+
78+
2. **Via Device List:**
79+
- Use the Roku Devices view in the sidebar to select a device (if device discovery is enabled)
80+
81+
3. **Via Debugging Session:**
82+
- The active device is automatically set when you start a debugging session with `${promptForHost}`
83+
84+
### Fallback Handling
85+
86+
If you use `${activeHost}` but no active device is set, it will automatically fallback to prompting for host selection (same behavior as `${promptForHost}`).
87+
88+
This provides a seamless experience:
89+
- **When active device is set**: Uses it automatically without prompting
90+
- **When no active device**: Falls back to the device picker/input dialog

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@
458458
},
459459
"deepLinkUrl": {
460460
"type": "string",
461-
"description": "A full deep link url to start the debugging session. There's no pretty way of launching directly to a deep link, so the app must be side-loaded, it auto-runs, we stop the app, and then launch it again using the deep link. You may use ${promptForHost}, ${host}, ${promptForQueryParams} which only asks for the URL-encoded querystring, and ${promptForDeepLinkUrl} to enter the entire deep link url at launch-time.",
461+
"description": "A full deep link url to start the debugging session. There's no pretty way of launching directly to a deep link, so the app must be side-loaded, it auto-runs, we stop the app, and then launch it again using the deep link. You may use ${promptForHost}, ${activeHost}, ${host}, ${promptForQueryParams} which only asks for the URL-encoded querystring, and ${promptForDeepLinkUrl} to enter the entire deep link url at launch-time.",
462462
"default": "http://${host}:8060/launch/dev?${promptForQueryParams}"
463463
},
464464
"password": {
@@ -2101,7 +2101,7 @@
21012101
},
21022102
"brightscript.debug.deepLinkUrl": {
21032103
"type": "string",
2104-
"description": "A full deep link url to start the debugging session. There's no pretty way of launching directly to a deep link, so the app must be side-loaded, it auto-runs, we stop the app, and then launch it again using the deep link. You may use ${promptForHost}, ${host}, ${promptForQueryParams} which only asks for the URL-encoded querystring, and ${promptForDeepLinkUrl} to enter the entire deep link url at launch-time.",
2104+
"description": "A full deep link url to start the debugging session. There's no pretty way of launching directly to a deep link, so the app must be side-loaded, it auto-runs, we stop the app, and then launch it again using the deep link. You may use ${promptForHost}, ${activeHost}, ${host}, ${promptForQueryParams} which only asks for the URL-encoded querystring, and ${promptForDeepLinkUrl} to enter the entire deep link url at launch-time.",
21052105
"default": "http://${host}:8060/launch/dev?${promptForQueryParams}",
21062106
"scope": "resource"
21072107
},

src/DebugConfigurationProvider.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ describe('BrightScriptConfigurationProvider', () => {
5353
activeDeviceManager,
5454
null,
5555
vscode.window.createOutputChannel('Extension'),
56-
userInputManager
56+
userInputManager,
57+
null // BrightScriptCommands is not used in this test
5758
);
5859
});
5960

src/DebugConfigurationProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import cloneDeep = require('clone-deep');
2121
import { rokuDeploy } from 'roku-deploy';
2222
import type { DeviceInfo } from 'roku-deploy';
2323
import type { UserInputManager } from './managers/UserInputManager';
24+
import type { BrightScriptCommands } from './BrightScriptCommands';
2425

2526

2627
export class BrightScriptDebugConfigurationProvider implements DebugConfigurationProvider {
@@ -30,7 +31,8 @@ export class BrightScriptDebugConfigurationProvider implements DebugConfiguratio
3031
private activeDeviceManager: ActiveDeviceManager,
3132
private telemetryManager: TelemetryManager,
3233
private extensionOutputChannel: vscode.OutputChannel,
33-
private userInputManager: UserInputManager
34+
private userInputManager: UserInputManager,
35+
private brightScriptCommands: BrightScriptCommands
3436
) {
3537
this.context = context;
3638
this.activeDeviceManager = activeDeviceManager;
@@ -429,6 +431,9 @@ export class BrightScriptDebugConfigurationProvider implements DebugConfiguratio
429431
} else {
430432
config.host = await this.userInputManager.promptForHostManual();
431433
}
434+
} else if (config.host.trim() === '${activeHost}') {
435+
// Get the current remote host from workspace state (it will prompt for host as a fallback)
436+
config.host = await this.brightScriptCommands.getRemoteHost();
432437
}
433438

434439
//check the host and throw error if not provided or update the workspace to set last host

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class Extension {
146146
);
147147

148148
//register the debug configuration provider
149-
let configProvider = new BrightScriptDebugConfigurationProvider(context, activeDeviceManager, this.telemetryManager, this.extensionOutputChannel, userInputManager);
149+
let configProvider = new BrightScriptDebugConfigurationProvider(context, activeDeviceManager, this.telemetryManager, this.extensionOutputChannel, userInputManager, this.brightScriptCommands);
150150
context.subscriptions.push(
151151
vscode.debug.registerDebugConfigurationProvider('brightscript', configProvider)
152152
);

0 commit comments

Comments
 (0)