Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,27 @@ public static ElementPattern<PsiElement> getFilterPattern() {
.withLanguage(TwigLanguage.INSTANCE);
}

/**
* {% apply <caret> %}foobar{% endapply %}
*/
static ElementPattern<PsiElement> getApplyFilterPattern() {
return PlatformPatterns
.psiElement(TwigTokenTypes.IDENTIFIER)
.afterLeafSkipping(
PlatformPatterns.or(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
),
PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).with(new PatternCondition<PsiElement>("aa") {
@Override
public boolean accepts(@NotNull PsiElement psiElement, ProcessingContext processingContext) {
return "apply".equalsIgnoreCase(psiElement.getText());
}
})
)
.withLanguage(TwigLanguage.INSTANCE);
}

public static ElementPattern<PsiElement> getForTagInVariablePattern() {

// {% for key, user in "users" %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ private void attachLookupElements(@NotNull CompletionResultSet resultSet, Collec
new FilterCompletionProvider()
);

// {% apply upper %}This text becomes uppercase{% endapply %}
extend(
CompletionType.BASIC,
TwigPattern.getApplyFilterPattern(),
new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
Project project = completionParameters.getPosition().getProject();
for(Map.Entry<String, TwigExtension> entry : new TwigExtensionParser(project).getFilters().entrySet()) {
completionResultSet.addElement(new TwigExtensionLookupElement(project, entry.getKey(), entry.getValue()));
}
}
}
);

// provides support for {{ '<xxx>' }}
extend(
CompletionType.BASIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public PsiElement[] getGotoDeclarationTargets(PsiElement psiElement, int offset,
targets.addAll(TranslationUtil.getDomainPsiFiles(psiElement.getProject(), psiElement.getText()));
}

if(TwigPattern.getFilterPattern().accepts(psiElement)) {
if(PlatformPatterns.or(TwigPattern.getFilterPattern(), TwigPattern.getApplyFilterPattern()).accepts(psiElement)) {
targets.addAll(getFilterGoTo(psiElement));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import com.jetbrains.twig.TwigFileType;
import com.jetbrains.twig.elements.TwigElementTypes;
import fr.adrienbrault.idea.symfony2plugin.templating.TwigPattern;
import fr.adrienbrault.idea.symfony2plugin.templating.TwigTemplateCompletionContributor;
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase;

/**
* @author Daniel Espendiller <daniel@espendiller.net>
* @see com.jetbrains.twig.completion.TwigCompletionContributor
* @see TwigTemplateCompletionContributor
*/
public class TwigFilterCompletionContributorTest extends SymfonyLightCodeInsightFixtureTestCase {

Expand All @@ -30,6 +31,11 @@ public void testTwigExtensionFilterCompletion() {
assertCompletionContains(TwigFileType.INSTANCE, "{{ 'test' | <caret> }}", "doctrine_minify_query", "doctrine_pretty_query");
}

public void testTwigExtensionFilterViaApplyCompletion() {
assertCompletionContains(TwigFileType.INSTANCE, "{% apply <caret> %}foo{% endapply %}", "doctrine_minify_query", "doctrine_pretty_query");
assertNavigationContains(TwigFileType.INSTANCE, "{% apply doctrine<caret>_minify_query %}foo{% endapply %}", "Doctrine\\Bundle\\DoctrineBundle\\Twig\\DoctrineExtension::minifyQuery");
}

public void testTwigExtensionFilterNavigation() {
assertNavigationContains(TwigFileType.INSTANCE, "{{ 'test'|<caret>doctrine_minify_query }}", "Doctrine\\Bundle\\DoctrineBundle\\Twig\\DoctrineExtension::minifyQuery");
assertNavigationContains(TwigFileType.INSTANCE, "{{ 'test'|<caret>doctrine_pretty_query }}", "SqlFormatter::format");
Expand Down Expand Up @@ -164,7 +170,7 @@ public void testControllerReferences() {

/**
* @see fr.adrienbrault.idea.symfony2plugin.templating.TwigTemplateCompletionContributor
* @see fr.adrienbrault.idea.symfony2plugin.templating.TwigTemplateGoToLocalDeclarationHandler
* @see fr.adrienbrault.idea.symfony2plugin.templating.TwigTemplateGoToDeclarationHandler
*/
public void testSetTagIsAvailableForFunctionReferences() {
assertCompletionContains(TwigFileType.INSTANCE, "{% set = <caret> %}", "json_bar");
Expand Down