-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2313 from Haehnchen/feature/search-everywhere-rou…
…te-matcher provide a full partial route matcher search for "Search Everywhere" urls
- Loading branch information
Showing
7 changed files
with
305 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...va/fr/adrienbrault/idea/symfony2plugin/navigation/NavigationItemPresentableOverwrite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.navigation; | ||
|
||
import com.intellij.ide.util.PsiNavigationSupport; | ||
import com.intellij.navigation.ItemPresentation; | ||
import com.intellij.navigation.NavigationItem; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import com.intellij.pom.Navigatable; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class NavigationItemPresentableOverwrite implements NavigationItem, ItemPresentation { | ||
|
||
@NotNull | ||
private final PsiElement psiElement; | ||
|
||
@NotNull | ||
private final String presentableText; | ||
|
||
@NotNull | ||
private final Icon icon; | ||
|
||
@NotNull | ||
private final String locationString; | ||
private final String name; | ||
|
||
private NavigationItemPresentableOverwrite(@NotNull PsiElement psiElement, @NotNull String presentableText, @NotNull Icon icon, @NotNull String locationString, @NotNull String name) { | ||
this.psiElement = psiElement; | ||
this.presentableText = presentableText; | ||
this.name = name; | ||
this.icon = icon; | ||
this.locationString = locationString; | ||
} | ||
|
||
@Override | ||
public @NotNull String getName() { | ||
return this.name; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ItemPresentation getPresentation() { | ||
return new ItemPresentation() { | ||
@Override | ||
public @NlsSafe @NotNull String getPresentableText() { | ||
return NavigationItemPresentableOverwrite.this.presentableText; | ||
} | ||
|
||
@Override | ||
public @NlsSafe @NotNull String getLocationString() { | ||
return NavigationItemPresentableOverwrite.this.locationString; | ||
} | ||
|
||
@Override | ||
public @Nullable Icon getIcon(boolean unused) { | ||
return NavigationItemPresentableOverwrite.this.getIcon(unused); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public void navigate(boolean requestFocus) { | ||
final Navigatable descriptor = PsiNavigationSupport.getInstance().getDescriptor(this.psiElement); | ||
if (descriptor != null) { | ||
descriptor.navigate(requestFocus); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canNavigate() { | ||
return PsiNavigationSupport.getInstance().canNavigate(this.psiElement); | ||
} | ||
|
||
@Override | ||
public boolean canNavigateToSource() { | ||
return canNavigate(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.presentableText; | ||
} | ||
|
||
@Override | ||
public @NotNull String getPresentableText() { | ||
return presentableText; | ||
} | ||
|
||
@Override | ||
public @NotNull String getLocationString() { | ||
return this.locationString; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Icon getIcon(boolean b) { | ||
return icon; | ||
} | ||
|
||
public static NavigationItemPresentableOverwrite create(@NotNull PsiElement psiElement, @NotNull String presentableText, @NotNull Icon icon, @NotNull String locationString, boolean appendBundleLocation, @NotNull String name) { | ||
String locationPathString = locationString; | ||
|
||
if(appendBundleLocation) { | ||
PsiFile psiFile = psiElement.getContainingFile(); | ||
if(psiFile != null) { | ||
locationPathString = locationString + " " + psiFile.getName(); | ||
|
||
String bundleName = psiFile.getVirtualFile().getPath(); | ||
|
||
if(bundleName.contains("Bundle")) { | ||
bundleName = bundleName.substring(0, bundleName.lastIndexOf("Bundle")); | ||
if(bundleName.length() > 1 && bundleName.contains("/")) { | ||
locationPathString = locationPathString + " " + bundleName.substring(bundleName.lastIndexOf("/") + 1) + "::" + psiFile.getName(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return new NavigationItemPresentableOverwrite( | ||
psiElement, | ||
presentableText, | ||
icon, | ||
locationPathString, | ||
name | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...java/fr/adrienbrault/idea/symfony2plugin/navigation/RouteUrlMatcherSymbolContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.navigation; | ||
|
||
import com.intellij.navigation.ChooseByNameContributorEx; | ||
import com.intellij.navigation.ChooseByNameContributorEx2; | ||
import com.intellij.navigation.NavigationItem; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.search.GlobalSearchScope; | ||
import com.intellij.util.Processor; | ||
import com.intellij.util.indexing.FindSymbolParameters; | ||
import com.intellij.util.indexing.IdFilter; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons; | ||
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent; | ||
import fr.adrienbrault.idea.symfony2plugin.routing.Route; | ||
import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper; | ||
import kotlin.Pair; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class RouteUrlMatcherSymbolContributor implements ChooseByNameContributorEx, ChooseByNameContributorEx2 { | ||
|
||
@Override | ||
public void processNames(@NotNull Processor<? super String> processor, @NotNull FindSymbolParameters parameters) { | ||
Project project = parameters.getProject(); | ||
if (!Symfony2ProjectComponent.isEnabled(project)) { | ||
return; | ||
} | ||
|
||
String name = parameters.getLocalPatternName(); | ||
if (RouteHelper.hasRoutesForPathWithPlaceholderMatch(project, name)) { | ||
processor.process(name); | ||
} | ||
} | ||
|
||
@Override | ||
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) { | ||
} | ||
|
||
@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 (Pair<Route, PsiElement> entry : RouteHelper.getMethodsForPathWithPlaceholderMatchRoutes(project, name)) { | ||
Route route = entry.getFirst(); | ||
|
||
String path = route.getPath(); | ||
if (path == null) { | ||
continue; | ||
} | ||
|
||
processor.process((NavigationItemPresentableOverwrite.create( | ||
entry.getSecond(), | ||
path, | ||
Symfony2Icons.ROUTE, | ||
"Symfony Route", | ||
true, | ||
name | ||
))); | ||
} | ||
} | ||
} |
Oops, something went wrong.