5
5
import com .intellij .openapi .vfs .VirtualFile ;
6
6
import com .intellij .openapi .vfs .VirtualFileVisitor ;
7
7
import com .intellij .psi .PsiDirectory ;
8
+ import com .intellij .psi .search .FilenameIndex ;
9
+ import com .intellij .psi .search .GlobalSearchScope ;
8
10
import fr .adrienbrault .idea .symfony2plugin .Settings ;
9
11
import fr .adrienbrault .idea .symfony2plugin .templating .webpack .SymfonyWebpackUtil ;
10
12
import fr .adrienbrault .idea .symfony2plugin .util .ProjectUtil ;
@@ -62,7 +64,8 @@ private static Collection<VirtualFile> getProjectAssetRoot(@NotNull Project proj
62
64
public Collection <AssetFile > getAssetFiles (@ NotNull Project project ) {
63
65
Collection <AssetFile > files = new ArrayList <>();
64
66
65
- for (VirtualFile webDirectory : getProjectAssetRoot (project )) {
67
+ Collection <VirtualFile > projectAssetRoots = getProjectAssetRoot (project );
68
+ for (VirtualFile webDirectory : projectAssetRoots ) {
66
69
VfsUtil .visitChildrenRecursively (webDirectory , new VirtualFileVisitor <VirtualFile >() {
67
70
@ Override
68
71
public boolean visitFile (@ NotNull VirtualFile virtualFile ) {
@@ -72,14 +75,13 @@ public boolean visitFile(@NotNull VirtualFile virtualFile) {
72
75
return super .visitFile (virtualFile );
73
76
}
74
77
});
78
+ }
75
79
76
- VirtualFile fileByRelativePath = webDirectory .findFileByRelativePath ("build/manifest.json" );
77
- if (fileByRelativePath != null ) {
78
- SymfonyWebpackUtil .visitManifestJsonEntries (
79
- fileByRelativePath ,
80
- pair -> files .add (AssetFile .createVirtualManifestEntry (fileByRelativePath , pair .getFirst ()))
81
- );
82
- }
80
+ for (VirtualFile projectManifestJsonFile : getProjectManifestJsonFiles (project , projectAssetRoots )) {
81
+ SymfonyWebpackUtil .visitManifestJsonEntries (
82
+ projectManifestJsonFile ,
83
+ pair -> files .add (AssetFile .createVirtualManifestEntry (projectManifestJsonFile , pair .getFirst ()))
84
+ );
83
85
}
84
86
85
87
if (!this .includeBundleDir ) {
@@ -155,7 +157,8 @@ public Collection<VirtualFile> resolveAssetFile(@NotNull Project project, @NotNu
155
157
156
158
Collection <VirtualFile > files = new HashSet <>();
157
159
158
- for (VirtualFile webDirectory : getProjectAssetRoot (project )) {
160
+ Collection <VirtualFile > projectAssetRoots = getProjectAssetRoot (project );
161
+ for (VirtualFile webDirectory : projectAssetRoots ) {
159
162
Matcher matcher = Pattern .compile ("^(.*[/\\ \\ ])\\ *([.\\ w+]*)$" ).matcher (assetName );
160
163
if (!matcher .find ()) {
161
164
VirtualFile assetFile = VfsUtil .findRelativeFile (webDirectory , assetName .split ("/" ));
@@ -167,18 +170,17 @@ public Collection<VirtualFile> resolveAssetFile(@NotNull Project project, @NotNu
167
170
// "/*.js"
168
171
files .addAll (collectWildcardDirectories (matcher , webDirectory ));
169
172
}
173
+ }
170
174
171
- VirtualFile fileByRelativePath = webDirectory .findFileByRelativePath ("build/manifest.json" );
172
- if (fileByRelativePath != null ) {
173
- SymfonyWebpackUtil .visitManifestJsonEntries (
174
- fileByRelativePath ,
175
- pair -> {
176
- if (filename .equalsIgnoreCase (pair .getFirst ())) {
177
- files .add (fileByRelativePath );
178
- }
175
+ for (VirtualFile projectManifestJsonFile : getProjectManifestJsonFiles (project , projectAssetRoots )) {
176
+ SymfonyWebpackUtil .visitManifestJsonEntries (
177
+ projectManifestJsonFile ,
178
+ pair -> {
179
+ if (filename .equalsIgnoreCase (pair .getFirst ())) {
180
+ files .add (projectManifestJsonFile );
179
181
}
180
- );
181
- }
182
+ }
183
+ );
182
184
}
183
185
184
186
return files ;
@@ -223,4 +225,20 @@ private boolean isValidFile(@NotNull VirtualFile virtualFile) {
223
225
String extension = virtualFile .getExtension ();
224
226
return extension != null && this .filterExtension .contains (extension );
225
227
}
228
+
229
+ private Collection <VirtualFile > getProjectManifestJsonFiles (@ NotNull Project project , @ NotNull Collection <VirtualFile > webDirectories ) {
230
+ HashSet <VirtualFile > manifestFiles = new HashSet <>(
231
+ FilenameIndex .getVirtualFilesByName ("manifest.json" , GlobalSearchScope .allScope (project ))
232
+ );
233
+
234
+ // for files which are ignored by indexing, resolve based on project web folder
235
+ for (VirtualFile webDirectory : webDirectories ) {
236
+ VirtualFile fileByRelativePath = webDirectory .findFileByRelativePath ("build/manifest.json" );
237
+ if (fileByRelativePath != null ) {
238
+ manifestFiles .add (fileByRelativePath );
239
+ }
240
+ }
241
+
242
+ return manifestFiles ;
243
+ }
226
244
}
0 commit comments