Skip to content

Commit

Permalink
Per #590, #790, #1033: Allow eglot-workspace-configuration to be a plist
Browse files Browse the repository at this point in the history
Suggested-by: Augusto Stoffel <arstoffel@gmail.com>

* NEWS.md: Mention change.

* README.md (eglot-workspace-configuration): Update yet again.  Update
examples to use pylsp.

* eglot.el (eglot--workspace-configuration-plist): Noop if already
a plist.
(eglot-handle-request workspace/configuration): Use
eglot--workspace-configuration-plist.
(eglot-workspace-configuration): Document variable.

#590: joaotavora/eglot#590
#790: joaotavora/eglot#790
#1033: joaotavora/eglot#1033
  • Loading branch information
joaotavora committed Sep 18, 2022
1 parent 82ec705 commit 20a8dd2
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions lisp/progmodes/eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -2198,14 +2198,32 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
'((name . eglot--signal-textDocument/didChange)))

(defvar-local eglot-workspace-configuration ()
"Alist of (SECTION . VALUE) entries configuring the LSP server.
SECTION should be a keyword or a string. VALUE is a
plist or a primitive type converted to JSON.
"Configure LSP servers specifically for a given project.
This variable's value should be a plist (SECTION VALUE ...).
SECTION is a keyword naming a parameter section relevant to a
particular server. VALUE is a plist or a primitive type
converted to JSON also understood by that server.
Instead of a plist, an alist ((SECTION . VALUE) ...) can be used
instead, but this variant is less reliable and not recommended.
This variable should be set as a directory-local variable. See
See info node `(emacs)Directory Variables' for various ways to to
that.
Here's an example value that establishes two sections relevant to
the Pylsp and Gopls LSP servers:
(:pylsp (:plugins (:jedi_completion (:include_params t
:fuzzy t)
:pylint (:enabled :json-false)))
:gopls (:usePlaceholders t))
The value of this variable can also be a unary function of a
single argument, which will be a connected `eglot-lsp-server'
instance. The function runs with `default-directory' set to the
root of the current project. It should return an alist of the
root of the current project. It should return an object of the
format described above.")

;;;###autoload
Expand All @@ -2232,12 +2250,15 @@ format described above.")
eglot-workspace-configuration))

(defun eglot--workspace-configuration-plist (server)
"Returns `eglot-workspace-configuraiton' suitable serialization."
(or (cl-loop for (section . v) in (eglot--workspace-configuration server)
collect (if (keywordp section) section
(intern (format ":%s" section)))
collect v)
eglot--{}))
"Returns `eglot-workspace-configuration' suitable for serialization."
(let ((val (eglot--workspace-configuration server)))
(or (and (consp (car val))
(cl-loop for (section . v) in val
collect (if (keywordp section) section
(intern (format ":%s" section)))
collect v))
val
eglot--{})))

(defun eglot-signal-didChangeConfiguration (server)
"Send a `:workspace/didChangeConfiguration' signal to SERVER.
Expand All @@ -2264,9 +2285,8 @@ When called interactively, use the currently active server"
(project-root (eglot--project server)))))
(setq-local major-mode (eglot--major-mode server))
(hack-dir-local-variables-non-file-buffer)
(alist-get section (eglot--workspace-configuration server)
nil nil
(lambda (wsection section)
(plist-get (eglot--workspace-configuration-plist server) section
(lambda (section wsection)
(string=
(if (keywordp wsection)
(substring (symbol-name wsection) 1)
Expand Down

0 comments on commit 20a8dd2

Please sign in to comment.