Skip to content

Commit

Permalink
perf(language-service): uneeded await blocking other iterations from …
Browse files Browse the repository at this point in the history
…running
  • Loading branch information
kalvenschraut committed May 11, 2023
1 parent f3e84b6 commit 82e5c0b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/vue-language-service/src/languageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,30 @@ function resolvePlugins(
);

// handle component auto-import patch
const nameCasingPromises: Promise<void>[] = [];
for (const [_, map] of _context.documents.getMapsByVirtualFileUri(document.uri)) {
const virtualFile = _context.documents.getSourceByUri(map.sourceFileDocument.uri)?.root;
if (virtualFile instanceof vue.VueFile) {
const isAutoImport = !!map.toSourcePosition(position, data => typeof data.completion === 'object' && !!data.completion.autoImportOnly);
if (isAutoImport) {
result.items.forEach(item => {
for (const item of result.items) {
item.data.__isComponentAutoImport = true;
});

// fix #2458
const source = _context.documents.getVirtualFileByUri(document.uri)[1];
if (source && _context.typescript) {
const casing = await getNameCasing(ts, _context, _context.env.fileNameToUri(source.fileName));
if (casing.tag === TagNameCasing.Kebab) {
result.items.forEach(item => {
item.filterText = hyphenate(item.filterText ?? item.label);
});
// fix #2458
const source = _context.documents.getVirtualFileByUri(document.uri)[1];
if (source && _context.typescript) {
nameCasingPromises.push(getNameCasing(ts, _context, _context.env.fileNameToUri(source.fileName)).then((casing) => {
if (casing.tag === TagNameCasing.Kebab) {
result.items.forEach(item => {
item.filterText = hyphenate(item.filterText ?? item.label);
});
}
}));
}
}
}
}
}
await Promise.all(nameCasingPromises);
}
return result;
},
Expand Down

0 comments on commit 82e5c0b

Please sign in to comment.