Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(language-service): avoid looping through all items twice #3158

Merged
merged 3 commits into from May 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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