Skip to content

Commit

Permalink
Merge pull request #2185 from Haehnchen/feature/if-incomplete-scope
Browse files Browse the repository at this point in the history
provide more completable Twig if statements
  • Loading branch information
Haehnchen authored Jun 24, 2023
2 parents aacdb16 + ff56aa2 commit 63c8da2
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,12 @@ public boolean accepts(@NotNull String s, ProcessingContext processingContext) {
private class IncompleteIfCompletionProvider extends CompletionProvider<CompletionParameters> {
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, @NotNull ProcessingContext processingContext, @NotNull CompletionResultSet resultSet) {
if(!Symfony2ProjectComponent.isEnabled(completionParameters.getPosition())) {
PsiElement originalPosition = completionParameters.getOriginalPosition();
if (originalPosition == null) {
return;
}

if (!Symfony2ProjectComponent.isEnabled(originalPosition)) {
return;
}

Expand All @@ -1136,7 +1141,7 @@ public boolean accepts(@NotNull String s, ProcessingContext processingContext) {
}

resultSet.addAllElements(processVariables(
completionParameters.getPosition(),
originalPosition,
PhpType::isBoolean,
entry -> String.format("if %s", entry.getKey())
));
Expand Down Expand Up @@ -1428,10 +1433,9 @@ private Collection<LookupElement> processVariables(@NotNull PsiElement psiElemen

Map<String, Pair<String, LookupElement>> arrays = new HashMap<>();
for(Map.Entry<String, PsiVariable> entry: TwigTypeResolveUtil.collectScopeVariables(psiElement).entrySet()) {
if (PhpType.from(entry.getValue().getTypes().toArray(new String[0])).isConvertibleFrom(project, new PhpType().add(PhpType.ARRAY))) {
PhpType phpType = PhpIndex.getInstance(project).completeType(project, PhpType.from(entry.getValue().getTypes().toArray(new String[0])), new HashSet<>());
System.out.println(phpType);
PhpType phpType = PhpType.from(entry.getValue().getTypes().toArray(new String[0]));

if (filter.test(phpType)) {
LookupElementBuilder lookupElement = LookupElementBuilder.create(entry.getKey())
.withIcon(PlatformIcons.VARIABLE_ICON)
.withTypeText(phpType.toString());
Expand Down

0 comments on commit 63c8da2

Please sign in to comment.