-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
fix55816: exclude files with re-exports if excluded by preferences.autoImportFileExcludePatterns #58537
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.
|
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;
?
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.
Yes, the broken import that we fixed was in thing,ts
, and the file that the codefix was triggered in is in a different part of the folder tree than thing
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 was trying to make cases with other file structures, since I was trying to test if the codefix would still crash in situations where the import map resolved to a different preferred file to generate the import from
I added a debug statement to only exit quietly if |
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
…toimport-excludePatternsFail
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.