microsoft / microsoft/vscode-json-languageservice

Order fileMatches from more specific to more generic

Open
#293 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
326
Forks
145
Avg merge
22h 10m
Merged PRs (30d)
9

Description

I have a .github/workflows/site.yml file that matches multiple entries from schemastore catalog:

    {
      "name": "Ansible Playbook",
      "description": "Ansible playbook files",
      "fileMatch": [
        "playbook.yml",
        "playbook.yaml",
        "site.yml",
        "site.yaml",
        "**/playbooks/*.yml",
        "**/playbooks/*.yaml"
      ],
      "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/ansible.json#/$defs/playbook"
    }

and

    {
      "name": "GitHub Workflow",
      "description": "YAML GitHub Workflow",
      "fileMatch": [
        "**/.github/workflows/*.yml",
        "**/.github/workflows/*.yaml",
        "**/.gitea/workflows/*.yml",
        "**/.gitea/workflows/*.yaml",
        "**/.forgejo/workflows/*.yml",
        "**/.forgejo/workflows/*.yaml"
      ],
      "url": "https://www.schemastore.org/github-workflow.json"
    }

Unfortunately, actually, Ansible Playbook is selected, which generates lots of false warnings in the file.

Could it be possible to prioritize the selection of the schema according to the number of characters matched outside of wildcards?
This way the more specific fileMatch will be selected if more that one match.


For example in my case, .github/workflows/site.yml:

  • matches 8 characters for site.yml
  • matches 23 characters for **/.github/workflows/*.yml, excluding characters matched by wildcards

The second one is more specific characters and should be preferred


This should fix most of the cases relatively easily
Regards

Contributor guide

No contributing guide indexed for this repository

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 tracing how the language service selects among matching schema fileMatch entries for .github/workflows/site.yml; compare the literal portions of the Ansible and GitHub Workflow patterns shown in the issue. Done when the more-specific GitHub Workflow schema is selected for this example and the behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, yaml
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.