projectile icon indicating copy to clipboard operation
projectile copied to clipboard

Invalidate projectile-project-root-cache

Open raxod502 opened this issue 9 months ago • 6 comments

I find that a frequent operation is:

  • Attempt to projectile-find-file
  • Realize my current directory is not marked as a project
  • Create .projectile file
  • Attempt to projectile-find-file again
  • To my surprise, Projectile still thinks the directory is not marked as a project, even though it is
  • Attempt to use projectile-invalidate-cache
  • To my further surprise, Projectile forces me to select a project to clear the cache for, even though what I need is just to clear projectile-project-root-cache, which is not associated with any project
  • Select an unrelated project to clear the cache for, which clears projectile-project-root-cache as a side effect
  • Now projectile-find-file works

Suggestions for improvement:

  • Detect cases where projectile-project-root-cache should be cleared automatically to avoid user confusion
  • Add a user command for clearing projectile-project-root-cache without needing to select a project
  • Document the fact that this cache exists (since it affects user-visible behavior)

I could help out with this, but creating an issue first for discussion.

raxod502 avatar Feb 27 '25 05:02 raxod502

All good suggestions. PR welcome!

Btw, does an empty cache get created in this case when there's no project? (this definitely is a bug if so)

bbatsov avatar Feb 27 '25 05:02 bbatsov

The nil return value of the entry in projectile-project-root-functions is cached if no project is detected:

https://github.com/bbatsov/projectile/blob/0163b335a18af0f077a474d4dc6b36e22b5e3274/projectile.el#L1335-L1340

I'm not sure if that is what you meant.

raxod502 avatar Feb 27 '25 20:02 raxod502

Ah, yeah - I had forgotten about this.

bbatsov avatar Feb 27 '25 21:02 bbatsov

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!

github-actions[bot] avatar May 29 '25 02:05 github-actions[bot]

Don't close this issue. This is an automatic message by Fresh - a bot against stale bots.

/remove-lifecycle stale

raxod502 avatar May 30 '25 01:05 raxod502

I've filed https://github.com/bbatsov/projectile/pull/1945 to implement some of this. Let's use that as a starting point, and then my subsequent idea is that there should be a buffer-local variable that is used to track whether or not the cache entry for that buffer's file is fresh - this would make it so that using M-x revert-buffer, a common way to clear settings for a buffer, would also have the side effect of allowing Projectile to re-resolve the containing project, which I feel would help match user expectations. Does that sound like a reasonable idea?

raxod502 avatar Jun 11 '25 22:06 raxod502

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed soon if no further activity occurs. Thank you for your contribution and understanding!

github-actions[bot] avatar Sep 10 '25 02:09 github-actions[bot]

We can close this for now, since the biggest issues were addressed, and discuss more specific improvements in other issues.

raxod502 avatar Sep 10 '25 22:09 raxod502