]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow :initializationoptions in eglot-server-programs
authorJoão Távora <joaotavora@gmail.com>
Sat, 17 Sep 2022 20:40:34 +0000 (21:40 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sat, 17 Sep 2022 23:40:21 +0000 (00:40 +0100)
Also see https://github.com/joaotavora/eglot/issues/1038.

This feature was poorly tested, and simply wouldn't work when trying
to initialize the server object.

The simple solution is to ignore :initializationOptions initarg in
this context.  It is still stored separately as and accessed as the
'eglot--saved-initargs' slot.

Another complication arises in eglot--guess-contact, which tried too
hard to be able to compose an interactive prompt (when the server
program can't be found).  The solution is just to give up when
:autoport or :initializationOptions is found.  It's not easy or
practical to have the user provide non-string arguments via a string
interface like the minibuffer.

* eglot.el (initialize-instance :before eglot-lsp-server): Don't pass
:initializationOptions initarg onward.
(eglot--guess-contact): Simplify.  Don't try heroics with
:autoport and :initializationOptions.

* eglot-tests.el (eglot-server-programs-simple-missing-executable):
  Update test.

GitHub-reference: fix https://github.com/joaotavora/eglot/issues/940

lisp/progmodes/eglot.el

index ff94d5ca5f4c30622b7d68dcf13d7bea5edd837c..493bfcc7d6ca3c878ba31dc7cf661ff8e4968462 100644 (file)
@@ -796,6 +796,9 @@ treated as in `eglot-dbind'."
   :documentation
   "Represents a server. Wraps a process for LSP communication.")
 
+(cl-defmethod initialize-instance :before ((_server eglot-lsp-server) &optional args)
+  (cl-remf args :initializationOptions))
+
 
 ;;; Process management
 (defvar eglot--servers-by-project (make-hash-table :test #'equal)
@@ -929,10 +932,10 @@ be guessed."
          (base-prompt
           (and interactive
                "Enter program to execute (or <host>:<port>): "))
-         (program-guess
+         (full-program-invocation
           (and program
-               (combine-and-quote-strings (cl-subst ":autoport:"
-                                                    :autoport guess))))
+               (cl-every #'stringp guess)
+               (combine-and-quote-strings guess)))
          (prompt
           (and base-prompt
                (cond (current-prefix-arg base-prompt)
@@ -942,25 +945,23 @@ be guessed."
                      ((and program
                            (not (file-name-absolute-p program))
                            (not (eglot--executable-find program t)))
-                      (concat (format "[eglot] I guess you want to run `%s'"
-                                      program-guess)
-                              (format ", but I can't find `%s' in PATH!" program)
-                              "\n" base-prompt)))))
+                      (if full-program-invocation
+                          (concat (format "[eglot] I guess you want to run `%s'"
+                                          full-program-invocation)
+                                  (format ", but I can't find `%s' in PATH!"
+                                          program)
+                                  "\n" base-prompt)
+                        (eglot--error
+                         (concat "`%s' not found in PATH, but can't form"
+                                 " an interactive prompt for to fix %s!")
+                         program guess))))))
          (contact
           (or (and prompt
-                   (let ((s (read-shell-command
-                             prompt
-                             program-guess
-                             'eglot-command-history)))
-                     (if (string-match "^\\([^\s\t]+\\):\\([[:digit:]]+\\)$"
-                                       (string-trim s))
-                         (list (match-string 1 s)
-                               (string-to-number (match-string 2 s)))
-                       (cl-subst
-                        :autoport ":autoport:" (split-string-and-unquote s)
-                        :test #'equal))))
-              guess
-              (eglot--error "Couldn't guess for `%s'!" managed-mode))))
+                   (read-shell-command
+                    prompt
+                    full-program-invocation
+                    'eglot-command-history))
+              guess)))
     (list managed-mode (eglot--current-project) class contact language-id)))
 
 (defvar eglot-lsp-context)