Fix #3166 and #3288: over-eager project-root caching

And prevent explicit projectile-project-root interfering with project
switching.
This commit is contained in:
Henrik Lissner 2020-06-04 19:15:25 -04:00
parent db25224e18
commit 60ca118eb2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 40 additions and 53 deletions

View file

@ -39,23 +39,6 @@ Emacs.")
:config
(projectile-mode +1)
;; REVIEW Resolve the project root once, when the file/buffer is opened. This
;; speeds up projectile's project root resolution by leaps, but does
;; put you at risk of having a stale project root.
(setq-hook! '(change-major-mode-after-body-hook
;; In case the user saves the file to a new location
after-save-hook
;; ...or makes external changes then returns to Emacs
focus-in-hook
;; ...or when we change the current project!
projectile-after-switch-project-hook)
projectile-project-root (if default-directory (doom-project-root)))
;; However, it may become a problem when switching projects, so remove the
;; cached value when switching projects.
(setq-hook! 'projectile-before-switch-project-hook
projectile-project-root nil)
;; Projectile runs four functions to determine the root (in this order):
;;
;; + `projectile-root-local' -> checks the `projectile-project-root' variable

View file

@ -525,6 +525,9 @@ the user to open a file in the new project.
This be hooked to `projectile-after-switch-project-hook'."
(when dir
(setq +workspaces--project-dir dir))
;; HACK Clear projectile-project-root, otherwise cached roots may interfere
;; with project switch (see #3166)
(let (projectile-project-root)
(when (and persp-mode +workspaces--project-dir)
(when projectile-before-switch-project-hook
(with-temp-buffer
@ -545,7 +548,8 @@ This be hooked to `projectile-after-switch-project-hook'."
(new-name (persp-name persp)))
(+workspace-switch new-name)
(with-current-buffer (doom-fallback-buffer)
(setq default-directory +workspaces--project-dir))
(setq default-directory +workspaces--project-dir)
(hack-dir-local-variables-non-file-buffer))
(unless current-prefix-arg
(funcall +workspaces-switch-project-function +workspaces--project-dir))
(+workspace-message
@ -560,7 +564,7 @@ This be hooked to `projectile-after-switch-project-hook'."
(unless current-prefix-arg
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
(run-hooks 'projectile-after-switch-project-hook)
(setq +workspaces--project-dir nil))))
(setq +workspaces--project-dir nil)))))
;;