From f6e0a6d1ff557719b11cdf357fc24246c9da6a86 Mon Sep 17 00:00:00 2001 From: dannyfreeman Date: Tue, 25 Oct 2022 08:22:20 -0400 Subject: [PATCH] Parse "jar" scheme URIs in eglot correctly jar schemes contain nested URIs, like-this' "jar:file:///home/user/some.jar!/path/in/jar" such that when eglot was parsing these URIs provided by lsp servers, it ended up trying to navigate to "file:///home/user/some.jar!/path/in/jar". This change parses the URIs twice if the scheme is "jar", so that the final parsed URI looks like "/home/user/some.jar!/path/in/jar" instead. When providing this path to a jar to tools like xref, emacs will still not correctly open the file within the jar, but this change makes that work easier. --- lisp/progmodes/eglot.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index a28df6c2d5..549de5cba4 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1501,12 +1501,22 @@ If optional MARKER, return a marker instead" (directory-file-name (file-local-name truepath)) eglot--uri-path-allowed-chars)))) +(defun eglot--parse-uri (uri) + (url-unhex-string + (url-filename + (let ((url (url-generic-parse-url uri))) + (if (string= "jar" (url-type url)) + ;; jar: URIs can contain a nested URI, so we need to parse twice. + ;; For example, `jar:file:///home/user/some.jar!/path/in/jar' + (url-generic-parse-url (url-filename url)) + url))))) + (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)))) + (retval (eglot--parse-uri uri)) ;; Remove the leading "/" for local MS Windows-style paths. (normalized (if (and (not remote-prefix) (eq system-type 'windows-nt) -- 2.37.3