-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Auto-import priority rules #51155
Comments
None of the things you've listed are first-class concepts in TS -- basically, when we're running, it's all just files and/or ambient module declarations. Formal definitions of what it means to "be defined locally in a monorepo" or "be a node internal" would be needed |
@RyanCavanaugh - thanks for replying! Do you think there would be a willingness to add these concepts and get something implemented? It seems this is the main file involved? I'm thinking some of the edge cases around monorepos might get pretty nasty, but I would think sorting the explicit imports before node built-in modules may be straightforward. |
Adding another similar issue from VS Code repo that was also closed: microsoft/vscode#42104. It seems like on of the issues tracked in this ticket was resolved, but the main issue of import priority was not. |
This is definitely annoying to our team as well - we have a lot of generic React components like , , etc. And each time the auto-import suggests alternatives found in external dependencies first, even though local code seems to be a fairly reasonable thing to prefer. |
would be great if this could be further customizable to allow solving for collisions across external packages as well a few anecdotal examples from our app
|
would really be great for us as well, we have many conflicting names of types which are imported first from the node_modules libraries rather than from our code (e.g. User, BaseEntity, etc) |
What about sorting suggestions by popularity? When you already imported There can also be other heuristics, but this feels like a good start. |
I thinks sane defaults would be in order:
Beyond that being able to specify overrides would make sense too though. |
Related on Stack Overflow: VS Code TypeScript auto import suggestion priority |
Second this, |
Have a similar experience with angular, |
@robiot If you have the alias configured in your tsconfig.json, there is already a setting that should do what you want.
![]() Snippet from tsconfig.json:{
"compilerOptions": {
...
"paths": {
"@/*": ["./src/*"]
}
} Import suggestion:![]() |
Thats a good tip, but in my case I have a design system built on top of MUI and it keeps preferring @mui vs our design system (in a monorepo using turbo)... I actually sort of hacked it with snippets by creating a couple that start with "import" i.e. "import-design-system" |
You can change the auto-complete suggestions and code fix (quick fix) with a TypeScript Plugin. A TypeScript Plugin has to be a package (cannot be a local file), so I made one: https://github.com/tidalhq/ts-plugin-sort-import-suggestions |
I feel I could forgive having to click an obtuse option once or twice but some general user popularity score would be really nice. This should be the goal IMO. Then this should also feed into the selection process for "Add All Missing Imports". Alternatively, maybe something we can just put in |
I think also closest relative should be first, and prefer down the tree before up the tree. should prefer this order: |
this has been driving me insane. everytimes vscode autoimports a component it crashes my dev server because it is always import the node module and not my local aliased module. is there not a workaround for this? |
Thanks, it works great! I just wrote a step-by-step guide so it’s easier if someone needs to implement this. Hopefully it helps. https://theodorusclarence.com/shorts/vscode/auto-import-sort |
This is great, and works with the in-file suggestions. But for auto completion on saves it doesn't work for some reason? "editor.codeActionsOnSave": {
"source.addMissingImports": "always",
} I guess this uses the VSCode typescript and not from the workspace. |
We really need this feature for monorepo projects... |
Suggestion
It seems there are many folks struggling with the priority/ordering of VSCode's auto-import (intellisense) suggestions. There are a few different cases, but they seem to be all somewhat related to the general theme of how these suggestions are prioritized.
watch
fromfs
is always prioritized overvue
(/cc @cabal95)It would be fantastic if VSCode provided a way to override the priority but it seems that TypeScript's language server suggestions could use some tweaking regardless.
⭐ Suggestion
Seems like a fairly reasonable priority would be:
fs
,path
)🔍 Search Terms
import priority prioritize prioritise auto-import vscode intellisense
🔗 Related Issues
open
closed
The text was updated successfully, but these errors were encountered: