Skip to content

Commit 127c8e8

Browse files
authored
Merge pull request #29 from abougouffa/fix/lsp-use-plists
Take `lsp-use-plists` into account
2 parents c351137 + e20b0eb commit 127c8e8

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

lsp-ltex.el

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ The editor need to send a completion request.")
287287
(cl-remove-if #'null args)
288288
" ")))))))
289289

290+
(defun lsp-ltex--plist-keys (plist)
291+
"Return the keys of PLIST."
292+
(let (keys)
293+
(while plist
294+
(push (car plist) keys)
295+
(setq plist (cddr plist)))
296+
keys))
297+
298+
(defun lsp-ltex--lsp-keys (table)
299+
"Similar to `lsp-get' and `lsp-put', it return the keys in TABLE."
300+
(if lsp-use-plists
301+
(lsp-ltex--plist-keys table)
302+
(hash-table-keys table)))
303+
290304
(defun lsp-ltex--serialize-symbol (sym dir)
291305
"Serialize SYM to DIR.
292306
Return the written file name, or nil if SYM is not bound."
@@ -320,13 +334,12 @@ Return the deserialized object, or nil if the SYM.el file dont exist."
320334

321335
(defun lsp-ltex--add-rule (lang rule rules-plist)
322336
"Add RULE of language LANG to the plist named RULES-PLIST (symbol)."
323-
(let ((lang-key (intern (concat ":" lang))))
324-
(when (null (eval rules-plist))
325-
(set rules-plist (list lang-key [])))
326-
(plist-put (eval rules-plist) lang-key
327-
(vconcat (list rule) (plist-get (eval rules-plist) lang-key)))
328-
(when-let (out-file (lsp-ltex--serialize-symbol rules-plist lsp-ltex-user-rules-path))
329-
(lsp-message "[INFO] Rule for language %s saved to file \"%s\"" lang out-file))))
337+
(when (null (eval rules-plist))
338+
(set rules-plist (list lang [])))
339+
(plist-put (eval rules-plist) lang
340+
(vconcat (list rule) (plist-get (eval rules-plist) lang)))
341+
(when-let (out-file (lsp-ltex--serialize-symbol rules-plist lsp-ltex-user-rules-path))
342+
(lsp-message "[INFO] Rule for language %s saved to file \"%s\"" (symbol-name lang) out-file)))
330343

331344
(defun lsp-ltex-combine-plists (&rest plists)
332345
"Create a single property list from all plists in PLISTS.
@@ -523,20 +536,21 @@ This file is use to activate the language server."
523536
"Execute action ACTION-HT by getting KEY and storing it in the RULES-PLIST.
524537
When STORE is non-nil, this will also store the new plist in the directory
525538
`lsp-ltex-user-rules-path'."
526-
(let ((args-ht (gethash key action-ht)))
527-
(dolist (lang (hash-table-keys args-ht))
528-
(mapc (lambda (rule)
529-
(lsp-ltex--add-rule lang rule rules-plist)
530-
(when store
531-
(lsp-ltex--serialize-symbol rules-plist lsp-ltex-user-rules-path)))
532-
(gethash lang args-ht)))))
539+
(let ((args-ht (lsp-get (if (vectorp action-ht) (elt action-ht 0) action-ht) key)))
540+
(dolist (lang (lsp-ltex--lsp-keys args-ht))
541+
(let ((lang-key (if (stringp lang) (intern (concat ":" lang)) lang)))
542+
(mapc (lambda (rule)
543+
(lsp-ltex--add-rule lang-key rule rules-plist)
544+
(when store
545+
(lsp-ltex--serialize-symbol rules-plist lsp-ltex-user-rules-path)))
546+
(lsp-get args-ht lang-key))))))
533547

534548
(lsp-defun lsp-ltex--code-action-add-to-dictionary ((&Command :arguments?))
535549
"Handle action for \"_ltex.addToDictionary\"."
536550
;; Add rule internally to the `lsp-ltex--stored-dictionary' plist and
537551
;; store it in the directory `lsp-ltex-user-rules-path'
538552
(lsp-ltex--action-add-to-rules
539-
(elt arguments? 0) "words" 'lsp-ltex--stored-dictionary t)
553+
arguments? :words 'lsp-ltex--stored-dictionary t)
540554
;; Combine user configured words `lsp-ltex-dictionary' and the internal
541555
;; interactively generated `lsp-ltex--stored-dictionary', and store them in
542556
;; the internal `lsp-ltex--combined-dictionary', which is sent to ltex-ls
@@ -546,7 +560,7 @@ When STORE is non-nil, this will also store the new plist in the directory
546560

547561
(lsp-defun lsp-ltex--code-action-hide-false-positives ((&Command :arguments?))
548562
"Handle action for \"_ltex.hideFalsePositives\"."
549-
(lsp-ltex--action-add-to-rules (elt arguments? 0) "falsePositives"
563+
(lsp-ltex--action-add-to-rules arguments? :falsePositives
550564
'lsp-ltex--stored-hidden-false-positives t)
551565
(setq lsp-ltex--combined-hidden-false-positives
552566
(lsp-ltex-combine-plists lsp-ltex-hidden-false-positives
@@ -555,7 +569,7 @@ When STORE is non-nil, this will also store the new plist in the directory
555569

556570
(lsp-defun lsp-ltex--code-action-disable-rules ((&Command :arguments?))
557571
"Handle action for \"_ltex.disableRules\"."
558-
(lsp-ltex--action-add-to-rules (elt arguments? 0) "ruleIds"
572+
(lsp-ltex--action-add-to-rules arguments? :ruleIds
559573
'lsp-ltex--stored-disabled-rules t)
560574
(setq lsp-ltex--combined-disabled-rules
561575
(lsp-ltex-combine-plists lsp-ltex-disabled-rules

0 commit comments

Comments
 (0)