Update symlink cache from AutoImportProvider resolution even if host project already contains the file via its realpath #46830
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.
This fixes part of a bug I noticed while writing #46569, mentioned in the test comment there. An AutoImportProviderProject contains only files that the host Project does not. However, it’s possible, as in the test written here, that the main project only knows about a file via its realpath, but it also exists as a symlink inside
node_modules
. Because that symlink was mentioned in the package.json dependencies, we discover it as part of spinning up an AutoImportProviderProject. However, when we see that the SourceFile we resolved to is already contained by the host Project, we skip it entirely, discarding the knowledge of the symlink we found. This PR allows the AutoImportProviderProject to add that symlink knowledge to the host project’s cache before it decides not to add the file to itself. This way, the host Project is still responsible for generating auto-imports of that SourceFile, but it can come up with the correct module specifier for it using the symlink information discovered by the AutoImportProviderProject.