-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to register custom json schema which is applied on file match pattern #38
Comments
I also found the JSONContribution which seems interesting also in my case, but could not find a way to register my own. |
@aeschli will know |
Oh, but first we'd need to ship a new |
The JSON plugin has an API that lets you add schemas (and schema associations). |
@aeschli I don't think we've shipped an editor version that contains the json language as a plugin yet |
up ? I also cannot see the JsonContribution interface in https://github.com/Microsoft/monaco-json/blob/master/src/monaco.d.ts. Any chance to see it appearing ? |
Yes, I made the update. |
Thanks, this is one part of the solution. The other part would be to have the posibility to apply the schema based on a file pattern (eg. package.json files). |
Use the fileMatch property for that... monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
schemas: [{
uri: "http://myserver/foo-schema.json",
fileMatch: [ 'foo.json' ],
schema: {
type: "object",
properties: {
p1: {
enum: [ "v1", "v2"]
},
p2: {
$ref: "http://myserver/bar-schema.json"
}
}
}
},{
uri: "http://myserver/bar-schema.json",
schema: {
type: "object",
properties: {
q1: {
enum: [ "x1", "x2"]
}
}
}
}]
});
monaco.editor.create(document.getElementById("container"), {
model: monaco.editor.createModel("{\n}\n", 'json', "inmemory://inmemory/foo.json")
}); |
great ! 👍 Is it possible also to have custom values for intellisense (like dependencies in package.json files) ? |
I added https://microsoft.github.io/monaco-editor/playground.html#extending-language-services-completion-provider-example to show how to add custom completions. |
awesome. Thanks a lot. |
One question though, wouldn't it be cleaner to expose the Jsoncontribution interface and a way to add customs ? It just looked better to my eyes as the retrieval of the current "node" is done in background. |
That's not so easy as the JSON language service runs in a web worker. Your contribution would have to be bundled as part of this web worker. |
I have tried fileMatch but useless.. |
Hi Team,
I am looking for registering my own schema. Additionnaly, I would like this schema automatically applied based on file uri match. I know this is doable in vscode (https://code.visualstudio.com/docs/languages/json#_json-schemas-settings) but could not find a way to do it. Could you please guide me ?
Thanks,
Nicolas
The text was updated successfully, but these errors were encountered: