emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/eglot2emacs a598352750 104/120: Allow eglot-workspace-configurat


From: João Távora
Subject: feature/eglot2emacs a598352750 104/120: Allow eglot-workspace-configuration to be a plist
Date: Thu, 20 Oct 2022 07:17:07 -0400 (EDT)

branch: feature/eglot2emacs
commit a5983527506d0d79137003dc9b5eb15dfd4c7365
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Allow eglot-workspace-configuration to be a plist
    
    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.
    
    GitHub-reference: per https://github.com/joaotavora/eglot/issues/590
    GitHub-reference: per https://github.com/joaotavora/eglot/issues/790
    GitHub-reference: per https://github.com/joaotavora/eglot/issues/1033
---
 lisp/progmodes/eglot.el | 46 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 038847c78f..c2db7e817f 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -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
@@ -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.
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]