From 393cb571c9256d4bea3143e6ff8ffcbfb0511487 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sun, 25 Jun 2023 11:11:24 +0200 Subject: [PATCH] add priority voting for Twig form_theme completion --- .../TwigTemplateCompletionContributor.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java index 4ab260487..b9dcefc13 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/TwigTemplateCompletionContributor.java @@ -678,7 +678,18 @@ protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull return; } - resultSet.addAllElements(TwigUtil.getTwigLookupElements(parameters.getPosition().getProject())); + Project project = parameters.getPosition().getProject(); + List prioritizedKeys = TwigUtil.getFormThemeTemplateUsageAsOrderedList(project); + + if (prioritizedKeys.size() > 0) { + CompletionSorter completionSorter = CompletionService.getCompletionService() + .defaultSorter(parameters, resultSet.getPrefixMatcher()) + .weighBefore("priority", new ServiceCompletionProvider.MyLookupElementWeigher(prioritizedKeys)); + + resultSet = resultSet.withRelevanceSorter(completionSorter); + } + + resultSet.addAllElements(TwigUtil.getTwigLookupElements(project, new HashSet<>(prioritizedKeys))); } }