From fe9d6daa57102c7daebdcced2d7b6253cecb047c Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 13 May 2021 08:55:31 -0700 Subject: [PATCH] Correct path/uri when using tramp from ms windows MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Co-authored-by: João Távora * eglot.el (eglot--connect): Ensure drive letter doesn't sneak into rootPath. (eglot--path-to-uri): Only add a leading "/" for local MS Windows paths. (eglot--uri-to-path): Only remove leading "/" from local MS Windows paths. GitHub-reference: fix https://github.com/joaotavora/eglot/issues/679 --- lisp/progmodes/eglot.el | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index fc82367f8e1..f17e795bfb5 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1046,8 +1046,8 @@ This docstring appeases checkdoc, that's all." (emacs-pid)) ;; Maybe turn trampy `/ssh:foo@bar:/path/to/baz.py' ;; into `/path/to/baz.py', so LSP groks it. - :rootPath (expand-file-name - (file-local-name default-directory)) + :rootPath (file-local-name + (expand-file-name default-directory)) :rootUri (eglot--path-to-uri default-directory) :initializationOptions (eglot-initialization-options server) @@ -1274,24 +1274,31 @@ If optional MARKER, return a marker instead" (defun eglot--path-to-uri (path) "URIfy PATH." - (concat "file://" (if (eq system-type 'windows-nt) "/") - (url-hexify-string - ;; Again watch out for trampy paths. - (directory-file-name (file-local-name (file-truename path))) - eglot--uri-path-allowed-chars))) + (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)))) (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* ((retval (url-filename (url-generic-parse-url (url-unhex-string uri)))) - (normalized (if (and (eq system-type 'windows-nt) - (cl-plusp (length retval))) - (substring retval 1) - retval)) - (server (eglot-current-server)) + (let* ((server (eglot-current-server)) (remote-prefix (and server (file-remote-p - (project-root (eglot--project server)))))) + (project-root (eglot--project server))))) + (retval (url-filename (url-generic-parse-url (url-unhex-string 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))) (defun eglot--snippet-expansion-fn () -- 2.39.2