fix(macros): smarter .env
loading, caching, and invalidation
#4053
+460
−288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andsqlx.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.