redhat-developer / redhat-developer/vscode-yaml

Rank schemas based on specificity

Open
#1,034 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your enhancement related to a problem? Please describe.

I have a GitHub Workflow at the file location .github/workflows/deploy.yml.

This is picked up as one of two schemas:

  • Deployer Recipe - A Deployer yaml recipes (schema.json)
  • GitHub Workflow - YAML GitHub Workflow (github-workflow.json)

I haven't reviewed the code yet, so I don't know why, but it's effectively using the first, which is not what I want.

Describe the solution you would like

Perhaps, borrowing from CSS, we could rank globs with a specificity score to select the most likely candidate?

For example, here are the following globs:

  • Deployer Recipe - deploy.yml
  • GitHub Workflow - **/.github/workflows/*.yml

If we to use a simple metric such as how many elements are there in the path, then Deployer Recipe would have a specificity of 1 while GitHub Workflow would have a specificity of 4. Since both match, but GitHub Workflow is more specific, we assume the desired schema is more likely GitHub Workflow.

Alternatively, and I think this is a better approach, we could use 2 numbers. This will account for fileMatches with many wildcards, or where two fileMatches have the same number of items in the path. The major number would increment on concrete paths, while the minor would increment on globs. So, Deployer Recipe gets a specificity of (1, 0) while GitHub Workflow gets (2, 2), where GitHub Workflow is chosen. Using a made up example, **/.github/**/*.yml gets (1, 3) while **/.github/workflows/*.yml gets (2, 2), so the latter is chosen.

Schemas defined in yaml.schemas should always get priority, but if there are also multiple matches there, it may be worth using the same logic to pick which one to use.

Describe alternatives you have considered

N/A

Additional context

You can see in this screenshot that I'm not getting proper code completion due to it using the wrong schema.

I had assumed that by pressing one of the schemas at the top, it would set the file to that schema, but it just opens it instead.

I've worked around the issue by setting the schema myself:

  "yaml.schemas": {
    "https://json.schemastore.org/github-workflow.json": ".github/workflows/**"
  },

I'm available to work on this if the feature is desirable, just thought I should get feedback first. Just not sure if this would need to be worked on in redhat-developer/vscode-yaml or redhat-developer/yaml-language-server.

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 by reproducing schema selection for .github/workflows/deploy.yml, comparing the deploy.yml and **/.github/workflows/*.yml matches and the yaml.schemas setting. Trace the matching entry point in vscode-yaml or yaml-language-server, then define and test deterministic specificity ordering; done means the GitHub Workflow schema wins for the reported path while explicit yaml.schemas mappings retain priority.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.