b0o/SchemaStore.nvim

website github github
neovim-0.5 plugin
star 74
stars
alert-circle 0
open issues
users 2
subscribers
git-branch 0
forks
CREATED

2021-10-07

UPDATED

1 hour ago

packer

require('packer').startup(function()
  use 'b0o/SchemaStore.nvim'
end)

paq

require "paq" { 
  'b0o/SchemaStore.nvim'
}

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(),
    },
  },
}

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',
        },
      },
    },
  },
}

To ignore certain schemas from the catalog:

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

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',
          },
        },
      },
    },
  },
}

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',
          },
        }
      ),
    },
  },
}

Changelog

15 Oct 2021                                                             v0.0.1
  Initial Release

License

© 2021 Maddison Hellstrom

Released under the Apache 2.0 License.