Skip to content

Commit

Permalink
feat: support normalize component name for import statement completion
Browse files Browse the repository at this point in the history
close #2286
  • Loading branch information
johnsoncodehk committed Jan 8, 2023
1 parent 6055877 commit 821cb28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vue-language-tools/vscode-vue/package.json
Expand Up @@ -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\")"
Expand Down
Expand Up @@ -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<boolean>('volar.completion.normalizeComponentAutoImportName') ?? true)
&& (await _context.env.configurationHost?.getConfiguration<boolean>('volar.completion.normalizeComponentImportName') ?? true)
) {
let newName = item.textEdit.newText.slice(0, -'Vue'.length);
newName = newName[0].toUpperCase() + newName.substring(1);
Expand All @@ -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) {
Expand Down

0 comments on commit 821cb28

Please sign in to comment.