Skip to content

Commit

Permalink
Use qualified name for deduping in completion list, should allow item…
Browse files Browse the repository at this point in the history
…s with same name from different packages
  • Loading branch information
m0rkeulv committed Dec 31, 2023
1 parent ecf5d9e commit b7c67a3
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.intellij.plugins.haxe.config.sdk.HaxeSdkAdditionalDataBase;
import com.intellij.plugins.haxe.config.sdk.HaxeSdkUtil;
import com.intellij.plugins.haxe.lang.lexer.HaxeTokenTypes;
import com.intellij.plugins.haxe.lang.psi.HaxeClass;
import com.intellij.plugins.haxe.lang.psi.HaxeComponentName;
import com.intellij.plugins.haxe.lang.psi.HaxeIdentifier;
import com.intellij.plugins.haxe.lang.psi.HaxeReferenceExpression;

Expand Down Expand Up @@ -86,10 +88,19 @@ private static Set<CompletionResult> filter(@NotNull CompletionParameters parame
return filtered;
}

private static String getFunctionName(CompletionResult candidate) {
private static String getDedupeName(CompletionResult candidate) {
LookupElement el = candidate.getLookupElement();
String name = null != el ? el.getLookupString() : null;
return name;
if (el == null) return null;
// we don't want to filter away classes with similar names we want to show classes from different packages and/or libs
// for now we try use fully Qualified name for classes but this might break de-duping for compiler completion
if (el.getObject() instanceof HaxeComponentName element) {
if (element.getParent() instanceof HaxeClass haxeClass) {
return haxeClass.getQualifiedName();
}
}else if (el.getObject() instanceof String stringValue) {
return stringValue;
}
return el.getLookupString();
}

private static boolean shouldRemoveDuplicateCompletions(PsiFile file) {
Expand Down Expand Up @@ -138,7 +149,7 @@ public int compare(CompletionResult o1, CompletionResult o2) {
ArrayList<CompletionResult> deduped = new ArrayList<CompletionResult>();
String lastName = null;
for (CompletionResult next: sorted) {
String nextName = getFunctionName(next);
String nextName = getDedupeName(next);
// In the long run, it's probably not good enough just to check the name. Multiple argument types may
// be present, and we may be able to filter based on the local variables available.
if (null == lastName || !lastName.equals(nextName)) {
Expand Down

0 comments on commit b7c67a3

Please sign in to comment.