Giter VIP home page Giter VIP logo

schemastore.nvim's Introduction

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

A Neovim Lua plugin providing access to the SchemaStore catalog.

Install

Lazy.nvim:

  "b0o/schemastore.nvim",

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.

yamlls is also supported:

require('lspconfig').yamlls.setup {
  settings = {
    yaml = {
      schemaStore = {
        -- You must disable built-in schemaStore support if you want to use
        -- this plugin and its advanced options like `ignore`.
        enable = false,
        -- Avoid TypeError: Cannot read properties of undefined (reading 'length')
        url = "",
      },
      schemas = require('schemastore').yaml.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',
        },
      },
      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 include additional schemas, you can use extra:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        extra = {
          {
            description = 'My custom JSON schema',
            fileMatch = 'foo.json',
            name = 'foo.json',
            url = 'https://example.com/schema/foo.json',
          },
          {
            description = 'My other custom JSON schema',
            fileMatch = { 'bar.json', '.baar.json' },
            name = 'bar.json',
            url = 'https://example.com/schema/bar.json',
          },
        },
      },
      validate = { enable = true },
    },
  },
}

To use a local schema file, specify the path using the file:// scheme or plain file paths:

require("schemastore").json.schemas({
  extra = {
    {
      description = "Local JSON schema",
      fileMatch = "local.json",
      name = "local.json",
      url = "file:///path/to/your/schema.json", -- or '/path/to/your/schema.json'
    },
  },
})

Changelog

26 May 2023                                                             v0.2.0
  Feat: Add `extra` option to add additional schemas (@williamboman)
  Docs: Mention disabling built-in for yaml (@davidosomething)
  Feat: Add support for yamlls (@ZenLian)

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-2023 Maddison Hellstrom and Contributors.

Released under the Apache 2.0 License.

schemastore.nvim's People

Contributors

b0o avatar williamboman avatar zachiah avatar davidosomething avatar jetm avatar zenlian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.