Skip to content

Commit

Permalink
perf(language-service): avoid looping through all items twice (#3158)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvenschraut committed May 13, 2023
1 parent 975ac36 commit f10d57e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions packages/vue-language-service/src/languageService.ts
Expand Up @@ -82,23 +82,24 @@ function resolvePlugins(
);

// handle component auto-import patch
let sourceIsKebabCasing: boolean | null = null;
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 => {
item.data.__isComponentAutoImport = true;
});

// fix #2458
const source = _context.documents.getVirtualFileByUri(document.uri)[1];
if (source && _context.typescript) {
const casing = await getNameCasing(_context, _context.typescript, _context.fileNameToUri(source.fileName));
if (casing.tag === TagNameCasing.Kebab) {
result.items.forEach(item => {
for (const item of result.items) {
item.data.__isComponentAutoImport = true;
// fix #2458
if (source && _context.typescript) {
if (sourceIsKebabCasing === null) {
const casing = await getNameCasing(_context, _context.typescript, _context.fileNameToUri(source.fileName));
sourceIsKebabCasing = casing.tag === TagNameCasing.Kebab;
}
if (sourceIsKebabCasing) {
item.filterText = hyphenate(item.filterText ?? item.label);
});
}
}
}
}
Expand Down

0 comments on commit f10d57e

Please sign in to comment.