Skip to content

Commit

Permalink
Use variable watcher with lsp-defcustom to support local variables. (#…
Browse files Browse the repository at this point in the history
…4349)

When custom variables are set locally using `hack-local-variables`, a
custom variable's registered setter is not invoked.  To address this,
a variable watcher is used instead to cause the setter to be invoked
when the variable is updated.
  • Loading branch information
brownts authored Jul 1, 2024
1 parent dc4d72b commit 581ce04
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8635,16 +8635,24 @@ TBL - a hash table, PATHS is the path to the nested VALUE."
"Defines `lsp-mode' server property."
(declare (doc-string 3) (debug (name body))
(indent defun))
(let ((path (plist-get args :lsp-path)))
(let ((path (plist-get args :lsp-path))
(setter (intern (concat (symbol-name symbol) "--set"))))
(cl-remf args :lsp-path)
`(progn
(lsp-register-custom-settings
(quote ((,path ,symbol ,(equal ''boolean (plist-get args :type))))))

(defcustom ,symbol ,standard ,doc
:set (lambda (sym val)
(lsp--set-custom-property sym val ,path))
,@args))))
(defcustom ,symbol ,standard ,doc ,@args)

;; Use a variable watcher instead of registering a `defcustom'
;; setter since `hack-local-variables' is not aware of custom
;; setters and won't invoke them.

(defun ,setter (sym val op _where)
(when (eq op 'set)
(lsp--set-custom-property sym val ,path)))

(add-variable-watcher ',symbol #',setter))))

(defun lsp--set-custom-property (sym val path)
(set sym val)
Expand Down

0 comments on commit 581ce04

Please sign in to comment.