Refactor completion/ivy & optimize projectile-find-file

counsel-projectile-find-file fontifies visited files and sorts the
resulting file list from projectile-find-file, adding considerable
overhead. Then, ivy-prescient performs a frecency sort and filter,
adding more overhead.

Altogether, this makes projectile-find-file unusable for larger projects
when fuzzy search is on (and in some extreme cases, when it's off). This
change disables both features specifically for projectile-find-file.

Fixes #774, hopefully
This commit is contained in:
Henrik Lissner 2018-08-03 16:12:27 +02:00
parent 3673067736
commit ab4052b8dc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -65,6 +65,9 @@ immediately runs it on the current candidate (ending the ivy session)."
(t . ivy--regex-fuzzy))
ivy-initial-inputs-alist nil))
;; make projectile-find-file faster
(add-to-list 'ivy-sort-functions-alist '(projectile-find-file))
(after! yasnippet
(add-to-list 'yas-prompt-functions #'+ivy-yas-prompt nil #'eq))
@ -73,17 +76,21 @@ immediately runs it on the current candidate (ending the ivy session)."
[remap persp-switch-to-buffer] #'+ivy/switch-workspace-buffer
[remap imenu-anywhere] #'ivy-imenu-anywhere)
(ivy-mode +1))
(ivy-mode +1)
;; Show more buffer information in switch-buffer commands
(def-package! ivy-rich
:after ivy
:config
(after! ivy-rich
(dolist (cmd '(ivy-switch-buffer +ivy/switch-workspace-buffer
counsel-projectile-switch-to-buffer))
(ivy-set-display-transformer cmd '+ivy-buffer-transformer)))
(def-package! ivy-hydra
:commands (ivy-dispatching-done-hydra ivy--matcher-desc)
:init
(define-key! ivy-minibuffer-map
"\C-o" #'+ivy-coo-hydra/body
(kbd "M-o") #'ivy-dispatching-done-hydra)))
(def-package! counsel
:commands counsel-describe-face
@ -147,11 +154,9 @@ immediately runs it on the current candidate (ending the ivy session)."
("L" (lambda (path) "Insert org-link with absolute path"
(with-ivy-window (insert (format "[[%s]]" path)))) "insert org-link (abs. path)")))
;; Configure `counsel-rg', `counsel-ag' & `counsel-pt'
(dolist (cmd '(counsel-ag counsel-rg counsel-pt))
(ivy-add-actions
cmd
'(("O" +ivy-git-grep-other-window-action "open in other window")))))
'counsel-ag ; also applies to `counsel-rg' & `counsel-pt'
'(("O" +ivy-git-grep-other-window-action "open in other window"))))
(def-package! counsel-projectile
@ -166,17 +171,30 @@ immediately runs it on the current candidate (ending the ivy session)."
[remap projectile-ag] #'counsel-projectile-ag
[remap projectile-switch-project] #'counsel-projectile-switch-project)
:config
;; Highlight entries that have been visited
;; Highlight entries that have been visited; opposite of default
(ivy-set-display-transformer #'counsel-projectile-find-file #'+ivy-projectile-find-file-transformer))
(def-package! ivy-hydra
:commands (ivy-dispatching-done-hydra ivy--matcher-desc)
(def-package! ivy-prescient
:after ivy
:init
(after! ivy
(define-key! ivy-minibuffer-map
"\C-o" #'+ivy-coo-hydra/body
(kbd "M-o") #'ivy-dispatching-done-hydra)))
(if (featurep! +fuzzy)
(setq prescient-filter-method 'fuzzy)
(setq prescient-filter-method 'regexp
ivy-prescient-retain-classic-highlighting t))
:config
(setq prescient-save-file (concat doom-cache-dir "presclient-save.el"))
;; `ivy-prescient' is too slow for fuzzy projectile-find-file and
;; counsel-file-jump, so ensure they're ignored
(when (featurep! +fuzzy)
(add-to-list 'ivy-re-builders-alist '(counsel-file-jump . +ivy--regex-fuzzy))
(add-to-list 'ivy-re-builders-alist '(projectile-find-file . +ivy--regex-fuzzy)))
(add-to-list 'ivy-prescient-excluded-commands 'counsel-find-jump nil #'eq)
(add-to-list 'ivy-prescient-excluded-commands 'projectile-find-file nil #'eq)
(prescient-persist-mode +1)
(ivy-prescient-mode +1))
(def-package! wgrep
@ -218,19 +236,6 @@ immediately runs it on the current candidate (ending the ivy session)."
(setf (alist-get fn ivy-display-functions-alist) #'ivy-display-function-fallback)))
(def-package! ivy-prescient
:after ivy
:init
(if (featurep! +fuzzy)
(setq prescient-filter-method 'fuzzy)
(setq prescient-filter-method 'regexp
ivy-prescient-retain-classic-highlighting t))
:config
(setq prescient-save-file (concat doom-cache-dir "presclient-save.el"))
(prescient-persist-mode +1)
(ivy-prescient-mode +1))
;; Used by `counsel-M-x'
(setq amx-save-file (concat doom-cache-dir "amx-items"))