From 99f7d0594801b966643c9338554b3dabcdae3662 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Thu, 8 Jan 2026 03:14:44 +0200 Subject: [PATCH] =?UTF-8?q?Properly=20resolved=20type=20parameters=20for?= =?UTF-8?q?=20autocomplete=20display=20(e.g.,=20T=20=E2=86=92=20EntityPlay?= =?UTF-8?q?erMP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/autocomplete/AutocompleteItem.java | 47 +++++++++++++++++-- .../autocomplete/JSAutocompleteProvider.java | 41 +++++++++------- 2 files changed, 67 insertions(+), 21 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 b845aae21..45c9ae31c 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 @@ -200,7 +200,7 @@ public class AutocompleteItem implements Comparable { * Create from a JavaScript JSMethodInfo. */ public static AutocompleteItem fromJSMethod(JSMethodInfo method) { - return fromJSMethod(method, 0); + return fromJSMethod(method, null, 0); } /** @@ -209,6 +209,16 @@ public class AutocompleteItem implements Comparable { * @param inheritanceDepth Depth in inheritance tree (0 = child, 1 = parent, etc.) */ public static AutocompleteItem fromJSMethod(JSMethodInfo method, int inheritanceDepth) { + return fromJSMethod(method, null, inheritanceDepth); + } + + /** + * Create from a JavaScript JSMethodInfo with type parameter resolution for display. + * @param method The method info + * @param contextType The TypeInfo context for resolving type parameters (e.g., IPlayer to resolve T → EntityPlayerMP) + * @param inheritanceDepth Depth in inheritance tree (0 = child, 1 = parent, etc.) + */ + public static AutocompleteItem fromJSMethod(JSMethodInfo method, TypeInfo contextType, int inheritanceDepth) { String name = method.getName(); StringBuilder insertText = new StringBuilder(name); insertText.append("("); @@ -220,14 +230,22 @@ public class AutocompleteItem implements Comparable { int returnIndex = sig.lastIndexOf(":"); if (returnIndex != -1) //remove ":ReturnType" displayName = sig.substring(0, returnIndex); - + + // Resolve type parameters for display (e.g., T → EntityPlayerMP) + String returnType = method.getReturnType(); + if (contextType != null) { + TypeInfo resolved = contextType.resolveTypeParamToTypeInfo(returnType); + if (resolved != null && resolved.isResolved()) + returnType = getName(resolved); + + } return new AutocompleteItem( displayName, name, // Search against just the method name insertText.toString(), Kind.METHOD, - method.getReturnType(), + returnType, method.getSignature(), method.getDocumentation(), method, @@ -242,7 +260,7 @@ public class AutocompleteItem implements Comparable { * Create from a JavaScript JSFieldInfo. */ public static AutocompleteItem fromJSField(JSFieldInfo field) { - return fromJSField(field, 0); + return fromJSField(field, null, 0); } /** @@ -251,12 +269,31 @@ public class AutocompleteItem implements Comparable { * @param inheritanceDepth Depth in inheritance tree (0 = child, 1 = parent, etc.) */ public static AutocompleteItem fromJSField(JSFieldInfo field, int inheritanceDepth) { + return fromJSField(field, null, inheritanceDepth); + } + + /** + * Create from a JavaScript JSFieldInfo with type parameter resolution for display. + * @param field The field info + * @param contextType The TypeInfo context for resolving type parameters + * @param inheritanceDepth Depth in inheritance tree (0 = child, 1 = parent, etc.) + */ + public static AutocompleteItem fromJSField(JSFieldInfo field, TypeInfo contextType, int inheritanceDepth) { + // Resolve type parameters for display (e.g., T → EntityPlayerMP) + String fieldType = field.getType(); + if (contextType != null) { + TypeInfo resolved = contextType.resolveTypeParamToTypeInfo(fieldType); + if (resolved != null && resolved.isResolved()) + fieldType = getName(resolved); + + } + return new AutocompleteItem( field.getName(), field.getName(), // searchName same as display name field.getName(), Kind.FIELD, - field.getType(), + fieldType, field.toString(), field.getDocumentation(), field, diff --git a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java index e9217a4d3..9aa839654 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/autocomplete/JSAutocompleteProvider.java @@ -49,10 +49,9 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { // For JS types, check JSTypeRegistry JSTypeInfo jsTypeInfo = receiverType.getJSTypeInfo(); if (jsTypeInfo != null) { - // Add methods - addMethodsFromType(jsTypeInfo, items, new HashSet<>()); - // Add fields - addFieldsFromType(jsTypeInfo, items, new HashSet<>()); + // Pass both: jsTypeInfo (current type in hierarchy) and receiverType (context for type params) + addMethodsFromType(jsTypeInfo, receiverType, items, new HashSet<>()); + addFieldsFromType(jsTypeInfo, receiverType, items, new HashSet<>()); return; } @@ -99,15 +98,19 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { /** * Recursively add methods from a type and its parents. + * @param type The current JS type to get methods from (changes as we walk up inheritance) + * @param contextType The original TypeInfo context for resolving type parameters (stays constant) */ - protected void addMethodsFromType(JSTypeInfo type, List items, Set added) { - addMethodsFromType(type, items, added, 0); + protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added) { + addMethodsFromType(type, contextType, items, added, 0); } /** * Recursively add methods from a type and its parents with inheritance depth tracking. + * @param type The current JS type in inheritance chain + * @param contextType The original TypeInfo context for resolving type parameters (e.g., IPlayer with T → EntityPlayerMP) */ - private void addMethodsFromType(JSTypeInfo type, List items, Set added, int depth) { + private void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth) { for (JSMethodInfo method : type.getMethods().values()) { String name = method.getName(); // Skip overload markers (name$1, name$2, etc.) @@ -116,37 +119,43 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider { } if (!added.contains(name)) { added.add(name); - items.add(AutocompleteItem.fromJSMethod(method, depth)); + // Pass contextType (original receiver) for type parameter resolution, not current type + items.add(AutocompleteItem.fromJSMethod(method, contextType, depth)); } } - // Add from parent type with incremented depth + // Add from parent type with incremented depth - keep same contextType if (type.getResolvedParent() != null) { - addMethodsFromType(type.getResolvedParent(), items, added, depth + 1); + addMethodsFromType(type.getResolvedParent(), contextType, items, added, depth + 1); } } /** * Recursively add fields from a type and its parents. + * @param type The current JS type to get fields from (changes as we walk up inheritance) + * @param contextType The original TypeInfo context for resolving type parameters (stays constant) */ - protected void addFieldsFromType(JSTypeInfo type, List items, Set added) { - addFieldsFromType(type, items, added, 0); + protected void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added) { + addFieldsFromType(type, contextType, items, added, 0); } /** * Recursively add fields from a type and its parents with inheritance depth tracking. + * @param type The current JS type in inheritance chain + * @param contextType The original TypeInfo context for resolving type parameters */ - private void addFieldsFromType(JSTypeInfo type, List items, Set added, int depth) { + private void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List items, Set added, int depth) { for (JSFieldInfo field : type.getFields().values()) { if (!added.contains(field.getName())) { added.add(field.getName()); - items.add(AutocompleteItem.fromJSField(field, depth)); + // Pass contextType (original receiver) for type parameter resolution, not current type + items.add(AutocompleteItem.fromJSField(field, contextType, depth)); } } - // Add from parent type with incremented depth + // Add from parent type with incremented depth - keep same contextType if (type.getResolvedParent() != null) { - addFieldsFromType(type.getResolvedParent(), items, added, depth + 1); + addFieldsFromType(type.getResolvedParent(), contextType, items, added, depth + 1); } }