diff options
| author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-11-13 13:06:01 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-13 13:06:01 -0800 |
| commit | f50ec8af8f29d5bc5bfc80908e997012a65fab7e (patch) | |
| tree | 6e177fa4032a874cb5d834492b6e4643f4d710d9 /lua | |
| parent | build: replace echo with printf so newlines are interpreted (#1419) (diff) | |
| download | nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar.gz nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar.bz2 nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar.lz nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar.xz nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.tar.zst nvim-lspconfig-f50ec8af8f29d5bc5bfc80908e997012a65fab7e.zip | |
docs(yammlls): add examples for schemas (#1421)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/yamlls.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/lua/lspconfig/yamlls.lua b/lua/lspconfig/yamlls.lua index 5f30d420..12fc2670 100644 --- a/lua/lspconfig/yamlls.lua +++ b/lua/lspconfig/yamlls.lua @@ -24,6 +24,59 @@ https://github.com/redhat-developer/yaml-language-server ```sh yarn global add yaml-language-server ``` + +To use a schema for validation, there are two options: + +1. Add a modeline to the file. A modeline is a comment of the form: + +``` +# yaml-language-server: $schema=<urlToTheSchema|relativeFilePath|absoluteFilePath}> +``` + +where the relative filepath is the path relative to the open yaml file, and the absolute filepath +is the filepath relative to the filesystem root ('/' on unix systems) + +2. Associated a schema url, relative , or absolute (to root of project, not to filesystem root) path to +the a glob pattern relative to the detected project root. Check `:LspInfo` to determine the resolved project +root. + +```lua +require('lspconfig').yamlls.setup { + ... -- other configuration for setup {} + settings = { + yaml = { + ... -- other settings. note this overrides the lspconfig defaults. + schemas = { + ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*" + ["../path/relative/to/file.yml"] = "/.github/workflows/*" + ["/path/from/root/of/project"] = "/.github/workflows/*" + }, + }, + } +} +``` + +Currently, kubernetes is special-cased in yammls, see the following upstream issues: +* [#211](https://github.com/redhat-developer/yaml-language-server/issues/211). +* [#307](https://github.com/redhat-developer/yaml-language-server/issues/307). + +To override a schema to use a specific k8s schema version (for example, to use 1.18): + +```lua +require('lspconfig').yamlls.setup { + ... -- other configuration for setup {} + settings = { + yaml = { + ... -- other settings. note this overrides the lspconfig defaults. + schemas = { + ["https://raw.githubusercontent.com/instrumenta/kubernetes-json-schema/master/v1.18.0-standalone-strict/all.json"] = "/*.k8s.yaml", + ... -- other schemas + }, + }, + } +} +``` + ]], default_config = { root_dir = [[util.find_git_ancestor]], |
