From 005d7a623a4cee6d5506bc8a1f768c499106f185 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Tue, 27 Aug 2024 21:40:09 +0200 Subject: [PATCH] clean up macro completion --- .../HaxeMacroCompletionContributor.java | 18 ++++++++++----- .../ide/hierarchy/HaxeHierarchyUtils.java | 4 ++-- .../ide/lookup/HaxeMacroLookupElement.java | 23 ++++++++++++------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/intellij/plugins/haxe/ide/completion/HaxeMacroCompletionContributor.java b/src/main/java/com/intellij/plugins/haxe/ide/completion/HaxeMacroCompletionContributor.java index 69825a35f..2e606aa91 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/completion/HaxeMacroCompletionContributor.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/completion/HaxeMacroCompletionContributor.java @@ -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; @@ -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 suggestedVariants = new HashSet<>(); + PsiTreeUtil.treeWalkUp(new ComponentNameScopeProcessor(suggestedVariants), position, null, new ResolveState()); + List 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()); - } + } } diff --git a/src/main/java/com/intellij/plugins/haxe/ide/hierarchy/HaxeHierarchyUtils.java b/src/main/java/com/intellij/plugins/haxe/ide/hierarchy/HaxeHierarchyUtils.java index 8743c8612..45d685539 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/hierarchy/HaxeHierarchyUtils.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/hierarchy/HaxeHierarchyUtils.java @@ -419,11 +419,11 @@ public static boolean cannotBeOverriding(final PsiMethod method) { || method.hasModifierProperty(PsiModifier.STATIC); } - public static List findMembersByWalkingTree (@NotNull PsiElement element) { + public static List findMembersByWalkingTree(@NotNull PsiElement element) { List 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 { diff --git a/src/main/java/com/intellij/plugins/haxe/ide/lookup/HaxeMacroLookupElement.java b/src/main/java/com/intellij/plugins/haxe/ide/lookup/HaxeMacroLookupElement.java index 5baea04a4..e267296f4 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/lookup/HaxeMacroLookupElement.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/lookup/HaxeMacroLookupElement.java @@ -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; } }