mirror of
https://github.com/danbulant/monaco-yaml
synced 2026-07-05 19:10:58 +00:00
Merge pull request #71 from remcohaszing/update-example-value
Add a more advanced example value
This commit is contained in:
commit
f16e46331e
1 changed files with 86 additions and 21 deletions
|
|
@ -23,39 +23,55 @@ window.MonacoEnvironment = {
|
||||||
setDiagnosticsOptions({
|
setDiagnosticsOptions({
|
||||||
validate: true,
|
validate: true,
|
||||||
enableSchemaRequest: true,
|
enableSchemaRequest: true,
|
||||||
|
format: true,
|
||||||
hover: true,
|
hover: true,
|
||||||
completion: true,
|
completion: true,
|
||||||
schemas: [
|
schemas: [
|
||||||
{
|
{
|
||||||
// Id of the first schema
|
// Id of the first schema
|
||||||
uri: 'http://myserver/foo-schema.json',
|
uri: 'https://example.com/example-schema.json',
|
||||||
// Associate with our model
|
// Associate with our model
|
||||||
fileMatch: ['*'],
|
fileMatch: ['*'],
|
||||||
schema: {
|
schema: {
|
||||||
// Id of the first schema
|
// Id of the first schema
|
||||||
id: 'http://myserver/foo-schema.json',
|
id: 'https://example.com/example-schema.json',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
p1: {
|
property: {
|
||||||
enum: ['v1', 'v2'],
|
description: 'I have a description',
|
||||||
},
|
},
|
||||||
p2: {
|
titledProperty: {
|
||||||
// Reference the second schema
|
title: 'I have a title',
|
||||||
$ref: 'http://myserver/bar-schema.json',
|
description: 'I also have a description',
|
||||||
},
|
},
|
||||||
},
|
markdown: {
|
||||||
},
|
markdownDescription: 'Even **markdown** _descriptions_ `are` ~~not~~ supported!',
|
||||||
},
|
},
|
||||||
{
|
enum: {
|
||||||
// Id of the first schema
|
description: 'Pick your starter',
|
||||||
uri: 'http://myserver/bar-schema.json',
|
enum: ['Bulbasaur', 'Squirtle', 'Charmander', 'Pikachu'],
|
||||||
schema: {
|
},
|
||||||
// Id of the first schema
|
number: {
|
||||||
id: 'http://myserver/bar-schema.json',
|
description: 'Numbers work!',
|
||||||
type: 'object',
|
minimum: 42,
|
||||||
properties: {
|
maximum: 1337,
|
||||||
q1: {
|
},
|
||||||
enum: ['x1', 'x2'],
|
boolean: {
|
||||||
|
description: 'Are boolean supported?',
|
||||||
|
type: 'boolean',
|
||||||
|
},
|
||||||
|
string: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
reference: {
|
||||||
|
description: 'JSON schemas can be referenced, even recursively',
|
||||||
|
$ref: 'https://example.com/example-schema.json',
|
||||||
|
},
|
||||||
|
array: {
|
||||||
|
description: 'It also works in arrays',
|
||||||
|
items: {
|
||||||
|
$ref: 'https://example.com/example-schema.json',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -63,9 +79,58 @@ setDiagnosticsOptions({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const value = `
|
||||||
|
# Property descriptions are displayed when hovering over properties using your cursor
|
||||||
|
property: This property has a JSON schema description
|
||||||
|
|
||||||
|
|
||||||
|
# Titles work too!
|
||||||
|
titledProperty: Titles work too!
|
||||||
|
|
||||||
|
|
||||||
|
# Even markdown descriptions work
|
||||||
|
markdown: hover me to get a markdown based description 😮
|
||||||
|
|
||||||
|
|
||||||
|
# Enums can be autocompleted by placing the cursor after the colon and pressing Ctrl+Space
|
||||||
|
enum:
|
||||||
|
|
||||||
|
|
||||||
|
# Of course numbers are supported!
|
||||||
|
number: 12
|
||||||
|
|
||||||
|
|
||||||
|
# As well as booleans!
|
||||||
|
boolean: true
|
||||||
|
|
||||||
|
|
||||||
|
# And strings
|
||||||
|
string: I am a string
|
||||||
|
|
||||||
|
|
||||||
|
# This property is using the JSON schema recursively
|
||||||
|
reference:
|
||||||
|
boolean: Not a boolean
|
||||||
|
|
||||||
|
|
||||||
|
# Also works in arrays
|
||||||
|
array:
|
||||||
|
- string: 12
|
||||||
|
enum: Mewtwo
|
||||||
|
|
||||||
|
|
||||||
|
formatting: Formatting is supported too! Under the hood this is powered by Prettier. Just press Ctrl+Shift+I or right click and press Format to format this document.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`.replace(/:$/m, ': ');
|
||||||
|
|
||||||
editor.create(document.getElementById('editor'), {
|
editor.create(document.getElementById('editor'), {
|
||||||
automaticLayout: true,
|
automaticLayout: true,
|
||||||
value: 'p1: ',
|
value,
|
||||||
language: 'yaml',
|
language: 'yaml',
|
||||||
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? 'vs-dark' : 'vs-light',
|
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? 'vs-dark' : 'vs-light',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue