redhat-developer / redhat-developer/vscode-yaml

yaml.schemas: document and support variable in schema paths

Open
#1,266 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
829
Forks
260
Avg merge
5h 43m
Merged PRs (30d)
1

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the configuration-reading code that handles yaml.schemas and trace how schema map keys are passed to the language server. Check the workspace variable APIs mentioned in the issue, then update the README and package.json setting description. Done means workspaceFolder and named multi-root variables resolve for local schema paths and the documented example validates successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.