vue-monaco
vue-monaco copied to clipboard
How to setup json schema?
I'm trying to use my custom JSON schema in editor content but it doesn't work.
editorWillMount(monaco) {
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
schemas: [
{
schema: schema /// from import
}
]
});
},
What am I missing?
I believe you need to set the fileMatch
property of your schema, which will link it to your editor. I was able to do this using editorDidMount
instead of editorWillMount
. It is a little tricky since this method uses the editor. You can get the monaco module and the model from these lines, using a ref to your editor:
editorDidMount(editor) {
const monaco = this.$refs.editor.monaco;
const model = editor.getModel();
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [{
uri: "http://example.com/schema.json",
fileMatch: [model.uri.toString()],
schema: schema
}]
});
}
I think the uri is also required for the schema to work.
I am also trying to setup the schema. I did what @lrduncan suggested, but I don't get what is the uri for. What am I suposed to write there?
This snippet doesn't work for me, I don't get any message error or anything, when I inspect monaco
it is correctly registered in the diagnostic options but nothing happens after that
It's like nothing happened
I get the same problem, and this snippet doesn't work for me too