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))); } }