25
25
; ;; Code:
26
26
27
27
(require 'lsp-mode )
28
+ (require 'dash )
28
29
29
30
(defgroup lsp-yaml nil
30
31
" LSP support for YAML, using yaml-language-server."
88
89
89
90
(defcustom lsp-yaml-schemas '()
90
91
" 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)" ))
92
93
:group 'lsp-yaml
93
94
:package-version '(lsp-mode . " 6.2" ))
94
95
164
165
(defconst lsp-yaml--built-in-kubernetes-schema
165
166
'((name . " Kubernetes" )
166
167
(description . " Built-in kubernetes manifest schema definition" )
167
- (url . : kubernetes )
168
+ (url . " kubernetes" )
168
169
(fileMatch . [" *-k8s.yaml" " *-k8s.yml" ])))
169
170
170
171
(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."
185
186
(alist-get 'schemas (json-read-file lsp-yaml-schema-store-local-db))))
186
187
(seq-concatenate 'list (list lsp-yaml--built-in-kubernetes-schema) lsp-yaml--schema-store-schemas-alist))
187
188
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 ."
190
191
(interactive " MURI: " )
191
- (let* ((workspace-path (file-relative-name
192
+ (let* ((uri (intern uri-string))
193
+ (workspace-path (file-relative-name
192
194
(lsp--uri-to-path (lsp--buffer-uri))
193
195
(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))
196
198
(current-patterns (and current-config (cdr current-config))))
197
199
(if current-config
198
- (or (cl- member glob-pattern current-patterns :test 'equal )
200
+ (or (member glob ( append current-patterns nil ) )
199
201
(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)))))
202
207
(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))))
204
210
(lsp--set-configuration (lsp-configuration-section " yaml" ))))
205
211
206
212
(defun lsp-yaml-select-buffer-schema ()
@@ -214,5 +220,11 @@ Set FORCE-DOWNLOADING to non-nil to force re-download the database."
214
220
(uri (alist-get 'url schema)))
215
221
(lsp-yaml-set-buffer-schema uri)))
216
222
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
+
217
229
(provide 'lsp-yaml )
218
230
; ;; lsp-yaml.el ends here
0 commit comments