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:
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:
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:
deploy.yml
**/.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 of4
. 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 twofileMatches
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:
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.