redhat-developer / redhat-developer/yaml-language-server
Got `MethodNotFound` error if `yaml.schemas` matches filename `fleet.yaml`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 352
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 11
Description
Describe the bug
Got MethodNotFound error if yaml.schemas matches filename fleet.yaml, no error if changed to other filename.
Expected Behavior
No diagonostics error.
Current Behavior
Ddiagonostics error:
Problems loading reference 'schemaservice:/Users/roc/dotfiles/kubeschemas/fleet-agones.dev-v1.json': Unable to load schema from 'schemaservice:/Users/roc/dotfiles/kubeschemas/fleet-agones.dev-v1.json': MethodNotFound. [768]
Steps to Reproduce
Neovim yamlls config matches filename fleet.yaml:
No error output if changed to another filename which not equal fleet.yaml.
Environment
- Windows
- Mac
- Linux
- other (please specify)
yaml-language-server is managed by Mason which uses latest release 1.15.0:
About My Neovim Usage
I write scripts to parse kubernetes YAML file, set json schema to yamlls according to apiVersion and kind, append current file path to related json schema.
The most important is to customize yamlls on_attach function, share my scripts:
local M = {}
local function remove_prefix(str, prefix)
if str:sub(1, #prefix) == prefix then
return str:sub(#prefix + 1)
else
return str
end
end
local path_separator = package.config:sub(1, 1)
local kubeschemas_dir = os.getenv("HOME") .. path_separator .. ".config" .. path_separator .. "kubeschemas"
-- local kubeschemas = kubeschemas_dir .. path_separator .. "kubernetes.json"
local regKind = vim.regex([[\v^kind: \S+$]])
local regApiVersion = vim.regex([[\v^apiVersion: \S+$]])
local regHelm = vim.regex([[\v\{\{.+\}\}]])
local detach = function(client, bufnr)
vim.diagnostic.enable(false, { bufnr = bufnr })
vim.defer_fn(function()
vim.diagnostic.reset(nil, bufnr)
vim.lsp.buf_detach_client(bufnr, client.id)
end, 500)
end
local get_new_settings = function(client, bufnr)
-- Ingore kustomization.yaml, it has schema in schemastore.
local buf_path = vim.api.nvim_buf_get_name(bufnr)
if buf_path:match("kustomization.ya?ml$") then
return client.config.settings
end
-- remove yamlls from not yaml files
-- https://github.com/towolf/vim-helm/issues/15
if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then
-- detach(client, bufnr)
return nil
end
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
local kind = nil
local apiVersion = nil
for _, line in ipairs(lines) do
if regHelm:match_str(line) then -- ignore helm template
detach(client, bufnr)
return nil
end
if not kind then
if regKind:match_str(line) then
kind = remove_prefix(line, "kind: ")
if apiVersion then
break
end
end
end
if not apiVersion then
if regApiVersion:match_str(line) then
apiVersion = remove_prefix(line, "apiVersion: ")
if kind then
break
end
end
end
end
if kind then
local filename = kind
if apiVersion then
filename = filename .. "-" .. string.gsub(apiVersion, "/", "-")
end
filename = string.lower(filename)
local jsonschema = kubeschemas_dir .. path_separator .. filename .. ".json"
if vim.uv.fs_stat(jsonschema) then
local schema = client.config.settings.yaml.schemas[jsonschema] or {}
local bufuri = vim.uri_from_bufnr(bufnr)
if not vim.tbl_contains(schema, bufuri) then
vim.list_extend(schema, { bufuri })
client.config.settings.yaml.schemas[jsonschema] = schema
return client.config.settings
end
end
end
end
M.on_attach = function(client, bufnr)
if client.name ~= "yamlls" then
return
end
local new_settings = get_new_settings(client, bufnr)
if new_settings then
client.server_capabilities.documentRangeFormattingProvider = true
client.workspace_did_change_configuration(client.config.settings)
end
end
return M
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with yaml-language-server 1.15.0 using the reported Neovim on_attach configuration and a schema mapping that matches fleet.yaml. Start by tracing yaml.schemas handling and the schemaservice request that reports MethodNotFound; done means the matching filename produces no diagnostics error while other schema mappings continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- neovim, typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100