Skip to content
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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Feb 15, 2025

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.

@@ -430,13 +431,6 @@ const hostImpl = {
return projectVersion;
},
// @ts-ignore Undocumented method.
getCachedExportInfoMap() {
return exportMapCache;
Copy link
Member Author

@dsherret dsherret Feb 15, 2025

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,
);
Copy link
Member Author

@dsherret dsherret Feb 16, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant