Skip to content

yaml.schemas: document and support variable in schema paths #1266

Description

@chirag127

Problem

The yaml.schemas setting requires absolute paths or URLs for local schema files. VS Code supports ${workspaceFolder} variable interpolation in many settings (e.g. launch.json, tasks.json, files.watcherExclude), but vscode-yaml does not resolve this variable. Users who work across machines (or share a committed .vscode/settings.json) must either hardcode an absolute path (breaks across machines) or use a schema registry URL (requires internet access).

Steps to Reproduce

  1. Create .vscode/settings.json:
    {
      "yaml.schemas": {
        "${workspaceFolder}/schemas/my-schema.json": "*.yaml"
      }
    }
  2. Open a .yaml file in that workspace.
  3. No schema validation occurs; the Output → YAML channel shows:
    Unable to load schema from ${workspaceFolder}/schemas/my-schema.json

Expected Behaviour

The extension should resolve VS Code variable substitutions (${workspaceFolder}, ${workspaceFolder:name} for multi-root) before passing the schema URI to the language server. VS Code exposes these via vscode.workspace.workspaceFolders and the vscode.commands.executeCommand('vscode.resolveWorkspaceSetting') path.

Workaround

Users can use a relative path like ./schemas/my-schema.json, but this is neither documented nor consistently resolved across all YAML files in sub-directories.

Proposed Fix

In the configuration-reading code, after reading the yaml.schemas map keys, run each key through a variable resolver:

function resolveVars(schemaPath: string, folder: vscode.WorkspaceFolder): string {
  return schemaPath.replace(/${workspaceFolder}/g, folder.uri.fsPath);
}

Document the supported variables in the extension README and the package.json setting description.

Environment

  • OS: Windows 11 + macOS (affects both — different absolute paths per machine)
  • VS Code: 1.89+, shared .vscode/settings.json in git
  • Extension: redhat.vscode-yaml latest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions