summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordannyfreeman <danny@dfreeman.email>2022-11-03 09:39:16 -0400
committerJoão Távora <joaotavora@gmail.com>2022-11-10 22:39:09 +0000
commit1a2d603bb3938ff68ed1a5412d131b41efd40a24 (patch)
tree358d7b2c83eb86d97633838451a857ee496d18a9
parentc3b64985aa6f61886a24974836635284c86478ef (diff)
downloademacs-1a2d603bb3938ff68ed1a5412d131b41efd40a24.tar.gz
emacs-1a2d603bb3938ff68ed1a5412d131b41efd40a24.tar.bz2
emacs-1a2d603bb3938ff68ed1a5412d131b41efd40a24.zip
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
-rw-r--r--lisp/progmodes/eglot.el43
1 files changed, 26 insertions, 17 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 1b1302d6897..2463f68f971 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.