From 1491c0cb31a88e381b56e48db630429fc4ae74f5 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 14 Feb 2025 23:03:36 +0200 Subject: [PATCH 1/4] 1639: Remove SearchGutterIconNavigationHandler and simplify markers Deleted the unused `SearchGutterIconNavigationHandler` class and replaced its implementation in `PluginLineMarkerProvider` with direct `NavigationGutterIconBuilder` usage. This simplifies the code and removes redundant complexity. --- .../SearchGutterIconNavigationHandler.java | 47 ------------------- .../php/PluginLineMarkerProvider.java | 24 ++-------- 2 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 src/main/java/com/magento/idea/magento2plugin/linemarker/SearchGutterIconNavigationHandler.java diff --git a/src/main/java/com/magento/idea/magento2plugin/linemarker/SearchGutterIconNavigationHandler.java b/src/main/java/com/magento/idea/magento2plugin/linemarker/SearchGutterIconNavigationHandler.java deleted file mode 100644 index 8f235a241..000000000 --- a/src/main/java/com/magento/idea/magento2plugin/linemarker/SearchGutterIconNavigationHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright © Magento, Inc. All rights reserved. - * See COPYING.txt for license details. - */ - -package com.magento.idea.magento2plugin.linemarker; - -import com.intellij.codeInsight.daemon.GutterIconNavigationHandler; -import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator; -import com.intellij.ide.util.DefaultPsiElementCellRenderer; -import com.intellij.psi.NavigatablePsiElement; -import com.intellij.psi.PsiElement; -import java.awt.event.MouseEvent; -import java.util.Collection; -import org.jetbrains.annotations.NotNull; - -public class SearchGutterIconNavigationHandler - implements GutterIconNavigationHandler { - - private final Collection myReferences; - private final @NotNull String popupTitle; - - /** - * Search gutter icon navigation handler constructor. - * - * @param references Collection - * @param popupTitle String - */ - public SearchGutterIconNavigationHandler( - final Collection references, - final @NotNull String popupTitle - ) { - this.popupTitle = popupTitle; - myReferences = references; - } - - @Override - public void navigate(final MouseEvent event, final T elt) { - PsiElementListNavigator.openTargets( - event, - myReferences.toArray(NavigatablePsiElement.EMPTY_NAVIGATABLE_ELEMENT_ARRAY), - popupTitle, - "Open in Find Tool Window",// Ignored - new DefaultPsiElementCellRenderer() - ); - } -} diff --git a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java index d29689ded..62a0b9ee8 100644 --- a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java +++ b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java @@ -5,19 +5,15 @@ package com.magento.idea.magento2plugin.linemarker.php; -import com.intellij.codeInsight.daemon.GutterIconNavigationHandler; import com.intellij.codeInsight.daemon.LineMarkerInfo; import com.intellij.codeInsight.daemon.LineMarkerProvider; import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder; import com.intellij.icons.AllIcons; -import com.intellij.psi.NavigatablePsiElement; import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.indexing.FileBasedIndex; import com.jetbrains.php.lang.psi.elements.Method; import com.jetbrains.php.lang.psi.elements.PhpClass; -import com.magento.idea.magento2plugin.linemarker.SearchGutterIconNavigationHandler; import com.magento.idea.magento2plugin.linemarker.php.data.PluginMethodData; import com.magento.idea.magento2plugin.project.Settings; import com.magento.idea.magento2plugin.stubs.indexes.PluginIndex; @@ -74,22 +70,12 @@ public void collectSlowLineMarkers( } if (!results.isEmpty()) { - final GutterIconNavigationHandler navigationHandler = - new SearchGutterIconNavigationHandler<>( - (Collection) results, - TOOLTIP_TEXT - ); - - collection.add( - NavigationGutterIconBuilder - .create(AllIcons.Nodes.Plugin) + // Add the property to a collection of line marker info + NavigationGutterIconBuilder builder = + NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin) .setTargets(results) - .setTooltipText(TOOLTIP_TEXT) - .createLineMarkerInfo( - PsiTreeUtil.getDeepestFirst(psiElement), - navigationHandler - ) - ); + .setTooltipText(TOOLTIP_TEXT); + collection.add(builder.createLineMarkerInfo(psiElement)); } } } From 6ee3a80ed54d582dc6e37c854e9197e1c5f59b0c Mon Sep 17 00:00:00 2001 From: vitaliy Date: Fri, 14 Feb 2025 23:13:24 +0200 Subject: [PATCH 2/4] 1639: Fix assertion error and improve line marker immutability Addressed an assertion failure related to improper `PsiElement` usage for popup models in `PluginLineMarkerProvider`. Made the `NavigationGutterIconBuilder` instance immutable by declaring it as `final`, enhancing code safety and readability. Updated the changelog for relevant changes. --- CHANGELOG.md | 1 + .../magento2plugin/linemarker/php/PluginLineMarkerProvider.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a5c2af67..d8d3f0633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). Replaced hardcoded Magento versions with dynamic fetching via Packagist API. Fixed UI icon references. Updated Run command. +- java.lang.Throwable: Assertion failed: Do not use PsiElement for popup model. See PsiTargetNavigator [#2485](https://github.com/magento/magento2-phpstorm-plugin/pull/2485) ### Changed diff --git a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java index 62a0b9ee8..2d9ff1b30 100644 --- a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java +++ b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java @@ -71,7 +71,7 @@ public void collectSlowLineMarkers( if (!results.isEmpty()) { // Add the property to a collection of line marker info - NavigationGutterIconBuilder builder = + final NavigationGutterIconBuilder builder = NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin) .setTargets(results) .setTooltipText(TOOLTIP_TEXT); From 67e7c1b894edf5fae20822fdf9d9c3e64fd90f34 Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 15 Feb 2025 08:51:19 +0200 Subject: [PATCH 3/4] 1639: Fix line marker creation targeting `PsiElement` node Ensured line markers are correctly created by targeting the `ASTNode` of type `IDENTIFIER` for `PsiElement`. This change prevents potential errors and improves precision in line marker rendering. Enhanced the stability and correctness of the `PluginLineMarkerProvider`. --- .../php/PluginLineMarkerProvider.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java index 2d9ff1b30..367faf468 100644 --- a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java +++ b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java @@ -9,9 +9,11 @@ import com.intellij.codeInsight.daemon.LineMarkerProvider; import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder; import com.intellij.icons.AllIcons; +import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.util.indexing.FileBasedIndex; +import com.jetbrains.php.lang.lexer.PhpTokenTypes; import com.jetbrains.php.lang.psi.elements.Method; import com.jetbrains.php.lang.psi.elements.PhpClass; import com.magento.idea.magento2plugin.linemarker.php.data.PluginMethodData; @@ -70,12 +72,15 @@ public void collectSlowLineMarkers( } if (!results.isEmpty()) { - // Add the property to a collection of line marker info - final NavigationGutterIconBuilder builder = - NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin) - .setTargets(results) - .setTooltipText(TOOLTIP_TEXT); - collection.add(builder.createLineMarkerInfo(psiElement)); + final ASTNode node = psiElement.getNode().findChildByType(PhpTokenTypes.IDENTIFIER); + if(node != null) { + // Add the property to a collection of line marker info + final NavigationGutterIconBuilder builder = + NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin) + .setTargets(results) + .setTooltipText(TOOLTIP_TEXT); + collection.add(builder.createLineMarkerInfo(node.getPsi())); + } } } } From b98e68afce1c8302f6519c297825b799fd7e426d Mon Sep 17 00:00:00 2001 From: vitaliy Date: Sat, 15 Feb 2025 08:55:55 +0200 Subject: [PATCH 4/4] 1639: static fix --- .../linemarker/php/PluginLineMarkerProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java index 367faf468..775d61f3f 100644 --- a/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java +++ b/src/main/java/com/magento/idea/magento2plugin/linemarker/php/PluginLineMarkerProvider.java @@ -72,8 +72,9 @@ public void collectSlowLineMarkers( } if (!results.isEmpty()) { - final ASTNode node = psiElement.getNode().findChildByType(PhpTokenTypes.IDENTIFIER); - if(node != null) { + final ASTNode node = psiElement.getNode() + .findChildByType(PhpTokenTypes.IDENTIFIER); + if (node != null) { // Add the property to a collection of line marker info final NavigationGutterIconBuilder builder = NavigationGutterIconBuilder.create(AllIcons.Nodes.Plugin)