irongit

My nvim configuration

hygo-nvim/lsp/yamlls.lua
87 lines3.2 KBLua
1---@brief
2---
3--- https://github.com/redhat-developer/yaml-language-server
4---
5--- `yaml-language-server` can be installed via `yarn`:
6--- ```sh
7--- yarn global add yaml-language-server
8--- ```
9---
10--- To use a schema for validation, there are two options:
11---
12--- 1. Add a modeline to the file. A modeline is a comment of the form:
13---
14--- ```
15--- # yaml-language-server: $schema=<urlToTheSchema|relativeFilePath|absoluteFilePath}>
16--- ```
17---
18--- where the relative filepath is the path relative to the open yaml file, and the absolute filepath
19--- is the filepath relative to the filesystem root ('/' on unix systems)
20---
21--- 2. Associated a schema url, relative , or absolute (to root of project, not to filesystem root) path to
22--- the a glob pattern relative to the detected project root. Check `:checkhealth vim.lsp` to determine the resolved project
23--- root.
24---
25--- ```lua
26--- vim.lsp.config('yamlls', {
27--- ...
28--- settings = {
29--- yaml = {
30--- ... -- other settings. note this overrides the lspconfig defaults.
31--- schemas = {
32--- ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*",
33--- ["../path/relative/to/file.yml"] = "/.github/workflows/*",
34--- ["/path/from/root/of/project"] = "/.github/workflows/*",
35--- },
36--- },
37--- }
38--- })
39--- ```
40---
41--- Currently, kubernetes is special-cased in yammls, see the following upstream issues:
42--- * [#211](https://github.com/redhat-developer/yaml-language-server/issues/211).
43--- * [#307](https://github.com/redhat-developer/yaml-language-server/issues/307).
44---
45--- To override a schema to use a specific k8s schema version (for example, to use 1.18):
46---
47--- ```lua
48--- vim.lsp.config('yamlls', {
49--- ...
50--- settings = {
51--- yaml = {
52--- ... -- other settings. note this overrides the lspconfig defaults.
53--- schemas = {
54--- ["https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.32.1-standalone-strict/all.json"] = "/*.k8s.yaml",
55--- ... -- other schemas
56--- },
57--- },
58--- }
59--- })
60--- ```
61
62---@type vim.lsp.Config
63return {
64 cmd = { 'yaml-language-server', '--stdio' },
65 filetypes = { 'yaml', 'yaml.docker-compose', 'yaml.gitlab', 'yaml.helm-values' },
66 root_markers = { '.git' },
67 settings = {
68 -- https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting
69 redhat = { telemetry = { enabled = false } },
70 -- formatting disabled by default in yaml-language-server; enable it
71 yaml = {
72 format = { enable = true },
73 schemas = {
74 -- aws buildspec schema
75 ["https://gist.githubusercontent.com/dacci/6ccf1b1cdcb93228f574137c05e82491/raw/9e9749dd77658096f7c75199abbb52c6d7cd233b/buildspec.schema.json"] =
76 "buildspec.yml",
77 },
78 },
79 },
80 on_init = function(client)
81 --- https://github.com/neovim/nvim-lspconfig/pull/4016
82 --- Since formatting is disabled by default if you check `client:supports_method('textDocument/formatting')`
83 --- during `LspAttach` it will return `false`. This hack sets the capability to `true` to facilitate
84 --- autocmd's which check this capability
85 client.server_capabilities.documentFormattingProvider = true
86 end,
87}