b0o / SchemaStore.nvim

🛍 JSON schemas for Neovim
https://schemastore.org
Apache License 2.0
697 stars 17 forks source link

docs: add example snippet for adding custom schema for yamlls #13

Closed williamboman closed 1 year ago

williamboman commented 1 year ago

I struggled for a while to get the YAML language server to pick up my custom schema as I was providing the same structure as to the JSON language server. However, as the YAML language server expects a { url = fileMatch } this was not working. I figured it'd be helpful for others to include this in the README.

I also believe #9 can be closed now because there's already a require('schemastore').yaml.schemas() function!

williamboman commented 1 year ago

Alternatively, maybe the require('schemastore').{yaml,json}.schemas() functions could accept additional schemas as an option, to abstract these operations away. Something like:

local extra_schemas = {
    {
        description = 'My Custom JSON schema',
        fileMatch = { 'foobar.json', '.foobar.json' },
        name = 'foobar.json',
        url = 'https://example.com/schema/foobar.json',
    },
}

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

require('lspconfig').yamlls.setup {
    settings = {
        yaml = {
            validate = true,
            schemas = require('schemastore').yaml.schemas {
                extra = extra_schemas,
            }
        }
    }
}
williamboman commented 1 year ago

14 supersedes this PR, if you think that approach makes sense!