-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
57 lines (53 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const yamlModelUri = monaco.Uri.parse('a://b/foo.yaml');
const jsonModelUri = monaco.Uri.parse('a://b/foo.json');
const diagnosticsOptions = {
enableSchemaRequest: true,
hover: true,
completion: true,
validate: true,
format: true,
schemas: [
{
// Id of the first schema
uri: 'http://myserver/foo-schema.json',
// Associate with our model
fileMatch: ['*'],
schema: {
type: 'object',
properties: {
p1: {
enum: ['v1', 'v2'],
},
p2: {
// Reference the second schema
$ref: 'http://myserver/bar-schema.json',
},
},
},
},
{
// Id of the first schema
uri: 'http://myserver/bar-schema.json',
schema: {
type: 'object',
properties: {
q1: {
enum: ['x1', 'x2'],
},
},
},
},
],
};
monacoYaml.configureMonacoYaml(monaco, diagnosticsOptions);
monaco.languages.json.jsonDefaults.setDiagnosticsOptions(diagnosticsOptions);
const yaml = 'p1: \np2: \n';
const json = '{\n "p1": "",\n "p2": ""\n}';
monaco.editor.create(document.getElementById('yaml-editor'), {
automaticLayout: true,
model: monaco.editor.createModel(yaml, 'yaml', yamlModelUri),
});
monaco.editor.create(document.getElementById('json-editor'), {
automaticLayout: true,
model: monaco.editor.createModel(json, 'json', jsonModelUri),
});