Function: eglot-uri-to-path
eglot-uri-to-path is a byte-compiled function defined in eglot.el.gz.
Signature
(eglot-uri-to-path URI)
Documentation
Convert URI to file path, helped by eglot-current-server.
Aliases
eglot--uri-to-path (obsolete since 1.16)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(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)))
(root (and server (project-root (eglot--project server))))
(trueroot (and server (eglot--trueroot server)))
(url (url-generic-parse-url uri)))
;; Only parse file:// URIs, leave other URI untouched as
;; `file-name-handler-alist' should know how to handle them
;; (bug#58790).
(if (string= "file" (url-type url))
(let* ((unhexed (decode-coding-string
(url-unhex-string (url-filename url)) 'utf-8-unix))
;; Remove the leading "/" for local MS Windows-style paths.
(norm (if (and (not remote-prefix)
(eq system-type 'windows-nt)
(cl-plusp (length unhexed))
(eq (aref unhexed 0) ?/))
(w32-long-file-name (substring unhexed 1))
unhexed))
;; Even though we exchange truename URIs with the server,
;; ensure paths exchanged with Emacs facilities such as
;; Xref contains the familiar root as found by
;; 'project-current', not a potentially obscure
;; canonicalized truename.
(norm
(if (and trueroot (string-prefix-p trueroot norm))
(expand-file-name (substring norm (length trueroot)) root)
norm)))
(concat remote-prefix norm))
uri)))