Subject: Re: bug#73472: [PATCH] Substitute quotation marks in Eglot messages

From: "Thomas Voss" <[email-masked]>
Date: Mon, 21 Oct 2024 23:58:42 +0200

On Sat Oct 19, 2024 at 10:33 AM CEST, Thomas Voss wrote:
> > > > I can do that.  I refrained from it at first because my original patch
> > > > seemed like a much simpler solution, but I do agree that this is probably
> > > > a better approach.  When I have the time I can send through a patch for
> > > > that.
> > > 
> > > Thanks, please do.
> >
> > Ping!
>
> I’ll see if I can send through a patch this weekend.  I’ve been a bit
> busy with life things (I moved countries recently) but I’ve got most of
> everything sorted now.

Hi,

I had some time today to quickly put together a patch.  You can find it
attachted to this email.

-- 
— Thomas
From 5121734428e3e3706378b1f1af49e944f2b48658 Mon Sep 17 00:00:00 2001
From: Thomas Voss <[email-masked]>
Date: Sat, 19 Oct 2024 11:12:30 +0200
Subject: [PATCH v2] Substitute quotation marks in Eglot messages

* lisp/progmodes/eglot.el
  (eglot--check-object)
  (eglot-register-capability)
  (eglot-unregister-capability)
  (eglot-server-capable-or-lose)
  (eglot--guess-contact)
  (eglot--connect)
  (eglot-handle-notification)
  (eglot--apply-text-edits): Wrap user-facing
  messages in `substitute-quotes'.
* lisp/progmodes/eglot.el (eglot-rename): Format the prompt using
  `format-prompt'.

