Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 019e589

Browse files
committed
Add namespace autocompletions, some adjustments to autocomplete logic
1 parent d7b0fff commit 019e589

File tree

4 files changed

+104
-93
lines changed

4 files changed

+104
-93
lines changed

src/Core/Reflection/ReflectionUtility.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ protected virtual void Initialize()
4545
/// <summary>Key: Type.FullName</summary>
4646
public static readonly SortedDictionary<string, Type> AllTypes = new SortedDictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
4747

48+
public static readonly List<string> AllNamespaces = new List<string>();
49+
private static readonly HashSet<string> uniqueNamespaces = new HashSet<string>();
50+
4851
private static string[] allTypesArray;
4952
public static string[] GetTypeNameArray()
5053
{
@@ -81,6 +84,19 @@ private static void CacheTypes(Assembly asm)
8184
{
8285
foreach (var type in asm.TryGetTypes())
8386
{
87+
if (!string.IsNullOrEmpty(type.Namespace) && !uniqueNamespaces.Contains(type.Namespace))
88+
{
89+
uniqueNamespaces.Add(type.Namespace);
90+
int i = 0;
91+
while (i < AllNamespaces.Count)
92+
{
93+
if (type.Namespace.CompareTo(AllNamespaces[i]) < 0)
94+
break;
95+
i++;
96+
}
97+
AllNamespaces.Insert(i, type.Namespace);
98+
}
99+
84100
if (AllTypes.ContainsKey(type.FullName))
85101
AllTypes[type.FullName] = type;
86102
else

src/Core/Tests/TestClass.cs

Lines changed: 66 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -14,72 +14,13 @@
1414

1515
namespace UnityExplorer.Tests
1616
{
17-
public struct TestValueStruct
18-
{
19-
public const object TestIgnoreThis = null;
20-
public const string TestIgnoreButValid = "";
21-
22-
public string aString;
23-
public int anInt;
24-
public float aFloat;
25-
public bool aBool;
26-
public Vector3 AVector3;
27-
public Vector4 aVector4;
28-
public DateTime aDateTime;
29-
public Color32 aColor32;
30-
public CameraClearFlags clearFlags;
31-
}
32-
33-
public enum TestEnum : long
34-
{
35-
Neg50 = -50,
36-
Neg1 = -1,
37-
Zero = 0,
38-
One = 1,
39-
Pos49 = 49,
40-
Implicit50,
41-
Also50 = 50,
42-
AlsoAlso50 = 50,
43-
};
44-
public enum TestEnum2 : ulong
45-
{
46-
Min = ulong.MinValue,
47-
Max = ulong.MaxValue
48-
}
49-
[Flags]
50-
public enum TestFlags : int
51-
{
52-
All = -1,
53-
Zero = 0,
54-
Ok = 1,
55-
Two = 2,
56-
Three = 4,
57-
Four = 8,
58-
Five = 16,
59-
Six = 32,
60-
Seven = 64,
61-
Thirteen = Six | Seven,
62-
Fifteen = Four | Five | Six,
63-
}
64-
6517
public static class TestClass
6618
{
6719
public static void ATestMethod(string s, float f, Vector3 vector, DateTime date, Quaternion quater, bool b, CameraClearFlags enumvalue)
6820
{
6921
ExplorerCore.Log($"{s}, {f}, {vector.ToString()}, {date}, {quater.eulerAngles.ToString()}, {b}, {enumvalue}");
7022
}
7123

72-
public static TestValueStruct AATestStruct;
73-
74-
public static string AAATooLongString = new string('#', UIManager.MAX_INPUTFIELD_CHARS + 2);
75-
public static string AAAMaxString = new string('@', UIManager.MAX_INPUTFIELD_CHARS);
76-
77-
public static TestEnum AATestEnumOne = TestEnum.Neg50;
78-
public static TestEnum2 AATestEnumTwo = TestEnum2.Max;
79-
public static TestFlags AATestFlags = TestFlags.Thirteen;
80-
public static BindingFlags AATestbinding;
81-
public static HideFlags AAHideFlags;
82-
8324
public static List<int> AWritableList = new List<int> { 1, 2, 3, 4, 5 };
8425
public static Dictionary<string, int> AWritableDict = new Dictionary<string, int> { { "one", 1 }, { "two", 2 } };
8526

@@ -121,7 +62,7 @@ public static void ATestMethod(string s, float f, Vector3 vector, DateTime date,
12162
}
12263
};
12364

124-
public static IDictionary DictTest = new Dictionary<object, object>
65+
public static IDictionary ARandomDictionary = new Dictionary<object, object>
12566
{
12667
{ 1, 2 },
12768
{ "one", "two" },
@@ -132,6 +73,13 @@ public static void ATestMethod(string s, float f, Vector3 vector, DateTime date,
13273
{ "subdict", new Dictionary<object,object> { { "key", "value" } } }
13374
};
13475

76+
public static Hashtable TestHashtable = new Hashtable
77+
{
78+
{ "one", "value" },
79+
{ "two", "value" },
80+
{ "three", "value" },
81+
};
82+
13583
public const int ConstantInt = 5;
13684

13785
public static Color AColor = Color.magenta;
@@ -194,17 +142,23 @@ private static object GetRandomObject()
194142

195143
#if CPP
196144

197-
public static Il2CppSystem.Collections.IList AAAAAAACppList;
145+
public static Il2CppSystem.Collections.IList IL2CPP_IList;
146+
public static Il2CppSystem.Collections.Generic.List<string> IL2CPP_ListString;
147+
public static Il2CppSystem.Collections.Generic.HashSet<string> IL2CPP_HashSet;
148+
149+
public static Il2CppSystem.Collections.Generic.Dictionary<string, string> IL2CPP_Dict;
150+
public static Il2CppSystem.Collections.Hashtable IL2CPP_HashTable;
151+
public static Il2CppSystem.Collections.IDictionary IL2CPP_IDict;
198152

199-
public static string testStringOne = "Test";
200-
public static Il2CppSystem.Object testStringTwo = "string boxed as cpp object";
201-
public static Il2CppSystem.String testStringThree = "string boxed as cpp string";
153+
public static string IL2CPP_systemString = "Test";
154+
public static Il2CppSystem.Object IL2CPP_objectString = "string boxed as cpp object";
155+
public static Il2CppSystem.String IL2CPP_il2cppString = "string boxed as cpp string";
202156
public static string nullString = null;
203157

204-
public static List<Il2CppSystem.Object> CppBoxedList;
205-
public static Il2CppStructArray<int> CppIntStructArray;
206-
public static Il2CppStringArray CppStringArray;
207-
public static Il2CppReferenceArray<Il2CppSystem.Object> CppReferenceArray;
158+
public static List<Il2CppSystem.Object> IL2CPP_listOfBoxedObjects;
159+
public static Il2CppStructArray<int> IL2CPP_structArray;
160+
public static Il2CppStringArray IL2CPP_stringArray;
161+
public static Il2CppReferenceArray<Il2CppSystem.Object> IL2CPP_ReferenceArray;
208162

209163
public static Il2CppSystem.Object cppBoxedInt;
210164
public static Il2CppSystem.Int32 cppInt;
@@ -239,10 +193,32 @@ static TestClass()
239193
BigList.Add(i.ToString());
240194

241195
#if CPP
196+
IL2CPP_Dict = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
197+
IL2CPP_Dict.Add("key1", "value1");
198+
IL2CPP_Dict.Add("key2", "value2");
199+
IL2CPP_Dict.Add("key3", "value3");
200+
201+
IL2CPP_HashTable = new Il2CppSystem.Collections.Hashtable();
202+
IL2CPP_HashTable.Add("key1", "value1");
203+
IL2CPP_HashTable.Add("key2", "value2");
204+
IL2CPP_HashTable.Add("key3", "value3");
205+
206+
var dict2 = new Il2CppSystem.Collections.Generic.Dictionary<string, string>();
207+
dict2.Add("key1", "value1");
208+
IL2CPP_IDict = dict2.TryCast<Il2CppSystem.Collections.IDictionary>();
209+
242210
var list = new Il2CppSystem.Collections.Generic.List<Il2CppSystem.Object>(5);
243211
list.Add("one");
244212
list.Add("two");
245-
AAAAAAACppList = list.TryCast<Il2CppSystem.Collections.IList>();
213+
IL2CPP_IList = list.TryCast<Il2CppSystem.Collections.IList>();
214+
215+
IL2CPP_ListString = new Il2CppSystem.Collections.Generic.List<string>();
216+
IL2CPP_ListString.Add("hello,");
217+
IL2CPP_ListString.Add("world!");
218+
219+
IL2CPP_HashSet = new Il2CppSystem.Collections.Generic.HashSet<string>();
220+
IL2CPP_HashSet.Add("one");
221+
IL2CPP_HashSet.Add("two");
246222

247223
CppBoxedDict = new Dictionary<Il2CppSystem.String, Il2CppSystem.Object>();
248224
CppBoxedDict.Add("1", new Il2CppSystem.Int32 { m_value = 1 }.BoxIl2CppObject());
@@ -255,44 +231,44 @@ static TestClass()
255231
cppVector3Boxed = Vector3.down.BoxIl2CppObject();
256232

257233

258-
CppBoxedList = new List<Il2CppSystem.Object>();
259-
CppBoxedList.Add((Il2CppSystem.String)"boxedString");
260-
CppBoxedList.Add(new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject());
261-
CppBoxedList.Add(Color.red.BoxIl2CppObject());
234+
IL2CPP_listOfBoxedObjects = new List<Il2CppSystem.Object>();
235+
IL2CPP_listOfBoxedObjects.Add((Il2CppSystem.String)"boxedString");
236+
IL2CPP_listOfBoxedObjects.Add(new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject());
237+
IL2CPP_listOfBoxedObjects.Add(Color.red.BoxIl2CppObject());
262238

263239
try
264240
{
265241
var cppType = Il2CppType.Of<CameraClearFlags>();
266242
if (cppType != null)
267243
{
268244
var boxedEnum = Il2CppSystem.Enum.Parse(cppType, "Color");
269-
CppBoxedList.Add(boxedEnum);
245+
IL2CPP_listOfBoxedObjects.Add(boxedEnum);
270246
}
271247

272248
var structBox = Vector3.one.BoxIl2CppObject();
273-
CppBoxedList.Add(structBox);
249+
IL2CPP_listOfBoxedObjects.Add(structBox);
274250

275251
}
276252
catch (Exception ex)
277253
{
278254
ExplorerCore.LogWarning($"Test fail: {ex}");
279255
}
280256

281-
CppIntStructArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
282-
CppIntStructArray[0] = 0;
283-
CppIntStructArray[1] = 1;
284-
CppIntStructArray[2] = 2;
285-
CppIntStructArray[3] = 3;
286-
CppIntStructArray[4] = 4;
287-
288-
CppStringArray = new UnhollowerBaseLib.Il2CppStringArray(2);
289-
CppStringArray[0] = "hello, ";
290-
CppStringArray[1] = "world!";
291-
292-
CppReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
293-
CppReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
294-
CppReferenceArray[1] = null;
295-
CppReferenceArray[2] = (Il2CppSystem.String)"whats up";
257+
IL2CPP_structArray = new UnhollowerBaseLib.Il2CppStructArray<int>(5);
258+
IL2CPP_structArray[0] = 0;
259+
IL2CPP_structArray[1] = 1;
260+
IL2CPP_structArray[2] = 2;
261+
IL2CPP_structArray[3] = 3;
262+
IL2CPP_structArray[4] = 4;
263+
264+
IL2CPP_stringArray = new UnhollowerBaseLib.Il2CppStringArray(2);
265+
IL2CPP_stringArray[0] = "hello, ";
266+
IL2CPP_stringArray[1] = "world!";
267+
268+
IL2CPP_ReferenceArray = new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Object>(3);
269+
IL2CPP_ReferenceArray[0] = new Il2CppSystem.Int32 { m_value = 5 }.BoxIl2CppObject();
270+
IL2CPP_ReferenceArray[1] = null;
271+
IL2CPP_ReferenceArray[2] = (Il2CppSystem.String)"whats up";
296272

297273
cppBoxedInt = new Il2CppSystem.Int32() { m_value = 5 }.BoxIl2CppObject();
298274
cppInt = new Il2CppSystem.Int32 { m_value = 420 };

src/UI/CSConsole/CSAutoCompleter.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,30 @@ public void CheckAutocompletes()
7777
select new Suggestion(GetHighlightString(prefix, completion), completion));
7878
}
7979

80+
// Get manual namespace completions
81+
82+
foreach (var ns in ReflectionUtility.AllNamespaces)
83+
{
84+
if (ns.StartsWith(input))
85+
{
86+
if (!namespaceHighlights.ContainsKey(ns))
87+
namespaceHighlights.Add(ns, $"<color=#CCCCCC>{ns}</color>");
88+
89+
string completion = ns.Substring(input.Length, ns.Length - input.Length);
90+
suggestions.Add(new Suggestion(namespaceHighlights[ns], completion));
91+
}
92+
}
93+
8094
// Get manual keyword completions
8195

8296
foreach (var kw in KeywordLexer.keywords)
8397
{
84-
if (kw.StartsWith(input) && kw.Length > input.Length)
98+
if (kw.StartsWith(input))// && kw.Length > input.Length)
8599
{
86100
if (!keywordHighlights.ContainsKey(kw))
87101
keywordHighlights.Add(kw, $"<color=#{SignatureHighlighter.keywordBlueHex}>{kw}</color>");
88102

89103
string completion = kw.Substring(input.Length, kw.Length - input.Length);
90-
91104
suggestions.Add(new Suggestion(keywordHighlights[kw], completion));
92105
}
93106
}
@@ -103,6 +116,9 @@ public void CheckAutocompletes()
103116
}
104117
}
105118

119+
120+
private readonly Dictionary<string, string> namespaceHighlights = new Dictionary<string, string>();
121+
106122
private readonly Dictionary<string, string> keywordHighlights = new Dictionary<string, string>();
107123

108124
private readonly StringBuilder highlightBuilder = new StringBuilder();

src/UI/CSConsole/ConsoleController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ private static void OnInputChanged(string value)
243243
}
244244

245245
HighlightVisibleInput();
246+
247+
UpdateCaret(out _);
246248
}
247249

248250
public static void Update()
@@ -260,7 +262,8 @@ public static void Update()
260262

261263
if (!settingCaretCoroutine && EnableSuggestions && caretMoved)
262264
{
263-
Completer.CheckAutocompletes();
265+
AutoCompleteModal.Instance.ReleaseOwnership(Completer);
266+
//Completer.CheckAutocompletes();
264267
}
265268

266269
if (EnableCtrlRShortcut

0 commit comments

Comments
 (0)