Skip to content

Commit

Permalink
feat: add lsp-yaml-schema-extensions (#4527)
Browse files Browse the repository at this point in the history
* feat: add `lsp-yaml-schema-extensions`

This commit replaces defconst `lsp-yaml--built-in-kubernetes-schema`
with defcustom `lsp-yaml-schema-extensions` to
enable users to extend the dropdown options provided by
`lsp-yaml--get-supported-schemas`. This is helpful since users are no
longer locked into the yaml-language-server's version of the Kubernetes
schema. This also enables users to provide more schemas and multiple
versions of schemas if need be i.e. multiple versions of the Kubernetes
schema, if you work across multiple clusters.

* fix: replace current Kubernetes schema with v1.30.3

The current schema provided `yaml-language-server` does not exist any
longer so is causing a bug when loading the schema.

* fix: docstring for `lsp-yaml-schema-extensions`
  • Loading branch information
Aaronzinhoo authored Aug 15, 2024
1 parent 168bf21 commit fa89327
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions clients/lsp-yaml.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,16 @@ Limited for performance reasons."
(lsp-package-ensure 'yaml-language-server
callback error-callback))))

(defconst lsp-yaml--built-in-kubernetes-schema
'((name . "Kubernetes")
(description . "Built-in kubernetes manifest schema definition")
(url . "kubernetes")
(fileMatch . ["*-k8s.yaml" "*-k8s.yml"])))
(defcustom lsp-yaml-schema-extensions '(((name . "Kubernetes v1.30.3")
(description . "Kubernetes v1.30.3 manifest schema definition")
(url . "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.30.3-standalone-strict/all.json")
(fileMatch . ["*-k8s.yaml" "*-k8s.yml"])))
"User defined schemas that extend default schema store.
Used in `lsp-yaml--get-supported-schemas' to supplement schemas provided by
`lsp-yaml-schema-store-uri'."
:type 'list
:group 'lsp-yaml
:package-version '(lsp-mode . "9.0.1"))

(defun lsp-yaml-download-schema-store-db (&optional force-downloading)
"Download remote schema store at `lsp-yaml-schema-store-uri' into local cache.
Expand All @@ -194,7 +199,7 @@ Set FORCE-DOWNLOADING to non-nil to force re-download the database."
(lsp-yaml-download-schema-store-db)
(setq lsp-yaml--schema-store-schemas-alist
(alist-get 'schemas (json-read-file lsp-yaml-schema-store-local-db))))
(seq-concatenate 'list (list lsp-yaml--built-in-kubernetes-schema) lsp-yaml--schema-store-schemas-alist))
(seq-concatenate 'list lsp-yaml-schema-extensions lsp-yaml--schema-store-schemas-alist))

(defun lsp-yaml-set-buffer-schema (uri-string)
"Set yaml schema for the current buffer to URI-STRING."
Expand Down

0 comments on commit fa89327

Please sign in to comment.