Open MariaSolOs opened 1 day ago
@MariaSolOs When you run organizeImports
, does the order of the first two imports (the one from @foo
and @bar
) also flip? Seems like this case should have autoimports adding onto the end because the original imports are unsorted.
@MariaSolOs When you run
organizeImports
, does the order of the first two imports (the one from@foo
and@bar
) also flip? Seems like this case should have autoimports adding onto the end because the original imports are unsorted.
@iisaduan It does. And indeed, if I follow the repro steps above using this file:
import { bar } from "@bar";
import { foo } from "@foo";
import { a } from "workspace-a";
import { b } from "workspace-b";
console.log(foo + bar + a + b)
Then the bug doesn't happen.
HOWEVER it does happen with this file:
import { bar } from "@bar";
import { foo } from "@foo";
import { a } from "workspace-a";
import { b } from "workspace-b";
import { x } from "../file1";
import { y } from "./file2";
console.log(foo + bar + a + b + x + y);
Using the above content, organizeImports
makes no changes. Now at the bottom of the file start typing is
and select the completion for isAccessor
. The import goes below the import of y
, but then it's moved above a
if one runs organizeImports
.
🔎 Search Terms
"auto-import", "order", "import", "organize imports"
🕗 Version & Regression Information
⏯ 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:
Now at the end of the file type
is
and select the completionisAccessor
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 https://github.com/microsoft/TypeScript/pull/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