microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.6k stars 29.03k forks source link

[json] schema fileMatch for all *.json files in root folder #44135

Open stkb opened 6 years ago

stkb commented 6 years ago

I've tried asking this on stackoverflow and gitter without success. I have a project with (among other things) lots of .json files. This is the .vscode/settings.json file:

{
    "json.schemas": [
        {
            "fileMatch": [
                "*.json"
            ],
            "url": "https://path/to/schema.json"
        }
    ]
}

The problem is that this matches all .json files in the project, but I need it to match only *.json files in the root directory. What can I put in fileMatch to enable this, or can this not be done with the file matching?

RMacfarlane commented 6 years ago

Does "./*.json" work?

stkb commented 6 years ago

Unfortunately not, and btw I had it slightly wrong in my first post (now edited)

aeschli commented 6 years ago

The patterns currently just match against the end of the full file path. The matcher is not aware of the workspace folder. A workaround for you is to add the name of the root folder to the pattern, e.g. myroot/*.json, but of course, that's not ideal.

We would need something like a `${workspaceFolder} variable to do this properly.

coodeneko commented 5 years ago

I'm getting a similar problem. The * in folder/*.json matches against sub-folders as well such as folder/child/file.json instead of just the current directly. Would it be possible to split * for just file pattern matching and ** for folder and file pattern matching similar to other implementations of file pattern matching such as glob?