[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 83a61f673a: Close #901: Easier initializationOpti
From: |
ELPA Syncer |
Subject: |
[elpa] externals/eglot 83a61f673a: Close #901: Easier initializationOptions in eglot-server-programs |
Date: |
Tue, 29 Mar 2022 08:57:28 -0400 (EDT) |
branch: externals/eglot
commit 83a61f673a0395e9ea3f17f8bf7afd7da37bce03
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Close #901: Easier initializationOptions in eglot-server-programs
Per #845.
* NEWS.md: Update.
* eglot.el (eglot-server-programs): Document new syntax.
(eglot-initialization-options): Can use initializationOptions from
server's saved initargs.
(eglot--connect): Allow a plist to be appended to a server
contact.
---
NEWS.md | 9 +++++++++
eglot.el | 51 +++++++++++++++++++++++++++++++++------------------
2 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index b3e6f58300..d17e49eb1a 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,12 @@
# (upcoming)
+##### Easier to use LSP initialize.initializationOptions ([#901][github#901],
[#845][github#845])
+In `eglot-server-programs` a plist may be appended to the usual list
+of strings passed as command line arguments. The value of its
+`:initializationOptions` key constructs the corresponding LSP JSON
+object. This may be easier than creating a `defclass` for a specific
+server and specializing `eglot-initialization-options` to that class.
+
##### Support on-type-formatting ([#899][github#899])
##### Provide basic workspace-folders support ([#893][github#893])
@@ -356,5 +363,7 @@ and now said bunch of references-->
[github#803]: https://github.com/joaotavora/eglot/issues/803
[github#810]: https://github.com/joaotavora/eglot/issues/810
[github#813]: https://github.com/joaotavora/eglot/issues/813
+[github#845]: https://github.com/joaotavora/eglot/issues/845
[github#893]: https://github.com/joaotavora/eglot/issues/893
[github#899]: https://github.com/joaotavora/eglot/issues/899
+[github#901]: https://github.com/joaotavora/eglot/issues/901
diff --git a/eglot.el b/eglot.el
index d71e5966a8..ade8a7c711 100644
--- a/eglot.el
+++ b/eglot.el
@@ -218,17 +218,24 @@ CONTACT can be:
PROGRAM is called with ARGS and is expected to serve LSP requests
over the standard input/output channels.
+* A list (PROGRAM [ARGS...] :initializationOptions OPTIONS),
+ whereupon PROGRAM is called with ARGS as in the first option,
+ and the LSP \"initializationOptions\" JSON object is
+ constructed from OPTIONS. If OPTIONS is a unary function, it
+ is called with the server instance and should return a JSON
+ object.
+
* A list (HOST PORT [TCP-ARGS...]) where HOST is a string and
PORT is a positive integer for connecting to a server via TCP.
Remaining ARGS are passed to `open-network-stream' for
upgrading the connection with encryption or other capabilities.
* A list (PROGRAM [ARGS...] :autoport [MOREARGS...]), whereupon a
- combination of the two previous options is used. First, an
- attempt is made to find an available server port, then PROGRAM
- is launched with ARGS; the `:autoport' keyword substituted for
- that number; and MOREARGS. Eglot then attempts to establish a
- TCP connection to that port number on the localhost.
+ combination of previous options is used. First, an attempt is
+ made to find an available server port, then PROGRAM is launched
+ with ARGS; the `:autoport' keyword substituted for that number;
+ and MOREARGS. Eglot then attempts to establish a TCP
+ connection to that port number on the localhost.
* A cons (CLASS-NAME . INITARGS) where CLASS-NAME is a symbol
designating a subclass of `eglot-lsp-server', for representing
@@ -627,7 +634,11 @@ treated as in `eglot-dbind'."
(cl-defgeneric eglot-initialization-options (server)
"JSON object to send under `initializationOptions'."
- (:method (_s) eglot--{})) ; blank default
+ (:method (s)
+ (let ((probe (plist-get (eglot--saved-initargs s) :initializationOptions)))
+ (cond ((functionp probe) (funcall probe s))
+ (probe)
+ (t eglot--{})))))
(cl-defgeneric eglot-register-capability (server method id &rest params)
"Ask SERVER to register capability METHOD marked with ID."
@@ -1116,18 +1127,22 @@ This docstring appeases checkdoc, that's all."
(setq autostart-inferior-process inferior)
connection))))
((stringp (car contact))
- `(:process
- ,(lambda ()
- (let ((default-directory default-directory))
- (make-process
- :name readable-name
- :command (setq server-info (eglot--cmd contact))
- :connection-type 'pipe
- :coding 'utf-8-emacs-unix
- :noquery t
- :stderr (get-buffer-create
- (format "*%s stderr*" readable-name))
- :file-handler t)))))))
+ (let* ((probe (cl-position-if #'keywordp contact))
+ (more-initargs (and probe (cl-subseq contact probe)))
+ (contact (cl-subseq contact 0 probe)))
+ `(:process
+ ,(lambda ()
+ (let ((default-directory default-directory))
+ (make-process
+ :name readable-name
+ :command (setq server-info (eglot--cmd contact))
+ :connection-type 'pipe
+ :coding 'utf-8-emacs-unix
+ :noquery t
+ :stderr (get-buffer-create
+ (format "*%s stderr*" readable-name))
+ :file-handler t)))
+ ,@more-initargs)))))
(spread (lambda (fn) (lambda (server method params)
(let ((eglot--cached-server server))
(apply fn server method (append params
nil))))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/eglot 83a61f673a: Close #901: Easier initializationOptions in eglot-server-programs,
ELPA Syncer <=