-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Help] Trying to load schema for LSP to use with neoconf #42
Comments
Calling modules["b0o/schemastore.nvim"] = {
version = false,
lazy = false,
config = function()
-- ...
require("schemastore").json.schemas({
extra = extra_schemas,
})
end,
} You will need to modify your config to pass -- LSP Setup:
M.jsonls_config = function(file_types)
return {
-- ...
settings = {
json = {
validate = { enable = true },
schemas = require("schemastore").json.schemas({ -- pass extra_schemas to this call
extra = {
{
description = "Schema for nvim project config",
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = "file://" .. _G.__os.home .. "/.config/json_schema/nvim.json",
},
},
}),
},
},
}
end |
Thanks, I've updated it as you suggested and temporarily simplified it like so: local extra_schemas = {
{
description = "ASTRO",
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = "/Users/ajay.mamtora/.local/share/nvim/lazy/neoconf.nvim/schemas/astro.json",
},
}
...
settings = {
json = {
validate = { enable = true },
schemas = require("schemastore").json.schemas({
extra = extra_schemas,
}),
},
}, And the jsonls lsp isn't suggesting properties defined in "https://github.com/folke/neoconf.nvim/blob/main/schemas/astro.json" -- am I misunderstanding something? |
Hi, @Ajaymamtora , you also need to add local extra_schemas = {
{
description = "ASTRO",
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = "/Users/ajay.mamtora/.local/share/nvim/lazy/neoconf.nvim/schemas/astro.json",
},
}
...
settings = {
json = {
validate = { enable = true },
schemas = require("schemastore").json.schemas({
select = { ...other_schemas, 'nvim.json' },
extra = extra_schemas,
}),
},
}, Warning Use the RecommendationI suggest you to use url = vim.fn.expand('~/.local/share/nvim/lazy/neoconf.nvim/schemas/astro.json') This way you will retrieve the file if you use your Have a good day n_n7 |
Hi I'm not sure what you mean by Heres what ive currently got: handlers["jsonls"] = function()
local extra_schemas = {
{
description = "Schema for nvim project config",
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = vim.fn.expand("~/.config/json_schema/nvim.json"),
},
}
local schema_path = vim.fn.expand("~/.local/share/nvim/lazy/neoconf.nvim/schemas")
local function add_schema(file)
local name = file:match("(.+)%.json$")
if name then
table.insert(extra_schemas, {
description = "Schema for " .. name,
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = schema_path .. "/" .. file,
})
end
end
local handle = vim.uv.fs_scandir(schema_path)
if handle then
local name, type
while true do
name, type = vim.uv.fs_scandir_next(handle)
if not name then
break
end
if type == "file" and name:match("%.json$") then
add_schema(name)
end
end
end
require("lspconfig").jsonls.setup({
flags = {
debounce_text_changes = default_debounce_time,
},
autostart = true,
filetypes = { "json" },
on_attach = function(client, bufnr)
M.omni(client, bufnr)
M.tag(client, bufnr)
M.document_highlight(client, bufnr)
M.inlay_hint(client, bufnr)
end,
capabilities = M.get_capabilities(),
settings = {
json = {
schemas = require("schemastore").json.schemas({
extra = extra_schemas,
}),
validate = { enable = true },
},
},
setup = {
commands = {
Format = {
function()
vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 })
end,
},
},
},
})
end Now my LSP is suggesting the $schema variable at the top level, then the url as its value. I want jsonls to suggest the content described by the schema, not text of the literal JSON files that describe the schema in the neoconf repo |
In If I'm not wrong, the following should be enough: handlers["jsonls"] = function()
local selected_schemas = {
"nvim.json", -- <-- `name` field
}
local extra_schemas = {
{
description = "Schema for nvim project config",
fileMatch = { "nvim.json", ".nvim.json" },
name = "nvim.json",
url = vim.fn.expand("~/.config/json_schema/nvim.json"),
},
}
local schema_path =
vim.fn.expand("~/.local/share/nvim/lazy/neoconf.nvim/schemas")
local function add_schema(file)
local name = file:match("(.+)%.json$")
if name then
table.insert(extra_schemas, {
description = "Schema for " .. name,
-- NOTE: `fileMatch` should match the filename(s) you expect to be used
-- it should be generated dynamically based on `name` local variable
-- see https://github.com/SchemaStore/schemastore/blob/master/src/api/json/catalog.json for references
fileMatch = { "nvim.json", ".nvim.json" },
name = name, -- NOTE: `name` field should be unique
url = schema_path .. "/" .. file,
})
-- add to selected schemas
table.insert(selected_schemas, name)
end
end
local handle = vim.uv.fs_scandir(schema_path)
if handle then
local name, type
while true do
name, type = vim.uv.fs_scandir_next(handle)
if not name then
break
end
if type == "file" and name:match("%.json$") then
add_schema(name)
end
end
end
require("lspconfig").jsonls.setup({
flags = {
debounce_text_changes = default_debounce_time,
},
autostart = true,
filetypes = { "json" },
on_attach = function(client, bufnr)
M.omni(client, bufnr)
M.tag(client, bufnr)
M.document_highlight(client, bufnr)
M.inlay_hint(client, bufnr)
end,
capabilities = M.get_capabilities(),
settings = {
json = {
schemas = require("schemastore").json.schemas({
-- DO NOT FORGET the `select` option!
select = selected_schemas,
extra = extra_schemas,
}),
validate = { enable = true },
},
},
setup = {
commands = {
Format = {
function()
vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line("$"), 0 })
end,
},
},
},
})
end
|
Oh. I think I misunderstood. You want suggestions for My approuch enable suggestions of available
|
Thanks for the response, for example, all the schema files in the neoconf repo: |
Hi I can't get this plugin to suggest anything from local schema files in jsonls.
I'm loading the local schemas (1 of my own, the rest being these https://github.com/folke/neoconf.nvim/blob/main/schemas) via my setup:
It successfully adds to extras but nothing is suggested by the LSP at all.
I'm triggering nvim cmp in files named nvim.json and .nvim.json and neither works
Please can I have some help?
The text was updated successfully, but these errors were encountered: