From 4e5e8e489e377ad2a70f5b7b20358b552e21d99c Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sun, 26 Apr 2026 11:23:54 +0200 Subject: [PATCH 1/2] optimize performance for inspection iteration --- .../ServiceNamedArgumentExistsInspection.java | 7 ++++++- .../php/AddRouteAttributeIntention.java | 6 +++--- .../php/CommandInvokeParameterIntention.java | 4 ++-- .../inspection/PhpRouteMissingInspection.java | 3 ++- .../PhpTemplateMissingInspection.java | 12 +++++------- .../TwigHtmlLineMarkerProvider.java | 19 ++++++++++++++----- .../inspection/PhpAssetMissingInspection.java | 3 ++- ...AnnotationPhpAttributeLocalInspection.java | 10 +++++----- .../TwigAssetMissingInspection.java | 10 +++++++++- .../TwigEnumFunctionInspection.java | 9 ++++++++- .../TwigTemplateMissingInspection.java | 7 +++++++ .../PhpTranslationDomainInspection.java | 10 ++++++---- .../PhpTranslationKeyInspection.java | 12 +++++++----- .../vite/ViteJavaScriptLineMarkerProvider.kt | 13 +++++++++++-- 14 files changed, 87 insertions(+), 38 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/ServiceNamedArgumentExistsInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/ServiceNamedArgumentExistsInspection.java index c700f2f6a..71038e7bd 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/ServiceNamedArgumentExistsInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/dic/inspection/ServiceNamedArgumentExistsInspection.java @@ -31,6 +31,7 @@ public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, bool private static class MyPsiElementVisitor extends PsiElementVisitor { @NotNull private final ProblemsHolder holder; + private ContainerCollectionResolver.LazyServiceCollector lazyServiceCollector; private ElementPattern namedArgumentPattern; MyPsiElementVisitor(@NotNull ProblemsHolder holder) { @@ -40,7 +41,7 @@ private static class MyPsiElementVisitor extends PsiElementVisitor { @Override public void visitElement(@NotNull PsiElement element) { if (getNamedArgumentPattern().accepts(element)) { - if (isSupportedDefinition(element) && ServiceContainerUtil.hasMissingYamlNamedArgumentForInspection(element, new ContainerCollectionResolver.LazyServiceCollector(holder.getProject()))) { + if (isSupportedDefinition(element) && ServiceContainerUtil.hasMissingYamlNamedArgumentForInspection(element, getLazyServiceCollector())) { holder.registerProblem(element, INSPECTION_MESSAGE, ProblemHighlightType.GENERIC_ERROR_OR_WARNING); } } @@ -48,6 +49,10 @@ public void visitElement(@NotNull PsiElement element) { super.visitElement(element); } + private ContainerCollectionResolver.LazyServiceCollector getLazyServiceCollector() { + return lazyServiceCollector != null ? lazyServiceCollector : (lazyServiceCollector = new ContainerCollectionResolver.LazyServiceCollector(holder.getProject())); + } + private ElementPattern getNamedArgumentPattern() { return namedArgumentPattern != null ? namedArgumentPattern : (namedArgumentPattern = YamlElementPatternHelper.getNamedArgumentPattern()); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/AddRouteAttributeIntention.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/AddRouteAttributeIntention.java index 52304f3a9..ae8b59aa2 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/AddRouteAttributeIntention.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/AddRouteAttributeIntention.java @@ -109,15 +109,15 @@ public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull Psi return false; } - if (!PhpElementsUtil.hasClassOrInterface(project, ROUTE_ATTRIBUTE_CLASS)) { + if (hasRouteAttribute(method)) { return false; } - if (hasRouteAttribute(method)) { + if (!isControllerClass(phpClass)) { return false; } - return isControllerClass(phpClass); + return PhpElementsUtil.hasClassOrInterface(project, ROUTE_ATTRIBUTE_CLASS); } private boolean hasRouteAttribute(@NotNull Method method) { diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/CommandInvokeParameterIntention.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/CommandInvokeParameterIntention.java index 71e800f3c..a7f9d3793 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/CommandInvokeParameterIntention.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/intentions/php/CommandInvokeParameterIntention.java @@ -137,11 +137,11 @@ public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull Psi return false; } - if (PhpElementsUtil.isInstanceOf(phpClass, "\\Symfony\\Component\\Console\\Command\\Command")) { + if (phpClass.getAttributes(AS_COMMAND_ATTRIBUTE).isEmpty()) { return false; } - if (phpClass.getAttributes(AS_COMMAND_ATTRIBUTE).isEmpty()) { + if (PhpElementsUtil.isInstanceOf(phpClass, "\\Symfony\\Component\\Console\\Command\\Command")) { return false; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/inspection/PhpRouteMissingInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/inspection/PhpRouteMissingInspection.java index 5f56c1c32..2c6484a6c 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/inspection/PhpRouteMissingInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/inspection/PhpRouteMissingInspection.java @@ -6,6 +6,7 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; +import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; import fr.adrienbrault.idea.symfony2plugin.routing.PhpRouteReferenceContributor; import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper; @@ -38,7 +39,7 @@ private static class MyPsiElementVisitor extends PsiElementVisitor { @Override public void visitElement(@NotNull PsiElement element) { - if(getMethodWithFirstStringPattern().accepts(element)) { + if(element instanceof StringLiteralExpression && getMethodWithFirstStringPattern().accepts(element)) { String contents = PhpElementsUtil.getStringValue(element); if(StringUtils.isNotBlank(contents)) { invoke(contents, element, holder); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/PhpTemplateMissingInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/PhpTemplateMissingInspection.java index 7e375594e..5a2b7c03b 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/PhpTemplateMissingInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/PhpTemplateMissingInspection.java @@ -35,18 +35,16 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean is return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { - invoke(holder, element); + if (element instanceof StringLiteralExpression stringLiteralExpression) { + invoke(holder, stringLiteralExpression); + } super.visitElement(element); } }; } - private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) { - if (!(psiElement instanceof StringLiteralExpression)) { - return; - } - - String templateNameIfMissing = getTemplateNameIfMissing((StringLiteralExpression) psiElement); + private void invoke(@NotNull ProblemsHolder holder, @NotNull StringLiteralExpression psiElement) { + String templateNameIfMissing = getTemplateNameIfMissing(psiElement); if(templateNameIfMissing == null) { return; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigHtmlLineMarkerProvider.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigHtmlLineMarkerProvider.java index 0f159cfa6..78df0cd78 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigHtmlLineMarkerProvider.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigHtmlLineMarkerProvider.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -32,15 +33,17 @@ public class TwigHtmlLineMarkerProvider implements LineMarkerProvider { @Override public void collectSlowLineMarkers(@NotNull List psiElements, @NotNull Collection> results) { - if (psiElements.isEmpty() || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) { + if (psiElements.isEmpty() || !Symfony2ProjectComponent.isEnabled(psiElements.getFirst())) { return; } - PsiFile file = psiElements.get(0).getContainingFile(); + PsiFile file = psiElements.getFirst().getContainingFile(); if (!isSupportedFile(file)) { return; } + Map componentBlockExistsCache = new HashMap<>(); + for (PsiElement psiElement : psiElements) { if (!(psiElement instanceof XmlToken xmlToken) || xmlToken.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) { continue; @@ -50,7 +53,7 @@ public void collectSlowLineMarkers(@NotNull List psiElemen continue; } - LineMarkerInfo blockOverride = attachTwigComponentBlockOverride(xmlAttributeValue, xmlToken); + LineMarkerInfo blockOverride = attachTwigComponentBlockOverride(xmlAttributeValue, xmlToken, componentBlockExistsCache); if (blockOverride != null) { results.add(blockOverride); } @@ -68,7 +71,7 @@ public static boolean isSupportedFile(@Nullable PsiFile file) { } @Nullable - protected LineMarkerInfo attachTwigComponentBlockOverride(@NotNull XmlAttributeValue xmlAttributeValue, @NotNull PsiElement lineMarkerTarget) { + protected LineMarkerInfo attachTwigComponentBlockOverride(@NotNull XmlAttributeValue xmlAttributeValue, @NotNull PsiElement lineMarkerTarget, @NotNull Map componentBlockExistsCache) { if (!(xmlAttributeValue.getParent() instanceof XmlAttribute xmlAttribute) || !"name".equals(xmlAttribute.getName())) { return null; } @@ -100,7 +103,8 @@ protected LineMarkerInfo attachTwigComponentBlockOverride(@NotNull XmlAttribu } Project project = xmlAttributeValue.getProject(); - if (!hasComponentBlock(project, componentName, blockName)) { + String cacheKey = componentName + "\0" + blockName; + if (!componentBlockExistsCache.computeIfAbsent(cacheKey, ignored -> hasComponentBlock(project, componentName, blockName))) { return null; } @@ -111,6 +115,11 @@ protected LineMarkerInfo attachTwigComponentBlockOverride(@NotNull XmlAttribu return builder.createLineMarkerInfo(lineMarkerTarget); } + @Nullable + protected LineMarkerInfo attachTwigComponentBlockOverride(@NotNull XmlAttributeValue xmlAttributeValue, @NotNull PsiElement lineMarkerTarget) { + return attachTwigComponentBlockOverride(xmlAttributeValue, lineMarkerTarget, new HashMap<>()); + } + @Nullable protected String resolveComponentName(@NotNull Project project, @NotNull String rawComponentName) { return UxUtil.resolveTwigComponentName(project, rawComponentName); diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/PhpAssetMissingInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/PhpAssetMissingInspection.java index f6b71319f..1e380865a 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/PhpAssetMissingInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/PhpAssetMissingInspection.java @@ -42,7 +42,8 @@ private static class AssetPackageElementVisitor extends PsiElementVisitor { public void visitElement(@NotNull PsiElement element) { if (element instanceof StringLiteralExpression) { MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter((StringLiteralExpression) element); - if (methodReference != null && (PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Component\\Asset\\Packages", "getUrl") + String methodName = methodReference != null ? methodReference.getName() : null; + if (methodName != null && ("getUrl".equals(methodName) || "getVersion".equals(methodName)) && (PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Component\\Asset\\Packages", "getUrl") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Component\\Asset\\Packages", "getVersion") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Component\\Asset\\PackageInterface", "getUrl") || PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, "\\Symfony\\Component\\Asset\\PackageInterface", "getVersion") diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TemplateMissingAnnotationPhpAttributeLocalInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TemplateMissingAnnotationPhpAttributeLocalInspection.java index 56e18a5d7..7b0d163ca 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TemplateMissingAnnotationPhpAttributeLocalInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TemplateMissingAnnotationPhpAttributeLocalInspection.java @@ -29,6 +29,10 @@ public class TemplateMissingAnnotationPhpAttributeLocalInspection extends LocalInspectionTool { @NotNull public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) { + if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) { + return super.buildVisitor(holder, isOnTheFly); + } + return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { @@ -38,7 +42,7 @@ public void visitElement(@NotNull PsiElement element) { if (element instanceof PhpAttribute) { String fqn = ((PhpAttribute) element).getFQN(); - if (fqn != null && Arrays.stream(TwigUtil.TEMPLATE_ANNOTATION_CLASS).anyMatch(s -> PhpElementsUtil.isInstanceOf(element.getProject(), fqn, s))) { + if (fqn != null && PhpElementsUtil.isEqualClassName(fqn, TwigUtil.TEMPLATE_ANNOTATION_CLASS)) { annotate((PhpAttribute) element, holder); } } @@ -74,10 +78,6 @@ private void annotate(@NotNull PhpAttribute phpAttribute, @NotNull ProblemsHolde } private void annotate(@NotNull PhpDocTag phpDocTag, @NotNull ProblemsHolder holder) { - if(!Symfony2ProjectComponent.isEnabled(phpDocTag.getProject())) { - return; - } - PhpDocTagAnnotation phpDocAnnotationContainer = AnnotationUtil.getPhpDocAnnotationContainer(phpDocTag); if (phpDocAnnotationContainer == null || !PhpElementsUtil.isEqualClassName(phpDocAnnotationContainer.getPhpClass(), TwigUtil.TEMPLATE_ANNOTATION_CLASS)) { return; diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigAssetMissingInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigAssetMissingInspection.java index 43023e9cc..995643fa3 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigAssetMissingInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigAssetMissingInspection.java @@ -5,11 +5,14 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.jetbrains.twig.TwigTokenTypes; import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; import fr.adrienbrault.idea.symfony2plugin.templating.TwigPattern; import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.NonNull; /** * asset('') @@ -36,7 +39,12 @@ private static class MyPsiElementVisitor extends PsiElementVisitor { } @Override - public void visitElement(PsiElement element) { + public void visitElement(@NonNull PsiElement element) { + if (!(element instanceof LeafPsiElement) || element.getNode().getElementType() != TwigTokenTypes.STRING_TEXT) { + super.visitElement(element); + return; + } + if(getAssetPattern().accepts(element) && TwigUtil.isValidStringWithoutInterpolatedOrConcat(element)) { invoke(element, holder); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigEnumFunctionInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigEnumFunctionInspection.java index 2e014b25a..b50c42a45 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigEnumFunctionInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigEnumFunctionInspection.java @@ -4,6 +4,7 @@ import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.patterns.ElementPattern; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.impl.source.tree.LeafPsiElement; @@ -51,7 +52,13 @@ private static class MyPsiElementVisitor extends PsiElementVisitor { @Override public void visitElement(@NotNull PsiElement element) { // Fast pre-filter: only STRING_TEXT elements can be enum/enum_cases arguments - if (element instanceof LeafPsiElement && element.getNode() == null || element.getNode().getElementType() != TwigTokenTypes.STRING_TEXT) { + if (!(element instanceof LeafPsiElement)) { + super.visitElement(element); + return; + } + + ASTNode node = element.getNode(); + if (node == null || node.getElementType() != TwigTokenTypes.STRING_TEXT) { super.visitElement(element); return; } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigTemplateMissingInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigTemplateMissingInspection.java index cc89309f2..ab856edda 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigTemplateMissingInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/inspection/TwigTemplateMissingInspection.java @@ -8,6 +8,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.jetbrains.twig.TwigTokenTypes; import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; import fr.adrienbrault.idea.symfony2plugin.templating.TwigPattern; import fr.adrienbrault.idea.symfony2plugin.templating.util.TwigUtil; @@ -48,6 +50,11 @@ private static class MyPsiElementVisitor extends PsiElementVisitor { @Override public void visitElement(PsiElement element) { + if (!(element instanceof LeafPsiElement) || element.getNode().getElementType() != TwigTokenTypes.STRING_TEXT) { + super.visitElement(element); + return; + } + if((getTemplateFileReferencePattern().accepts(element) || getIncludeFunctionPattern().accepts(element)) && TwigUtil.isValidStringWithoutInterpolatedOrConcat(element)) { invoke(element, holder); } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationDomainInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationDomainInspection.java index fc95dd1d7..368052b1d 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationDomainInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationDomainInspection.java @@ -36,13 +36,15 @@ public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean is return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { - invoke(holder, element); + if (element instanceof StringLiteralExpression stringLiteralExpression) { + invoke(holder, stringLiteralExpression); + } super.visitElement(element); } }; } - private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) { + private void invoke(@NotNull ProblemsHolder holder, @NotNull StringLiteralExpression psiElement) { ParameterListOwner methodReferenceOrNewExpression = TranslationUtil.getTranslationFunctionContext(psiElement); if (methodReferenceOrNewExpression == null) { return; @@ -58,7 +60,7 @@ private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiEleme && TranslationUtil.isTranslationReference(methodReferenceOrNewExpression); if (isSupportedAttributeInsideContext) { - annotateTranslationDomain((StringLiteralExpression) psiElement, holder); + annotateTranslationDomain(psiElement, holder); } } @@ -70,7 +72,7 @@ private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiEleme if (domainParameter >= 0) { ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement); if(currentIndex != null && currentIndex.getIndex() == domainParameter) { - annotateTranslationDomain((StringLiteralExpression) psiElement, holder); + annotateTranslationDomain(psiElement, holder); } } } diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationKeyInspection.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationKeyInspection.java index aacae8fcd..cd68ff849 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationKeyInspection.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/translation/PhpTranslationKeyInspection.java @@ -24,20 +24,22 @@ public class PhpTranslationKeyInspection extends LocalInspectionTool { @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { - if(!Symfony2ProjectComponent.isEnabled(holder.getProject())) { + if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) { return super.buildVisitor(holder, isOnTheFly); } return new PsiElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { - invoke(holder, element); + if (element instanceof StringLiteralExpression stringLiteralExpression) { + invoke(holder, stringLiteralExpression); + } super.visitElement(element); } }; } - private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) { + private void invoke(@NotNull ProblemsHolder holder, @NotNull StringLiteralExpression psiElement) { ParameterListOwner methodReferenceOrNewExpression = TranslationUtil.getTranslationFunctionContext(psiElement); if (methodReferenceOrNewExpression == null) { return; @@ -55,12 +57,12 @@ private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiEleme PsiElement domainElement = parameterList.getParameter("domain", PhpTranslationDomainInspection.getDomainParameter(methodReferenceOrNewExpression)); if(domainElement == null) { // no domain found; fallback to default domain - annotateTranslationKey((StringLiteralExpression) psiElement, "messages", holder); + annotateTranslationKey(psiElement, "messages", holder); } else { // resolve string in parameter String domain = PhpElementsUtil.getStringValue(domainElement); if(domain != null) { - annotateTranslationKey((StringLiteralExpression) psiElement, domain, holder); + annotateTranslationKey(psiElement, domain, holder); } } } diff --git a/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt b/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt index 78627893d..946beb3af 100644 --- a/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt +++ b/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt @@ -8,6 +8,7 @@ import com.intellij.lang.javascript.psi.JSFile import com.intellij.lang.javascript.psi.JSProperty import com.intellij.openapi.util.NotNullLazyValue import com.intellij.openapi.vfs.VfsUtil +import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiElement import com.intellij.psi.PsiManager import com.intellij.psi.search.GlobalSearchScope @@ -49,16 +50,24 @@ class ViteJavaScriptLineMarkerProvider : LineMarkerProvider { return } + var viteConfigFiles: Collection? = null + for (element in elements) { // Only fire once per file — match on the JSFile node itself if (element !is JSFile) continue - val project = element.project val virtualFile = element.virtualFile ?: continue + val project = element.project + val configs = viteConfigFiles ?: ViteUtil.getViteConfigFiles(project).also { + if (it.isEmpty()) { + return + } + viteConfigFiles = it + } val entryNames = mutableSetOf() - for (configVirtualFile in ViteUtil.getViteConfigFiles(project)) { + for (configVirtualFile in configs) { val configDir = configVirtualFile.parent ?: continue val relPath = VfsUtil.getRelativePath(virtualFile, configDir, '/') ?: continue val normalized = relPath.removePrefix("./").removePrefix("/") From 2351b19b22a6159d47f88b46d1b3b6fc6ee11b43 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sun, 26 Apr 2026 11:45:27 +0200 Subject: [PATCH 2/2] optimize performance for inspection iteration --- .../symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt b/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt index 946beb3af..6520e56fe 100644 --- a/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt +++ b/src/main/kotlin/fr/adrienbrault/idea/symfony2plugin/vite/ViteJavaScriptLineMarkerProvider.kt @@ -57,8 +57,7 @@ class ViteJavaScriptLineMarkerProvider : LineMarkerProvider { if (element !is JSFile) continue val virtualFile = element.virtualFile ?: continue - val project = element.project - val configs = viteConfigFiles ?: ViteUtil.getViteConfigFiles(project).also { + val configs = viteConfigFiles ?: ViteUtil.getViteConfigFiles(element.project).also { if (it.isEmpty()) { return } @@ -73,7 +72,7 @@ class ViteJavaScriptLineMarkerProvider : LineMarkerProvider { val normalized = relPath.removePrefix("./").removePrefix("/") FileBasedIndex.getInstance() - .getValues(VITE_ENTRY_STUB_INDEX_KEY, normalized, GlobalSearchScope.fileScope(project, configVirtualFile)) + .getValues(VITE_ENTRY_STUB_INDEX_KEY, normalized, GlobalSearchScope.fileScope(element.project, configVirtualFile)) .forEach { entryNames.add(it) } }