Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use variable watcher with lsp-defcustom to support local variables. #4349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -8551,16 +8551,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