Skip to content

Conversation

abonander
Copy link
Collaborator

Having looked over both #4018 and #4039, neither seemed like a complete solution on its own. Rather than choose which one to bless and still need to have a tedious back and-forth to arrive at a satisfactory solution, I decided to try my hand at it myself.

The major thing both PRs were missing was a way to invalidate the loaded .env and sqlx.toml files after caching, since otherwise the user would need to completely reload RustAnalyzer if they made any changes to either. This necessitated the creation of a wrapper that could watch a set of files and automatically invalidate the cached value if the modified-time on any of them changed.

I also felt that #4018 was just too complex in general while in #4039 I wasn't really comfortable with caching the full contents of the .env file since that could conceivably contain various secrets that we shouldn't be storing, even temporarily.

cc and thanks to both @AlexTMjugador (#4018) and @Diggsey (#4039) for their proposed solutions. I'll be sure to credit your contributions in the changelog. It would be a great help if you both could look this over and let me know if it correctly fixes the issues you've raised. I'd also love your help figuring out how to create a regression test for this since we clearly don't test .env loading well enough in CI.

Does your PR solve an issue?

closes #4018 (superceded PR)
closes #4039 (superceded PR)

Is this a breaking change?

Only with respect to currently unreleased changes.

@abonander abonander force-pushed the ab/fix-dotenv-loading branch 2 times, most recently from 43cb27a to b3f4186 Compare October 8, 2025 01:41
@abonander abonander force-pushed the ab/fix-dotenv-loading branch from b3f4186 to 7e69f23 Compare October 8, 2025 20:15
@AlexTMjugador
Copy link
Contributor

Awesome, thanks a lot for giving this a try as well! The more solutions we have to a problem, the merrier (ignoring the new problem of choosing the right one... 😂).

I've skimmed through the changes, and they look quite good to me. I really like the addition of a new Clippy lint for std::env::var, and how the general issue of caching is tackled at a deeper level with the introduction of the MtimeCache struct.

I'll try giving this PR a spin in a production codebase once I'm back at work, and get back with the results 👍

@Diggsey
Copy link
Contributor

Diggsey commented Oct 8, 2025

Yep, looks good to me on the surface! Haven't had a chance to test it out for real yet, but it looks like it should work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants