From 07ff5105307d627e178b493bc6901d3859311a81 Mon Sep 17 00:00:00 2001 From: Peter Jaap Blaakmeer Date: Sat, 6 Nov 2021 07:13:09 +0100 Subject: [PATCH 1/2] Added Generate Debug Step Filters button --- .../GenerateDebugStepFiltersListener.java | 63 +++++++++++++++++++ .../magento2plugin/project/SettingsForm.form | 33 ++++++++-- .../magento2plugin/project/SettingsForm.java | 7 +++ 3 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java diff --git a/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java b/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java new file mode 100644 index 000000000..46ccc8f1b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java @@ -0,0 +1,63 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.project; + +import com.intellij.javaee.ExternalResourceManager; +import com.intellij.javaee.ExternalResourceManagerEx; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiManager; +import com.intellij.psi.search.FilenameIndex; +import com.intellij.psi.search.GlobalSearchScope; +import com.magento.idea.magento2plugin.magento.packages.ComposerPackageModel; +import com.magento.idea.magento2plugin.magento.packages.MagentoComponent; +import com.magento.idea.magento2plugin.magento.packages.MagentoComponentManager; +import com.magento.idea.magento2plugin.magento.packages.MagentoModule; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.Collection; +import java.util.Stack; + +class GenerateDebugStepFiltersListener extends MouseAdapter { + protected final Project project; + + + public GenerateDebugStepFiltersListener(final @NotNull Project project) { + super(); + this.project = project; + } + + /** + * Handler for mouse click. + * + * @param event MouseEvent + */ + @Override + public void mouseClicked(final MouseEvent event) { + final ExternalResourceManager externalResourceManager = + ExternalResourceManager.getInstance(); + final PsiManager psiManager = PsiManager.getInstance(project); + final MagentoComponentManager componentManager = + MagentoComponentManager.getInstance(project); + + ApplicationManager.getApplication().runWriteAction( + new Runnable() { + @Override + public void run() { + + } + } + ); + + super.mouseClicked(event); + } +} diff --git a/src/com/magento/idea/magento2plugin/project/SettingsForm.form b/src/com/magento/idea/magento2plugin/project/SettingsForm.form index 58fc6561b..6310367e7 100644 --- a/src/com/magento/idea/magento2plugin/project/SettingsForm.form +++ b/src/com/magento/idea/magento2plugin/project/SettingsForm.form @@ -9,6 +9,8 @@ + + @@ -38,7 +40,7 @@ - + @@ -47,7 +49,7 @@ - + @@ -59,7 +61,7 @@ - + @@ -68,7 +70,7 @@ - + @@ -85,7 +87,7 @@ - + @@ -94,13 +96,32 @@ - + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/project/SettingsForm.java b/src/com/magento/idea/magento2plugin/project/SettingsForm.java index 6bd5386c3..c79b0a5e6 100644 --- a/src/com/magento/idea/magento2plugin/project/SettingsForm.java +++ b/src/com/magento/idea/magento2plugin/project/SettingsForm.java @@ -47,6 +47,7 @@ public class SettingsForm implements PhpFrameworkConfigurable { private JButton buttonReindex; private JPanel panel; private JButton regenerateUrnMapButton; + private JButton generateDebugStepFiltersButton; private JTextField magentoVersion; private JTextField moduleDefaultLicenseName; private JCheckBox mftfSupportEnabled; @@ -88,6 +89,10 @@ public void mouseClicked(final MouseEvent event) { new RegenerateUrnMapListener(project) ); + generateDebugStepFiltersButton.addMouseListener( + new GenerateDebugStepFiltersListener(project) + ); + refreshFormStatus(getSettings().pluginEnabled); pluginEnabled.addActionListener(e -> refreshFormStatus(pluginEnabled.isSelected())); @@ -106,6 +111,7 @@ public void mouseClicked(final MouseEvent event) { private void refreshFormStatus(final boolean isEnabled) { buttonReindex.setEnabled(isEnabled); regenerateUrnMapButton.setEnabled(isEnabled); + generateDebugStepFiltersButton.setEnabled(isEnabled); magentoVersion.setEnabled(isEnabled); mftfSupportEnabled.setEnabled(isEnabled); magentoPath.setEnabled(isEnabled); @@ -163,6 +169,7 @@ private void saveSettings() { getSettings().magentoPath = getMagentoPath(); buttonReindex.setEnabled(getSettings().pluginEnabled); regenerateUrnMapButton.setEnabled(getSettings().pluginEnabled); + generateDebugStepFiltersButton.setEnabled(getSettings().pluginEnabled); } @NotNull From c5a9441eb33794fe7616cba484edf879606cb338 Mon Sep 17 00:00:00 2001 From: Peter Jaap Blaakmeer Date: Sat, 6 Nov 2021 08:04:21 +0100 Subject: [PATCH 2/2] Added some non-working logic to set the Skipped Paths configuration --- .../GenerateDebugStepFiltersListener.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java b/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java index 46ccc8f1b..03b229b2b 100644 --- a/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java +++ b/src/com/magento/idea/magento2plugin/project/GenerateDebugStepFiltersListener.java @@ -5,22 +5,14 @@ package com.magento.idea.magento2plugin.project; -import com.intellij.javaee.ExternalResourceManager; -import com.intellij.javaee.ExternalResourceManagerEx; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.intellij.psi.search.FilenameIndex; -import com.intellij.psi.search.GlobalSearchScope; -import com.magento.idea.magento2plugin.magento.packages.ComposerPackageModel; -import com.magento.idea.magento2plugin.magento.packages.MagentoComponent; -import com.magento.idea.magento2plugin.magento.packages.MagentoComponentManager; -import com.magento.idea.magento2plugin.magento.packages.MagentoModule; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -43,17 +35,38 @@ public GenerateDebugStepFiltersListener(final @NotNull Project project) { */ @Override public void mouseClicked(final MouseEvent event) { - final ExternalResourceManager externalResourceManager = - ExternalResourceManager.getInstance(); final PsiManager psiManager = PsiManager.getInstance(project); - final MagentoComponentManager componentManager = - MagentoComponentManager.getInstance(project); + // There might be a more efficient way to grab all Interceptors and Proxies in the generated folder + // But with my limited Java knowledge, I can't find it. + final Collection phpFiles = FilenameIndex.getAllFilesByExt(project, "php"); ApplicationManager.getApplication().runWriteAction( new Runnable() { @Override public void run() { + final Stack skippedPaths = new Stack<>(); + for (final VirtualFile virtualFile: phpFiles) { + final PsiFile psiFile = psiManager.findFile(virtualFile); + if (psiFile == null) { + continue; + } + // If we have a more efficient way to find these files, this check hopefully + // wouldn't be necessary + if (!psiFile.getName().contains("Interceptor") && !psiFile.getName().contains("Proxy")) { + continue; + } + + skippedPaths.push(psiFile.getName()); + } + + // At this point we should have a stack with all paths to the interceptors and proxies + // However, it is unclear to me how (or even if) we can place these in the Skipped Paths + // list in the configuration under Settings > PHP > Debug > Step Filters > Skipped Paths + // since the code below doesn't work. We might have to resort to appending the data + // to .idea/php.xml manually. + PropertiesComponent.getInstance() + .setValue("settings.php.debug.skipped.paths", skippedPaths.toString()); } } );