Skip to content

Commit

Permalink
Merge pull request #2314 from Haehnchen/feature/ux-component-search
Browse files Browse the repository at this point in the history
add Twig components to "Search Everywhere"
  • Loading branch information
Haehnchen authored Mar 30, 2024
2 parents 928a20d + 45ba5b7 commit 8167860
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fr.adrienbrault.idea.symfony2plugin.ux;

import com.intellij.navigation.ChooseByNameContributorEx;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Processor;
import com.intellij.util.indexing.FindSymbolParameters;
import com.intellij.util.indexing.IdFilter;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.navigation.NavigationItemExStateless;
import fr.adrienbrault.idea.symfony2plugin.util.UxUtil;
import icons.TwigIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author Daniel Espendiller <[email protected]>
*/
public class UxComponentSymbolContributor implements ChooseByNameContributorEx {
@Override
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
Project project = scope.getProject();
if (!Symfony2ProjectComponent.isEnabled(project)) {
return;
}

for (UxUtil.TwigComponent allComponentName : UxUtil.getAllComponentNames(project)) {
processor.process(allComponentName.name());
}
}

@Override
public void processElementsWithName(@NotNull String name, @NotNull Processor<? super NavigationItem> processor, @NotNull FindSymbolParameters parameters) {
Project project = parameters.getProject();
if (!Symfony2ProjectComponent.isEnabled(project)) {
return;
}

for (PhpClass component : UxUtil.getTwigComponentPhpClasses(project, name)) {
processor.process(NavigationItemExStateless.create(component, name, component.getIcon(), "TwigComponent (" + component.getName() + ")", false));
}

for (PsiFile component : UxUtil.getComponentTemplates(project, name)) {
processor.process(NavigationItemExStateless.create(component, name, TwigIcons.TwigFileIcon, "TwigComponent (" + component.getName() + ")", false));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<gotoSymbolContributor implementation="fr.adrienbrault.idea.symfony2plugin.navigation.SymfonyCommandSymbolContributor"/>
<gotoSymbolContributor implementation="fr.adrienbrault.idea.symfony2plugin.navigation.TwigBlockSymbolContributor"/>
<gotoSymbolContributor implementation="fr.adrienbrault.idea.symfony2plugin.navigation.RouteUrlMatcherSymbolContributor"/>
<gotoSymbolContributor implementation="fr.adrienbrault.idea.symfony2plugin.ux.UxComponentSymbolContributor"/>

<implicitUsageProvider implementation="fr.adrienbrault.idea.symfony2plugin.codeInsight.SymfonyImplicitUsageProvider"/>

Expand Down

0 comments on commit 8167860

Please sign in to comment.