From 151684ff826e54a5165d016bf6f8ea0bbb548996 Mon Sep 17 00:00:00 2001 From: Nacho Barrientos Date: Mon, 24 Oct 2022 10:05:08 +0200 Subject: [PATCH] Fix "File: " skipping when building the elements of the imenu We shouldn't be using `skip-chars-forward' here as this function skips over any _character set_ passed as argument, not just a string. Without this patch, for instance entries like: File: lol/foo.bar Will be added to the candidates list as "ol/foo.bar" as ?l is in the character set "File: ". Instead, just skips 6 chars forward. --- rg-result.el | 2 +- test/data/limenu.el | 1 + test/rg.el-test.el | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/data/limenu.el diff --git a/rg-result.el b/rg-result.el index 69d1516..f9ec1c8 100644 --- a/rg-result.el +++ b/rg-result.el @@ -777,7 +777,7 @@ previous file with grouped matches." (while (setq nextfile (rg-navigate-file-message nextfile nil 1)) (save-excursion (goto-char nextfile) - (skip-chars-forward "File: ") + (and (looking-at-p "^File: ") (forward-char 6)) (setq filepath (buffer-substring-no-properties (point) (line-end-position)))) (push (cons filepath nextfile) elements)) (nreverse elements)))))) diff --git a/test/data/limenu.el b/test/data/limenu.el new file mode 100644 index 0000000..7213da4 --- /dev/null +++ b/test/data/limenu.el @@ -0,0 +1 @@ +imenu diff --git a/test/rg.el-test.el b/test/rg.el-test.el index 82f6dcb..335c186 100644 --- a/test/rg.el-test.el +++ b/test/rg.el-test.el @@ -343,6 +343,7 @@ matching alias." (should (eq called 'compilation-previous-file)) (should (eq arg 1)))))) + (ert-deftest rg-unit/match-grouped-filename () "Test that `rg-match-grouped-filename' finds correct match and restores state." (let (saved-pos) @@ -619,6 +620,18 @@ method. " (rg-project-root "/tmp/foo.el")) "/tmp/"))) +(ert-deftest rg-integration-test/imenu-populated () + "Test that the imenu entries are correct." + :tags '(need-rg) + (rg-run "imenu" "elisp" (concat default-directory "test/data")) + (with-current-buffer (rg-buffer-name) + (rg-wait-for-search-result) + (let ((ientries (funcall imenu-create-index-function))) + (should (equal (length ientries) 1)) + (should (equal + '("limenu.el") + (seq-sort #'string-lessp (mapcar #'car ientries))))))) + (ert-deftest rg-integration/command-hiding-hide () "Test command hiding when `rg-hide-command` is non nil." :tags '(need-rg)