Subject: bug#58790:

From: Robert Brown <[email-masked]>
Date: Tue, 8 Nov 2022 19:59:45 -0500

I use a Java language server with Eglot that returns "jar:" URIs like
those discussed in this bug thread.
I took Danny's jarchive.el and combined it with the attached patch,
which modifies Eglot so that it does not convert non-file URIs into
file paths.
With this patch and jarchive.el, "goto definition" works as expected
when the Java source code is inside a jar file.
From 7a5e9959ca9c1989f4611199710d95a84ac9d26b Mon Sep 17 00:00:00 2001
From: Robert Brown <[email-masked]>
Date: Tue, 8 Nov 2022 19:57:50 -0500
Subject: [PATCH] Do not convert non-file URIs into file paths.

---
 eglot.el | 57 ++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/eglot.el b/eglot.el
index 901bf30..83b47c6 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1483,31 +1483,44 @@ If optional MARKER, return a marker instead"
   "Like `url-path-allows-chars' but more restrictive.")
 
 (defun eglot--path-to-uri (path)
-  "URIfy PATH."
-  (let ((truepath (file-truename path)))
-    (concat "file://"
-            ;; Add a leading "/" for local MS Windows-style paths.
-            (if (and (eq system-type 'windows-nt)
-                     (not (file-remote-p truepath)))
-                "/")
-            (url-hexify-string
-             ;; Again watch out for trampy paths.
-             (directory-file-name (file-local-name truepath))
-             eglot--uri-path-allowed-chars))))
+  "When PATH is a file path derived from a file URI, convert it into a URI.
+Otherwise, PATH is already a URI, so just return it."
+  (let ((url (url-generic-parse-url path)))
+    (if (null (url-type url))
+        ;; PATH is a file path.  Convert it into a URI.
+        (let ((truepath (file-truename path)))
+          (concat "file://"
+                  ;; Add a leading "/" for local MS Windows-style paths.
+                  (if (and (eq system-type 'windows-nt)
+                           (not (file-remote-p truepath)))
+                      "/")
+                  (url-hexify-string
+                   ;; Again watch out for trampy paths.
+                   (directory-file-name (file-local-name truepath))
+                   eglot--uri-path-allowed-chars)))
+      ;; PATH is already a URI.
+      path)))
 
 (defun eglot--uri-to-path (uri)
-  "Convert URI to file path, helped by `eglot--current-server'."
+  "When URI is a file URI, convert it into a file path, helped by
+`eglot--current-server'.  Otherwise, just return the URI unchanged."
   (when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
-  (let* ((server (eglot-current-server))
-         (remote-prefix (and server (eglot--trampish-p server)))
-         (retval (url-unhex-string (url-filename (url-generic-parse-url uri))))
-         ;; Remove the leading "/" for local MS Windows-style paths.
-         (normalized (if (and (not remote-prefix)
-                              (eq system-type 'windows-nt)
-                              (cl-plusp (length retval)))
-                         (substring retval 1)
-                       retval)))
-    (concat remote-prefix normalized)))
+  (let ((url (url-generic-parse-url uri)))
+    (if (equal (url-type url) "file")
+        ;; Transform a file URI into a file path, which may be a
+        ;; remote tramp path.
+        (let* ((server (eglot-current-server))
+               (remote-prefix (and server (eglot--trampish-p server)))
+               (retval (url-unhex-string (url-filename url)))
+               ;; Remove the leading "/" for local MS Windows-style paths.
+               (normalized (if (and (not remote-prefix)
+                                    (eq system-type 'windows-nt)
+                                    (cl-plusp (length retval)))
+                               (substring retval 1)
+                             retval)))
+          (concat remote-prefix normalized))
+      ;; Non-file URIs are unmodifiled.
+      uri)))
 
 (defun eglot--snippet-expansion-fn ()
   "Compute a function to expand snippets.
-- 
2.25.1