BrightScript Tasks

The BrightScript language extension provides a task system that integrates with VS Code's task runner, allowing you to automate common development workflows like building, testing, and linting.

Features

Basic Task Configuration

Tasks are defined in .vscode/tasks.json in your workspace. Here's a simple example:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "brightscript",
            "label": "Build Project",
            "command": "npx bsc"
        }
    ]
}

Required Properties

Variable Substitution

BrightScript tasks support variable substitution in the command field. Variables are resolved before the command is executed.

Using ${folderForFile: <glob>}

The ${folderForFile: <glob>} variable finds files matching a glob pattern and resolves to the directory containing those files. This is useful in monorepos or multi-project workspaces.

Example: Build a specific project

{
    "type": "brightscript",
    "label": "Build Selected Project",
    "command": "cd ${folderForFile: **/bsconfig.json} && npx bsc"
}

When you run this task:

Common glob patterns:

Pattern Matches
**/bsconfig.json Any bsconfig.json file at any depth
apps/**/package.json package.json files under the apps directory
*.config.js Config files in the root directory only

Note: Files in node_modules are automatically excluded.

Advanced Configuration

Environment Variables

Add environment variables available to your command:

{
    "type": "brightscript",
    "label": "Build with Custom Env",
    "command": "npx bsc",
    "options": {
        "env": {
            "NODE_ENV": "production"
        }
    }
}

Custom Working Directory

{
    "type": "brightscript",
    "label": "Build from Subdirectory",
    "command": "npx bsc",
    "options": {
        "cwd": "${workspaceFolder}/apps/my-roku-app"
    }
}

Problem Matchers

Problem matchers parse command output to detect errors and warnings. Here's a basic example for BrighterScript compiler output:

{
    "type": "brightscript",
    "label": "Compile",
    "command": "npx bsc",
    "problemMatcher": {
        "owner": "brightscript",
        "fileLocation": "relative",
        "pattern": {
            "regexp": "^(.*)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

Background Tasks

Background tasks are useful for file watchers or development servers:

{
    "type": "brightscript",
    "label": "Watch",
    "command": "npx bsc --watch",
    "isBackground": true
}

Pre-Launch Tasks

Use tasks as pre-launch actions to build your project before debugging:

{
    "type": "brightscript",
    "name": "Launch on Roku",
    "request": "launch",
    "host": "${promptForHost}",
    "password": "${promptForPassword}",
    "preLaunchTask": "Build Project"
}

Complete Example

Here's a basic tasks.json for a monorepo workflow:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "brightscript",
            "label": "Build Selected Project",
            "command": "cd ${folderForFile: **/bsconfig.json} && npx bsc",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "brightscript",
            "label": "Watch Selected Project",
            "command": "cd ${folderForFile: **/bsconfig.json} && npx bsc --watch",
            "isBackground": true
        }
    ]
}

Troubleshooting

Task not found:

Variable not resolving:

Command not executing:

Best Practices

See Also

Supported Variables

Variable Description Example Value
Workspace Variables
${workspaceFolder} Path of the workspace folder /Users/user/project
${workspaceFolderBasename} Name of the workspace folder project
${fileWorkspaceFolderBasename} Name of workspace folder containing active file my-app
File Variables (require an active file)
${file} Full path of the currently opened file /Users/user/project/src/main.brs
${fileWorkspaceFolder} Workspace folder of the currently opened file /Users/user/project
${relativeFile} Current file relative to workspace folder src/main.brs
${relativeFileDirname} Current file's directory relative to workspace src
${fileBasename} Current file's basename main.brs
${fileBasenameNoExtension} Current file's basename without extension main
${fileExtname} Current file's extension .brs
${fileDirname} Current file's directory path /Users/user/project/src
${fileDirnameBasename} Current file's directory name src
Editor Variables (require an active editor)
${lineNumber} Current line number in active file (1-based) 42
${columnNumber} Current column number in active file (1-based) 15
${selectedText} Currently selected text in active file function main()
System Variables
${userHome} User's home directory /Users/user
${cwd} Current working directory of VS Code /Users/user/project
${execPath} Path to VS Code executable /Applications/VSCode.app
${pathSeparator} OS-specific path separator / (macOS/Linux) or \ (Windows)
${/} Shorthand for ${pathSeparator} / or \
Custom Variables
${folderForFile: <glob>} Directory containing file(s) matching glob pattern /Users/user/project/apps/app1