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
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
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'.")
(defvar doom-projectile-fd-binary
(or (cl-find-if #'executable-find '("fdfind" "fd"))
"fd")
"name of `fd-find' executable binary")
(cl-find-if #'executable-find (list "fdfind" "fd"))
"The filename of the `fd' executable. On some distros it's 'fdfind' (ubuntu,
debian, and derivatives). On most it's 'fd'.")
;;
@ -131,6 +131,11 @@ c) are not valid projectile projects."
projectile-project-root-files)
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
;; 7 commands to maintain, versus the more generic, reliable and
;; performant `fd' or `ripgrep'.
@ -142,48 +147,38 @@ And if it's a function, evaluate it."
(funcall projectile-generic-command vcs)
projectile-generic-command))
(cond
;; If fd exists, use it for git and generic projects. fd is a rust program
;; that is significantly faster than git ls-files or find, and it respects
;; .gitignore. This is recommended in the projectile docs.
((executable-find doom-projectile-fd-binary)
(setq projectile-generic-command
;; `projectile-generic-command' doesn't typically support a function.
;; My `doom--only-use-generic-command-a' advice allows this. I do it
;; this way so that future changes to
;; `projectile-globally-ignored-directories' are respected.
(lambda (_)
(concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow"
(or (cl-find-if (if EMACS27+
(doom-rpartial #'executable-find t)
#'executable-find)
'("fdfind" "fd"))
"fd"))
(cl-loop for dir in projectile-globally-ignored-directories
concat " -E "
concat (shell-quote-argument dir))
(if IS-WINDOWS " --path-separator=//")))
projectile-git-submodule-command nil
;; ensure Windows users get fd's benefits
projectile-indexing-method 'alien))
;; Otherwise, resort to ripgrep, which is also faster than find
((executable-find "rg")
(setq projectile-generic-command
(lambda (_)
(concat "rg -0 --files --follow --color=never --hidden"
(cl-loop for dir in projectile-globally-ignored-directories
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
(setq projectile-git-submodule-command nil)))
;; `projectile-generic-command' doesn't typically support a function, but my
;; `doom--only-use-generic-command-a' advice allows this. I do it this way so
;; that projectile can adapt to remote systems (over TRAMP), rather then look
;; for fd/ripgrep on the remote system simply because it exists on the host.
;; It's faster too.
(setq projectile-git-submodule-command nil
projectile-indexing-method 'hybrid
projectile-generic-command
(lambda (_)
(let ((find-exe-fn
(if EMACS27+
(doom-rpartial #'executable-find t)
#'executable-find)))
;; If fd exists, use it for git and generic projects. fd is a rust
;; program that is significantly faster than git ls-files or find, and
;; it respects .gitignore. This is recommended in the projectile docs.
(cond
((when-let
(bin (if (file-remote-p buffer-file-name nil t)
(cl-find-if find-exe-fn (list "fdfind" "fd"))
doom-projectile-fd-binary))
(concat (format "%s . -0 -H -E .git --color=never --type file --type symlink --follow"
bin)
(if IS-WINDOWS " --path-separator=/"))))
;; Otherwise, resort to ripgrep, which is also faster than find
((funcall find-exe-fn "rg")
(concat "rg -0 --files --follow --color=never --hidden"
(cl-loop for dir in projectile-globally-ignored-directories
concat " --glob "
concat (shell-quote-argument (concat "!" dir)))
(if IS-WINDOWS " --path-separator /")))
("find . -type f -print0")))))
(defadvice! doom--projectile-default-generic-command-a (orig-fn &rest args)
"If projectile can't tell what kind of project you're in, it issues an error