From fa8932742202dea664959135f9a44340849139f6 Mon Sep 17 00:00:00 2001 From: Aaron Gonzales Date: Thu, 15 Aug 2024 21:23:00 +0800 Subject: [PATCH] feat: add `lsp-yaml-schema-extensions` (#4527) * 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` --- clients/lsp-yaml.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/clients/lsp-yaml.el b/clients/lsp-yaml.el index 24db7e511eb..376cac7bae8 100644 --- a/clients/lsp-yaml.el +++ b/clients/lsp-yaml.el @@ -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. @@ -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."