Skip to content

Commit 50b96f3

Browse files
authored
Merge pull request #1415 from Haehnchen/feature/twig-fix-globals
support multiple Twig global types on same variable like "app"
2 parents 6a804f1 + be650ff commit 50b96f3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigTypeResolveUtil.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.jetbrains.annotations.NotNull;
3535

3636
import java.util.*;
37+
import java.util.function.BiConsumer;
3738
import java.util.regex.Matcher;
3839
import java.util.regex.Pattern;
3940
import java.util.stream.Collectors;
@@ -148,7 +149,7 @@ public static Collection<TwigTypeContainer> resolveTwigMethodName(@NotNull PsiEl
148149
Collection<List<TwigTypeContainer>> previousElements = new ArrayList<>();
149150
previousElements.add(new ArrayList<>(type));
150151

151-
String[] typeNames = types.toArray(new String[types.size()]);
152+
String[] typeNames = types.toArray(new String[0]);
152153
for (int i = 1; i <= typeNames.length - 1; i++ ) {
153154
type = resolveTwigMethodName(type, typeNames[i], previousElements);
154155
previousElements.add(new ArrayList<>(type));
@@ -252,7 +253,16 @@ public static Map<String, PsiVariable> collectScopeVariables(@NotNull PsiElement
252253

253254
TwigFileVariableCollectorParameter collectorParameter = new TwigFileVariableCollectorParameter(psiElement, visitedFiles);
254255
for(TwigFileVariableCollector collector: TWIG_FILE_VARIABLE_COLLECTORS.getExtensions()) {
255-
collector.collect(collectorParameter, globalVars);
256+
Map<String, Set<String>> globalVarsScope = new HashMap<>();
257+
collector.collect(collectorParameter, globalVarsScope);
258+
259+
// @TODO: resolve this in change extension point, so that its only possible to provide data and dont give full scope to break / overwrite other variables
260+
globalVarsScope.forEach((s, strings) -> {
261+
globalVars.putIfAbsent(s, new HashSet<>());
262+
globalVars.get(s).addAll(strings);
263+
});
264+
265+
// @TODO: provide merge for multiple matches
256266
collector.collectPsiVariables(collectorParameter, controllerVars);
257267
}
258268

0 commit comments

Comments
 (0)