Skip to content

Commit

Permalink
Merge pull request #2365 from Haehnchen/feature/model-entity-metadata
Browse files Browse the repository at this point in the history
use indexed model classes to resolve Entity targets on linemarker to reduce wall time
  • Loading branch information
Haehnchen authored Apr 28, 2024
2 parents 2e26bfb + 29440a8 commit c28c265
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import fr.adrienbrault.idea.symfony2plugin.dic.ClassServiceDefinitionTargetLazyValue;
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerService;
import fr.adrienbrault.idea.symfony2plugin.dic.container.ServiceInterface;
import fr.adrienbrault.idea.symfony2plugin.doctrine.EntityHelper;
import fr.adrienbrault.idea.symfony2plugin.doctrine.metadata.util.DoctrineMetadataUtil;
import fr.adrienbrault.idea.symfony2plugin.form.util.FormUtil;
import fr.adrienbrault.idea.symfony2plugin.stubs.ContainerCollectionResolver;
import fr.adrienbrault.idea.symfony2plugin.stubs.ServiceIndexUtil;
import fr.adrienbrault.idea.symfony2plugin.translation.ConstraintMessageGotoCompletionRegistrar;
import fr.adrienbrault.idea.symfony2plugin.translation.dict.TranslationUtil;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import fr.adrienbrault.idea.symfony2plugin.util.dict.DoctrineModel;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
import icons.ExternalSystemIcons;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -157,31 +156,22 @@ private void classNameMarker(@NotNull Project project, @NotNull PsiElement psiEl
}

private void entityClassMarker(@NotNull Project project, PsiElement psiElement, Collection<? super RelatedItemLineMarkerInfo<?>> result) {

PsiElement phpClassContext = psiElement.getContext();
if(!(phpClassContext instanceof PhpClass)) {
if (!(phpClassContext instanceof PhpClass phpClass)) {
return;
}

Collection<PsiFile> psiFiles = new ArrayList<>();
// @TODO: use DoctrineMetadataUtil, for single resolve; we have collecting overhead here
for(DoctrineModel doctrineModel: EntityHelper.getModelClasses(project)) {
PhpClass phpClass = doctrineModel.getPhpClass();
if(!PhpElementsUtil.isEqualClassName(phpClass, (PhpClass) phpClassContext)) {
continue;
}

PsiFile psiFile = EntityHelper.getModelConfigFile(phpClass);

for (PsiFile metadataFile : PsiElementUtils.convertVirtualFilesToPsiFiles(project, DoctrineMetadataUtil.findMetadataFiles(project, phpClass.getFQN()))) {
// prevent self navigation for line marker
if(psiFile == null || psiFile instanceof PhpFile) {
if (metadataFile instanceof PhpFile) {
continue;
}

psiFiles.add(psiFile);
psiFiles.add(metadataFile);
}

if(psiFiles.isEmpty()) {
if (psiFiles.isEmpty()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static PhpClass getClassRepository(final @NotNull Project project, final

@NotNull
public static Collection<VirtualFile> findMetadataFiles(@NotNull Project project, @NotNull String className) {

className = StringUtils.stripStart(className, "\\");
final Collection<VirtualFile> virtualFiles = new ArrayList<>();

FileBasedIndex.getInstance().getFilesWithKey(DoctrineMetadataFileStubIndex.KEY, new HashSet<>(Collections.singletonList(className)), virtualFile -> {
Expand Down

0 comments on commit c28c265

Please sign in to comment.