branch: elpa/projectile
commit 0da59734fbc23fc26222a7d03f6671b3116b0b77
Author: Radon Rosborough <ra...@intuitiveexplanations.com>
Commit: Bozhidar Batsov <bozhi...@batsov.dev>

    Handle the projects cache better
---
 CHANGELOG.md                                |  1 +
 doc/modules/ROOT/pages/troubleshooting.adoc | 13 +++++++++++++
 projectile.el                               | 20 +++++++++++++-------
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f80204beef..05fcee0d44 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
 
 * Set `projectile-auto-discover` to `nil` by default.
 * [#1943](https://github.com/bbatsov/projectile/pull/1943): Consider 
`projectile-indexing-method` to be safe as a dir-local variable if it is one of 
the preset values.
+* [#1936](https://github.com/bbatsov/projectile/issues/1936): Do not require 
selecting a project when using `M-x projectile-invalidate-cache`, since there 
is a global cache that is also cleared by that command, even when not operating 
on any specific project.
 
 ## 2.9.1 (2025-02-13)
 
diff --git a/doc/modules/ROOT/pages/troubleshooting.adoc 
b/doc/modules/ROOT/pages/troubleshooting.adoc
index d567ac1f72..e8004a99b7 100644
--- a/doc/modules/ROOT/pages/troubleshooting.adoc
+++ b/doc/modules/ROOT/pages/troubleshooting.adoc
@@ -57,6 +57,19 @@ This will bring up a backtrace with the entire function 
stack, including
 function arguments. So you should be able to figure out what's going on (or at
 least what's being required).
 
+=== Projectile recognizes the wrong project
+
+If Projectile does not think you are in a project, check how you
+expect Projectile to recognize the project: it needs the presence of
+an indicator file like `.git` or similar at the project root. If the
+directory you want to be a project is not version-controlled, a file
+named `.projectile` will do.
+
+Note that Projectile caches the operation of checking which project
+(if any) a file belongs to. If you have already opened a file, then
+later added a marker file like `.projectile`, run `M-x
+projectile-invalidate-cache` to reset the cache.
+
 === I upgraded Projectile using `package.el` and nothing changed
 
 Emacs doesn't load the new files, it only installs them on disk.  To see the
diff --git a/projectile.el b/projectile.el
index ecd166c942..00867249e1 100644
--- a/projectile.el
+++ b/projectile.el
@@ -1089,15 +1089,21 @@ A wrapper around `file-exists-p' with additional 
caching support."
   "Remove the current project's files from `projectile-projects-cache'.
 
 With a prefix argument PROMPT prompts for the name of the project whose cache
-to invalidate."
+to invalidate.
+
+The global (project-independent) cache for checking which project a file
+belongs to, is also cleared. Therefore this function is still useful even
+when not operating on a specific project, and as such only the global cache
+is cleared when there is no current project (unless you give a prefix
+argument)."
   (interactive "P")
-  (let ((project-root
-         (if prompt
-             (completing-read "Remove cache for: "
-                              (hash-table-keys projectile-projects-cache))
-           (projectile-acquire-root))))
+  (setq projectile-project-root-cache (make-hash-table :test 'equal))
+  (when-let ((project-root
+              (if prompt
+                  (completing-read "Remove cache for: "
+                                   (hash-table-keys projectile-projects-cache))
+                (projectile-project-root))))
     ;; reset the in-memory cache
-    (setq projectile-project-root-cache (make-hash-table :test 'equal))
     (remhash project-root projectile-project-type-cache)
     (remhash project-root projectile-projects-cache)
     (remhash project-root projectile-projects-cache-time)

Reply via email to