Skip to content

Commit d358ee1

Browse files
authored
change lsp-yaml-schemas to work with native json-serialize (#2357)
* change lsp-yaml-schemas to be compatible with emacs 27's native json * remove seq-contains-p, as it's new in emacs 27 * use -filter from 'dash instead of seq-filter * use assq-delete-all instead of assoc-delete-all
1 parent 3e60818 commit d358ee1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

clients/lsp-yaml.el

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
;;; Code:
2626

2727
(require 'lsp-mode)
28+
(require 'dash)
2829

2930
(defgroup lsp-yaml nil
3031
"LSP support for YAML, using yaml-language-server."
@@ -88,7 +89,7 @@
8889

8990
(defcustom lsp-yaml-schemas '()
9091
"Associate schemas to YAML files in a glob pattern."
91-
:type '(alist :key-type (string :tag "schema") :value-type (string :tag "files (glob)"))
92+
:type '(alist :key-type (symbol :tag "schema") :value-type (vector :tag "files (glob)"))
9293
:group 'lsp-yaml
9394
:package-version '(lsp-mode . "6.2"))
9495

@@ -164,7 +165,7 @@
164165
(defconst lsp-yaml--built-in-kubernetes-schema
165166
'((name . "Kubernetes")
166167
(description . "Built-in kubernetes manifest schema definition")
167-
(url . :kubernetes)
168+
(url . "kubernetes")
168169
(fileMatch . ["*-k8s.yaml" "*-k8s.yml"])))
169170

170171
(defun lsp-yaml-download-schema-store-db (&optional force-downloading)
@@ -185,22 +186,27 @@ Set FORCE-DOWNLOADING to non-nil to force re-download the database."
185186
(alist-get 'schemas (json-read-file lsp-yaml-schema-store-local-db))))
186187
(seq-concatenate 'list (list lsp-yaml--built-in-kubernetes-schema) lsp-yaml--schema-store-schemas-alist))
187188

188-
(defun lsp-yaml-set-buffer-schema (uri)
189-
"Set yaml schema for the current buffer to URI."
189+
(defun lsp-yaml-set-buffer-schema (uri-string)
190+
"Set yaml schema for the current buffer to URI-STRING."
190191
(interactive "MURI: ")
191-
(let* ((workspace-path (file-relative-name
192+
(let* ((uri (intern uri-string))
193+
(workspace-path (file-relative-name
192194
(lsp--uri-to-path (lsp--buffer-uri))
193195
(lsp-workspace-root (lsp--buffer-uri))))
194-
(glob-pattern (concat "/" workspace-path))
195-
(current-config (cl-assoc uri lsp-yaml-schemas :test 'equal))
196+
(glob (concat "/" workspace-path))
197+
(current-config (assoc uri lsp-yaml-schemas))
196198
(current-patterns (and current-config (cdr current-config))))
197199
(if current-config
198-
(or (cl-member glob-pattern current-patterns :test 'equal)
200+
(or (member glob (append current-patterns nil))
199201
(setq lsp-yaml-schemas
200-
(cl-acons uri (cl-list* glob-pattern current-patterns)
201-
(cl-remove current-config lsp-yaml-schemas))))
202+
(cl-acons uri
203+
(vconcat (vector glob) current-patterns)
204+
(assq-delete-all uri
205+
(mapcar (lambda (x) (lsp-yaml--remove-glob x glob))
206+
lsp-yaml-schemas)))))
202207
(setq lsp-yaml-schemas
203-
(cl-acons uri (cl-list* glob-pattern nil) lsp-yaml-schemas)))
208+
(cl-acons uri (vector glob) (mapcar (lambda (x) (lsp-yaml--remove-glob x glob))
209+
lsp-yaml-schemas))))
204210
(lsp--set-configuration (lsp-configuration-section "yaml"))))
205211

206212
(defun lsp-yaml-select-buffer-schema ()
@@ -214,5 +220,11 @@ Set FORCE-DOWNLOADING to non-nil to force re-download the database."
214220
(uri (alist-get 'url schema)))
215221
(lsp-yaml-set-buffer-schema uri)))
216222

223+
(defun lsp-yaml--remove-glob (mapping glob)
224+
(let ((patterns (cdr mapping)))
225+
(cons (car mapping)
226+
(vconcat (-filter (lambda (p) (not (equal p glob)))
227+
(append patterns nil)) nil))))
228+
217229
(provide 'lsp-yaml)
218230
;;; lsp-yaml.el ends here

0 commit comments

Comments
 (0)