-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix(lsp): improve auto-imports to take into account only package exports #28131
base: main
Are you sure you want to change the base?
Conversation
@@ -430,13 +431,6 @@ const hostImpl = { | |||
return projectVersion; | |||
}, | |||
// @ts-ignore Undocumented method. | |||
getCachedExportInfoMap() { | |||
return exportMapCache; |
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 was not exactly correct. It needs to be created per language service instance so that a program can be provided.
// todo: check if the referrer is cjs and provide require | ||
ResolutionMode::Import, | ||
NodeResolutionKind::Types, | ||
); |
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.
We'll need to add some caching for this because it will be slow for certain packages (because it requires traversing the directories when using wildcards)
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.