Skip to content

Commit

Permalink
Fix "File: " skipping when building the elements of the imenu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nbarrientos committed Oct 24, 2022
1 parent 51596cb commit 151684f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rg-result.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))))
Expand Down
1 change: 1 addition & 0 deletions test/data/limenu.el
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
imenu
13 changes: 13 additions & 0 deletions test/rg.el-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 151684f

Please sign in to comment.