From cee28931c591ee0bddc30f0cc38fc0967cb2e09b Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 23 Feb 2025 10:22:12 +0200 Subject: [PATCH 1/5] 2491: Prevent URN map generation during indexing. Added a check to avoid URN map generation when the project is in indexing (dumb) mode. A warning notification is shown to inform users that they need to wait until indexing is complete. This prevents potential errors or performance issues. --- .../project/RegenerateUrnMapListener.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java index 908067823..527fad561 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java @@ -10,6 +10,7 @@ import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiDirectory; @@ -53,6 +54,20 @@ public void mouseClicked(final MouseEvent event) { final MagentoComponentManager componentManager = MagentoComponentManager.getInstance(project); + if (DumbService.getInstance(project).isDumb()) { + NotificationGroupManager.getInstance() + .getNotificationGroup("Magento Notifications") + .createNotification( + "URN map generation unavailable", + "Indexing is in progress." + + " Please wait for it to complete" + + " before running URN mapping generation.", + NotificationType.WARNING + ) + .notify(project); + return; + } + ApplicationManager.getApplication().runWriteAction( new Runnable() { @Override From a4e2f8a45612dc8e3dba88bde12b069e0d20dd2f Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 23 Feb 2025 10:26:45 +0200 Subject: [PATCH 2/5] 2491: Prevent URN map generation during indexing. Updated functionality to skip URN map generation while the project is indexing. This helps avoid potential errors and enhances performance stability. A warning notifies users to wait until indexing finishes. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd0d34a67..2b97223af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). - Compatibility with PhpStorm/IntelliJ 2025.* [#2495](https://github.com/magento/magento2-phpstorm-plugin/pull/2495) - "Copy Path/Reference" does not show the preview value [#2497](https://github.com/magento/magento2-phpstorm-plugin/pull/2497) +- URN map generation during indexing [#2499](https://github.com/magento/magento2-phpstorm-plugin/pull/2499) ## 2025.0.0 From c8cc8522deb4571b495bc5e48481ac1775026b6e Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 23 Feb 2025 10:35:45 +0200 Subject: [PATCH 3/5] 2491: Prevent URN map generation during indexing. Refactored notification text formatting for clarity and consistency. This ensures users are properly informed to wait until indexing is complete before generating URN maps. Enhances user guidance and prevents unwanted actions during indexing. --- .../magento2plugin/project/RegenerateUrnMapListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java index 527fad561..c6da0ea2b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java @@ -59,9 +59,9 @@ public void mouseClicked(final MouseEvent event) { .getNotificationGroup("Magento Notifications") .createNotification( "URN map generation unavailable", - "Indexing is in progress." + - " Please wait for it to complete" + - " before running URN mapping generation.", + "Indexing is in progress." + + " Please wait for it to complete" + + " before running URN mapping generation.", NotificationType.WARNING ) .notify(project); From 283f3121c6cffa0b96320a44cfc0de876d802d6b Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 23 Feb 2025 10:39:23 +0200 Subject: [PATCH 4/5] 2491: Refactor URN map generation to avoid indexing issues. Moved ExternalResourceManager initialization into the runnable to prevent execution during indexing. This ensures better stability and avoids potential premature resource access. --- .../idea/magento2plugin/project/RegenerateUrnMapListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java index c6da0ea2b..a4edb6e0a 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java @@ -48,8 +48,6 @@ public RegenerateUrnMapListener(final @NotNull Project project) { */ @Override public void mouseClicked(final MouseEvent event) { - final ExternalResourceManager manager = - ExternalResourceManager.getInstance(); final PsiManager psiManager = PsiManager.getInstance(project); final MagentoComponentManager componentManager = MagentoComponentManager.getInstance(project); @@ -72,6 +70,8 @@ public void mouseClicked(final MouseEvent event) { new Runnable() { @Override public void run() { + final ExternalResourceManager manager = + ExternalResourceManager.getInstance(); final Collection xsdFiles = FilenameIndex.getAllFilesByExt(project, "xsd"); final Collection components From 14456abb54e5ef963d61c43a201fe27f9dd6b29d Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sun, 23 Feb 2025 10:44:21 +0200 Subject: [PATCH 5/5] 2491: Refactor mouse click handling for safer resource usage. Moved PsiManager and MagentoComponentManager initialization into the runnable to delay their usage until the appropriate execution context. Added a suppression for PMD warning to ensure clarity and maintain compatibility with standards. --- .../magento2plugin/project/RegenerateUrnMapListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java index a4edb6e0a..1772db65b 100644 --- a/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java +++ b/src/main/java/com/magento/idea/magento2plugin/project/RegenerateUrnMapListener.java @@ -47,11 +47,8 @@ public RegenerateUrnMapListener(final @NotNull Project project) { * @param event MouseEvent */ @Override + @SuppressWarnings("PMD.UseNotifyAllInsteadOfNotify") public void mouseClicked(final MouseEvent event) { - final PsiManager psiManager = PsiManager.getInstance(project); - final MagentoComponentManager componentManager = - MagentoComponentManager.getInstance(project); - if (DumbService.getInstance(project).isDumb()) { NotificationGroupManager.getInstance() .getNotificationGroup("Magento Notifications") @@ -70,6 +67,9 @@ public void mouseClicked(final MouseEvent event) { new Runnable() { @Override public void run() { + final PsiManager psiManager = PsiManager.getInstance(project); + final MagentoComponentManager componentManager = + MagentoComponentManager.getInstance(project); final ExternalResourceManager manager = ExternalResourceManager.getInstance(); final Collection xsdFiles