Skip to content

Commit a2285fc

Browse files
jacktasiaclaude
andauthored
Warn when ripgrep PCRE2 is not available (#542)
* Warn when ripgrep returns PCRE2 not available error (closes #303) When rg lacks PCRE2 support and returns an error, dumb-jump previously showed a confusing "not found" message. Now detect the PCRE2 error in rg output and display a clear warning directing users to either install rg with PCRE2 or customize `dumb-jump-rg-search-args`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Anchor PCRE2 error detection to line start to avoid false positives The previous substring check could match search hits containing "PCRE2 is not available" in source code. Use ^ anchor so only the actual rg error line (emitted on stderr) triggers the warning. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1cc7a57 commit a2285fc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

dumb-jump.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,6 +4859,9 @@ The parameters are:
48594859
(dumb-jump-debug-message cmd)
48604860
(setq rawresults (shell-command-to-string cmd))
48614861
(dumb-jump-debug-message rawresults)
4862+
(when (string-match-p "^PCRE2 is not available" rawresults)
4863+
(dumb-jump-message "dumb-jump: Ripgrep PCRE2 support is not available. Install ripgrep with PCRE2 support or customize `dumb-jump-rg-search-args' to remove \"--pcre2\".")
4864+
(dumb-jump-env-problem "Ripgrep PCRE2 support is not available in the current build."))
48624865
(when (and (string-blank-p rawresults)
48634866
dumb-jump-fallback-search
48644867
(not (eq dumb-jump--search-mode 'references)))

test/dumb-jump-test.el

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,46 @@ VARIANT must be one of: ag, rg, grep, gnu-grep, git-grep, or git-grep-plus-ag."
645645
(first-result (car results)))
646646
(should (null first-result)))))
647647

648+
(ert-deftest dumb-jump-run-cmd-pcre2-warning-test ()
649+
"Test that a warning is shown when rg output contains PCRE2 error."
650+
(let ((dumb-jump--detected-env-problems nil)
651+
(warned nil))
652+
(cl-letf (((symbol-function 'shell-command-to-string)
653+
(lambda (_cmd) "PCRE2 is not available in this build of ripgrep"))
654+
((symbol-function 'dumb-jump-message)
655+
(lambda (str &rest _args)
656+
(when (string-match-p "PCRE2" str)
657+
(setq warned t)))))
658+
(let* ((generate-fn (lambda (&rest _args) "rg --pcre2 test"))
659+
(parse-fn (lambda (_raw _file _line) nil))
660+
(results (dumb-jump-run-command "test-func" "/tmp" '("regex") "c" "" "test.c" 1
661+
parse-fn generate-fn)))
662+
(should (null results))
663+
(should warned)
664+
(should (cl-some (lambda (p) (string-match-p "PCRE2" p))
665+
dumb-jump--detected-env-problems))))))
666+
667+
(ert-deftest dumb-jump-run-cmd-pcre2-warning-no-false-positive-test ()
668+
"Test that a search hit containing the PCRE2 error text does not trigger the warning."
669+
(let ((dumb-jump--detected-env-problems nil)
670+
(warned nil))
671+
(cl-letf (((symbol-function 'shell-command-to-string)
672+
(lambda (_cmd) "src/foo.c:42:// PCRE2 is not available in this build"))
673+
((symbol-function 'dumb-jump-message)
674+
(lambda (str &rest _args)
675+
(when (string-match-p "PCRE2" str)
676+
(setq warned t)))))
677+
(let* ((generate-fn (lambda (&rest _args) "rg --pcre2 test"))
678+
(parse-fn (lambda (raw _file _line)
679+
(unless (string-blank-p raw)
680+
(list (list :context "PCRE2 is not available"
681+
:path "src/foo.c"
682+
:line 42)))))
683+
(results (dumb-jump-run-command "PCRE2" "/tmp" '("regex") "c" "" "test.c" 1
684+
parse-fn generate-fn)))
685+
(should-not warned)
686+
(should (null dumb-jump--detected-env-problems))))))
687+
648688
(ert-deftest dumb-jump-find-proj-root-test ()
649689
(let* ((js-file (f-join test-data-dir-proj1 "src" "js"))
650690
(found-project (dumb-jump-get-project-root js-file)))

0 commit comments

Comments
 (0)