|
5 | 5 | import com.intellij.openapi.project.Project;
|
6 | 6 | import com.intellij.openapi.vfs.VfsUtil;
|
7 | 7 | import com.intellij.openapi.vfs.VirtualFile;
|
8 |
| -import com.intellij.psi.PsiElement; |
9 |
| -import com.intellij.psi.PsiFile; |
10 |
| -import com.intellij.psi.PsiManager; |
| 8 | +import com.intellij.psi.*; |
| 9 | +import com.intellij.psi.search.GlobalSearchScope; |
11 | 10 | import com.intellij.psi.util.PsiTreeUtil;
|
12 | 11 | import com.intellij.util.Processor;
|
13 | 12 | import com.intellij.util.indexing.FileBasedIndexImpl;
|
14 | 13 | import com.jetbrains.php.PhpIndex;
|
15 | 14 | import com.jetbrains.php.lang.psi.PhpFile;
|
16 | 15 | import com.jetbrains.php.lang.psi.elements.*;
|
| 16 | +import com.jetbrains.twig.TwigFileType; |
17 | 17 | import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
|
18 | 18 | import fr.adrienbrault.idea.symfony2plugin.Symfony2InterfacesUtil;
|
19 | 19 | import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
|
|
24 | 24 | import fr.adrienbrault.idea.symfony2plugin.util.controller.ControllerIndex;
|
25 | 25 | import fr.adrienbrault.idea.symfony2plugin.util.yaml.YamlHelper;
|
26 | 26 | import org.jetbrains.annotations.Nullable;
|
| 27 | +import org.jetbrains.yaml.YAMLFileType; |
27 | 28 | import org.jetbrains.yaml.psi.YAMLCompoundValue;
|
28 | 29 | import org.jetbrains.yaml.psi.YAMLDocument;
|
29 | 30 | import org.jetbrains.yaml.psi.YAMLKeyValue;
|
@@ -291,7 +292,7 @@ public boolean process(VirtualFile virtualFile) {
|
291 | 292 | virtualFiles.add(virtualFile);
|
292 | 293 | return true;
|
293 | 294 | }
|
294 |
| - }, PhpIndex.getInstance(project).getSearchScope()); |
| 295 | + }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), YAMLFileType.YML)); |
295 | 296 |
|
296 | 297 | return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
|
297 | 298 |
|
@@ -388,4 +389,46 @@ public static String getRouteUrl(List<Collection<String>> routeTokens) {
|
388 | 389 | return url.length() == 0 ? null : url;
|
389 | 390 | }
|
390 | 391 |
|
| 392 | + public static List<LookupElement> getRoutesLookupElements(Project project) { |
| 393 | + |
| 394 | + Symfony2ProjectComponent symfony2ProjectComponent = project.getComponent(Symfony2ProjectComponent.class); |
| 395 | + Map<String, Route> routes = symfony2ProjectComponent.getRoutes(); |
| 396 | + |
| 397 | + final List<LookupElement> lookupElements = new ArrayList<LookupElement>(); |
| 398 | + |
| 399 | + final Set<String> uniqueSet = new HashSet<String>(); |
| 400 | + for (Route route : routes.values()) { |
| 401 | + lookupElements.add(new RouteLookupElement(route)); |
| 402 | + uniqueSet.add(route.getName()); |
| 403 | + } |
| 404 | + |
| 405 | + FileBasedIndexImpl.getInstance().processAllKeys(YamlRoutesStubIndex.KEY, new Processor<String>() { |
| 406 | + @Override |
| 407 | + public boolean process(String s) { |
| 408 | + |
| 409 | + if(!uniqueSet.contains(s)) { |
| 410 | + lookupElements.add(new RouteLookupElement(new Route(s, null), true)); |
| 411 | + } |
| 412 | + |
| 413 | + return true; |
| 414 | + } |
| 415 | + }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), YAMLFileType.YML), null); |
| 416 | + |
| 417 | + return lookupElements; |
| 418 | + |
| 419 | + } |
| 420 | + |
| 421 | + public static List<PsiElement> getRouteDefinitionTargets(Project project, String routeName) { |
| 422 | + |
| 423 | + List<PsiElement> targets = new ArrayList<PsiElement>(); |
| 424 | + Collections.addAll(targets, RouteHelper.getMethods(project, routeName)); |
| 425 | + |
| 426 | + PsiElement yamlKey = RouteHelper.getRouteNameTarget(project, routeName); |
| 427 | + if(yamlKey != null) { |
| 428 | + targets.add(yamlKey); |
| 429 | + } |
| 430 | + |
| 431 | + return targets; |
| 432 | + } |
| 433 | + |
391 | 434 | }
|
0 commit comments