alphapapa / magit-todos

Show source files' TODOs (and FIXMEs, etc) in Magit status buffer
GNU General Public License v3.0
747 stars 48 forks source link

rg scanner doesn't work on Windows #156

Open svraka opened 1 year ago

svraka commented 1 year ago

The recent changes which introduced directory-form in the rg scanner broke magit-todos on Windows.

With the default settings magit-todos-list starts an rg command, which looks like does it's job but the process keeps running and TODOs aren't inserted in the buffer. With a custom scanner that leaves :directory-form empty but otherwise is identical to the default one, everthing works (and results have a leading ./).

As far as I can tell, the default scanner runs rg <OPTIONS> <PATTERN> ./, while a scanner with empty :directory-form runs rg <OPTIONS> <PATTERN> (without the path at the end). In a shell both commands work, and their output differs in the leading ./.

On macOS with the same config works without any issues. All testing done with Emacs 29.1 and latest MELPA packages.

alphapapa commented 1 year ago

Hi András,

Thanks for reporting this problem.

What versions of ripgrep did you use to test for and reproduce this bug on each platform?

svraka commented 1 year ago

13.0 on all platforms. On Windows installed via MSYS2:

> rg --version
ripgrep 13.0.0 (rev af6b6c543b)
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

On macOS installed via Homebrew:

> rg --version
ripgrep 13.0.0
-SIMD -AVX (compiled)
alphapapa commented 1 year ago

So you're saying that the same version of rg behaves differently on Windows than on *nix platforms?

Anyway, I don't generally use Windows, so I'm afraid a Windows user will have to debug this and suggest a patch.

It's also not inconceivable that some compile-time options of Emacs or rg, or other settings involved in Windows process arguments, are related.

donniebreve commented 10 months ago

I'm running into a similar issue.

This snippet to revert the directory-form change seems to fix things on Windows.

(setq magit-todos-scanners nil)
(magit-todos-defscanner "rg"
  :test (executable-find "rg")
  :directory-form (f-relative directory default-directory) ;; revert
  :allow-exit-codes (0 1)
  :command (list "rg" "--no-heading" "--line-number"
                 (when depth
                   (list "--maxdepth" (1+ depth)))
                 (when magit-todos-ignore-case
                   "--ignore-case")
                 (when magit-todos-exclude-globs
                   (--map (list "--glob" (concat "!" it))
                          magit-todos-exclude-globs))
                 (unless magit-todos-submodule-list
                   (--map (list "--glob" (concat "!" it))
                          (magit-list-module-paths)))
                 extra-args search-regexp-pcre directory))

I tested running rg in eshell and found that not including the ./ seems to never return.

in eshell rg -i todo: doesn't return rg -i todo ./: returns matches

I tested these scenarios with ripgrep 13.0.0 and ripgrep 14.1.0 (latest) with the same results.

I have no idea if this helps, feel free to ask for more information.

alphapapa commented 10 months ago

@donniebreve Thanks. I'll try to implement that workaround in 1.8 then.