Respect importModuleSpecifierPreference
in sort order between fixes for the same symbol from different files
#58597
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.
Fixes #55863
There were two bugs in play:
importModuleSpecifierPreference
was only being considered in how to generate module specifiers between a given pair of files. But when computing auto-imports, there may be multiple files a missing symbol can be imported from, so the module specifier generation code is called multiple times, and multiple fixes are generated. Those fixes are then sorted, but the sort logic didn’t considerimportModuleSpecifierPreference
. In most cases, all the generated fixes either successfully satisfied the preference or didn’t, but it’s possible, as in the bug repro and test case, that e.g. the symbol being imported is available from one file that can only be reached by relative path and another file that can be reached by a non-relativepaths
/baseUrl
module specifier.paths
/baseUrl
. We were incorrectly checking whether thesepaths
/baseUrl
specifiers were package.json dependencies, which would further deprioritize them under relative paths. (Writing this out makes me realize that I need to follow up with a separate test to ensure that package.jsonimports
and self-name imports are not being deprioritized for the same reason.)