Properly resolved type parameters for autocomplete display (e.g., T → EntityPlayerMP)

This commit is contained in:
bigguy345 committed 2026-01-08 03:14:44 +02:00
1 parent 2632ff4bc6
commit 99f7d05948
2 files changed
+67 -21

No files matched your search

@@ -200,7 +200,7 @@ public class AutocompleteItem implements Comparable<AutocompleteItem> {
* 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<AutocompleteItem> {
* @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<AutocompleteItem> {
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<AutocompleteItem> {
* 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<AutocompleteItem> {
* @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,
@@ -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<AutocompleteItem> items, Set<String> added) {
addMethodsFromType(type, items, added, 0);
protected void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List<AutocompleteItem> items, Set<String> 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<AutocompleteItem> items, Set<String> added, int depth) {
private void addMethodsFromType(JSTypeInfo type, TypeInfo contextType, List<AutocompleteItem> items, Set<String> 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<AutocompleteItem> items, Set<String> added) {
addFieldsFromType(type, items, added, 0);
protected void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List<AutocompleteItem> items, Set<String> 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<AutocompleteItem> items, Set<String> added, int depth) {
private void addFieldsFromType(JSTypeInfo type, TypeInfo contextType, List<AutocompleteItem> items, Set<String> 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);
}
}