Reputation: 12428
The documentation for contributes.jsonValidation says:
The url value can be either a local path to a schema file included in the extension or a remote server URL such as a json schema store.
The URL value works as described:
"jsonValidation": [{
"fileMatch": ".jshintrc",
"url": "http://json.schemastore.org/jshintrc"
}]
However, if I create a test extension and give a path to a file that's local to my extension, it does not:
"jsonValidation": [{
"fileMatch": "*.testing",
"url": "/schemas/testing.schema.json"
}]
I have a folder schemas
at the root of my extension, with a file testing.schema.json
in it. It's just a copy of the jshintrc schema.
When I launch my test extension, and load a file that matches the pattern, I get a little green squiggle under the first open brace. If I hover the green squiggle, I see a familiar error:
Unable to load schema from '/schemas/edfoo.schema.json': <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>IIS 10.0 Detailed Error - 404.0 - Not Found</title>
Clearly, it is reaching out to a server, not reading a local file from the extension. But the docs say I can include a schema file in an extension. How do I make it work?
Upvotes: 0
Views: 4746
Reputation: 12428
Figured it out: url
was missing a leading dot, like this:
"jsonValidation": [{
"fileMatch": "*.testing",
"url": "./schemas/testing.schema.json"
}]
When url
starts with this ./
pattern, it is automatically understood to be a file that shipped with the extension. If the ./
or even just the .
is missing off the front, it will be treated as a URL to be fetched from a server instead.
Since vscode is open source, I can reference the line of code that implements this behavior.
It's here: jsonMain.ts#L105
Upvotes: 4