Copyright-paperwork-exempt: yes
---
 lisp/progmodes/eglot.el | 86 ++++++++++++++++++++++++-----------------
 1 file changed, 50 insertions(+), 36 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 0a14146..f02a1d8 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -713,19 +713,22 @@ eglot--check-object
     (when-let ((missing (and enforce-required
                              (cl-set-difference required-keys
                                                 (eglot--plist-keys object)))))
-      (eglot--error "A `%s' must have %s" interface-name missing))
+      (eglot--error (substitute-quotes "A `%s' must have %s")
+                    interface-name missing))
     (when-let ((excess (and disallow-non-standard
                             (cl-set-difference
                              (eglot--plist-keys object)
                              (append required-keys optional-keys)))))
-      (eglot--error "A `%s' mustn't have %s" interface-name excess))
+      (eglot--error (substitute-quotes "A `%s' mustn't have %s")
+                    interface-name excess))
     (when check-types
       (cl-loop
        for (k v) on object by #'cddr
        for type = (or (cdr (assoc k types)) t) ;; FIXME: enforce nil type?
        unless (cl-typep v type)
-       do (eglot--error "A `%s' must have a %s as %s, but has %s"
-                        interface-name)))
+       do (eglot--error
+           (substitute-quotes "A `%s' must have a %s as %s, but has %s")
+           interface-name)))
     t))
 
 (eval-and-compile
@@ -917,15 +920,17 @@ eglot-register-capability
   "Ask SERVER to register capability METHOD marked with ID."
   (:method
    (_s method _id &rest _params)
-   (eglot--warn "Server tried to register unsupported capability `%s'"
-                method)))
+   (eglot--warn
+    (substitute-quotes "Server tried to register unsupported capability `%s'")
+    method)))
 
 (cl-defgeneric eglot-unregister-capability (server method id &rest params)
   "Ask SERVER to register capability METHOD marked with ID."
   (:method
    (_s method _id &rest _params)
-   (eglot--warn "Server tried to unregister unsupported capability `%s'"
-                method)))
+   (eglot--warn
+    (substitute-quotes "Server tried to unregister unsupported capability `%s'")
+    method)))
 
 (cl-defgeneric eglot-client-capabilities (server)
   "What the Eglot LSP client supports for SERVER."
@@ -1144,8 +1149,9 @@ eglot-server-capable-or-lose
   "Like `eglot-server-capable', but maybe error out."
   (let ((retval (apply #'eglot-server-capable feats)))
     (unless retval
-      (eglot--error "Unsupported or ignored LSP capability `%s'"
-                    (mapconcat #'symbol-name feats " ")))
+      (eglot--error
+       (substitute-quotes "Unsupported or ignored LSP capability `%s'")
+       (mapconcat #'symbol-name feats " ")))
     retval))
 
 
@@ -1290,7 +1296,9 @@ eglot--guess-contact
               (mapcar #'symbol-name (eglot--all-major-modes)) nil t
               guessed-mode-name nil guessed-mode-name nil)))
            ((not guessed-mode)
-            (eglot--error "Can't guess mode to manage for `%s'" (current-buffer)))
+            (eglot--error
+             (substitute-quotes "Can't guess mode to manage for `%s'")
+             (current-buffer)))
            (t guessed-mode)))
          (languages-and-contact (eglot--lookup-mode main-mode))
          (managed-modes (mapcar #'car (car languages-and-contact)))
@@ -1320,24 +1328,25 @@ eglot--guess-contact
                (combine-and-quote-strings guess)))
          (prompt
           (and base-prompt
-               (cond (current-prefix-arg base-prompt)
-                     ((null guess)
-                      (format "[eglot] Couldn't guess LSP server for `%s'\n%s"
-                              main-mode base-prompt))
-                     ((and program
-                           (not (file-name-absolute-p program))
-                           (not (compat-call executable-find program t)))
-                      (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 help you fix"
-                                 " this.")
-                         program guess))))))
+               (substitute-quotes
+                (cond (current-prefix-arg base-prompt)
+                      ((null guess)
+                       (format "[eglot] Couldn't guess LSP server for `%s'\n%s"
+                               main-mode base-prompt))
+                      ((and program
+                            (not (file-name-absolute-p program))
+                            (not (compat-call executable-find program t)))
+                       (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 help you fix"
+                                  " this.")
+                          program guess)))))))
          (input (and prompt (read-shell-command prompt
                                                 full-program-invocation
                                                 'eglot-command-history)))
@@ -1661,12 +1670,13 @@ eglot--connect
                                            (null eglot-autoreconnect)))))))
                           (run-hook-with-args 'eglot-connect-hook server)
                           (eglot--message
-                           "Connected! Server `%s' now managing `%s' buffers \
+                           (substitute-quotes
+                            "Connected! Server `%s' now managing `%s' buffers \
 in project `%s'."
                            (or (plist-get serverInfo :name)
                                (jsonrpc-name server))
                            managed-modes
-                           (eglot-project-nickname server))
+                           (eglot-project-nickname server)))
                           (when tag (throw tag t))))
                       :timeout eglot-connect-timeout
                       :error-fn (eglot--lambda ((ResponseError) code message)
@@ -1689,7 +1699,8 @@ eglot--connect
                                       nil eglot-connect-timeout)))))))
               (pcase retval
                 (`(error . ,msg) (eglot--error msg))
-                (`nil (eglot--message "Waiting in background for server `%s'"
+                (`nil (eglot--message (substitute-quotes
+                                       "Waiting in background for server `%s'")
                                       (jsonrpc-name server))
                       nil)
                 (_ server)))
@@ -2332,7 +2343,9 @@ eglot-handle-notification
   "Handle unknown notification."
   (unless (or (string-prefix-p "$" (format "%s" method))
               (not (memq 'disallow-unknown-methods eglot-strict-mode)))
-    (eglot--warn "Server sent unknown notification method `%s'" method)))
+    (eglot--warn (substitute-quotes
+                  "Server sent unknown notification method `%s'")
+                 method)))
 
 (cl-defmethod eglot-handle-request
   (_server method &key &allow-other-keys)
@@ -3586,7 +3599,8 @@ eglot--apply-text-edits
            (howmany (length edits))
            (reporter (unless silent
                        (make-progress-reporter
-                        (format "[eglot] applying %s edits to `%s'..."
+                        (format (substitute-quotes
+                                 "[eglot] applying %s edits to `%s'...")
                                 howmany (current-buffer))
                         0 howmany)))
            (done 0))
@@ -3708,8 +3722,8 @@ eglot-rename
   "Rename the current symbol to NEWNAME."
   (interactive
    (list (read-from-minibuffer
-          (format "Rename `%s' to: " (or (thing-at-point 'symbol t)
-                                         "unknown symbol"))
+          (format-prompt "Rename `%s' to" nil (or (thing-at-point 'symbol t)
+                                                  "unknown symbol"))
           nil nil nil nil
           (symbol-name (symbol-at-point)))))
   (eglot-server-capable-or-lose :renameProvider)
-- 
2.47.0