Skip to content

Commit 6b6ddc8

Browse files
authored
Merge pull request #3 from voleye/broken-file-path-reference
Reference for file path declared in XMl/JavaScript are broken
2 parents 348aeca + b8595a8 commit 6b6ddc8

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/com/magento/idea/magento2plugin/reference/provider/FilePathReferenceProvider.java

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.magento.idea.magento2plugin.reference.provider;
22

3-
import com.intellij.ide.highlighter.XmlFileType;
43
import com.intellij.openapi.util.TextRange;
54
import com.intellij.openapi.vfs.*;
65
import com.intellij.psi.*;
76
import com.intellij.psi.search.FilenameIndex;
87
import com.intellij.psi.search.GlobalSearchScope;
98
import com.intellij.util.ProcessingContext;
109
import com.intellij.util.indexing.FileBasedIndex;
10+
import com.jetbrains.php.lang.PhpFileType;
1111
import com.magento.idea.magento2plugin.reference.xml.PolyVariantReferenceBase;
1212
import com.magento.idea.magento2plugin.stubs.indexes.ModuleNameIndex;
1313
import gnu.trove.THashMap;
@@ -33,6 +33,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu
3333
return PsiReference.EMPTY_ARRAY;
3434
}
3535

36+
// Find all files based on provided path
3637
Collection<VirtualFile> files = getFiles(element);
3738
if (!(files.size() > 0)) {
3839
return PsiReference.EMPTY_ARRAY;
@@ -92,12 +93,9 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu
9293
}
9394

9495
if (psiPathElements.size() > 0) {
95-
psiPathElements.forEach(new BiConsumer<TextRange, List<PsiElement>>() {
96-
@Override
97-
public void accept(TextRange textRange, List<PsiElement> psiElements) {
98-
psiReferences.add(new PolyVariantReferenceBase(element, textRange, psiElements));
99-
}
100-
});
96+
psiPathElements.forEach(((textRange, psiElements) ->
97+
psiReferences.add(new PolyVariantReferenceBase(element, textRange, psiElements))
98+
));
10199
}
102100
}
103101

@@ -141,7 +139,7 @@ private Collection<VirtualFile> getFiles(@NotNull PsiElement element)
141139
Collection<VirtualFile> vfs = getModuleSourceFiles(element);
142140
if (null != vfs) {
143141
for (VirtualFile vf : vfs) {
144-
Collection<VirtualFile> vfChildren = getAllSubFiles(vf.findChild("view"));
142+
Collection<VirtualFile> vfChildren = getAllSubFiles(vf);
145143
if (null != vfChildren) {
146144
vfChildren.removeIf(f -> {
147145
if (!f.isDirectory()) {
@@ -171,7 +169,7 @@ private Collection<VirtualFile> getModuleFile(@NotNull PsiElement element)
171169
.getContainingFiles(ModuleNameIndex.KEY, moduleName,
172170
GlobalSearchScope.getScopeRestrictedByFileTypes(
173171
GlobalSearchScope.allScope(element.getProject()),
174-
XmlFileType.INSTANCE
172+
PhpFileType.INSTANCE
175173
)
176174
);
177175
}
@@ -182,10 +180,10 @@ private Collection<VirtualFile> getModuleSourceFiles(@NotNull PsiElement element
182180
if (null == virtualFiles) {
183181
return null;
184182
}
185-
virtualFiles.removeIf(vf -> !(vf != null && vf.getParent() != null && vf.getParent().getParent() != null));
183+
virtualFiles.removeIf(vf -> !(vf != null && vf.getParent() != null));
186184
Collection<VirtualFile> sourceVfs = new ArrayList<>();
187185
for (VirtualFile vf : virtualFiles) {
188-
sourceVfs.add(vf.getParent().getParent());
186+
sourceVfs.add(vf.getParent());
189187
}
190188
return sourceVfs;
191189
}
@@ -223,10 +221,6 @@ private Collection<VirtualFile> getAllSubFiles(VirtualFile virtualFile)
223221
{
224222
Collection<VirtualFile> list = new ArrayList<>();
225223

226-
if (null == virtualFile) {
227-
return list;
228-
}
229-
230224
VfsUtilCore.visitChildrenRecursively(virtualFile, new VirtualFileVisitor() {
231225
@Override
232226
public boolean visitFile(@NotNull VirtualFile file) {

0 commit comments

Comments
 (0)