Closed
Description
After #51565 and #51579, I noticed that auto-import still sometimes puts new things on the bottom. It turns out that it seems to only happen in files that import __String
. Given this test:
/// <reference path="fourslash.ts" />
// @Filename: /a.ts
////export interface HasBar { bar: number }
////export function hasBar(x: unknown): x is HasBar { return x && typeof x.bar === "number" }
////export function foo() {}
////export type __String = string;
// @Filename: /b.ts
////import { __String, HasBar, hasBar } from "./a";
////f/**/;
verify.completions({
marker: "",
includes: {
name: "foo",
source: "/a",
sourceDisplay: "./a",
text: "function foo(): void",
kind: "function",
kindModifiers: "export",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions
},
preferences: { includeCompletionsForModuleExports: true },
});
verify.applyCodeActionFromCompletion("", {
name: "foo",
source: "/a",
description: `Update import from "./a"`,
newFileContent: `import { __String, foo, HasBar, hasBar } from "./a";
f;`,
});
The import gets placed at the end:
Expected:
import { __String, foo, HasBar, hasBar } from "./a";
f;
Actual:
import { __String, HasBar, hasBar, foo } from "./a";
f;
Remove the import of __String
, and foo
is placed in the correct place.