b0o / SchemaStore.nvim

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

module 'schemastore' not found #32

Closed mrt181 closed 2 months ago

mrt181 commented 2 months ago

This is my nvim-lspconfig.lua config

return {
  "neovim/nvim-lspconfig",
  dependencies = {
    { "b0o/schemastore.nvim" },
  },
  opts = {
    servers = {
      jsonls = {
    settings = {
      json = {
        schemas = require("schemastore").json.schemas(),
        validate = { enable = true },
      },
    },
      },
      yamlls = {
    settings = {
      yaml = {
        schemaStore = {
          enable = true,
          url = "https://www.schemastore.org/api/json/catalog.json",
        },
        schemas = require("schemastore").yaml.schemas(),
      },
    },
      },
    },
  },
}

I get this error:

  Error  11:29:20 notify.error lazy.nvim Failed to load `plugins.nvim-lspconfig`

/home/martin/.config/nvim/lua/plugins/nvim-lspconfig.lua:61: module 'schemastore' not found:
    no field package.preload['schemastore']
cache_loader: module schemastore not found
cache_loader_lib: module schemastore not found
    no file './schemastore.lua'
    no file '/build/nvim/parts/nvim/build/.deps/usr/share/luajit-2.1/schemastore.lua'
    no file '/usr/local/share/lua/5.1/schemastore.lua'
    no file '/usr/local/share/lua/5.1/schemastore/init.lua'
    no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/schemastore.lua'
    no file '/build/nvim/parts/nvim/build/.deps/usr/share/lua/5.1/schemastore/init.lua'
    no file './schemastore.so'
    no file '/usr/local/lib/lua/5.1/schemastore.so'
    no file '/build/nvim/parts/nvim/build/.deps/usr/lib/lua/5.1/schemastore.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'

# stacktrace:
  - ~/.config/nvim/lua/plugins/nvim-lspconfig.lua:61
  - ~/.config/nvim/lua/config/lazy.lua:10
  - ~/.config/nvim/init.lua:2

How can I fix that?

b0o commented 2 months ago

Try using a config function instead of an opts table:

return {
  "neovim/nvim-lspconfig",
  dependencies = {
    { "b0o/schemastore.nvim" },
  },
  config = function()
    require("lspconfig").jsonls.setup {
      settings = {
        json = {
          schemas = require("schemastore").json.schemas(),
          validate = { enable = true },
        },
      },
    }

    require("lspconfig").yamlls.setup {
      settings = {
        yaml = {
          schemaStore = {
            enable = true,
            url = "https://www.schemastore.org/api/json/catalog.json",
          },
          schemas = require("schemastore").yaml.schemas(),
        },
      },
    }
  end,
}
b0o commented 2 months ago

I'm going to close this issue. If you're still experiencing this error, please feel free to re-open it.