crumpled paper texture

Sorting Auto Import Suggestions on VSCode

If you're frustrated because VSCode recommends you the wrong import when they have the same name, this is for you.

––– views

2 min read

0 likes

autosort-before

Are you’re frustrated because VSCode recommends you the wrong import when they have the same name?

Yeah me too, but I found a solution 👀. Turns out there’s a plugin for that! You can actually sort and re-order import suggestions.

Let me guide you through the installation process

Step-by-step Guide

The plugin is called ts-plugin-sort-import-suggestions.

  1. Install it as a dev dependency

    pnpm add --save-dev ts-plugin-sort-import-suggestions
  2. Make sure you have typescript in your package.json. If you don’t have them you can install them

    pnpm add --save-dev typescript
  3. Add this to your tsconfig

    You can customize the imports that you want to move up and down

    tsconfig.json
    "compilerOptions": {
      "plugins": [
        {
          "name": "ts-plugin-sort-import-suggestions",
          "moveUpPatterns": ["@/", "\\.{1,2}/"],
          "moveDownPatterns": ["@radix-ui", "lucide-react"]
        }
      ]
    }
  4. Add workspace typescript setting

    This plugin is installed on the workspace typescript, so we need to make sure we are using the workspace version.

    Command Palette (Cmd + Shift + P) > TypeScript: Select TypeScript Version... > Use Workspace Version

    workspace-version-cmd-p

    If you can’t find the option, make sure you’re opening a typescript file (can be any file)

  5. Reload the VSCode

    Sometimes it doesn’t work automatically, reloading VSCode usually works

Result

Now it's sorted nicely!

autosort-after