Skip to content

Commit e66a049

Browse files
committed
fix(typescript-plugin): handle import type { ... } for component import
close #5874
1 parent c8f8bfe commit e66a049

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/typescript-plugin/lib/common.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,27 @@ export function resolveCompletionEntryDetails(
554554
'import ' + oldName + ' from ',
555555
'import ' + newName + ' from ',
556556
);
557-
// #5874
558-
if (data.__vue__autoImportSuggestions) {
557+
}
558+
}
559+
}
560+
}
561+
// #5874
562+
if (data?.__vue__autoImportSuggestions) {
563+
for (const codeAction of details?.codeActions ?? []) {
564+
for (const change of codeAction.changes) {
565+
for (const textChange of change.textChanges) {
566+
if (data.__vue__componentAutoImport) {
567+
const { oldName, newName } = data.__vue__componentAutoImport;
559568
textChange.newText = textChange.newText.replace(
560569
'import type ' + oldName + ' from ',
561570
'import ' + newName + ' from ',
562571
);
563572
}
573+
const { entryName } = data.__vue__autoImportSuggestions;
574+
textChange.newText = textChange.newText.replace(
575+
'import type { ' + entryName + ' } from ',
576+
'import { ' + entryName + ' } from ',
577+
);
564578
}
565579
}
566580
}

0 commit comments

Comments
 (0)