Support `vim.lsp.config()`
This plugin could provide lsp/* files to avoid dependency on lspconfig.
It actually supports vim.lp.config(...),
maybe just not lazy loading:
vim.lsp.config("jsonls", {
settings = {
json = {
schemas = require("schemastore").json.schemas(),
validate = { enable = true },
},
},
})
My approach is to harness the ability of on_init hook:
That's the content of my lsp/jsonls.lua:
return {
-- use on_init hook to defer the schema load as third-party plugins are not loaded
on_init = function (client)
client.config.settings.json = vim.tbl_deep_extend("force", client.config.settings.json, {
schemas = require('schemastore').json.schemas(),
validate = { enable = true },
})
end
}
Here's my full configuration: nvim config
My approach is to harness the ability of
on_inithook: That's the content of mylsp/jsonls.lua:return { -- use on_init hook to defer the schema load as third-party plugins are not loaded on_init = function (client) client.config.settings.json = vim.tbl_deep_extend("force", client.config.settings.json, { schemas = require('schemastore').json.schemas(), validate = { enable = true }, }) end }
Here's my full configuration: nvim config
@ZWindL, it doesn't work for me. It seems that injecting the config directly into the client instance doesn't have any effect.
@carlos-algms , have you enabled the lsp client by vim.lsp.enable('jsonls')?
Yeah, it's working without the on_init you suggested.
By moving this line schemas = require('schemastore').json.schemas(),, to the on_init, it stops working.
Wait, mine doesn't work either now, I need a closer look. 🤔
It needs to be set before the language server starts. Try this:
---@type vim.lsp.Config
return {
before_init = function(_, client_config)
client_config.settings.json = require('schemastore').json.schemas()
end
}
It needs to be set before the language server starts. Try this:
---@type vim.lsp.Config return { before_init = function(_, client_config) client_config.settings.json = require('schemastore').json.schemas() end }
there's a typo, but it works, thanks !!!!
- client_config.settings.json = require('schemastore').json.schemas()
+ client_config.settings.json.schemas = require('schemastore').json.schemas()
it will not work if the settings table is nil:
---@diagnostic disable: missing-fields, inject-field
---@type vim.lsp.ClientConfig
return {
settings = {
json = {
validate = {
enable = true,
}
}
},
before_init = function(_, config)
-- can't assign new table because of
-- https://github.com/neovim/neovim/issues/27740#issuecomment-1978629315
config.settings.json.schemas = require("schemastore").json.schemas()
end,
}
My approach is to harness the ability of
on_inithook: That's the content of mylsp/jsonls.lua:return { -- use on_init hook to defer the schema load as third-party plugins are not loaded on_init = function (client) client.config.settings.json = vim.tbl_deep_extend("force", client.config.settings.json, { schemas = require('schemastore').json.schemas(), validate = { enable = true }, }) end }
Here's my full configuration: nvim config
but how to write dependencies if I use lazy.nvim or packer.nvim
Here's how I do it for globally installed json-ls/yaml-ls: https://github.com/polyzen/dotfiles/blob/18c6ffde934da6161b718aa0dd9cf04b068cdcf1/base/.config/nvim/lua/plugins.lua#L532-L542