diff --git a/extensions/typescript/src/features/completionItemProvider.ts b/extensions/typescript/src/features/completionItemProvider.ts index 35823bbca73..76982a3323d 100644 --- a/extensions/typescript/src/features/completionItemProvider.ts +++ b/extensions/typescript/src/features/completionItemProvider.ts @@ -328,21 +328,27 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP const detail = details[0]; item.detail = Previewer.plain(detail.displayParts); const documentation = new MarkdownString(); - if (item.source) { - let importPath = `'${item.source}'`; - // Try to resolve the real import name that will be added - if (detail.codeActions && detail.codeActions[0]) { - const action = detail.codeActions[0]; - if (action.changes[0] && action.changes[0].textChanges[0]) { - const textChange = action.changes[0].textChanges[0]; - const matchedImport = textChange.newText.match(/(['"])(.+?)\1/); - if (matchedImport) { - importPath = matchedImport[0]; - item.detail += ` — from ${matchedImport[0]}`; + if (detail.source) { + let importPath = `'${Previewer.plain(detail.source)}'`; + + if (this.client.apiVersion.has260Features() && !this.client.apiVersion.has262Features()) { + // Try to resolve the real import name that will be added + if (detail.codeActions && detail.codeActions[0]) { + const action = detail.codeActions[0]; + if (action.changes[0] && action.changes[0].textChanges[0]) { + const textChange = action.changes[0].textChanges[0]; + const matchedImport = textChange.newText.match(/(['"])(.+?)\1/); + if (matchedImport) { + importPath = matchedImport[0]; + item.detail += ` — from ${matchedImport[0]}`; + } } } + documentation.appendMarkdown(localize('autoImportLabel', 'Auto import from {0}', importPath)); + } else { + const autoImportLabel = localize('autoImportLabel', 'Auto import from {0}', importPath); + item.detail = `${autoImportLabel}\n${item.detail}`; } - documentation.appendMarkdown(localize('autoImportLabel', 'Auto import from {0}', importPath)); documentation.appendMarkdown('\n\n'); } diff --git a/extensions/typescript/src/utils/api.ts b/extensions/typescript/src/utils/api.ts index 51a630b83a0..6e13c01a574 100644 --- a/extensions/typescript/src/utils/api.ts +++ b/extensions/typescript/src/utils/api.ts @@ -72,4 +72,8 @@ export default class API { public has260Features(): boolean { return semver.gte(this.version, '2.6.0'); } + + public has262Features(): boolean { + return semver.gte(this.version, '2.6.2'); + } } \ No newline at end of file