|
3 | 3 | import com.intellij.openapi.project.Project;
|
4 | 4 | import com.intellij.openapi.util.Key;
|
5 | 5 | import com.intellij.openapi.util.Pair;
|
| 6 | +import com.intellij.openapi.vfs.VfsUtil; |
6 | 7 | import com.intellij.openapi.vfs.VirtualFile;
|
7 | 8 | import com.intellij.psi.PsiElement;
|
8 | 9 | import com.intellij.psi.PsiFile;
|
@@ -53,8 +54,8 @@ public static Collection<PsiElement> getEnvironmentVariableTargetsForParameter(@
|
53 | 54 |
|
54 | 55 | // https://github.com/symfony/symfony/pull/23901 => RegisterEnvVarProcessorsPass
|
55 | 56 | // '%env(int:DATABASE_PORT)%'
|
56 |
| - // '%env(resolve:DB)%' |
57 |
| - Matcher matcher = Pattern.compile("^[\\w]+:(.*)$", Pattern.MULTILINE).matcher(parameterName); |
| 57 | + // '%env(resolve:int:foo:DB)%' |
| 58 | + Matcher matcher = Pattern.compile("^[\\w-_^:]+:(.*)$", Pattern.MULTILINE).matcher(parameterName); |
58 | 59 | if(matcher.find()){
|
59 | 60 | parameterName = matcher.group(1);
|
60 | 61 | }
|
@@ -96,23 +97,42 @@ public static Collection<PsiElement> getEnvironmentVariableTargets(@NotNull Proj
|
96 | 97 | }
|
97 | 98 |
|
98 | 99 | private static void visitEnvironment(@NotNull Project project, @NotNull Consumer<Pair<String, PsiElement>> consumer) {
|
99 |
| - for (VirtualFile virtualFile : FilenameIndex.getAllFilesByExt(project, "env", GlobalSearchScope.allScope(project))) { |
100 |
| - Properties variables = new Properties(); |
101 |
| - try { |
102 |
| - variables.load(virtualFile.getInputStream()); |
103 |
| - } catch (IOException e) { |
104 |
| - continue; |
| 100 | + Set<VirtualFile> files = new HashSet<>( |
| 101 | + FilenameIndex.getAllFilesByExt(project, "env", GlobalSearchScope.allScope(project)) |
| 102 | + ); |
| 103 | + |
| 104 | + // try to find some env's ;) |
| 105 | + for (String file : new String[]{".env", ".env.dist", ".env.test", ".env.local"}) { |
| 106 | + files.addAll(FilenameIndex.getVirtualFilesByName(project, file, GlobalSearchScope.allScope(project))); |
| 107 | + } |
| 108 | + |
| 109 | + // search root directory for all ".env*" files |
| 110 | + VirtualFile projectDir = VfsUtil.findRelativeFile(project.getBaseDir()); |
| 111 | + if (projectDir != null) { |
| 112 | + for (VirtualFile child : projectDir.getChildren()) { |
| 113 | + if (child.getName().startsWith(".env")) { |
| 114 | + files.add(child); |
| 115 | + } |
105 | 116 | }
|
| 117 | + } |
106 | 118 |
|
| 119 | + for (VirtualFile virtualFile : files) { |
107 | 120 | PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
|
108 | 121 | if(file == null) {
|
109 | 122 | continue;
|
110 | 123 | }
|
111 | 124 |
|
| 125 | + Properties variables = new Properties(); |
| 126 | + try { |
| 127 | + variables.load(virtualFile.getInputStream()); |
| 128 | + } catch (IOException e) { |
| 129 | + continue; |
| 130 | + } |
| 131 | + |
112 | 132 | for (Map.Entry<Object, Object> variable : variables.entrySet()) {
|
113 | 133 | Object key = variable.getKey();
|
114 | 134 | if(key instanceof String) {
|
115 |
| - consumer.accept(Pair.create(key.toString(), file)); |
| 135 | + consumer.accept(Pair.create((String) key, file)); |
116 | 136 | }
|
117 | 137 | }
|
118 | 138 | }
|
|
0 commit comments