Skip to content

Commit

Permalink
clean up macro completion
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Aug 27, 2024
1 parent 6dc3153 commit 005d7a6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.plugins.haxe.ide.hierarchy.HaxeHierarchyUtils;
import com.intellij.plugins.haxe.ide.lookup.HaxeMacroLookupElement;
import com.intellij.plugins.haxe.lang.psi.HaxeClass;
import com.intellij.plugins.haxe.lang.psi.HaxeComponentName;
import com.intellij.plugins.haxe.model.HaxeBaseMemberModel;
import com.intellij.plugins.haxe.model.HaxeMethodModel;
import com.intellij.plugins.haxe.lang.psi.impl.ComponentNameScopeProcessor;
import com.intellij.plugins.haxe.model.*;
import com.intellij.plugins.haxe.model.type.HaxeGenericResolver;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.ResolveState;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -64,15 +68,17 @@ private void reificationAndMacroIds(CompletionResultSet result, PsiElement posit
}

private static void addMacroIdentifiers(CompletionResultSet result, PsiElement position) {
//TODO we need to add enum extractor values in some way.
Set<HaxeComponentName> suggestedVariants = new HashSet<>();
PsiTreeUtil.treeWalkUp(new ComponentNameScopeProcessor(suggestedVariants), position, null, new ResolveState());

List<HaxeComponentName> members = HaxeHierarchyUtils.findMembersByWalkingTree(position);
for (HaxeComponentName name : members) {
// ignoring type definitions and method/function definitions
HaxeBaseMemberModel model = HaxeBaseMemberModel.fromPsi(name);
if (model != null && !(model instanceof HaxeMethodModel)) {
HaxeModel model = HaxeBaseMemberModel.fromPsi(name);
if ((model instanceof HaxeMethodModel) || (name.getParent() instanceof HaxeClass)) continue;
HaxeMacroLookupElement lookupElement = HaxeMacroLookupElement.create(name, new HaxeGenericResolver());
result.addElement(lookupElement.toPrioritized());
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,11 @@ public static boolean cannotBeOverriding(final PsiMethod method) {
|| method.hasModifierProperty(PsiModifier.STATIC);
}

public static List<HaxeComponentName> findMembersByWalkingTree (@NotNull PsiElement element) {
public static List<HaxeComponentName> findMembersByWalkingTree(@NotNull PsiElement element) {
List<HaxeComponentName> members = new ArrayList<>();
CollectMembersScopeProcessor processor = new CollectMembersScopeProcessor(members);
PsiTreeUtil.treeWalkUp(processor, element, element.getContainingFile(), new ResolveState());
return members;
return members;
}

private static class CollectMembersScopeProcessor implements PsiScopeProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,22 @@ public void calculatePresentation() {

if (!isFunctionType) {
final ItemPresentation myComponentNamePresentation = myComponentName.getPresentation();
if (myComponentNamePresentation == null) return;
icon = myComponentNamePresentation.getIcon(true);
} else {
// TODO functionType references should perhaps have its own icon?
icon = HaxeIcons.Field;
if (myComponentNamePresentation != null) {
icon = myComponentNamePresentation.getIcon(true);
}
else {
// TODO functionType references should perhaps have its own icon?
icon = HaxeIcons.Field;
}
if (model != null) {
determineStriketrough();
evaluateTypeTextAndPriorityBoost();
}
}
if (model != null) {
determineStriketrough();
evaluateTypeTextAndPriorityBoost();
// currently defaulting to Variable icon for unspecified types (enum extracted values etc.)
if (icon == null) {
//TODO should probably make icons for extracted values etc.
icon = HaxeIcons.Variable;
}
}

Expand Down

0 comments on commit 005d7a6

Please sign in to comment.