Skip to content
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

docs(yammlls): add examples for schemas #1421

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions lua/lspconfig/yamlls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down