-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
fix55816: exclude files with re-exports if excluded by preferences.autoImportFileExcludePatterns #58537
base: main
Are you sure you want to change the base?
Conversation
Is that the right issue? It seems unrelated. |
It is the correct issue, see the call stack here. The quick fix is not offered because getting autoimports fails when the file is excluded in preferences |
if (skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol && info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) { | ||
if ( | ||
skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol | ||
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol) |
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.
Plot twist: all existing tests pass if you delete this entire info.some(...)
part of the condition. That might be all that’s needed to fix the bug?
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.
I tried that and wasn't sure if that was the best fix, since I tracked it back to here, where it looked like it was intentionally added. :D if your opinion is that the check was unnecessary, I'll change it back to just deleting this extra check
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.
Actually, I remember something did break when I tried that-- tests/cases/fourslash/server/autoImportReExportFromAmbientModule.ts
breaks with the info.some
call removed. Since exporting ambient modules doesn't use filenames, I figured it would be alright to skip the check for ignored files
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.
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol) | |
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) |
if (skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol && info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) { | ||
if ( | ||
skipAlias(info[0].symbol, getChecker(info[0].isFromPackageJson)) === symbol | ||
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol) |
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.
&& info.some(i => moduleSymbolExcluded || i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol) | |
&& (moduleSymbolExcluded || info.some(i => i.moduleSymbol === moduleSymbol || i.symbol.parent === moduleSymbol)) |
@typescript-bot pack this |
Starting jobs; this comment will be updated as builds start and complete.
|
@@ -286,8 +286,11 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog | |||
const checker = program.getTypeChecker(); | |||
const symbol = checker.getMergedSymbol(skipAlias(exportedSymbol, checker)); | |||
const exportInfo = getAllExportInfoForSymbol(sourceFile, symbol, symbolName, moduleSymbol, /*preferCapitalized*/ false, program, host, preferences, cancellationToken); | |||
|
|||
// If no exportInfo is found, this means the export could not be resolved, so we should not generate an import | |||
if (!exportInfo) return; |
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.
Maybe we should at least ensure this never happens unless there are preferences.autoImportFileExcludePatterns
verify.codeFix({ | ||
description: "Implement interface 'Parts'", | ||
newFileContent: | ||
`import { Event } from '../event/event'; |
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.
Huh, this one with the broken import ended up working? What’s different from when we debugged it yesterday and this was crashing? Is there a test case that exercises if (!exportInfo) return;
?
Fixes #55816
This failure happened when a file
foo.ts
that re-exports some variableT
is ignored by"typescript.preferences.autoImportFileExcludePatterns"
.foo.ts
was properly ignored byexportMap
, but the autoImports still attempted to generate the import withfoo.ts
instead of the file that originally exportedT
, which lead to a failure.This PR allows the
moduleSymbol
found by autoImports to not match themoduleSymbol
found byexportInfoMap
if the moduleSymbol found by autoimports is excluded. Furthermore, if the import info still cannot be resolved, the quickfix will still be available and we will generate the implementation code without the import statement.