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

@ -525,42 +525,46 @@ 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))
(when (and persp-mode +workspaces--project-dir)
(when projectile-before-switch-project-hook
(with-temp-buffer
;; Load the project dir-local variables into the switch buffer, so the
;; action can make use of them
(setq default-directory +workspaces--project-dir)
(hack-dir-local-variables-non-file-buffer)
(run-hooks 'projectile-before-switch-project-hook)))
(unwind-protect
(if (and (not (null +workspaces-on-switch-project-behavior))
(or (eq +workspaces-on-switch-project-behavior t)
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
(+workspace-buffer-list)))
(let* ((persp
(let ((project-name (doom-project-name +workspaces--project-dir)))
(or (+workspace-get project-name t)
(+workspace-new project-name))))
(new-name (persp-name persp)))
(+workspace-switch new-name)
(with-current-buffer (doom-fallback-buffer)
(setq default-directory +workspaces--project-dir))
(unless current-prefix-arg
(funcall +workspaces-switch-project-function +workspaces--project-dir))
(+workspace-message
(format "Switched to '%s' in new workspace" new-name)
'success))
(with-current-buffer (doom-fallback-buffer)
(setq default-directory +workspaces--project-dir)
(hack-dir-local-variables-non-file-buffer)
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
(with-demoted-errors "Workspace error: %s"
(+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir)))
(unless current-prefix-arg
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
(run-hooks 'projectile-after-switch-project-hook)
(setq +workspaces--project-dir nil))))
;; 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
;; Load the project dir-local variables into the switch buffer, so the
;; action can make use of them
(setq default-directory +workspaces--project-dir)
(hack-dir-local-variables-non-file-buffer)
(run-hooks 'projectile-before-switch-project-hook)))
(unwind-protect
(if (and (not (null +workspaces-on-switch-project-behavior))
(or (eq +workspaces-on-switch-project-behavior t)
(equal (safe-persp-name (get-current-persp)) persp-nil-name)
(+workspace-buffer-list)))
(let* ((persp
(let ((project-name (doom-project-name +workspaces--project-dir)))
(or (+workspace-get project-name t)
(+workspace-new project-name))))
(new-name (persp-name persp)))
(+workspace-switch new-name)
(with-current-buffer (doom-fallback-buffer)
(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
(format "Switched to '%s' in new workspace" new-name)
'success))
(with-current-buffer (doom-fallback-buffer)
(setq default-directory +workspaces--project-dir)
(hack-dir-local-variables-non-file-buffer)
(message "Switched to '%s'" (doom-project-name +workspaces--project-dir)))
(with-demoted-errors "Workspace error: %s"
(+workspace-rename (+workspace-current-name) (doom-project-name +workspaces--project-dir)))
(unless current-prefix-arg
(funcall +workspaces-switch-project-function +workspaces--project-dir)))
(run-hooks 'projectile-after-switch-project-hook)
(setq +workspaces--project-dir nil)))))
;;