Skip to content

Commit

Permalink
fix: components options is not set correctly when component name is k…
Browse files Browse the repository at this point in the history
…ebab-case and auto-importing

close #2745
  • Loading branch information
johnsoncodehk committed Apr 27, 2023
1 parent 175e95a commit 068dfd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@
- fix: namespaced tag not working without script setup
- fix: component intellisense not working in template if TS version < 5.0 ([#2742](https://github.com/johnsoncodehk/volar/issues/2742))
- fix: class is not assignable to generic components ([#2744](https://github.com/johnsoncodehk/volar/issues/2744))
- fix: components options is not set correctly when component name is kebab-case and auto-importing ([#2745](https://github.com/johnsoncodehk/volar/issues/2745))

## 1.6.0 (2023/4/27)

Expand Down
6 changes: 4 additions & 2 deletions packages/vue-language-service/src/languageService.ts
Expand Up @@ -113,6 +113,8 @@ function resolvePlugins(

const itemData = item.data as { uri?: string; } | undefined;

let newName: string | undefined;

if (itemData?.uri && item.additionalTextEdits) {
patchAdditionalTextEdits(itemData.uri, item.additionalTextEdits);
}
Expand All @@ -126,7 +128,7 @@ function resolvePlugins(
&& item.additionalTextEdits?.length === 1 && item.additionalTextEdits[0].newText.indexOf('import ' + item.textEdit.newText + ' from ') >= 0
&& (await _context.configurationHost?.getConfiguration<boolean>('vue.complete.normalizeComponentImportName') ?? true)
) {
let newName = item.textEdit.newText.slice(0, -suffix.length);
newName = item.textEdit.newText.slice(0, -suffix.length);
newName = newName[0].toUpperCase() + newName.substring(1);
if (newName === 'Index') {
const tsItem = (item.data as Data).originalItem;
Expand Down Expand Up @@ -163,7 +165,7 @@ function resolvePlugins(
const virtualFile = _context.documents.getSourceByUri(map.sourceFileDocument.uri)?.root;
if (virtualFile instanceof vue.VueFile) {
const sfc = virtualFile.sfc;
const componentName = item.textEdit.newText;
const componentName = newName ?? item.textEdit.newText;
const textDoc = _context.documents.getDocumentByFileName(virtualFile.snapshot, virtualFile.fileName);
if (sfc.scriptAst && sfc.script) {
const _scriptRanges = vue.scriptRanges.parseScriptRanges(ts, sfc.scriptAst, !!sfc.scriptSetup, true);
Expand Down

0 comments on commit 068dfd7

Please sign in to comment.