From 821cb28ef4112db70a1f7e5976462a8008a275ba Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sun, 8 Jan 2023 18:52:16 +0800 Subject: [PATCH] feat: support normalize component name for import statement completion close #2286 --- vue-language-tools/vscode-vue/package.json | 2 +- .../vue-language-service/src/languageService.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/vue-language-tools/vscode-vue/package.json b/vue-language-tools/vscode-vue/package.json index 34f86990b..7ef7e011d 100644 --- a/vue-language-tools/vscode-vue/package.json +++ b/vue-language-tools/vscode-vue/package.json @@ -568,7 +568,7 @@ "default": "auto-kebab", "description": "Preferred attr name case." }, - "volar.completion.normalizeComponentAutoImportName": { + "volar.completion.normalizeComponentImportName": { "type": "boolean", "default": true, "description": "Normalize import name for auto import. (\"myCompVue\" -> \"MyComp\")" diff --git a/vue-language-tools/vue-language-service/src/languageService.ts b/vue-language-tools/vue-language-service/src/languageService.ts index b1d03836f..52c5b4c52 100644 --- a/vue-language-tools/vue-language-service/src/languageService.ts +++ b/vue-language-tools/vue-language-service/src/languageService.ts @@ -82,7 +82,7 @@ export function getLanguageServicePlugins(vueCompilerOptions: VueCompilerOptions if ( item.textEdit?.newText && /\w*Vue$/.test(item.textEdit.newText) && item.additionalTextEdits?.length === 1 && item.additionalTextEdits[0].newText.indexOf('import ' + item.textEdit.newText + ' from ') >= 0 - && (await _context.env.configurationHost?.getConfiguration('volar.completion.normalizeComponentAutoImportName') ?? true) + && (await _context.env.configurationHost?.getConfiguration('volar.completion.normalizeComponentImportName') ?? true) ) { let newName = item.textEdit.newText.slice(0, -'Vue'.length); newName = newName[0].toUpperCase() + newName.substring(1); @@ -92,6 +92,13 @@ export function getLanguageServicePlugins(vueCompilerOptions: VueCompilerOptions ); item.textEdit.newText = newName; } + else if ( + item.textEdit?.newText && /import \w*Vue\$1 from \S*/.test(item.textEdit.newText) + && !item.additionalTextEdits?.length + ) { + // https://github.com/johnsoncodehk/volar/issues/2286 + item.textEdit.newText = item.textEdit.newText.replace('Vue$1', ''); + } const data: Data = item.data; if (item.data?.__isComponentAutoImport && data && item.additionalTextEdits?.length && item.textEdit) {