Subject: Re: bug#58790: Eglot URI parsing bug when using clojure-lsp server

From: Danny Freeman <[email-masked]>
Date: Sun, 13 Nov 2022 16:04:02 -0500

Michael Albinus <[email-masked]> writes:

> Well, using nil as operation might work in this special case, but it
> disables an important feature of file name handlers: use of
> inhibit-file-name-operation. That's why it shouldn't be documented as
> such.
>
> Using just an arbitrary symbol as operation looks better to me. If you
> use an existing operation name, like access-file, it could conflict later
> with the inhibit-file-name-operation/inhibit-file-name-handlers machinery.
>
> This said, I don't understand why you need this check at all. But I
> haven't followed the eglot discussion closely.
>
> Best regards, Michael.

Thanks for your insights Michael! If you are curious, this code in eglot
is about to round-aboutly call `find-file-noselect' on a URI, which
Emacs will probably fail to open if there is no registered file name
handler. So before doing that we write a message warning the user if no
file name handler is registered. That's the idea.

With this info I've written up another patch that checks
find-file-name-handler with an arbitrary symbol (with a better name than
my first attempt, IMO). I've tried to strike a balance between inline
comments and the commit message.

>From 86a444be767a3e160f60e46086e38ef154134683 Mon Sep 17 00:00:00 2001
From: dannyfreeman <[email-masked]>
Date: Thu, 10 Nov 2022 19:07:46 -0500
Subject: [PATCH] Eglot: Warn when receiving a non-file type URI (bug#58790)

When this occurs, Emacs will probably not know how to open up the
URI. The warning may help users when investigating a potential
solution.

* lisp/progmodes/eglot.el (eglot--uri-to-path): warn on unhandled URI
---
 lisp/progmodes/eglot.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 97c674f7aa..97febdacc2 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1534,7 +1534,11 @@ If optional MARKER, return a marker instead"
                                (substring retval 1)
                              retval)))
           (concat remote-prefix normalized))
-
+      ;; Use a fake operation, eglot--fake-file-name-op because we
+      ;; don't want this check to be suppressed by `inhibit-file-name-operation'.
+      ;; We just want to see if a handler exists.
+      (unless (find-file-name-handler uri 'eglot--fake-file-name-op)
+        (eglot--message "Received URI with unexpected scheme: %s" uri))
       uri)))
 
 (defun eglot--snippet-expansion-fn ()
-- 
2.38.1

-- 
Danny Freeman