redguardtoo / counsel-etags

Fast, energy-saving, and powerful code navigation solution
174 stars 15 forks source link

When calling "counsel-etags-find-tag-at-point", rg report separator is error #74

Closed lczch closed 3 years ago

lczch commented 3 years ago

On windows, When calling "counsel-etags-find-tag-at-point", rg report separator is error. The separator should be "\\" instead of "\".

I fix it by change "counsel-etags-grep-cli" a little(only about constructing the separator):

(defun counsel-etags-grep-cli (keyword use-cache)
  "Use KEYWORD and USE-CACHE to build CLI.
Extended regex is used, like (pattern1|pattern2)."
  (cond
   ((counsel-etags-has-quick-grep-p)
    ;; "--hidden" force ripgrep to search hidden files/directories, that's default
    ;; behavior of grep
    (format "%s %s %s --hidden %s \"%s\" --"
            ;; if rg is not in $PATH, then it's in `counsel-etags-grep-program'
            (or (executable-find "rg") counsel-etags-grep-program)
            ;; (if counsel-etags-debug " --debug")
            (concat 
             "-n -M 1024 --no-heading --color never -s "
             "--path-separator "
             (if (eq system-type 'windows-nt)
                 "\\\\"
               "\\"))
            counsel-etags-grep-extra-arguments
            (counsel-etags-exclude-opts use-cache)
            keyword))
   (t
    ;; use extended regex always
    (format "%s -rsnE %s %s \"%s\" *"
            (or counsel-etags-grep-program (counsel-etags-guess-program "grep"))
            counsel-etags-grep-extra-arguments
            (counsel-etags-exclude-opts use-cache)
            keyword))))

I use msys2 + win10 + emacs26.1

redguardtoo commented 3 years ago

Both Emacs and ripgrep can handle slash. Check my updated doc.

c109519 windows setup (Chen Bin)

lczch commented 3 years ago

It doesn't work. The errors occurs again.

redguardtoo commented 3 years ago

Can you give me a minimum example and exact steps to reproduce the bug? I also need the ripgrep details.

lczch commented 3 years ago

I configure emacs using only use-package and counsel-etags as below:

(use-package counsel-etags
  ;; :commands (counsel-etags-find-tag-at-point
  ;;            counsel-etags-virtual-update-tags)
  :config
  (add-hook 'prog-mode-hook
        (lambda ()
          (add-hook 'after-save-hook
                    'counsel-etags-virtual-update-tags 'append 'local)))

  (setq counsel-etags-update-interval 60)
  (push "build" counsel-etags-ignore-directories)

  ;; counsel-etags-ignore-directories does NOT support wildcast
  (push "build_clang" counsel-etags-ignore-directories)
  (push "build_clang" counsel-etags-ignore-directories)
  (push ".git" counsel-etags-ignore-directories)
  ;; counsel-etags-ignore-filenames supports wildcast
  (push "TAGS" counsel-etags-ignore-filenames)
  (push "*.json" counsel-etags-ignore-filenames)
  (push "#.*" counsel-etags-ignore-filenames)

  ;; Don't ask before rereading the TAGS files if they have changed
  (setq tags-revert-without-query t)
  ;; Do case-sensitive tag searches
  (setq tags-case-fold-search nil) ;; t=case-insensitive, nil=case-sensitive
  ;; Don't warn when TAGS files are large
  (setq large-file-warning-threshold nil)

  ;; list tags by imenu.
  (setq imenu-create-index-function 'counsel-etags-imenu-default-create-index-function)

  (when (eq system-type 'windows-nt)
    (setq counsel-etags-ctags-program "C:\\\\msys64\\\\home\\\\lzh\\\\bin\\\\ctags")
    (setq counsel-etags-grep-program "C:\\\\Users\\\\lzh\\\\.cargo\\\\bin\\\\rg"))

  ;; don't ignore files in ".gitignore": need to search for installed packages.
  ;; use `counsel-etags-ignore-directories' and `counsel-etags-ignore-filenames' to prevent generating tags.
  (setq counsel-etags-ignore-config-files nil)
  ;; It is wonderful that counsel-etags also prevent ripgrep to match files in `counsel-etags-ignore-directories' or `counsel-etags-ignore-filenames'
  (setq counsel-etags-grep-extra-arguments "--no-ignore"))

Then in buffer *scratch*, I enter "xxxx", then using command counsel-etags-find-tag-at-point, the error occurs: (there is a picture) image

emacs version: 27.1 system: win10 + msys2 counsel-etags: commit "windows setup"

redguardtoo commented 3 years ago

85c82ff fixed ripgrep windows path separator problem (Chen Bin)

lczch commented 3 years ago

It works! Thank you!