emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/eglot 9673cb598f 1/2: Per #590, #790, #1033: Allow eglo


From: ELPA Syncer
Subject: [elpa] externals/eglot 9673cb598f 1/2: Per #590, #790, #1033: Allow eglot-workspace-configuration to be a plist
Date: Sun, 18 Sep 2022 06:57:39 -0400 (EDT)

branch: externals/eglot
commit 9673cb598f9853133b5809856c8766c2660bff6b
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Per #590, #790, #1033: 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.
---
 NEWS.md   |  9 ++++++++-
 README.md | 59 +++++++++++++++++++++++++++++++----------------------------
 eglot.el  | 46 +++++++++++++++++++++++++++++++++-------------
 3 files changed, 72 insertions(+), 42 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index f771327191..c439a2c1ca 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -8,7 +8,12 @@ other than `M-x imenu` itself.  Since the special 
functionality it
 enabled wasn't being used anyway, decided to remove it to fix these
 longstanding problems.
 
-##### `eglot-workspace-configuration` can be a function ([#967][github#967])
+##### `eglot-workspace-configuration` overhauled ([#967][github#967], 
[#590][github#590], [#790][github#790])
+
+This variable and its uses are now more thoroughly documented.  It can
+be a set to a function for dynamic calculation of the configuration.
+The preferred format is a plist, though the earlier alist format is
+still supported.
 
 ##### C-u M-. lists and completes arbitrary workspace symbols 
([#131][github#131])
 
@@ -371,6 +376,7 @@ and now said bunch of references-->
 [github#494]: https://github.com/joaotavora/eglot/issues/494
 [github#535]: https://github.com/joaotavora/eglot/issues/535
 [github#536]: https://github.com/joaotavora/eglot/issues/536
+[github#590]: https://github.com/joaotavora/eglot/issues/590
 [github#603]: https://github.com/joaotavora/eglot/issues/603
 [github#637]: https://github.com/joaotavora/eglot/issues/637
 [github#643]: https://github.com/joaotavora/eglot/issues/643
@@ -388,6 +394,7 @@ and now said bunch of references-->
 [github#758]: https://github.com/joaotavora/eglot/issues/758
 [github#769]: https://github.com/joaotavora/eglot/issues/769
 [github#787]: https://github.com/joaotavora/eglot/issues/787
+[github#790]: https://github.com/joaotavora/eglot/issues/790
 [github#792]: https://github.com/joaotavora/eglot/issues/792
 [github#794]: https://github.com/joaotavora/eglot/issues/794
 [github#797]: https://github.com/joaotavora/eglot/issues/797
diff --git a/README.md b/README.md
index 86366dfa61..d8c4069eb8 100644
--- a/README.md
+++ b/README.md
@@ -173,24 +173,27 @@ functions][dir-locals-emacs-manual].
 
 #### Format of the value
 
-The variable's value is an _association list_:
+The recommended format for this variable's value is a [_property
+list_][plist]:
 
 ```
-((SECTION-1 . PARAM-OBJECT-1)
- ...
- (SECTION-N . PARAM-OBJECT-N))
+(SECTION-1 PARAM-OBJECT-1 ... SECTION-N PARAM-OBJECT-N)
 ```
 
-`SECTION-N` is an Elisp keyword naming the parameter section
-understood by the server.  `PARAM-OBJECT-N` contains one or more
-settings pertaining to that server.
+(Yes, earlier it used to be an association list, a format that is
+still supported, but discouraged.)
 
-`PARAM-OBJECT-N` is an Elisp object serialized to JSON by
-[`json-serialize`][json-serialize].  The recommended format used in
-this manual's examples is a [plist][plist] of keyword-value pairs,
-though `json-serialize` also accepts other formats.  In any case, the
-JSON values `true`, `false` and `{}` are represented by the Elisp
-values `t`, `:json-false` and `nil`, respectively.
+Each `SECTION-N` is an Elisp keyword naming a parameter section
+relevant to an LSP server.
+
+`PARAM-OBJECT-N` contains one or more settings pertaining to the
+server that is interested in `SECTION-N`.  Its value is an Elisp
+object serialized to JSON by [`json-serialize`][json-serialize].  The
+recommended format is again a [plist][plist], though `json-serialize`
+also accepts other formats.
+
+In any case, the JSON values `true`, `false` and `{}` are represented
+by the Elisp values `t`, `:json-false` and `nil`, respectively.
 
 When experimenting with settings, one may use `M-x
 eglot-show-workspace-configuration` to inspect/debug the definite JSON
@@ -199,7 +202,7 @@ actually connecting to the server.
 
 #### Simple example
 
-To make a particular Python project always enable [Pyls][pyls]'s
+To make a particular Python project always enable [Pylsp][pylsp]'s
 snippet support, put a file named `.dir-locals.el` in the project's
 root:
 
@@ -208,9 +211,9 @@ root:
   . ((eglot-workspace-configuration
       .
       ;; the value in the format described above starts here
-      ((:pyls . (:plugins (:jedi_completion (:include_params t
-                                             :fuzzy t)
-                           :pylint (:enabled :json-false)))))
+      (:pylsp (:plugins (:jedi_completion (:include_params t
+                                           :fuzzy t)
+                         :pylint (:enabled :json-false))))
       ;; and ends here
       ))))
 ```
@@ -218,13 +221,13 @@ root:
 This tells Emacs that any `python-mode` buffers in that directory
 should have a particular value of `eglot-workspace-configuration`.
 
-Here, the value in question associates a parameter section `:pyls`
-with a parameter objct that is a plist of plists.  It is converted to
+Here, the value in question associates the parameter section `:pylsp`
+with a parameter object that is a plist of plists.  It is converted to
 JSON before being sent to the server:
 
 ```json
 {
-  "pyls": {
+  "pylsp": {
     "plugins": {
       "jedi_completion": { "include_params": true, "fuzzy": true },
       "pylint": { "enabled": false }
@@ -242,12 +245,12 @@ file.  Adding a section for `go-mode`, the file's 
contents now become:
 ```lisp
 ((python-mode
   . ((eglot-workspace-configuration
-      . ((:pyls . (:plugins (:jedi_completion (:include_params t
-                                               :fuzzy t)
-                             :pylint (:enabled :json-false))))))))
+      . (:pylsp (:plugins (:jedi_completion (:include_params t
+                                             :fuzzy t)
+                           :pylint (:enabled :json-false)))))))
  (go-mode
   . ((eglot-workspace-configuration
-      . ((:gopls . (:usePlaceholders t)))))))
+      . (:gopls (:usePlaceholders t))))))
 ```
 
 Alternatively, as a matter of taste, one may choose to lay out 
@@ -256,10 +259,10 @@ Alternatively, as a matter of taste, one may choose to 
lay out
 ```lisp
 ((nil
   . ((eglot-workspace-configuration
-      . ((:pyls . (:plugins (:jedi_completion (:include_params t
-                                               :fuzzy t)
-                             :pylint (:enabled :json-false))))
-         (:gopls . (:usePlaceholders t)))))))
+      . (:pylsp (:plugins (:jedi_completion (:include_params t
+                                             :fuzzy t)
+                           :pylint (:enabled :json-false)))
+         :gopls (:usePlaceholders t))))))
 ```
 
 This is an equivalent setup which sets the value in all major-modes
diff --git a/eglot.el b/eglot.el
index 038847c78f..c2db7e817f 100644
--- a/eglot.el
+++ b/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]