Skip to content

Auto-imports from code actions and completions don't match order that "Organize imports" outputsΒ #60492

Open
@MariaSolOs

Description

@MariaSolOs

πŸ”Ž Search Terms

"auto-import", "order", "import", "organize imports"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

No response

πŸ’» Code

In a simple npm package with just TypeScript 5.6.3 installed, create a TypeScript file with the following content:

import { foo } from "@foo";
import { bar } from "@bar";
import { a } from "workspace-a";
import { b } from "workspace-b";

console.log(foo + bar + a + b)

Now at the end of the file type is and select the completion isAccessor that brings the import from TypeScript.

πŸ™ Actual behavior

The import from the completion is added below import { b } from "workspace-b";, but notice how the import gets moved to the middle if one runs the "Organize imports" command in VS Code.

πŸ™‚ Expected behavior

For completions and code actions that add an import to use the same ordering logic that the "Organize imports" command uses. After all this seems to be advertised by #52115 ("These rules will also apply to auto-imports and import fixes, which will use the user's collation preferences to determine if a list of import or export specifiers is already sorted before selecting an insertion point").

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions