Add namespace autocompletions, some adjustments to autocomplete logic

This commit is contained in:
Sinai
2021-05-17 23:20:06 +10:00
parent d7b0fff949
commit 019e589947
4 changed files with 102 additions and 91 deletions
+16
View File
@@ -45,6 +45,9 @@ namespace UnityExplorer
/// <summary>Key: Type.FullName</summary>
public static readonly SortedDictionary<string, Type> AllTypes = new SortedDictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
public static readonly List<string> AllNamespaces = new List<string>();
private static readonly HashSet<string> uniqueNamespaces = new HashSet<string>();
private static string[] allTypesArray;
public static string[] GetTypeNameArray()
{
@@ -81,6 +84,19 @@ namespace UnityExplorer
{
foreach (var type in asm.TryGetTypes())
{
if (!string.IsNullOrEmpty(type.Namespace) && !uniqueNamespaces.Contains(type.Namespace))
{
uniqueNamespaces.Add(type.Namespace);
int i = 0;
while (i < AllNamespaces.Count)
{
if (type.Namespace.CompareTo(AllNamespaces[i]) < 0)
break;
i++;
}
AllNamespaces.Insert(i, type.Namespace);
}
if (AllTypes.ContainsKey(type.FullName))
AllTypes[type.FullName] = type;
else
File diff suppressed because it is too large Load Diff
+18 -2
View File
@@ -77,17 +77,30 @@ namespace UnityExplorer.UI.CSConsole
select new Suggestion(GetHighlightString(prefix, completion), completion));
}
// Get manual namespace completions
foreach (var ns in ReflectionUtility.AllNamespaces)
{
if (ns.StartsWith(input))
{
if (!namespaceHighlights.ContainsKey(ns))
namespaceHighlights.Add(ns, $"<color=#CCCCCC>{ns}</color>");
string completion = ns.Substring(input.Length, ns.Length - input.Length);
suggestions.Add(new Suggestion(namespaceHighlights[ns], completion));
}
}
// Get manual keyword completions
foreach (var kw in KeywordLexer.keywords)
{
if (kw.StartsWith(input) && kw.Length > input.Length)
if (kw.StartsWith(input))// && kw.Length > input.Length)
{
if (!keywordHighlights.ContainsKey(kw))
keywordHighlights.Add(kw, $"<color=#{SignatureHighlighter.keywordBlueHex}>{kw}</color>");
string completion = kw.Substring(input.Length, kw.Length - input.Length);
suggestions.Add(new Suggestion(keywordHighlights[kw], completion));
}
}
@@ -103,6 +116,9 @@ namespace UnityExplorer.UI.CSConsole
}
}
private readonly Dictionary<string, string> namespaceHighlights = new Dictionary<string, string>();
private readonly Dictionary<string, string> keywordHighlights = new Dictionary<string, string>();
private readonly StringBuilder highlightBuilder = new StringBuilder();
+4 -1
View File
@@ -243,6 +243,8 @@ namespace UnityExplorer.UI.CSConsole
}
HighlightVisibleInput();
UpdateCaret(out _);
}
public static void Update()
@@ -260,7 +262,8 @@ namespace UnityExplorer.UI.CSConsole
if (!settingCaretCoroutine && EnableSuggestions && caretMoved)
{
Completer.CheckAutocompletes();
AutoCompleteModal.Instance.ReleaseOwnership(Completer);
//Completer.CheckAutocompletes();
}
if (EnableCtrlRShortcut