From a36cc044bd483eefe425b76c61cfee06b3c78ffe Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sun, 4 Jan 2026 19:15:32 +0200 Subject: [PATCH] Shoved object methods all the way down in autocomplete menu --- .../script/autocomplete/AutocompleteItem.java | 10 ++------ .../JavaAutocompleteProvider.java | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/AutocompleteItem.java b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/AutocompleteItem.java index ee7921cec..80ad10f0c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/AutocompleteItem.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/AutocompleteItem.java @@ -508,22 +508,16 @@ public class AutocompleteItem implements Comparable { @Override public int compareTo(AutocompleteItem other) { - // First by match score (descending) + // First by match score (descending) - this includes all penalties and boosts if (this.matchScore != other.matchScore) { return other.matchScore - this.matchScore; } - // Push inherited Object methods to the bottom - boolean thisIsObjectMethod = this.isInheritedObjectMethod(); - boolean otherIsObjectMethod = other.isInheritedObjectMethod(); - if (thisIsObjectMethod != otherIsObjectMethod) { - return thisIsObjectMethod ? 1 : -1; // Object methods go to bottom - } - // Then by kind priority if (this.kind.getPriority() != other.kind.getPriority()) { return this.kind.getPriority() - other.kind.getPriority(); } + // Finally alphabetically return this.name.compareToIgnoreCase(other.name); } diff --git a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JavaAutocompleteProvider.java b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JavaAutocompleteProvider.java index 57ac351d7..f7e3f2aa2 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JavaAutocompleteProvider.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JavaAutocompleteProvider.java @@ -357,6 +357,7 @@ public class JavaAutocompleteProvider implements AutocompleteProvider { item.calculateMatchScore("", false); applyUsageBoost(item, tracker, ownerFullName); applyStaticPenalty(item, isMemberAccess, isStaticContext); + applyObjectMethodPenalty(item); } return; } @@ -365,7 +366,7 @@ public class JavaAutocompleteProvider implements AutocompleteProvider { // For member access (after dot), allow fuzzy/contains matching boolean requirePrefix = !isMemberAccess; - // Filter, score, apply usage boosts, and apply static penalties + // Filter, score, apply usage boosts, and apply penalties Iterator iter = items.iterator(); while (iter.hasNext()) { AutocompleteItem item = iter.next(); @@ -375,6 +376,7 @@ public class JavaAutocompleteProvider implements AutocompleteProvider { } else { applyUsageBoost(item, tracker, ownerFullName); applyStaticPenalty(item, isMemberAccess, isStaticContext); + applyObjectMethodPenalty(item); } } } @@ -422,6 +424,27 @@ public class JavaAutocompleteProvider implements AutocompleteProvider { } } + /** + * Apply penalty to inherited Object methods to push them to bottom. + * Strong matches get lighter penalty, weak matches get pushed all the way down. + */ + private void applyObjectMethodPenalty(AutocompleteItem item) { + if (!item.isInheritedObjectMethod()) { + return; + } + + int matchScore = item.getMatchScore(); + // Strong prefix matches (score >= 900) get a moderate penalty + // Everything else gets pushed to the very bottom + if (matchScore >= 900) { + // Strong match - moderate penalty to keep it visible but below normal methods + item.addScoreBoost(-500); + } else { + // Weak match - heavy penalty to push to bottom + item.addScoreBoost(-10000); + } + } + /** * Builder class for AutocompleteItem to handle cases without source data. */