Skip to content

Commit

Permalink
fix: normalizeComponentAutoImportName not working at import statement
Browse files Browse the repository at this point in the history
close #2286
  • Loading branch information
johnsoncodehk committed Mar 29, 2023
1 parent dc7ad4a commit 2147c98
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/vue-language-service/src/languageService.ts
Expand Up @@ -151,12 +151,9 @@ function resolvePlugins(
}
}
}
else if (
item.textEdit?.newText && new RegExp(`import \w*${suffix}\$1 from \S*`).test(item.textEdit.newText)
&& !item.additionalTextEdits?.length
) {
else if (item.textEdit?.newText && new RegExp(`import \\w*${suffix}\\$1 from [\\S\\s]*`).test(item.textEdit.newText)) {
// https://github.com/johnsoncodehk/volar/issues/2286
item.textEdit.newText = item.textEdit.newText.replace(`${suffix}$1`, '');
item.textEdit.newText = item.textEdit.newText.replace(`${suffix}$1`, '$1');
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/vue-language-service/tests/complete.ts
Expand Up @@ -71,7 +71,9 @@ for (const dirName of testDirs) {
edits = edits.concat(item.additionalTextEdits);
}

const result = TextDocument.applyEdits(TextDocument.create('', '', 0, fileText), edits);
let result = TextDocument.applyEdits(TextDocument.create('', '', 0, fileText), edits);

result = result.replaceAll('$0', '').replaceAll('$1', '');

expect(result.replace(/\r\n/g, '\n')).toBe(expectedFileText.replace(/\r\n/g, '\n'));
});
Expand Down
@@ -0,0 +1 @@
<script setup lang="ts"></script>
4 changes: 4 additions & 0 deletions packages/vue-test-workspace/complete/#2511/input/entry.vue
@@ -0,0 +1,4 @@
<script setup lang="ts">
import componentFor
// ^complete: componentForAutoImportVue
</script>
4 changes: 4 additions & 0 deletions packages/vue-test-workspace/complete/#2511/output/entry.vue
@@ -0,0 +1,4 @@
<script setup lang="ts">
import componentForAutoImport from './component-for-auto-import.vue';
// ^complete: componentForAutoImportVue
</script>

0 comments on commit 2147c98

Please sign in to comment.