mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 14:17:51 +08:00
Fix results TypeCompleter issues
This commit is contained in:
parent
1643d4b7dd
commit
3afee7254c
@ -36,7 +36,6 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
readonly bool allowGeneric;
|
readonly bool allowGeneric;
|
||||||
|
|
||||||
private HashSet<Type> allowedTypes;
|
private HashSet<Type> allowedTypes;
|
||||||
private HashSet<Type> allAllowedTypes;
|
|
||||||
|
|
||||||
readonly List<Suggestion> suggestions = new();
|
readonly List<Suggestion> suggestions = new();
|
||||||
readonly HashSet<string> suggestedNames = new();
|
readonly HashSet<string> suggestedNames = new();
|
||||||
@ -77,7 +76,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
|
|
||||||
inputField.OnValueChanged += OnInputFieldChanged;
|
inputField.OnValueChanged += OnInputFieldChanged;
|
||||||
|
|
||||||
if (BaseType != null)
|
if (BaseType != null || AllTypes)
|
||||||
CacheTypes();
|
CacheTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,25 +86,51 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
allowedTypes = ReflectionUtility.GetImplementationsOf(BaseType, allowAbstract, allowGeneric, allowEnum);
|
allowedTypes = ReflectionUtility.GetImplementationsOf(BaseType, allowAbstract, allowGeneric, allowEnum);
|
||||||
else
|
else
|
||||||
allowedTypes = GetAllAllowedTypes();
|
allowedTypes = GetAllAllowedTypes();
|
||||||
|
|
||||||
|
// Check generic parameter constraints
|
||||||
|
if (GenericConstraints != null && GenericConstraints.Any())
|
||||||
|
{
|
||||||
|
List<Type> typesToRemove = new();
|
||||||
|
foreach (Type type in allowedTypes)
|
||||||
|
{
|
||||||
|
bool allowed = true;
|
||||||
|
foreach (Type constraint in GenericConstraints)
|
||||||
|
{
|
||||||
|
if (!constraint.IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
allowed = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!allowed)
|
||||||
|
typesToRemove.Add(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Type type in typesToRemove)
|
||||||
|
allowedTypes.Remove(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<Type> GetAllAllowedTypes()
|
HashSet<Type> GetAllAllowedTypes()
|
||||||
{
|
{
|
||||||
if (allAllowedTypes == null)
|
HashSet<Type> allAllowedTypes = new();
|
||||||
|
foreach (KeyValuePair<string, Type> entry in ReflectionUtility.AllTypes)
|
||||||
{
|
{
|
||||||
allAllowedTypes = new();
|
Type type = entry.Value;
|
||||||
foreach (KeyValuePair<string, Type> entry in ReflectionUtility.AllTypes)
|
|
||||||
|
if ((!allowAbstract && type.IsAbstract)
|
||||||
|
|| (!allowGeneric && type.IsGenericType)
|
||||||
|
|| (!allowEnum && type.IsEnum))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// skip <PrivateImplementationDetails> and <AnonymousClass> classes
|
||||||
|
if (type.FullName.Contains("PrivateImplementationDetails")
|
||||||
|
|| type.FullName.Contains("DisplayClass")
|
||||||
|
|| type.FullName.Contains('<'))
|
||||||
{
|
{
|
||||||
// skip <PrivateImplementationDetails> and <AnonymousClass> classes
|
continue;
|
||||||
Type type = entry.Value;
|
|
||||||
if (type.FullName.Contains("PrivateImplementationDetails")
|
|
||||||
|| type.FullName.Contains("DisplayClass")
|
|
||||||
|| type.FullName.Contains('<'))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
allAllowedTypes.Add(type);
|
|
||||||
}
|
}
|
||||||
|
allAllowedTypes.Add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return allAllowedTypes;
|
return allAllowedTypes;
|
||||||
@ -152,16 +177,13 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shorthand types all inherit from System.Object
|
// shorthand types all inherit from System.Object
|
||||||
if (AllTypes || BaseType == typeof(object))
|
if (shorthandToType.TryGetValue(input, out Type shorthand) && allowedTypes.Contains(shorthand))
|
||||||
{
|
AddSuggestion(shorthand);
|
||||||
if (shorthandToType.TryGetValue(input, out Type shorthand))
|
|
||||||
AddSuggestion(shorthand);
|
|
||||||
|
|
||||||
foreach (KeyValuePair<string, Type> entry in shorthandToType)
|
foreach (KeyValuePair<string, Type> entry in shorthandToType)
|
||||||
{
|
{
|
||||||
if (entry.Key.StartsWith(input, StringComparison.InvariantCultureIgnoreCase))
|
if (allowedTypes.Contains(entry.Value) && entry.Key.StartsWith(input, StringComparison.InvariantCultureIgnoreCase))
|
||||||
AddSuggestion(entry.Value);
|
AddSuggestion(entry.Value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for exact match first
|
// Check for exact match first
|
||||||
|
Loading…
x
Reference in New Issue
Block a user