Skip to content

Commit 0da5973

Browse files
raxod502bbatsov
authored andcommitted
Handle the projects cache better
1 parent e961fb9 commit 0da5973

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Set `projectile-auto-discover` to `nil` by default.
88
* [#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.
9+
* [#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.
910

1011
## 2.9.1 (2025-02-13)
1112

doc/modules/ROOT/pages/troubleshooting.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ This will bring up a backtrace with the entire function stack, including
5757
function arguments. So you should be able to figure out what's going on (or at
5858
least what's being required).
5959

60+
=== Projectile recognizes the wrong project
61+
62+
If Projectile does not think you are in a project, check how you
63+
expect Projectile to recognize the project: it needs the presence of
64+
an indicator file like `.git` or similar at the project root. If the
65+
directory you want to be a project is not version-controlled, a file
66+
named `.projectile` will do.
67+
68+
Note that Projectile caches the operation of checking which project
69+
(if any) a file belongs to. If you have already opened a file, then
70+
later added a marker file like `.projectile`, run `M-x
71+
projectile-invalidate-cache` to reset the cache.
72+
6073
=== I upgraded Projectile using `package.el` and nothing changed
6174

6275
Emacs doesn't load the new files, it only installs them on disk. To see the

projectile.el

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,15 +1089,21 @@ A wrapper around `file-exists-p' with additional caching support."
10891089
"Remove the current project's files from `projectile-projects-cache'.
10901090
10911091
With a prefix argument PROMPT prompts for the name of the project whose cache
1092-
to invalidate."
1092+
to invalidate.
1093+
1094+
The global (project-independent) cache for checking which project a file
1095+
belongs to, is also cleared. Therefore this function is still useful even
1096+
when not operating on a specific project, and as such only the global cache
1097+
is cleared when there is no current project (unless you give a prefix
1098+
argument)."
10931099
(interactive "P")
1094-
(let ((project-root
1095-
(if prompt
1096-
(completing-read "Remove cache for: "
1097-
(hash-table-keys projectile-projects-cache))
1098-
(projectile-acquire-root))))
1100+
(setq projectile-project-root-cache (make-hash-table :test 'equal))
1101+
(when-let ((project-root
1102+
(if prompt
1103+
(completing-read "Remove cache for: "
1104+
(hash-table-keys projectile-projects-cache))
1105+
(projectile-project-root))))
10991106
;; reset the in-memory cache
1100-
(setq projectile-project-root-cache (make-hash-table :test 'equal))
11011107
(remhash project-root projectile-project-type-cache)
11021108
(remhash project-root projectile-projects-cache)
11031109
(remhash project-root projectile-projects-cache-time)

0 commit comments

Comments
 (0)