Skip to content

Support ${taskVar:name} variables from problem matcher named capture groups #303361

@hediet

Description

@hediet

Problem

When a background task's endsPattern matches terminal output, VS Code only uses the match as a signal that background processing has ended. Any data captured by the regex (e.g., a dynamically assigned port or URL) is discarded.

This means launch configurations that depend on dynamic values from task output (like a server URL) must hardcode values or rely on workarounds.

Proposed Solution

Introduce ${taskVar:name} variables that capture named groups from a problem matcher's endsPattern regex and make them available for substitution in launch configurations (and anywhere else variables are resolved).

How it works

  1. A task's problem matcher endsPattern uses a named capture group:

    "endsPattern": "  current session url: (?<componentExplorerUrl>.*)"
  2. When the pattern matches, the named group values are extracted and registered as contributed variables.

  3. A launch configuration references the captured value:

    "url": "${taskVar:componentExplorerUrl}"

Naming convention

The ${taskVar:name} syntax follows VS Code's existing ${name:arg} convention (like ${env:PATH}, ${config:setting}, ${command:id}).

Implementation

  • WatchingProblemCollector.tryFinish() extracts matches.groups from the endsPattern match
  • IProblemCollectorEvent carries captured variables in the BackgroundProcessingEnds event
  • TerminalTaskSystem registers captured variables via IConfigurationResolverService.contributeVariable()
  • VariableKind.TaskVar added for completeness

Example

// tasks.json
{
    "label": "Start Server",
    "type": "shell",
    "command": "npm start",
    "isBackground": true,
    "problemMatcher": {
        "background": {
            "activeOnStart": true,
            "beginsPattern": ".*Starting.*",
            "endsPattern": "Server listening on (?<serverUrl>http://localhost:\\d+)"
        }
    }
}

// launch.json
{
    "name": "Debug in Browser",
    "type": "chrome",
    "request": "launch",
    "url": "${taskVar:serverUrl}",
    "preLaunchTask": "Start Server"
}

Metadata

Metadata

Labels

feature-requestRequest for new features or functionalityinsiders-releasedPatch has been released in VS Code InsiderstasksTask system issuesverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions