Ensure LSP requests don't use stale data #57
Merged
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.
Another bugfix for something I ran into working on typesafe reexports. This struck particularly frequently with autosuggest (for reasons that will become clear) but was actually a potential problem for any LSP request coming in immediately after an editor change.
Prior to this change, requests to the language server would use the most recently calculated transform information about open files without triggering a recalculation themselves. This nearly always worked, because following any sequence of changes with a brief cooldown, we'd interrogate the TS language service for diagnostics, which would trigger a fresh transformation of any changed modules. If a request came in during that cooldown period, though, they would operate against the version of the workspace from before the change, potentially leading to incorrect results.
This change ensures all operations go through a flow that validates the document hasn't changed since the last transform, rather than only attempts to read the file contents.