Skip to content

Commit

Permalink
Store server settings in hash-table instead of using plist (#4038)
Browse files Browse the repository at this point in the history
- this will speedup loading of lsp-mode
  • Loading branch information
yyoncho authored May 3, 2023
1 parent cd586eb commit e51317d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
33 changes: 16 additions & 17 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8384,13 +8384,10 @@ session workspace folder configuration for the server."
(funcall initialization-options-or-fn)
initialization-options-or-fn)))

(defvar lsp-client-settings nil
(defvar lsp-client-settings (make-hash-table)
"For internal use, any external users please use
`lsp-register-custom-settings' function instead")

(defun lsp--compare-setting-path (a b)
(equal (car a) (car b)))

(defun lsp-register-custom-settings (props)
"Register PROPS.
PROPS is list of triple (path value boolean?) where PATH is the path to the
Expand All @@ -8401,8 +8398,10 @@ property will be ignored if the VALUE is nil.

Example: `(lsp-register-custom-settings `((\"foo.bar.buzz.enabled\" t t)))'
\(note the double parentheses)"
(let ((-compare-fn #'lsp--compare-setting-path))
(setq lsp-client-settings (-uniq (append props lsp-client-settings)))))
(mapc
(-lambda ((path . rest))
(puthash path rest lsp-client-settings))
props))

(defun lsp-region-text (region)
"Get the text for REGION in current buffer."
Expand Down Expand Up @@ -8448,17 +8447,17 @@ TBL - a hash table, PATHS is the path to the nested VALUE."
(defun lsp-configuration-section (section)
"Get settings for SECTION."
(let ((ret (ht-create)))
(mapc (-lambda ((path variable boolean?))
(when (s-matches? (concat (regexp-quote section) "\\..*") path)
(let* ((symbol-value (-> variable
lsp-resolve-value
lsp-resolve-value))
(value (if (and boolean? (not symbol-value))
:json-false
symbol-value)))
(when (or boolean? value)
(lsp-ht-set ret (s-split "\\." path) value)))))
lsp-client-settings)
(maphash (-lambda (path (variable boolean?))
(when (s-matches? (concat (regexp-quote section) "\\..*") path)
(let* ((symbol-value (-> variable
lsp-resolve-value
lsp-resolve-value))
(value (if (and boolean? (not symbol-value))
:json-false
symbol-value)))
(when (or boolean? value)
(lsp-ht-set ret (s-split "\\." path) value)))))
lsp-client-settings)
ret))


Expand Down
7 changes: 5 additions & 2 deletions test/lsp-common-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@
(lsp-register-custom-settings '(("section2.nested.prop2" lsp-nested-prop2)))

(ert-deftest lsp--custom-settings-test-2 ()
(cl-assert (equal (lsp-ht->alist (lsp-configuration-section "section2"))
'(("section2" ("nested" ("prop1" . "10") ("prop2" . "20")))))))
(let ((actual (lsp-ht->alist (lsp-configuration-section "section2"))))
(cl-assert (or (equal actual
'(("section2" ("nested" ("prop1" . "10") ("prop2" . "20")))))
(equal actual
'(("section2" ("nested" ("prop2" . "20") ("prop1" . "10")))))))))

(ert-deftest lsp--build-workspace-configuration-response-test-2 ()
(-let* ((request (lsp-make-configuration-params
Expand Down

0 comments on commit e51317d

Please sign in to comment.