You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First, the user renames a file normally using the file explorer in their editor.
Tsserver will pick up on this change and update the project (which will break a lot of imports to the old location).
After the rename, the editor will offer the user to update references to the file.
If the user says yes, it will then ask tsserver to get code edits, passing in the old and new paths to the file.
Tsserver will walk all imports, see which ones are unresolved now and could have resolved to the old path (but don't since that's been moved now), and update them to the new path instead, and send these edits to the editor.
The editor will apply the edits to all files. (Hopefully with undo functionality if the user decides against renaming the file.)
This is a bit tricky on the tsserver side since we need to be able to figure out what unresolved imports could have resolved to. This meant I had to leave moduleResolutionCache around so we could look at the failed lookup locations for failed imports.
Fully expecting to need a lot of revision on this. CC @mjbvz for protocol review.
FWIW: most IDEs I’ve used, asked me – before the file was actually moved: “Do you also want to update references?”
Naively, it seems like that could simplify the algorithm.
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.
Here's how I think it would work:
This is a bit tricky on the tsserver side since we need to be able to figure out what unresolved imports could have resolved to. This meant I had to leave
moduleResolutionCache
around so we could look at the failed lookup locations for failed imports.Fully expecting to need a lot of revision on this. CC @mjbvz for protocol review.