emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1a2d603bb3: Eglot: Only handle URIs with the file:// scheme (bug#


From: João Távora
Subject: master 1a2d603bb3: Eglot: Only handle URIs with the file:// scheme (bug#58790)
Date: Thu, 10 Nov 2022 17:41:48 -0500 (EST)

branch: master
commit 1a2d603bb3938ff68ed1a5412d131b41efd40a24
Author: dannyfreeman <danny@dfreeman.email>
Commit: João Távora <joaotavora@gmail.com>

    Eglot: Only handle URIs with the file:// scheme (bug#58790)
    
    Eglot will not attempt to parse URIs that are not file:// type at all.
    Instead let 'file-name-handler-alist' entries to deal with those.  Not
    parsing them at all allows the 'file-name-handler-alist' regexps to
    identify them more accurately.
    
    By also checking if Eglot received a URI in 'eglot--path-to-uri',
    'file-name-handler-alist' can provide the non-file type URI back to
    the lsp server, which presumably will know how to handle them since it
    is also giving them out to clients.
    
    This issue originated with clojure-lsp sending clients "jar:" type
    URIs that Emacs is unable to handle out of the box.  Before this
    change, "jar:" URIs were parsed once, but since they contain a nested
    URI, this resulted in a file being dispatched with a partially parsed
    path that looked like "file://path/to.jar!/path/in/jar".
    
    * lisp/progmodes/eglot.el (eglot--path-to-uri): Noop if already an
    URI.  (eglot--uri-to-path):  Only handle file:// URIs
---
 lisp/progmodes/eglot.el | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 1b1302d689..2463f68f97 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1501,29 +1501,38 @@ If optional MARKER, return a marker instead"
 (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))))
+    (if (url-type (url-generic-parse-url truepath))
+        ;; Path is already a URI, so forward it to the lsp server untouched.
+        truepath
+      (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)))))
 
 (defun eglot--uri-to-path (uri)
   "Convert URI to file path, helped by `eglot--current-server'."
   (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)))
+         (url (url-generic-parse-url uri)))
+    ;; Only attempt to parse URIs with the file scheme.
+    (if (string= "file" (url-type url))
+        (let* ((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))
+      ;; Leave non-file type URIs untouched, `file-name-handler-alist'
+      ;; handlers can be used to dispatch them properly.
+      uri)))
 
 (defun eglot--snippet-expansion-fn ()
   "Compute a function to expand snippets.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]