From 9afc88daa473bb4c954836d6d53fc96bf70cf243 Mon Sep 17 00:00:00 2001 From: Benoit Duffez Date: Wed, 13 Dec 2023 19:26:46 -0800 Subject: [PATCH 1/3] add canonical routes to index --- .../symfony2plugin/routing/RouteHelper.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java index f47257bf2..1bb92987e 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java @@ -492,6 +492,7 @@ private static boolean isRouteClass(@NotNull PhpClass phpClass) { @NotNull public static Map getRoutesInsideUrlGeneratorFile(@NotNull PsiFile psiFile) { Map routes = new HashMap<>(); + HashSet canonicalRoutes = new HashSet<>(); // Symfony >= 4 // extract the routes on a return statement @@ -510,7 +511,24 @@ public static Map getRoutesInsideUrlGeneratorFile(@NotNull PsiFil routeArrayOptions.add(PsiTreeUtil.getChildOfType(routeOption, ArrayCreationExpression.class)); } - routes.put(routeArray.getKey(), convertRouteConfigForReturnArray(routeArray.getKey(), routeArrayOptions)); + Route route = convertRouteConfigForReturnArray(routeArray.getKey(), routeArrayOptions); + routes.put(routeArray.getKey(), route); + + for (ArrayCreationExpression expression : routeArrayOptions) { + for (ArrayHashElement e : expression.getHashElements()) { + PhpPsiElement key = e.getKey(); + if (key != null && "'_canonical_route'".equals(key.getText())) { + PhpPsiElement value = e.getValue(); + if (value != null) { + String canonical = value.getText().replace("'", ""); + if (!canonicalRoutes.contains(canonical)) { + canonicalRoutes.add(canonical); + routes.put(canonical, route); + } + } + } + } + } } } From aaba7760db229ec3abd7570b6812e14890cc6884 Mon Sep 17 00:00:00 2001 From: Benoit Duffez Date: Thu, 14 Dec 2023 05:17:37 -0800 Subject: [PATCH 2/3] optimized cache/search --- .../adrienbrault/idea/symfony2plugin/routing/RouteHelper.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java index 1bb92987e..576c3e9b2 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java @@ -492,7 +492,6 @@ private static boolean isRouteClass(@NotNull PhpClass phpClass) { @NotNull public static Map getRoutesInsideUrlGeneratorFile(@NotNull PsiFile psiFile) { Map routes = new HashMap<>(); - HashSet canonicalRoutes = new HashSet<>(); // Symfony >= 4 // extract the routes on a return statement @@ -521,8 +520,7 @@ public static Map getRoutesInsideUrlGeneratorFile(@NotNull PsiFil PhpPsiElement value = e.getValue(); if (value != null) { String canonical = value.getText().replace("'", ""); - if (!canonicalRoutes.contains(canonical)) { - canonicalRoutes.add(canonical); + if (!routes.containsKey(canonical)) { routes.put(canonical, route); } } From 25410e6fc1519263da5af7463fd977d02cd1411a Mon Sep 17 00:00:00 2001 From: Benoit Duffez Date: Thu, 14 Dec 2023 05:20:10 -0800 Subject: [PATCH 3/3] stop searching after canonical route is found --- .../fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java index 576c3e9b2..fb392caa0 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java @@ -524,6 +524,7 @@ public static Map getRoutesInsideUrlGeneratorFile(@NotNull PsiFil routes.put(canonical, route); } } + break; } } }