jacktasia / dumb-jump

an Emacs "jump to definition" package for 50+ languages
GNU General Public License v3.0
1.57k stars 150 forks source link

Dumb-jump in Windows Emacs with WSL files does not jump correctly #429

Open bastibe opened 1 year ago

bastibe commented 1 year ago

I'm using Emacs on Windows to work on files in a WSL virtual machine. Windows maps the WSL's directory structure into a virtual network drive at //wsl$/Ubuntu-20.04/home/.... However, running ag on such a path has two issues:

At the moment, I'm using the following workaround:

  (defun fix-WSL-errors (orig-fun resp &rest args)
    (let* (;; CMD.exe likes to inject a useless error message, so filter it out:
           (filtered (replace-regexp-in-string "'[^']+'\nCMD.EXE was started with the above path as the current directory.\nUNC paths are not supported.  Defaulting to Windows directory.\n" "" resp))
           ;; for some reason, ag returns paths as /wsl$/... instead of //wsl$/..., which
           ;; dumb-jump interprets as a relative path instead of an absolute one,
           ;; so fix that:
           (fixed (replace-regexp-in-string "^\\\\wsl\\$" "\\\\\\\\wsl$" filtered)))
      (apply orig-fun fixed args)))
  (advice-add 'dumb-jump-parse-ag-response :around #'fix-WSL-errors)

I don't know if that's something dumb-jump can fix, or if this needs to be forwarded to ag or indeed Microsoft.