Awesome Open Source
Awesome Open Source

SchemaStore.nvim Version License: Apache 2.0 Test Status Build Status

A Neovim Lua plugin providing access to the SchemaStore catalog.

Install

Packer:

use "b0o/schemastore.nvim"

Usage

To use SchemaStore.nvim with lspconfig + jsonls:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas(),
      validate = { enable = true },
    },
  },
}

For an explanation of why the validate = { enable = true } option is recommended, see #8.

To use a subset of the catalog, you can select schemas by name (see the catalog for a full list):

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        select = {
          '.eslintrc',
          'package.json',
        },
      },
      validate = { enable = true },
    },
  },
}

To ignore certain schemas from the catalog:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        ignore = {
          '.eslintrc',
          'package.json',
        },
      },
      validate = { enable = true },
    },
  },
}

Note that the select and ignore options are mutually exclusive and attempting to use them together will throw an error.

To replace certain schemas from the catalog with your own:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        replace = {
          ['package.json'] = {
            description = 'package.json overriden',
            fileMatch = { 'package.json' },
            name = 'package.json',
            url = 'https://example.com/package.json',
          },
        },
      },
      validate = { enable = true },
    },
  },
}

If you want to use your own schemas in addition to schemas from SchemaStore, you can merge them:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = vim.list_extend(
        {
          {
            description = 'My Custom JSON schema',
            fileMatch = { 'foobar.json', '.foobar.json' },
            name = 'foobar.json',
            url = 'https://example.com/schema/foobar.json',
          },
        },
        require('schemastore').json.schemas {
          select = {
            '.eslintrc',
            'package.json',
          },
        }
      ),
      validate = { enable = true },
    },
  },
}

Changelog

21 Dec 2021                                                             v0.1.0
  Perf: Add lookup table from schema name to schema index
  Note that select & ignore are mutually exclusive
  Exit with non-zero code if generate script fails
  Update docs
  Update NOTICE
  Clean up formatting
  Update tests
  Fix example in README
  Feat: Add option to ignore schemas by name

15 Oct 2021                                                             v0.0.1
  Initial Release

License

© 2021-2022 Maddison Hellstrom

Released under the Apache 2.0 License.

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Json (39,467
Lua (34,691
Linting (9,090
Neovim (4,144
Nvim (1,520
Autocompletion (1,191
Lsp (983
Intellisense (768
Neovim Plugin (685
Language Server Protocol (340
Schema Registry (241
Nvim Plugin (119
Json Schemas (22
Schemastore (3