Fix #3215: ripgrep reporting error code 2 on Windows

Closes #3512
This commit is contained in:
Henrik Lissner
2020-07-17 01:08:30 -04:00
parent 576eb40b50
commit 523e945a3a
3 changed files with 46 additions and 51 deletions

View File

@ -11,9 +11,9 @@ Emacs.")
"If non-nil, non-projects are purged from the cache on `kill-emacs-hook'.") "If non-nil, non-projects are purged from the cache on `kill-emacs-hook'.")
(defvar doom-projectile-fd-binary (defvar doom-projectile-fd-binary
(or (cl-find-if #'executable-find '("fdfind" "fd")) (cl-find-if #'executable-find (list "fdfind" "fd"))
"fd") "The filename of the `fd' executable. On some distros it's 'fdfind' (ubuntu,
"name of `fd-find' executable binary") debian, and derivatives). On most it's 'fd'.")
;; ;;
@ -131,6 +131,11 @@ c) are not valid projectile projects."
(append projectile-project-root-files-bottom-up (append projectile-project-root-files-bottom-up
projectile-project-root-files) projectile-project-root-files)
projectile-project-root-files-bottom-up nil))) projectile-project-root-files-bottom-up nil)))
;; Some utilities have issues with windows-style paths in MSYS, so emit
;; unix-style paths instead.
(when IS-WINDOWS
(setenv "MSYS_NO_PATHCONV" "1"))
;; HACK Don't rely on VCS-specific commands to generate our file lists. That's ;; HACK Don't rely on VCS-specific commands to generate our file lists. That's
;; 7 commands to maintain, versus the more generic, reliable and ;; 7 commands to maintain, versus the more generic, reliable and
@ -142,48 +147,38 @@ And if it's a function, evaluate it."
(if (functionp projectile-generic-command) (if (functionp projectile-generic-command)
(funcall projectile-generic-command vcs) (funcall projectile-generic-command vcs)
projectile-generic-command)) projectile-generic-command))
(cond ;; `projectile-generic-command' doesn't typically support a function, but my
;; If fd exists, use it for git and generic projects. fd is a rust program ;; `doom--only-use-generic-command-a' advice allows this. I do it this way so
;; that is significantly faster than git ls-files or find, and it respects ;; that projectile can adapt to remote systems (over TRAMP), rather then look
;; .gitignore. This is recommended in the projectile docs. ;; for fd/ripgrep on the remote system simply because it exists on the host.
((executable-find doom-projectile-fd-binary) ;; It's faster too.
(setq projectile-generic-command (setq projectile-git-submodule-command nil
;; `projectile-generic-command' doesn't typically support a function. projectile-indexing-method 'hybrid
;; My `doom--only-use-generic-command-a' advice allows this. I do it projectile-generic-command
;; this way so that future changes to (lambda (_)
;; `projectile-globally-ignored-directories' are respected. (let ((find-exe-fn
(lambda (_) (if EMACS27+
(concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow" (doom-rpartial #'executable-find t)
(or (cl-find-if (if EMACS27+ #'executable-find)))
(doom-rpartial #'executable-find t) ;; If fd exists, use it for git and generic projects. fd is a rust
#'executable-find) ;; program that is significantly faster than git ls-files or find, and
'("fdfind" "fd")) ;; it respects .gitignore. This is recommended in the projectile docs.
"fd")) (cond
(cl-loop for dir in projectile-globally-ignored-directories ((when-let
concat " -E " (bin (if (file-remote-p buffer-file-name nil t)
concat (shell-quote-argument dir)) (cl-find-if find-exe-fn (list "fdfind" "fd"))
(if IS-WINDOWS " --path-separator=//"))) doom-projectile-fd-binary))
projectile-git-submodule-command nil (concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow"
;; ensure Windows users get fd's benefits bin)
projectile-indexing-method 'alien)) (if IS-WINDOWS " --path-separator=/"))))
;; Otherwise, resort to ripgrep, which is also faster than find
;; Otherwise, resort to ripgrep, which is also faster than find ((funcall find-exe-fn "rg")
((executable-find "rg") (concat "rg -0 --files --follow --color=never --hidden"
(setq projectile-generic-command (cl-loop for dir in projectile-globally-ignored-directories
(lambda (_) concat " --glob "
(concat "rg -0 --files --follow --color=never --hidden" concat (shell-quote-argument (concat "!" dir)))
(cl-loop for dir in projectile-globally-ignored-directories (if IS-WINDOWS " --path-separator /")))
concat " --glob "
concat (shell-quote-argument (concat "!" dir)))
(if IS-WINDOWS " --path-separator //")))
projectile-git-submodule-command nil
;; ensure Windows users get rg's benefits
projectile-indexing-method 'alien))
;; Fix breakage on windows in git projects with submodules, since Windows
;; doesn't have tr
(IS-WINDOWS
("find . -type f -print0"))))) ("find . -type f -print0")))))
(defadvice! doom--projectile-default-generic-command-a (orig-fn &rest args) (defadvice! doom--projectile-default-generic-command-a (orig-fn &rest args)

View File

@ -278,11 +278,11 @@ evil-ex-specific constructs, so we disable it solely in evil-ex."
"Change `counsel-file-jump' to use fd or ripgrep, if they are available." "Change `counsel-file-jump' to use fd or ripgrep, if they are available."
:override #'counsel--find-return-list :override #'counsel--find-return-list
(cl-destructuring-bind (find-program . args) (cl-destructuring-bind (find-program . args)
(cond ((executable-find doom-projectile-fd-binary) (cond ((when-let (fd (executable-find (or doom-projectile-fd-binary "fd")))
(append (list doom-projectile-fd-binary (append (list fd
"--color=never" "-E" ".git" "--color=never" "-E" ".git"
"--type" "file" "--type" "symlink" "--follow") "--type" "file" "--type" "symlink" "--follow")
(if IS-WINDOWS '("--path-separator=/")))) (if IS-WINDOWS '("--path-separator=/")))))
((executable-find "rg") ((executable-find "rg")
(append (list "rg" "--files" "--follow" "--color=never" "--hidden" "--no-messages") (append (list "rg" "--files" "--follow" "--color=never" "--hidden" "--no-messages")
(cl-loop for dir in projectile-globally-ignored-directories (cl-loop for dir in projectile-globally-ignored-directories

View File

@ -162,7 +162,7 @@ we have to clean it up ourselves."
(use-package! fd-dired (use-package! fd-dired
:when (executable-find doom-projectile-fd-binary) :when doom-projectile-fd-binary
:defer t :defer t
:init :init
(global-set-key [remap find-dired] #'fd-dired) (global-set-key [remap find-dired] #'fd-dired)