-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Eagerly resolve module specifiers for auto-import completions in --moduleResolution node12+
#48752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrewbranch
merged 9 commits into
microsoft:main
from
andrewbranch:auto-imports-nodenext
Apr 27, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8964677
Add failing test
andrewbranch b10892c
Block auto-import module specifiers including node_modules path
andrewbranch 7298111
Eagerly resolve module specifiers in completions in nodenext so failu…
andrewbranch f4cf71f
Add completion info flags for telemetry
andrewbranch d95f7bf
Update API baseline
andrewbranch 06be70d
Update completions baselines
andrewbranch 0b2e920
Fix missed boolean flip
andrewbranch 122bfa6
Fix remaining tests
andrewbranch 9e4f900
Merge branch 'main' into auto-imports-nodenext
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -644,6 +644,7 @@ namespace ts.codefix { | |
const compilerOptions = program.getCompilerOptions(); | ||
const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host); | ||
const getChecker = memoizeOne((isFromPackageJson: boolean) => isFromPackageJson ? host.getPackageJsonAutoImportProvider!()!.getTypeChecker() : program.getTypeChecker()); | ||
const rejectNodeModulesRelativePaths = moduleResolutionUsesNodeModules(getEmitModuleResolutionKind(compilerOptions)); | ||
const getModuleSpecifiers = fromCacheOnly | ||
? (moduleSymbol: Symbol) => ({ moduleSpecifiers: moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }) | ||
: (moduleSymbol: Symbol, checker: TypeChecker) => moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); | ||
|
@@ -655,19 +656,19 @@ namespace ts.codefix { | |
const importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & SymbolFlags.Value); | ||
const addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions); | ||
computedWithoutCacheCount += computedWithoutCache ? 1 : 0; | ||
return moduleSpecifiers?.map((moduleSpecifier): FixAddNewImport | FixAddJsdocTypeImport => | ||
return mapDefined(moduleSpecifiers, (moduleSpecifier): FixAddNewImport | FixAddJsdocTypeImport | undefined => | ||
rejectNodeModulesRelativePaths && pathContainsNodeModules(moduleSpecifier) ? undefined : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is the most important change. |
||
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types. | ||
!importedSymbolHasValueMeaning && isJs && position !== undefined | ||
? { kind: ImportFixKind.JsdocTypeImport, moduleSpecifier, position, exportInfo, isReExport: i > 0 } | ||
: { | ||
kind: ImportFixKind.AddNew, | ||
moduleSpecifier, | ||
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions), | ||
useRequire, | ||
addAsTypeOnly, | ||
exportInfo, | ||
isReExport: i > 0, | ||
} | ||
!importedSymbolHasValueMeaning && isJs && position !== undefined ? { kind: ImportFixKind.JsdocTypeImport, moduleSpecifier, position, exportInfo, isReExport: i > 0 } : | ||
{ | ||
kind: ImportFixKind.AddNew, | ||
moduleSpecifier, | ||
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions), | ||
useRequire, | ||
addAsTypeOnly, | ||
exportInfo, | ||
isReExport: i > 0, | ||
} | ||
); | ||
}); | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a behavior change, but the property became a misnomer because in nodenext, factors that don't contribute to this property can make the module specifiers not auto-importable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Blocked" sounds like it means "not auto-importable". Is that correct and, if so, does that mean that the meaning of the flag has flipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For other reviewers, yes, the meaning has flipped.