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 715fe33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rg-result.el
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
@@ -0,0 +1 @@
imenu
20 changes: 20 additions & 0 deletions test/rg.el-test.el
Expand Up @@ -619,6 +619,26 @@ 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")
(mapcar #'car ientries)))))
(rg-run "hello" "*.baz" (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) 2))
(should (equal
'("bar.baz" "foo.baz")
(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 715fe33

Please sign in to comment.