No description
Find a file
Remco Haszing 95fd123191
Build project using esbuild
This is much more flexible than `monaco-plugin-helpers`. Because of
this, it’s possible to use Prettier as an external dependency, so users
can ignore it in their own build process of they choose not to support
formatting.

Instead of rewriting YAML language service imports in the build tool, I
decided to just import them from where they need to be imported in the
source code.

Closes #63
2021-08-15 12:37:13 +02:00
.github/workflows Update documentation 2021-07-31 16:15:45 +02:00
.husky Bump dependencies 2021-07-17 14:20:08 +02:00
examples/webpack Merge pull request #71 from remcohaszing/update-example-value 2021-08-09 22:37:28 +02:00
src Build project using esbuild 2021-08-15 12:37:13 +02:00
.editorconfig Introduce ESLint 2021-07-17 17:12:17 +02:00
.eslintrc.yaml Build project using esbuild 2021-08-15 12:37:13 +02:00
.gitignore Build project using esbuild 2021-08-15 12:37:13 +02:00
.nvmrc Add .nvmrc 2021-08-07 09:31:34 +02:00
.prettierignore Apply prettier on all committed files 2021-03-25 17:59:58 +01:00
.prettierrc.yaml Introduce ESLint 2021-07-17 17:12:17 +02:00
build.js Build project using esbuild 2021-08-15 12:37:13 +02:00
CONTRIBUTING.md Update documentation 2021-07-31 16:15:45 +02:00
index.d.ts Expose setDiagnosticsOptions in monaco-yaml 2021-07-18 14:58:42 +02:00
LICENSE.md Introduce ESLint 2021-07-17 17:12:17 +02:00
netlify.toml Fix command for netlify 2021-08-07 09:33:29 +02:00
package-lock.json Build project using esbuild 2021-08-15 12:37:13 +02:00
package.json Build project using esbuild 2021-08-15 12:37:13 +02:00
README.md Update metadata 2021-08-09 20:49:00 +02:00
test-demo.png chore: align with pengx17/master branch 2018-10-25 10:12:07 +08:00
tsconfig.json Introduce ESLint 2021-07-17 17:12:17 +02:00

Monaco YAML

ci workflow npm version prettier code style demo netlify status

YAML language plugin for the Monaco Editor. It provides the following features when editing YAML files:

  • Code completion, based on JSON schemas or by looking at similar objects in the same file
  • Hovers, based on JSON schemas
  • Validation: Syntax errors and schema validation
  • Formatting using Prettier
  • Document Symbols
  • Automatically load remote schema files (by enabling DiagnosticsOptions.enableSchemaRequest)

Schemas can also be provided by configuration. See here for the API that the plugin offers to configure the YAML language support.

Installation

npm install monaco-yaml

Usage

Import monaco-yaml and configure it before an editor instance is created.

import { editor, Uri } from 'monaco-editor';
import { setDiagnosticsOptions } from 'monaco-yaml';

// The uri is used for the schema file match.
const modelUri = Uri.parse('a://b/foo.yaml');

setDiagnosticsOptions({
  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: [String(modelUri)],
      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'],
          },
        },
      },
    },
  ],
});

editor.create(document.createElement('editor'), {
  // Monaco-yaml features should just work if the editor language is set to 'yaml'.
  language: 'yaml',
  model: editor.createModel('p1: \n', 'yaml', modelUri),
});

Also make sure to register the web worker.

Examples

A demo is available on monaco-yaml.js.org.

A running example: demo-image

Some usage examples can be found in the examples directory.

Contributing

Please see our contributing guidelines

Credits

Originally @kpdecker forked this repository from monaco-json by @microsoft and rewrote it to work with yaml-language-server instead. Later the repository maintenance was taken over by @pengx17. Eventually the repository was tranferred to the account of @remcohaszing, who is currently maintaining this repository with the help of fleon and @yazaabed.

The heavy processing is done in yaml-language-server, best known for being the backbone for vscode-yaml. This repository provides a thin layer to add functionality provided by yaml-language-server into monaco-editor.

License

MIT