fix(lsp): improve auto-imports to take into account only package exports#28131
Closed
dsherret wants to merge 16 commits intodenoland:mainfrom
Closed
fix(lsp): improve auto-imports to take into account only package exports#28131dsherret wants to merge 16 commits intodenoland:mainfrom
dsherret wants to merge 16 commits intodenoland:mainfrom
Conversation
dsherret
commented
Feb 15, 2025
dsherret
commented
Feb 16, 2025
| // todo: check if the referrer is cjs and provide require | ||
| ResolutionMode::Import, | ||
| NodeResolutionKind::Types, | ||
| ); |
Contributor
Author
There was a problem hiding this comment.
We might need to add some per-package caching for this because it will be slow for certain packages (because it requires traversing the directories when using wildcards)
dsherret
commented
Apr 4, 2025
| const excludePatterns = preferences.autoImportFileExcludePatterns && getIsExcludedPatterns(preferences, useCaseSensitiveFileNames2); | ||
| forEachExternalModule(program.getTypeChecker(), program.getSourceFiles(), excludePatterns, host, (module2, file) => cb( | ||
| const importableFilePaths = host.getExportImportablePathsFromModule(referrerFile.path); | ||
| const files = importableFilePaths.map((path) => program.getSourceFile(path)).filter((s) => s != null); |
Contributor
Author
There was a problem hiding this comment.
Investigated why the tests are now failing and it's because the discovered files aren't in the program anymore. I think maybe we should have them in getPackageJsonAutoImportProvider (files2 below)?
Contributor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TypeScript's auto-import implementation is implemented specifically for node_modules. Additionally, it seems to traverse through all the source files in a program then filter out any results that aren't importable. This changes things so that we instead provide TypeScript with a limited list of modules to resolve exports from (the entrypoints of every package from JSR or npm in a project) and then modify it not do a subsequent filter.
Fixes .. #28412.Fixes #27700.